Commit 53bbfa9e authored by Ingo Molnar's avatar Ingo Molnar

time: ntp: clean up kernel/time/ntp.c

Impact: cleanup, no functionality changed

Make this file a bit more readable by applying a consistent coding style.

No code changed:

kernel/time/ntp.o:

   text	   data	    bss	    dec	    hex	filename
   2552	    170	    168	   2890	    b4a	ntp.o.before
   2552	    170	    168	   2890	    b4a	ntp.o.after

md5:
   eae1275df0b7d6290c13f6f6f8f05c8c  ntp.o.before.asm
   eae1275df0b7d6290c13f6f6f8f05c8c  ntp.o.after.asm
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent fdcedf7b
/* /*
* linux/kernel/time/ntp.c
*
* NTP state machine interfaces and logic. * NTP state machine interfaces and logic.
* *
* This code was mainly moved from kernel/timer.c and kernel/time.c * This code was mainly moved from kernel/timer.c and kernel/time.c
* Please see those files for relevant copyright info and historical * Please see those files for relevant copyright info and historical
* changelogs. * changelogs.
*/ */
#include <linux/mm.h>
#include <linux/time.h>
#include <linux/timex.h>
#include <linux/jiffies.h>
#include <linux/hrtimer.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/math64.h>
#include <linux/clocksource.h> #include <linux/clocksource.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <asm/timex.h> #include <linux/hrtimer.h>
#include <linux/jiffies.h>
#include <linux/math64.h>
#include <linux/timex.h>
#include <linux/time.h>
#include <linux/mm.h>
/* /*
* Timekeeping variables * NTP timekeeping variables:
*/ */
unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */
unsigned long tick_nsec; /* ACTHZ period (nsec) */ /* USER_HZ period (usecs): */
unsigned long tick_usec = TICK_USEC;
/* ACTHZ period (nsecs): */
unsigned long tick_nsec;
u64 tick_length; u64 tick_length;
static u64 tick_length_base; static u64 tick_length_base;
static struct hrtimer leap_timer; static struct hrtimer leap_timer;
#define MAX_TICKADJ 500 /* microsecs */ #define MAX_TICKADJ 500 /* usecs */
#define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \ #define MAX_TICKADJ_SCALED \
NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
/* /*
* phase-lock loop variables * phase-lock loop variables
*/ */
/* TIME_ERROR prevents overwriting the CMOS clock */
static int time_state = TIME_OK; /* clock synchronization status */ /*
int time_status = STA_UNSYNC; /* clock status bits */ * clock synchronization status
static long time_tai; /* TAI offset (s) */ *
static s64 time_offset; /* time adjustment (ns) */ * (TIME_ERROR prevents overwriting the CMOS clock)
static long time_constant = 2; /* pll time constant */ */
long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ static int time_state = TIME_OK;
long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
static s64 time_freq; /* frequency offset (scaled ns/s)*/ /* clock status bits: */
static long time_reftime; /* time at last adjustment (s) */ int time_status = STA_UNSYNC;
/* TAI offset (secs): */
static long time_tai;
/* time adjustment (nsecs): */
static s64 time_offset;
/* pll time constant: */
static long time_constant = 2;
/* maximum error (usecs): */
long time_maxerror = NTP_PHASE_LIMIT;
/* estimated error (usecs): */
long time_esterror = NTP_PHASE_LIMIT;
/* frequency offset (scaled nsecs/secs): */
static s64 time_freq;
/* time at last adjustment (secs): */
static long time_reftime;
long time_adjust; long time_adjust;
static long ntp_tick_adj; static long ntp_tick_adj;
/*
* NTP methods:
*/
static void ntp_update_frequency(void) static void ntp_update_frequency(void)
{ {
u64 old_tick_length_base = tick_length_base; u64 old_tick_length_base = tick_length_base;
...@@ -147,8 +175,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) ...@@ -147,8 +175,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
xtime.tv_sec--; xtime.tv_sec--;
wall_to_monotonic.tv_sec++; wall_to_monotonic.tv_sec++;
time_state = TIME_OOP; time_state = TIME_OOP;
printk(KERN_NOTICE "Clock: " printk(KERN_NOTICE
"inserting leap second 23:59:60 UTC\n"); "Clock: inserting leap second 23:59:60 UTC\n");
hrtimer_add_expires_ns(&leap_timer, NSEC_PER_SEC); hrtimer_add_expires_ns(&leap_timer, NSEC_PER_SEC);
res = HRTIMER_RESTART; res = HRTIMER_RESTART;
break; break;
...@@ -157,8 +185,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) ...@@ -157,8 +185,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
time_tai--; time_tai--;
wall_to_monotonic.tv_sec--; wall_to_monotonic.tv_sec--;
time_state = TIME_WAIT; time_state = TIME_WAIT;
printk(KERN_NOTICE "Clock: " printk(KERN_NOTICE
"deleting leap second 23:59:59 UTC\n"); "Clock: deleting leap second 23:59:59 UTC\n");
break; break;
case TIME_OOP: case TIME_OOP:
time_tai++; time_tai++;
...@@ -240,12 +268,13 @@ static void sync_cmos_clock(struct work_struct *work) ...@@ -240,12 +268,13 @@ static void sync_cmos_clock(struct work_struct *work)
* This code is run on a timer. If the clock is set, that timer * This code is run on a timer. If the clock is set, that timer
* may not expire at the correct time. Thus, we adjust... * may not expire at the correct time. Thus, we adjust...
*/ */
if (!ntp_synced()) if (!ntp_synced()) {
/* /*
* Not synced, exit, do not restart a timer (if one is * Not synced, exit, do not restart a timer (if one is
* running, let it run out). * running, let it run out).
*/ */
return; return;
}
getnstimeofday(&now); getnstimeofday(&now);
if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2)
...@@ -277,7 +306,8 @@ static void notify_cmos_timer(void) ...@@ -277,7 +306,8 @@ static void notify_cmos_timer(void)
static inline void notify_cmos_timer(void) { } static inline void notify_cmos_timer(void) { }
#endif #endif
/* adjtimex mainly allows reading (and writing, if superuser) of /*
* adjtimex mainly allows reading (and writing, if superuser) of
* kernel time-keeping variables. used by xntpd. * kernel time-keeping variables. used by xntpd.
*/ */
int do_adjtimex(struct timex *txc) int do_adjtimex(struct timex *txc)
...@@ -298,7 +328,10 @@ int do_adjtimex(struct timex *txc) ...@@ -298,7 +328,10 @@ int do_adjtimex(struct timex *txc)
if (txc->modes && !capable(CAP_SYS_TIME)) if (txc->modes && !capable(CAP_SYS_TIME))
return -EPERM; return -EPERM;
/* if the quartz is off by more than 10% something is VERY wrong! */ /*
* if the quartz is off by more than 10% then
* something is VERY wrong!
*/
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))
......
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