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: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
fdcedf7b75
commit
53bbfa9e94
@ -1,53 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
* 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) */
|
|
||||||
u64 tick_length;
|
|
||||||
static u64 tick_length_base;
|
|
||||||
|
|
||||||
static struct hrtimer leap_timer;
|
/* USER_HZ period (usecs): */
|
||||||
|
unsigned long tick_usec = TICK_USEC;
|
||||||
|
|
||||||
#define MAX_TICKADJ 500 /* microsecs */
|
/* ACTHZ period (nsecs): */
|
||||||
#define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \
|
unsigned long tick_nsec;
|
||||||
NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
|
|
||||||
|
u64 tick_length;
|
||||||
|
static u64 tick_length_base;
|
||||||
|
|
||||||
|
static struct hrtimer leap_timer;
|
||||||
|
|
||||||
|
#define MAX_TICKADJ 500 /* usecs */
|
||||||
|
#define MAX_TICKADJ_SCALED \
|
||||||
|
(((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;
|
||||||
long time_adjust;
|
|
||||||
static long ntp_tick_adj;
|
/* 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;
|
||||||
|
|
||||||
|
static long ntp_tick_adj;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NTP methods:
|
||||||
|
*/
|
||||||
|
|
||||||
static void ntp_update_frequency(void)
|
static void ntp_update_frequency(void)
|
||||||
{
|
{
|
||||||
@ -118,15 +146,15 @@ static void ntp_update_offset(long offset)
|
|||||||
*/
|
*/
|
||||||
void ntp_clear(void)
|
void ntp_clear(void)
|
||||||
{
|
{
|
||||||
time_adjust = 0; /* stop active adjtime() */
|
time_adjust = 0; /* stop active adjtime() */
|
||||||
time_status |= STA_UNSYNC;
|
time_status |= STA_UNSYNC;
|
||||||
time_maxerror = NTP_PHASE_LIMIT;
|
time_maxerror = NTP_PHASE_LIMIT;
|
||||||
time_esterror = NTP_PHASE_LIMIT;
|
time_esterror = NTP_PHASE_LIMIT;
|
||||||
|
|
||||||
ntp_update_frequency();
|
ntp_update_frequency();
|
||||||
|
|
||||||
tick_length = tick_length_base;
|
tick_length = tick_length_base;
|
||||||
time_offset = 0;
|
time_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -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)
|
|||||||
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++;
|
||||||
@ -199,10 +227,10 @@ void second_overflow(void)
|
|||||||
* Compute the phase adjustment for the next second. The offset is
|
* Compute the phase adjustment for the next second. The offset is
|
||||||
* reduced by a fixed factor times the time constant.
|
* reduced by a fixed factor times the time constant.
|
||||||
*/
|
*/
|
||||||
tick_length = tick_length_base;
|
tick_length = tick_length_base;
|
||||||
time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
|
time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
|
||||||
time_offset -= time_adj;
|
time_offset -= time_adj;
|
||||||
tick_length += time_adj;
|
tick_length += time_adj;
|
||||||
|
|
||||||
if (unlikely(time_adjust)) {
|
if (unlikely(time_adjust)) {
|
||||||
if (time_adjust > MAX_TICKADJ) {
|
if (time_adjust > MAX_TICKADJ) {
|
||||||
@ -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)
|
|||||||
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)
|
|||||||
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user