Commit ee9851b2 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds

ntp: cleanup ntp.c

This is mostly a style cleanup of ntp.c and extracts part of do_adjtimex as
ntp_update_offset().  Otherwise the functionality is still the same as before.
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Cc: john stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f8bd2258
...@@ -57,6 +57,44 @@ static void ntp_update_frequency(void) ...@@ -57,6 +57,44 @@ static void ntp_update_frequency(void)
tick_length_base = div_u64(tick_length_base, NTP_INTERVAL_FREQ); tick_length_base = div_u64(tick_length_base, NTP_INTERVAL_FREQ);
} }
static void ntp_update_offset(long offset)
{
long mtemp;
s64 freq_adj;
if (!(time_status & STA_PLL))
return;
time_offset = offset * NSEC_PER_USEC;
/*
* Scale the phase adjustment and
* clamp to the operating range.
*/
time_offset = min(time_offset, (s64)MAXPHASE * NSEC_PER_USEC);
time_offset = max(time_offset, (s64)-MAXPHASE * NSEC_PER_USEC);
/*
* Select how the frequency is to be controlled
* and in which mode (PLL or FLL).
*/
if (time_status & STA_FREQHOLD || time_reftime == 0)
time_reftime = xtime.tv_sec;
mtemp = xtime.tv_sec - time_reftime;
time_reftime = xtime.tv_sec;
freq_adj = time_offset * mtemp;
freq_adj = shift_right(freq_adj, time_constant * 2 +
(SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC))
freq_adj += div_s64(time_offset << (SHIFT_NSEC - SHIFT_FLL), mtemp);
freq_adj += time_freq;
freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC);
time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC);
time_offset = div_s64(time_offset, NTP_INTERVAL_FREQ);
time_offset <<= SHIFT_UPDATE;
}
/** /**
* ntp_clear - Clears the NTP state variables * ntp_clear - Clears the NTP state variables
* *
...@@ -234,8 +272,7 @@ static inline void notify_cmos_timer(void) { } ...@@ -234,8 +272,7 @@ static inline void notify_cmos_timer(void) { }
*/ */
int do_adjtimex(struct timex *txc) int do_adjtimex(struct timex *txc)
{ {
long mtemp, save_adjust; long save_adjust;
s64 freq_adj;
int result; int result;
/* In order to modify anything, you gotta be super-user! */ /* In order to modify anything, you gotta be super-user! */
...@@ -272,13 +309,12 @@ int do_adjtimex(struct timex *txc) ...@@ -272,13 +309,12 @@ int do_adjtimex(struct timex *txc)
time_status &= ~STA_CLOCKERR; /* reset STA_CLOCKERR */ time_status &= ~STA_CLOCKERR; /* reset STA_CLOCKERR */
#endif #endif
/* If there are input parameters, then process them */ /* If there are input parameters, then process them */
if (txc->modes) if (txc->modes) {
{
if (txc->modes & ADJ_STATUS) /* only set allowed bits */ if (txc->modes & ADJ_STATUS) /* only set allowed bits */
time_status = (txc->status & ~STA_RONLY) | time_status = (txc->status & ~STA_RONLY) |
(time_status & STA_RONLY); (time_status & STA_RONLY);
if (txc->modes & ADJ_FREQUENCY) { /* p. 22 */ if (txc->modes & ADJ_FREQUENCY) {
if (txc->freq > MAXFREQ || txc->freq < -MAXFREQ) { if (txc->freq > MAXFREQ || txc->freq < -MAXFREQ) {
result = -EINVAL; result = -EINVAL;
goto leave; goto leave;
...@@ -303,7 +339,7 @@ int do_adjtimex(struct timex *txc) ...@@ -303,7 +339,7 @@ int do_adjtimex(struct timex *txc)
time_esterror = txc->esterror; time_esterror = txc->esterror;
} }
if (txc->modes & ADJ_TIMECONST) { /* p. 24 */ if (txc->modes & ADJ_TIMECONST) {
if (txc->constant < 0) { /* NTP v4 uses values > 6 */ if (txc->constant < 0) { /* NTP v4 uses values > 6 */
result = -EINVAL; result = -EINVAL;
goto leave; goto leave;
...@@ -311,51 +347,21 @@ int do_adjtimex(struct timex *txc) ...@@ -311,51 +347,21 @@ int do_adjtimex(struct timex *txc)
time_constant = min(txc->constant + 4, (long)MAXTC); time_constant = min(txc->constant + 4, (long)MAXTC);
} }
if (txc->modes & ADJ_OFFSET) { /* values checked earlier */ if (txc->modes & ADJ_OFFSET) {
if (txc->modes == ADJ_OFFSET_SINGLESHOT) { if (txc->modes == ADJ_OFFSET_SINGLESHOT)
/* adjtime() is independent from ntp_adjtime() */ /* adjtime() is independent from ntp_adjtime() */
time_adjust = txc->offset; time_adjust = txc->offset;
else
ntp_update_offset(txc->offset);
} }
else if (time_status & STA_PLL) {
time_offset = txc->offset * NSEC_PER_USEC;
/*
* Scale the phase adjustment and
* clamp to the operating range.
*/
time_offset = min(time_offset, (s64)MAXPHASE * NSEC_PER_USEC);
time_offset = max(time_offset, (s64)-MAXPHASE * NSEC_PER_USEC);
/*
* Select whether the frequency is to be controlled
* and in which mode (PLL or FLL). Clamp to the operating
* range. Ugly multiply/divide should be replaced someday.
*/
if (time_status & STA_FREQHOLD || time_reftime == 0)
time_reftime = xtime.tv_sec;
mtemp = xtime.tv_sec - time_reftime;
time_reftime = xtime.tv_sec;
freq_adj = time_offset * mtemp;
freq_adj = shift_right(freq_adj, time_constant * 2 +
(SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC))
freq_adj += div_s64(time_offset << (SHIFT_NSEC - SHIFT_FLL), mtemp);
freq_adj += time_freq;
freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC);
time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC);
time_offset = div_s64(time_offset, NTP_INTERVAL_FREQ);
time_offset <<= SHIFT_UPDATE;
} /* STA_PLL */
} /* txc->modes & ADJ_OFFSET */
if (txc->modes & ADJ_TICK) if (txc->modes & ADJ_TICK)
tick_usec = txc->tick; tick_usec = txc->tick;
if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET))
ntp_update_frequency(); ntp_update_frequency();
} /* txc->modes */ }
leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0) leave:
if (time_status & (STA_UNSYNC|STA_CLOCKERR))
result = TIME_ERROR; result = TIME_ERROR;
if ((txc->modes == ADJ_OFFSET_SINGLESHOT) || if ((txc->modes == ADJ_OFFSET_SINGLESHOT) ||
...@@ -384,9 +390,12 @@ leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0) ...@@ -384,9 +390,12 @@ leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0)
txc->errcnt = 0; txc->errcnt = 0;
txc->stbcnt = 0; txc->stbcnt = 0;
write_sequnlock_irq(&xtime_lock); write_sequnlock_irq(&xtime_lock);
do_gettimeofday(&txc->time); do_gettimeofday(&txc->time);
notify_cmos_timer(); notify_cmos_timer();
return(result);
return result;
} }
static int __init ntp_tick_adj_setup(char *str) static int __init ntp_tick_adj_setup(char *str)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment