time: ntp: refactor do_adjtimex() some more
Impact: cleanup, no functionality changed Further simplify do_adjtimex(): - introduce the ntp_start_leap_timer() helper function - eliminate the goto adj_done complication Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
@@ -332,14 +332,33 @@ static void notify_cmos_timer(void)
|
|||||||
static inline void notify_cmos_timer(void) { }
|
static inline void notify_cmos_timer(void) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the leap seconds timer:
|
||||||
|
*/
|
||||||
|
static inline void ntp_start_leap_timer(struct timespec *ts)
|
||||||
|
{
|
||||||
|
long now = ts->tv_sec;
|
||||||
|
|
||||||
|
if (time_status & STA_INS) {
|
||||||
|
time_state = TIME_INS;
|
||||||
|
now += 86400 - now % 86400;
|
||||||
|
hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time_status & STA_DEL) {
|
||||||
|
time_state = TIME_DEL;
|
||||||
|
now += 86400 - (now + 1) % 86400;
|
||||||
|
hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Propagate a new txc->status value into the NTP state:
|
* Propagate a new txc->status value into the NTP state:
|
||||||
*/
|
*/
|
||||||
static inline void process_adj_status(struct timex *txc, struct timespec *ts)
|
static inline void process_adj_status(struct timex *txc, struct timespec *ts)
|
||||||
{
|
{
|
||||||
long now;
|
|
||||||
|
|
||||||
if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
|
if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
|
||||||
time_state = TIME_OK;
|
time_state = TIME_OK;
|
||||||
time_status = STA_UNSYNC;
|
time_status = STA_UNSYNC;
|
||||||
@@ -358,22 +377,12 @@ static inline void process_adj_status(struct timex *txc, struct timespec *ts)
|
|||||||
|
|
||||||
switch (time_state) {
|
switch (time_state) {
|
||||||
case TIME_OK:
|
case TIME_OK:
|
||||||
start_timer:
|
ntp_start_leap_timer(ts);
|
||||||
now = ts->tv_sec;
|
|
||||||
if (time_status & STA_INS) {
|
|
||||||
time_state = TIME_INS;
|
|
||||||
now += 86400 - now % 86400;
|
|
||||||
hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
|
|
||||||
} else if (time_status & STA_DEL) {
|
|
||||||
time_state = TIME_DEL;
|
|
||||||
now += 86400 - (now + 1) % 86400;
|
|
||||||
hrtimer_start(&leap_timer, ktime_set(now, 0), HRTIMER_MODE_ABS);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TIME_INS:
|
case TIME_INS:
|
||||||
case TIME_DEL:
|
case TIME_DEL:
|
||||||
time_state = TIME_OK;
|
time_state = TIME_OK;
|
||||||
goto start_timer;
|
ntp_start_leap_timer(ts);
|
||||||
case TIME_WAIT:
|
case TIME_WAIT:
|
||||||
if (!(time_status & (STA_INS | STA_DEL)))
|
if (!(time_status & (STA_INS | STA_DEL)))
|
||||||
time_state = TIME_OK;
|
time_state = TIME_OK;
|
||||||
@@ -394,6 +403,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
|
|||||||
|
|
||||||
if (txc->modes & ADJ_NANO)
|
if (txc->modes & ADJ_NANO)
|
||||||
time_status |= STA_NANO;
|
time_status |= STA_NANO;
|
||||||
|
|
||||||
if (txc->modes & ADJ_MICRO)
|
if (txc->modes & ADJ_MICRO)
|
||||||
time_status &= ~STA_NANO;
|
time_status &= ~STA_NANO;
|
||||||
|
|
||||||
@@ -405,6 +415,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
|
|||||||
|
|
||||||
if (txc->modes & ADJ_MAXERROR)
|
if (txc->modes & ADJ_MAXERROR)
|
||||||
time_maxerror = txc->maxerror;
|
time_maxerror = txc->maxerror;
|
||||||
|
|
||||||
if (txc->modes & ADJ_ESTERROR)
|
if (txc->modes & ADJ_ESTERROR)
|
||||||
time_esterror = txc->esterror;
|
time_esterror = txc->esterror;
|
||||||
|
|
||||||
@@ -421,6 +432,7 @@ static inline void process_adjtimex_modes(struct timex *txc, struct timespec *ts
|
|||||||
|
|
||||||
if (txc->modes & ADJ_OFFSET)
|
if (txc->modes & ADJ_OFFSET)
|
||||||
ntp_update_offset(txc->offset);
|
ntp_update_offset(txc->offset);
|
||||||
|
|
||||||
if (txc->modes & ADJ_TICK)
|
if (txc->modes & ADJ_TICK)
|
||||||
tick_usec = txc->tick;
|
tick_usec = txc->tick;
|
||||||
|
|
||||||
@@ -457,7 +469,7 @@ int do_adjtimex(struct timex *txc)
|
|||||||
if (txc->modes & ADJ_TICK &&
|
if (txc->modes & ADJ_TICK &&
|
||||||
(txc->tick < 900000/USER_HZ ||
|
(txc->tick < 900000/USER_HZ ||
|
||||||
txc->tick > 1100000/USER_HZ))
|
txc->tick > 1100000/USER_HZ))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (txc->modes & ADJ_STATUS && time_state != TIME_OK)
|
if (txc->modes & ADJ_STATUS && time_state != TIME_OK)
|
||||||
hrtimer_cancel(&leap_timer);
|
hrtimer_cancel(&leap_timer);
|
||||||
@@ -467,7 +479,6 @@ int do_adjtimex(struct timex *txc)
|
|||||||
|
|
||||||
write_seqlock_irq(&xtime_lock);
|
write_seqlock_irq(&xtime_lock);
|
||||||
|
|
||||||
/* If there are input parameters, then process them */
|
|
||||||
if (txc->modes & ADJ_ADJTIME) {
|
if (txc->modes & ADJ_ADJTIME) {
|
||||||
long save_adjust = time_adjust;
|
long save_adjust = time_adjust;
|
||||||
|
|
||||||
@@ -477,19 +488,18 @@ int do_adjtimex(struct timex *txc)
|
|||||||
ntp_update_frequency();
|
ntp_update_frequency();
|
||||||
}
|
}
|
||||||
txc->offset = save_adjust;
|
txc->offset = save_adjust;
|
||||||
goto adj_done;
|
} else {
|
||||||
|
|
||||||
|
/* If there are input parameters, then process them: */
|
||||||
|
if (txc->modes)
|
||||||
|
process_adjtimex_modes(txc, &ts);
|
||||||
|
|
||||||
|
txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
|
||||||
|
NTP_SCALE_SHIFT);
|
||||||
|
if (!(time_status & STA_NANO))
|
||||||
|
txc->offset /= NSEC_PER_USEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there are input parameters, then process them: */
|
|
||||||
if (txc->modes)
|
|
||||||
process_adjtimex_modes(txc, &ts);
|
|
||||||
|
|
||||||
txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
|
|
||||||
NTP_SCALE_SHIFT);
|
|
||||||
if (!(time_status & STA_NANO))
|
|
||||||
txc->offset /= NSEC_PER_USEC;
|
|
||||||
|
|
||||||
adj_done:
|
|
||||||
result = time_state; /* mostly `TIME_OK' */
|
result = time_state; /* mostly `TIME_OK' */
|
||||||
if (time_status & (STA_UNSYNC|STA_CLOCKERR))
|
if (time_status & (STA_UNSYNC|STA_CLOCKERR))
|
||||||
result = TIME_ERROR;
|
result = TIME_ERROR;
|
||||||
@@ -514,6 +524,7 @@ adj_done:
|
|||||||
txc->calcnt = 0;
|
txc->calcnt = 0;
|
||||||
txc->errcnt = 0;
|
txc->errcnt = 0;
|
||||||
txc->stbcnt = 0;
|
txc->stbcnt = 0;
|
||||||
|
|
||||||
write_sequnlock_irq(&xtime_lock);
|
write_sequnlock_irq(&xtime_lock);
|
||||||
|
|
||||||
txc->time.tv_sec = ts.tv_sec;
|
txc->time.tv_sec = ts.tv_sec;
|
||||||
|
Reference in New Issue
Block a user