aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/timex.h6
-rw-r--r--kernel/time/ntp.c40
2 files changed, 20 insertions, 26 deletions
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 261381b5da82..049dfe4a11f2 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -198,21 +198,15 @@ extern int tickadj; /* amount of adjustment per tick */
198/* 198/*
199 * phase-lock loop variables 199 * phase-lock loop variables
200 */ 200 */
201extern int time_state; /* clock status */
202extern int time_status; /* clock synchronization status bits */ 201extern int time_status; /* clock synchronization status bits */
203extern long time_offset; /* time adjustment (us) */
204extern long time_constant; /* pll time constant */
205extern long time_precision; /* clock precision (us) */
206extern long time_maxerror; /* maximum error */ 202extern long time_maxerror; /* maximum error */
207extern long time_esterror; /* estimated error */ 203extern long time_esterror; /* estimated error */
208 204
209extern long time_freq; /* frequency offset (scaled ppm) */ 205extern long time_freq; /* frequency offset (scaled ppm) */
210extern long time_reftime; /* time at last adjustment (s) */
211 206
212extern long time_adjust; /* The amount of adjtime left */ 207extern long time_adjust; /* The amount of adjtime left */
213 208
214extern void ntp_clear(void); 209extern void ntp_clear(void);
215extern void ntp_update_frequency(void);
216 210
217/** 211/**
218 * ntp_synced - Returns 1 if the NTP status is not UNSYNC 212 * ntp_synced - Returns 1 if the NTP status is not UNSYNC
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 1ab5e9d7fa50..47195fa0ec4f 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -30,17 +30,31 @@ static u64 tick_length, tick_length_base;
30 * phase-lock loop variables 30 * phase-lock loop variables
31 */ 31 */
32/* TIME_ERROR prevents overwriting the CMOS clock */ 32/* TIME_ERROR prevents overwriting the CMOS clock */
33int time_state = TIME_OK; /* clock synchronization status */ 33static int time_state = TIME_OK; /* clock synchronization status */
34int time_status = STA_UNSYNC; /* clock status bits */ 34int time_status = STA_UNSYNC; /* clock status bits */
35long time_offset; /* time adjustment (ns) */ 35static long time_offset; /* time adjustment (ns) */
36long time_constant = 2; /* pll time constant */ 36static long time_constant = 2; /* pll time constant */
37long time_precision = 1; /* clock precision (us) */
38long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ 37long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */
39long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ 38long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
40long time_freq; /* frequency offset (scaled ppm)*/ 39long time_freq; /* frequency offset (scaled ppm)*/
41long time_reftime; /* time at last adjustment (s) */ 40static long time_reftime; /* time at last adjustment (s) */
42long time_adjust; 41long time_adjust;
43 42
43#define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE)
44#define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \
45 (s64)CLOCK_TICK_RATE)
46
47static void ntp_update_frequency(void)
48{
49 tick_length_base = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) << TICK_LENGTH_SHIFT;
50 tick_length_base += (s64)CLOCK_TICK_ADJUST << TICK_LENGTH_SHIFT;
51 tick_length_base += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC);
52
53 do_div(tick_length_base, HZ);
54
55 tick_nsec = tick_length_base >> TICK_LENGTH_SHIFT;
56}
57
44/** 58/**
45 * ntp_clear - Clears the NTP state variables 59 * ntp_clear - Clears the NTP state variables
46 * 60 *
@@ -59,20 +73,6 @@ void ntp_clear(void)
59 time_offset = 0; 73 time_offset = 0;
60} 74}
61 75
62#define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE)
63#define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / (s64)CLOCK_TICK_RATE)
64
65void ntp_update_frequency(void)
66{
67 tick_length_base = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) << TICK_LENGTH_SHIFT;
68 tick_length_base += (s64)CLOCK_TICK_ADJUST << TICK_LENGTH_SHIFT;
69 tick_length_base += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC);
70
71 do_div(tick_length_base, HZ);
72
73 tick_nsec = tick_length_base >> TICK_LENGTH_SHIFT;
74}
75
76/* 76/*
77 * this routine handles the overflow of the microsecond field 77 * this routine handles the overflow of the microsecond field
78 * 78 *
@@ -330,7 +330,7 @@ leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0)
330 txc->esterror = time_esterror; 330 txc->esterror = time_esterror;
331 txc->status = time_status; 331 txc->status = time_status;
332 txc->constant = time_constant; 332 txc->constant = time_constant;
333 txc->precision = time_precision; 333 txc->precision = 1;
334 txc->tolerance = MAXFREQ; 334 txc->tolerance = MAXFREQ;
335 txc->tick = tick_usec; 335 txc->tick = tick_usec;
336 336