diff options
-rw-r--r-- | include/linux/timex.h | 6 | ||||
-rw-r--r-- | kernel/time/ntp.c | 40 |
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 | */ |
201 | extern int time_state; /* clock status */ | ||
202 | extern int time_status; /* clock synchronization status bits */ | 201 | extern int time_status; /* clock synchronization status bits */ |
203 | extern long time_offset; /* time adjustment (us) */ | ||
204 | extern long time_constant; /* pll time constant */ | ||
205 | extern long time_precision; /* clock precision (us) */ | ||
206 | extern long time_maxerror; /* maximum error */ | 202 | extern long time_maxerror; /* maximum error */ |
207 | extern long time_esterror; /* estimated error */ | 203 | extern long time_esterror; /* estimated error */ |
208 | 204 | ||
209 | extern long time_freq; /* frequency offset (scaled ppm) */ | 205 | extern long time_freq; /* frequency offset (scaled ppm) */ |
210 | extern long time_reftime; /* time at last adjustment (s) */ | ||
211 | 206 | ||
212 | extern long time_adjust; /* The amount of adjtime left */ | 207 | extern long time_adjust; /* The amount of adjtime left */ |
213 | 208 | ||
214 | extern void ntp_clear(void); | 209 | extern void ntp_clear(void); |
215 | extern 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 */ |
33 | int time_state = TIME_OK; /* clock synchronization status */ | 33 | static int time_state = TIME_OK; /* clock synchronization status */ |
34 | int time_status = STA_UNSYNC; /* clock status bits */ | 34 | int time_status = STA_UNSYNC; /* clock status bits */ |
35 | long time_offset; /* time adjustment (ns) */ | 35 | static long time_offset; /* time adjustment (ns) */ |
36 | long time_constant = 2; /* pll time constant */ | 36 | static long time_constant = 2; /* pll time constant */ |
37 | long time_precision = 1; /* clock precision (us) */ | ||
38 | long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ | 37 | long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ |
39 | long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ | 38 | long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ |
40 | long time_freq; /* frequency offset (scaled ppm)*/ | 39 | long time_freq; /* frequency offset (scaled ppm)*/ |
41 | long time_reftime; /* time at last adjustment (s) */ | 40 | static long time_reftime; /* time at last adjustment (s) */ |
42 | long time_adjust; | 41 | long 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 | |||
47 | static 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 | |||
65 | void 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 | ||