diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-02-20 01:58:42 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-02-25 12:38:06 -0500 |
commit | 53bbfa9e9437e70b322368e82c723112d690e304 (patch) | |
tree | 050817a4748d7cb7c5102273356136bbcfc2ea7e /kernel/time/ntp.c | |
parent | fdcedf7b75808dd72c3cc0b931be11b04d75c60a (diff) |
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>
Diffstat (limited to 'kernel/time/ntp.c')
-rw-r--r-- | kernel/time/ntp.c | 129 |
1 files changed, 81 insertions, 48 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index e1fa3689a903..3479ec48e604 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c | |||
@@ -1,53 +1,81 @@ | |||
1 | /* | 1 | /* |
2 | * linux/kernel/time/ntp.c | ||
3 | * | ||
4 | * NTP state machine interfaces and logic. | 2 | * NTP state machine interfaces and logic. |
5 | * | 3 | * |
6 | * This code was mainly moved from kernel/timer.c and kernel/time.c | 4 | * This code was mainly moved from kernel/timer.c and kernel/time.c |
7 | * Please see those files for relevant copyright info and historical | 5 | * Please see those files for relevant copyright info and historical |
8 | * changelogs. | 6 | * changelogs. |
9 | */ | 7 | */ |
10 | |||
11 | #include <linux/mm.h> | ||
12 | #include <linux/time.h> | ||
13 | #include <linux/timex.h> | ||
14 | #include <linux/jiffies.h> | ||
15 | #include <linux/hrtimer.h> | ||
16 | #include <linux/capability.h> | 8 | #include <linux/capability.h> |
17 | #include <linux/math64.h> | ||
18 | #include <linux/clocksource.h> | 9 | #include <linux/clocksource.h> |
19 | #include <linux/workqueue.h> | 10 | #include <linux/workqueue.h> |
20 | #include <asm/timex.h> | 11 | #include <linux/hrtimer.h> |
12 | #include <linux/jiffies.h> | ||
13 | #include <linux/math64.h> | ||
14 | #include <linux/timex.h> | ||
15 | #include <linux/time.h> | ||
16 | #include <linux/mm.h> | ||
21 | 17 | ||
22 | /* | 18 | /* |
23 | * Timekeeping variables | 19 | * NTP timekeeping variables: |
24 | */ | 20 | */ |
25 | unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */ | ||
26 | unsigned long tick_nsec; /* ACTHZ period (nsec) */ | ||
27 | u64 tick_length; | ||
28 | static u64 tick_length_base; | ||
29 | 21 | ||
30 | static struct hrtimer leap_timer; | 22 | /* USER_HZ period (usecs): */ |
23 | unsigned long tick_usec = TICK_USEC; | ||
24 | |||
25 | /* ACTHZ period (nsecs): */ | ||
26 | unsigned long tick_nsec; | ||
31 | 27 | ||
32 | #define MAX_TICKADJ 500 /* microsecs */ | 28 | u64 tick_length; |
33 | #define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \ | 29 | static u64 tick_length_base; |
34 | NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) | 30 | |
31 | static struct hrtimer leap_timer; | ||
32 | |||
33 | #define MAX_TICKADJ 500 /* usecs */ | ||
34 | #define MAX_TICKADJ_SCALED \ | ||
35 | (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) | ||
35 | 36 | ||
36 | /* | 37 | /* |
37 | * phase-lock loop variables | 38 | * phase-lock loop variables |
38 | */ | 39 | */ |
39 | /* TIME_ERROR prevents overwriting the CMOS clock */ | 40 | |
40 | static int time_state = TIME_OK; /* clock synchronization status */ | 41 | /* |
41 | int time_status = STA_UNSYNC; /* clock status bits */ | 42 | * clock synchronization status |
42 | static long time_tai; /* TAI offset (s) */ | 43 | * |
43 | static s64 time_offset; /* time adjustment (ns) */ | 44 | * (TIME_ERROR prevents overwriting the CMOS clock) |
44 | static long time_constant = 2; /* pll time constant */ | 45 | */ |
45 | long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ | 46 | static int time_state = TIME_OK; |
46 | long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ | 47 | |
47 | static s64 time_freq; /* frequency offset (scaled ns/s)*/ | 48 | /* clock status bits: */ |
48 | static long time_reftime; /* time at last adjustment (s) */ | 49 | int time_status = STA_UNSYNC; |
49 | long time_adjust; | 50 | |
50 | static long ntp_tick_adj; | 51 | /* TAI offset (secs): */ |
52 | static long time_tai; | ||
53 | |||
54 | /* time adjustment (nsecs): */ | ||
55 | static s64 time_offset; | ||
56 | |||
57 | /* pll time constant: */ | ||
58 | static long time_constant = 2; | ||
59 | |||
60 | /* maximum error (usecs): */ | ||
61 | long time_maxerror = NTP_PHASE_LIMIT; | ||
62 | |||
63 | /* estimated error (usecs): */ | ||
64 | long time_esterror = NTP_PHASE_LIMIT; | ||
65 | |||
66 | /* frequency offset (scaled nsecs/secs): */ | ||
67 | static s64 time_freq; | ||
68 | |||
69 | /* time at last adjustment (secs): */ | ||
70 | static long time_reftime; | ||
71 | |||
72 | long time_adjust; | ||
73 | |||
74 | static long ntp_tick_adj; | ||
75 | |||
76 | /* | ||
77 | * NTP methods: | ||
78 | */ | ||
51 | 79 | ||
52 | static void ntp_update_frequency(void) | 80 | static void ntp_update_frequency(void) |
53 | { | 81 | { |
@@ -118,15 +146,15 @@ static void ntp_update_offset(long offset) | |||
118 | */ | 146 | */ |
119 | void ntp_clear(void) | 147 | void ntp_clear(void) |
120 | { | 148 | { |
121 | time_adjust = 0; /* stop active adjtime() */ | 149 | time_adjust = 0; /* stop active adjtime() */ |
122 | time_status |= STA_UNSYNC; | 150 | time_status |= STA_UNSYNC; |
123 | time_maxerror = NTP_PHASE_LIMIT; | 151 | time_maxerror = NTP_PHASE_LIMIT; |
124 | time_esterror = NTP_PHASE_LIMIT; | 152 | time_esterror = NTP_PHASE_LIMIT; |
125 | 153 | ||
126 | ntp_update_frequency(); | 154 | ntp_update_frequency(); |
127 | 155 | ||
128 | tick_length = tick_length_base; | 156 | tick_length = tick_length_base; |
129 | time_offset = 0; | 157 | time_offset = 0; |
130 | } | 158 | } |
131 | 159 | ||
132 | /* | 160 | /* |
@@ -147,8 +175,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) | |||
147 | xtime.tv_sec--; | 175 | xtime.tv_sec--; |
148 | wall_to_monotonic.tv_sec++; | 176 | wall_to_monotonic.tv_sec++; |
149 | time_state = TIME_OOP; | 177 | time_state = TIME_OOP; |
150 | printk(KERN_NOTICE "Clock: " | 178 | printk(KERN_NOTICE |
151 | "inserting leap second 23:59:60 UTC\n"); | 179 | "Clock: inserting leap second 23:59:60 UTC\n"); |
152 | hrtimer_add_expires_ns(&leap_timer, NSEC_PER_SEC); | 180 | hrtimer_add_expires_ns(&leap_timer, NSEC_PER_SEC); |
153 | res = HRTIMER_RESTART; | 181 | res = HRTIMER_RESTART; |
154 | break; | 182 | break; |
@@ -157,8 +185,8 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) | |||
157 | time_tai--; | 185 | time_tai--; |
158 | wall_to_monotonic.tv_sec--; | 186 | wall_to_monotonic.tv_sec--; |
159 | time_state = TIME_WAIT; | 187 | time_state = TIME_WAIT; |
160 | printk(KERN_NOTICE "Clock: " | 188 | printk(KERN_NOTICE |
161 | "deleting leap second 23:59:59 UTC\n"); | 189 | "Clock: deleting leap second 23:59:59 UTC\n"); |
162 | break; | 190 | break; |
163 | case TIME_OOP: | 191 | case TIME_OOP: |
164 | time_tai++; | 192 | time_tai++; |
@@ -199,10 +227,10 @@ void second_overflow(void) | |||
199 | * Compute the phase adjustment for the next second. The offset is | 227 | * Compute the phase adjustment for the next second. The offset is |
200 | * reduced by a fixed factor times the time constant. | 228 | * reduced by a fixed factor times the time constant. |
201 | */ | 229 | */ |
202 | tick_length = tick_length_base; | 230 | tick_length = tick_length_base; |
203 | time_adj = shift_right(time_offset, SHIFT_PLL + time_constant); | 231 | time_adj = shift_right(time_offset, SHIFT_PLL + time_constant); |
204 | time_offset -= time_adj; | 232 | time_offset -= time_adj; |
205 | tick_length += time_adj; | 233 | tick_length += time_adj; |
206 | 234 | ||
207 | if (unlikely(time_adjust)) { | 235 | if (unlikely(time_adjust)) { |
208 | if (time_adjust > MAX_TICKADJ) { | 236 | if (time_adjust > MAX_TICKADJ) { |
@@ -240,12 +268,13 @@ static void sync_cmos_clock(struct work_struct *work) | |||
240 | * This code is run on a timer. If the clock is set, that timer | 268 | * This code is run on a timer. If the clock is set, that timer |
241 | * may not expire at the correct time. Thus, we adjust... | 269 | * may not expire at the correct time. Thus, we adjust... |
242 | */ | 270 | */ |
243 | if (!ntp_synced()) | 271 | if (!ntp_synced()) { |
244 | /* | 272 | /* |
245 | * Not synced, exit, do not restart a timer (if one is | 273 | * Not synced, exit, do not restart a timer (if one is |
246 | * running, let it run out). | 274 | * running, let it run out). |
247 | */ | 275 | */ |
248 | return; | 276 | return; |
277 | } | ||
249 | 278 | ||
250 | getnstimeofday(&now); | 279 | getnstimeofday(&now); |
251 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) | 280 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) |
@@ -277,7 +306,8 @@ static void notify_cmos_timer(void) | |||
277 | static inline void notify_cmos_timer(void) { } | 306 | static inline void notify_cmos_timer(void) { } |
278 | #endif | 307 | #endif |
279 | 308 | ||
280 | /* adjtimex mainly allows reading (and writing, if superuser) of | 309 | /* |
310 | * adjtimex mainly allows reading (and writing, if superuser) of | ||
281 | * kernel time-keeping variables. used by xntpd. | 311 | * kernel time-keeping variables. used by xntpd. |
282 | */ | 312 | */ |
283 | int do_adjtimex(struct timex *txc) | 313 | int do_adjtimex(struct timex *txc) |
@@ -298,7 +328,10 @@ int do_adjtimex(struct timex *txc) | |||
298 | if (txc->modes && !capable(CAP_SYS_TIME)) | 328 | if (txc->modes && !capable(CAP_SYS_TIME)) |
299 | return -EPERM; | 329 | return -EPERM; |
300 | 330 | ||
301 | /* if the quartz is off by more than 10% something is VERY wrong! */ | 331 | /* |
332 | * if the quartz is off by more than 10% then | ||
333 | * something is VERY wrong! | ||
334 | */ | ||
302 | if (txc->modes & ADJ_TICK && | 335 | if (txc->modes & ADJ_TICK && |
303 | (txc->tick < 900000/USER_HZ || | 336 | (txc->tick < 900000/USER_HZ || |
304 | txc->tick > 1100000/USER_HZ)) | 337 | txc->tick > 1100000/USER_HZ)) |