]>
Commit | Line | Data |
---|---|---|
734efb46 JS |
1 | /* |
2 | * linux/kernel/time/clocksource.c | |
3 | * | |
4 | * This file contains the functions which manage clocksource drivers. | |
5 | * | |
6 | * Copyright (C) 2004, 2005 IBM, John Stultz (johnstul@us.ibm.com) | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | * | |
22 | * TODO WishList: | |
23 | * o Allow clocksource drivers to be unregistered | |
734efb46 JS |
24 | */ |
25 | ||
d369a5d8 | 26 | #include <linux/device.h> |
734efb46 | 27 | #include <linux/clocksource.h> |
734efb46 JS |
28 | #include <linux/init.h> |
29 | #include <linux/module.h> | |
dc29a365 | 30 | #include <linux/sched.h> /* for spin_unlock_irq() using preempt_count() m68k */ |
79bf2bb3 | 31 | #include <linux/tick.h> |
01548f4d | 32 | #include <linux/kthread.h> |
734efb46 | 33 | |
03e13cf5 | 34 | #include "tick-internal.h" |
3a978377 | 35 | #include "timekeeping_internal.h" |
03e13cf5 | 36 | |
7d2f944a TG |
37 | /** |
38 | * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks | |
39 | * @mult: pointer to mult variable | |
40 | * @shift: pointer to shift variable | |
41 | * @from: frequency to convert from | |
42 | * @to: frequency to convert to | |
5fdade95 | 43 | * @maxsec: guaranteed runtime conversion range in seconds |
7d2f944a TG |
44 | * |
45 | * The function evaluates the shift/mult pair for the scaled math | |
46 | * operations of clocksources and clockevents. | |
47 | * | |
48 | * @to and @from are frequency values in HZ. For clock sources @to is | |
49 | * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock | |
50 | * event @to is the counter frequency and @from is NSEC_PER_SEC. | |
51 | * | |
5fdade95 | 52 | * The @maxsec conversion range argument controls the time frame in |
7d2f944a TG |
53 | * seconds which must be covered by the runtime conversion with the |
54 | * calculated mult and shift factors. This guarantees that no 64bit | |
55 | * overflow happens when the input value of the conversion is | |
56 | * multiplied with the calculated mult factor. Larger ranges may | |
57 | * reduce the conversion accuracy by chosing smaller mult and shift | |
58 | * factors. | |
59 | */ | |
60 | void | |
5fdade95 | 61 | clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) |
7d2f944a TG |
62 | { |
63 | u64 tmp; | |
64 | u32 sft, sftacc= 32; | |
65 | ||
66 | /* | |
67 | * Calculate the shift factor which is limiting the conversion | |
68 | * range: | |
69 | */ | |
5fdade95 | 70 | tmp = ((u64)maxsec * from) >> 32; |
7d2f944a TG |
71 | while (tmp) { |
72 | tmp >>=1; | |
73 | sftacc--; | |
74 | } | |
75 | ||
76 | /* | |
77 | * Find the conversion shift/mult pair which has the best | |
78 | * accuracy and fits the maxsec conversion range: | |
79 | */ | |
80 | for (sft = 32; sft > 0; sft--) { | |
81 | tmp = (u64) to << sft; | |
b5776c4a | 82 | tmp += from / 2; |
7d2f944a TG |
83 | do_div(tmp, from); |
84 | if ((tmp >> sftacc) == 0) | |
85 | break; | |
86 | } | |
87 | *mult = tmp; | |
88 | *shift = sft; | |
89 | } | |
90 | ||
734efb46 JS |
91 | /*[Clocksource internal variables]--------- |
92 | * curr_clocksource: | |
f1b82746 | 93 | * currently selected clocksource. |
734efb46 JS |
94 | * clocksource_list: |
95 | * linked list with the registered clocksources | |
75c5158f MS |
96 | * clocksource_mutex: |
97 | * protects manipulations to curr_clocksource and the clocksource_list | |
734efb46 JS |
98 | * override_name: |
99 | * Name of the user-specified clocksource. | |
100 | */ | |
f1b82746 | 101 | static struct clocksource *curr_clocksource; |
734efb46 | 102 | static LIST_HEAD(clocksource_list); |
75c5158f | 103 | static DEFINE_MUTEX(clocksource_mutex); |
29b54078 | 104 | static char override_name[CS_NAME_LEN]; |
54a6bc0b | 105 | static int finished_booting; |
734efb46 | 106 | |
5d8b34fd | 107 | #ifdef CONFIG_CLOCKSOURCE_WATCHDOG |
f79e0258 | 108 | static void clocksource_watchdog_work(struct work_struct *work); |
332962f2 | 109 | static void clocksource_select(void); |
f79e0258 | 110 | |
5d8b34fd TG |
111 | static LIST_HEAD(watchdog_list); |
112 | static struct clocksource *watchdog; | |
113 | static struct timer_list watchdog_timer; | |
f79e0258 | 114 | static DECLARE_WORK(watchdog_work, clocksource_watchdog_work); |
5d8b34fd | 115 | static DEFINE_SPINLOCK(watchdog_lock); |
fb63a0eb | 116 | static int watchdog_running; |
9fb60336 | 117 | static atomic_t watchdog_reset_pending; |
b52f52a0 | 118 | |
01548f4d | 119 | static int clocksource_watchdog_kthread(void *data); |
d0981a1b | 120 | static void __clocksource_change_rating(struct clocksource *cs, int rating); |
c55c87c8 | 121 | |
5d8b34fd | 122 | /* |
35c35d1a | 123 | * Interval: 0.5sec Threshold: 0.0625s |
5d8b34fd TG |
124 | */ |
125 | #define WATCHDOG_INTERVAL (HZ >> 1) | |
35c35d1a | 126 | #define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4) |
5d8b34fd | 127 | |
01548f4d MS |
128 | static void clocksource_watchdog_work(struct work_struct *work) |
129 | { | |
130 | /* | |
131 | * If kthread_run fails the next watchdog scan over the | |
132 | * watchdog_list will find the unstable clock again. | |
133 | */ | |
134 | kthread_run(clocksource_watchdog_kthread, NULL, "kwatchdog"); | |
135 | } | |
136 | ||
7285dd7f | 137 | static void __clocksource_unstable(struct clocksource *cs) |
5d8b34fd | 138 | { |
5d8b34fd | 139 | cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG); |
c55c87c8 | 140 | cs->flags |= CLOCK_SOURCE_UNSTABLE; |
54a6bc0b TG |
141 | if (finished_booting) |
142 | schedule_work(&watchdog_work); | |
5d8b34fd TG |
143 | } |
144 | ||
7285dd7f TG |
145 | static void clocksource_unstable(struct clocksource *cs, int64_t delta) |
146 | { | |
147 | printk(KERN_WARNING "Clocksource %s unstable (delta = %Ld ns)\n", | |
148 | cs->name, delta); | |
149 | __clocksource_unstable(cs); | |
150 | } | |
151 | ||
152 | /** | |
153 | * clocksource_mark_unstable - mark clocksource unstable via watchdog | |
154 | * @cs: clocksource to be marked unstable | |
155 | * | |
156 | * This function is called instead of clocksource_change_rating from | |
157 | * cpu hotplug code to avoid a deadlock between the clocksource mutex | |
158 | * and the cpu hotplug mutex. It defers the update of the clocksource | |
159 | * to the watchdog thread. | |
160 | */ | |
161 | void clocksource_mark_unstable(struct clocksource *cs) | |
162 | { | |
163 | unsigned long flags; | |
164 | ||
165 | spin_lock_irqsave(&watchdog_lock, flags); | |
166 | if (!(cs->flags & CLOCK_SOURCE_UNSTABLE)) { | |
167 | if (list_empty(&cs->wd_list)) | |
168 | list_add(&cs->wd_list, &watchdog_list); | |
169 | __clocksource_unstable(cs); | |
170 | } | |
171 | spin_unlock_irqrestore(&watchdog_lock, flags); | |
172 | } | |
173 | ||
5d8b34fd TG |
174 | static void clocksource_watchdog(unsigned long data) |
175 | { | |
c55c87c8 | 176 | struct clocksource *cs; |
3a978377 | 177 | cycle_t csnow, wdnow, delta; |
5d8b34fd | 178 | int64_t wd_nsec, cs_nsec; |
9fb60336 | 179 | int next_cpu, reset_pending; |
5d8b34fd TG |
180 | |
181 | spin_lock(&watchdog_lock); | |
fb63a0eb MS |
182 | if (!watchdog_running) |
183 | goto out; | |
5d8b34fd | 184 | |
9fb60336 TG |
185 | reset_pending = atomic_read(&watchdog_reset_pending); |
186 | ||
c55c87c8 MS |
187 | list_for_each_entry(cs, &watchdog_list, wd_list) { |
188 | ||
189 | /* Clocksource already marked unstable? */ | |
01548f4d | 190 | if (cs->flags & CLOCK_SOURCE_UNSTABLE) { |
54a6bc0b TG |
191 | if (finished_booting) |
192 | schedule_work(&watchdog_work); | |
c55c87c8 | 193 | continue; |
01548f4d | 194 | } |
c55c87c8 | 195 | |
b5199515 | 196 | local_irq_disable(); |
8e19608e | 197 | csnow = cs->read(cs); |
b5199515 TG |
198 | wdnow = watchdog->read(watchdog); |
199 | local_irq_enable(); | |
b52f52a0 | 200 | |
8cf4e750 | 201 | /* Clocksource initialized ? */ |
9fb60336 TG |
202 | if (!(cs->flags & CLOCK_SOURCE_WATCHDOG) || |
203 | atomic_read(&watchdog_reset_pending)) { | |
8cf4e750 | 204 | cs->flags |= CLOCK_SOURCE_WATCHDOG; |
b5199515 TG |
205 | cs->wd_last = wdnow; |
206 | cs->cs_last = csnow; | |
b52f52a0 TG |
207 | continue; |
208 | } | |
209 | ||
3a978377 TG |
210 | delta = clocksource_delta(wdnow, cs->wd_last, watchdog->mask); |
211 | wd_nsec = clocksource_cyc2ns(delta, watchdog->mult, | |
212 | watchdog->shift); | |
b5199515 | 213 | |
3a978377 TG |
214 | delta = clocksource_delta(csnow, cs->cs_last, cs->mask); |
215 | cs_nsec = clocksource_cyc2ns(delta, cs->mult, cs->shift); | |
b5199515 TG |
216 | cs->cs_last = csnow; |
217 | cs->wd_last = wdnow; | |
218 | ||
9fb60336 TG |
219 | if (atomic_read(&watchdog_reset_pending)) |
220 | continue; | |
221 | ||
b5199515 | 222 | /* Check the deviation from the watchdog clocksource. */ |
9fb60336 | 223 | if ((abs(cs_nsec - wd_nsec) > WATCHDOG_THRESHOLD)) { |
8cf4e750 MS |
224 | clocksource_unstable(cs, cs_nsec - wd_nsec); |
225 | continue; | |
226 | } | |
227 | ||
228 | if (!(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES) && | |
229 | (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) && | |
230 | (watchdog->flags & CLOCK_SOURCE_IS_CONTINUOUS)) { | |
332962f2 | 231 | /* Mark it valid for high-res. */ |
8cf4e750 | 232 | cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; |
332962f2 TG |
233 | |
234 | /* | |
235 | * clocksource_done_booting() will sort it if | |
236 | * finished_booting is not set yet. | |
237 | */ | |
238 | if (!finished_booting) | |
239 | continue; | |
240 | ||
8cf4e750 | 241 | /* |
332962f2 TG |
242 | * If this is not the current clocksource let |
243 | * the watchdog thread reselect it. Due to the | |
244 | * change to high res this clocksource might | |
245 | * be preferred now. If it is the current | |
246 | * clocksource let the tick code know about | |
247 | * that change. | |
8cf4e750 | 248 | */ |
332962f2 TG |
249 | if (cs != curr_clocksource) { |
250 | cs->flags |= CLOCK_SOURCE_RESELECT; | |
251 | schedule_work(&watchdog_work); | |
252 | } else { | |
253 | tick_clock_notify(); | |
254 | } | |
5d8b34fd TG |
255 | } |
256 | } | |
257 | ||
9fb60336 TG |
258 | /* |
259 | * We only clear the watchdog_reset_pending, when we did a | |
260 | * full cycle through all clocksources. | |
261 | */ | |
262 | if (reset_pending) | |
263 | atomic_dec(&watchdog_reset_pending); | |
264 | ||
c55c87c8 MS |
265 | /* |
266 | * Cycle through CPUs to check if the CPUs stay synchronized | |
267 | * to each other. | |
268 | */ | |
269 | next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask); | |
270 | if (next_cpu >= nr_cpu_ids) | |
271 | next_cpu = cpumask_first(cpu_online_mask); | |
272 | watchdog_timer.expires += WATCHDOG_INTERVAL; | |
273 | add_timer_on(&watchdog_timer, next_cpu); | |
fb63a0eb | 274 | out: |
5d8b34fd TG |
275 | spin_unlock(&watchdog_lock); |
276 | } | |
0f8e8ef7 | 277 | |
fb63a0eb MS |
278 | static inline void clocksource_start_watchdog(void) |
279 | { | |
280 | if (watchdog_running || !watchdog || list_empty(&watchdog_list)) | |
281 | return; | |
282 | init_timer(&watchdog_timer); | |
283 | watchdog_timer.function = clocksource_watchdog; | |
fb63a0eb MS |
284 | watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL; |
285 | add_timer_on(&watchdog_timer, cpumask_first(cpu_online_mask)); | |
286 | watchdog_running = 1; | |
287 | } | |
288 | ||
289 | static inline void clocksource_stop_watchdog(void) | |
290 | { | |
291 | if (!watchdog_running || (watchdog && !list_empty(&watchdog_list))) | |
292 | return; | |
293 | del_timer(&watchdog_timer); | |
294 | watchdog_running = 0; | |
295 | } | |
296 | ||
0f8e8ef7 MS |
297 | static inline void clocksource_reset_watchdog(void) |
298 | { | |
299 | struct clocksource *cs; | |
300 | ||
301 | list_for_each_entry(cs, &watchdog_list, wd_list) | |
302 | cs->flags &= ~CLOCK_SOURCE_WATCHDOG; | |
303 | } | |
304 | ||
b52f52a0 TG |
305 | static void clocksource_resume_watchdog(void) |
306 | { | |
9fb60336 | 307 | atomic_inc(&watchdog_reset_pending); |
b52f52a0 TG |
308 | } |
309 | ||
fb63a0eb | 310 | static void clocksource_enqueue_watchdog(struct clocksource *cs) |
5d8b34fd | 311 | { |
5d8b34fd TG |
312 | unsigned long flags; |
313 | ||
314 | spin_lock_irqsave(&watchdog_lock, flags); | |
315 | if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { | |
fb63a0eb | 316 | /* cs is a clocksource to be watched. */ |
5d8b34fd | 317 | list_add(&cs->wd_list, &watchdog_list); |
fb63a0eb | 318 | cs->flags &= ~CLOCK_SOURCE_WATCHDOG; |
948ac6d7 | 319 | } else { |
fb63a0eb | 320 | /* cs is a watchdog. */ |
948ac6d7 | 321 | if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) |
5d8b34fd | 322 | cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; |
fb63a0eb | 323 | /* Pick the best watchdog. */ |
5d8b34fd | 324 | if (!watchdog || cs->rating > watchdog->rating) { |
5d8b34fd | 325 | watchdog = cs; |
5d8b34fd | 326 | /* Reset watchdog cycles */ |
0f8e8ef7 | 327 | clocksource_reset_watchdog(); |
5d8b34fd TG |
328 | } |
329 | } | |
fb63a0eb MS |
330 | /* Check if the watchdog timer needs to be started. */ |
331 | clocksource_start_watchdog(); | |
5d8b34fd TG |
332 | spin_unlock_irqrestore(&watchdog_lock, flags); |
333 | } | |
fb63a0eb MS |
334 | |
335 | static void clocksource_dequeue_watchdog(struct clocksource *cs) | |
336 | { | |
fb63a0eb MS |
337 | unsigned long flags; |
338 | ||
339 | spin_lock_irqsave(&watchdog_lock, flags); | |
a89c7edb TG |
340 | if (cs != watchdog) { |
341 | if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { | |
342 | /* cs is a watched clocksource. */ | |
343 | list_del_init(&cs->wd_list); | |
344 | /* Check if the watchdog timer needs to be stopped. */ | |
345 | clocksource_stop_watchdog(); | |
fb63a0eb MS |
346 | } |
347 | } | |
fb63a0eb MS |
348 | spin_unlock_irqrestore(&watchdog_lock, flags); |
349 | } | |
350 | ||
332962f2 | 351 | static int __clocksource_watchdog_kthread(void) |
c55c87c8 MS |
352 | { |
353 | struct clocksource *cs, *tmp; | |
354 | unsigned long flags; | |
6ea41d25 | 355 | LIST_HEAD(unstable); |
332962f2 | 356 | int select = 0; |
c55c87c8 MS |
357 | |
358 | spin_lock_irqsave(&watchdog_lock, flags); | |
332962f2 | 359 | list_for_each_entry_safe(cs, tmp, &watchdog_list, wd_list) { |
c55c87c8 MS |
360 | if (cs->flags & CLOCK_SOURCE_UNSTABLE) { |
361 | list_del_init(&cs->wd_list); | |
6ea41d25 | 362 | list_add(&cs->wd_list, &unstable); |
332962f2 TG |
363 | select = 1; |
364 | } | |
365 | if (cs->flags & CLOCK_SOURCE_RESELECT) { | |
366 | cs->flags &= ~CLOCK_SOURCE_RESELECT; | |
367 | select = 1; | |
c55c87c8 | 368 | } |
332962f2 | 369 | } |
c55c87c8 MS |
370 | /* Check if the watchdog timer needs to be stopped. */ |
371 | clocksource_stop_watchdog(); | |
6ea41d25 TG |
372 | spin_unlock_irqrestore(&watchdog_lock, flags); |
373 | ||
374 | /* Needs to be done outside of watchdog lock */ | |
375 | list_for_each_entry_safe(cs, tmp, &unstable, wd_list) { | |
376 | list_del_init(&cs->wd_list); | |
d0981a1b | 377 | __clocksource_change_rating(cs, 0); |
6ea41d25 | 378 | } |
332962f2 TG |
379 | return select; |
380 | } | |
381 | ||
382 | static int clocksource_watchdog_kthread(void *data) | |
383 | { | |
384 | mutex_lock(&clocksource_mutex); | |
385 | if (__clocksource_watchdog_kthread()) | |
386 | clocksource_select(); | |
d0981a1b | 387 | mutex_unlock(&clocksource_mutex); |
01548f4d | 388 | return 0; |
c55c87c8 MS |
389 | } |
390 | ||
7eaeb343 TG |
391 | static bool clocksource_is_watchdog(struct clocksource *cs) |
392 | { | |
393 | return cs == watchdog; | |
394 | } | |
395 | ||
fb63a0eb MS |
396 | #else /* CONFIG_CLOCKSOURCE_WATCHDOG */ |
397 | ||
398 | static void clocksource_enqueue_watchdog(struct clocksource *cs) | |
5d8b34fd TG |
399 | { |
400 | if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) | |
401 | cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; | |
402 | } | |
b52f52a0 | 403 | |
fb63a0eb | 404 | static inline void clocksource_dequeue_watchdog(struct clocksource *cs) { } |
b52f52a0 | 405 | static inline void clocksource_resume_watchdog(void) { } |
332962f2 | 406 | static inline int __clocksource_watchdog_kthread(void) { return 0; } |
7eaeb343 | 407 | static bool clocksource_is_watchdog(struct clocksource *cs) { return false; } |
397bbf6d | 408 | void clocksource_mark_unstable(struct clocksource *cs) { } |
fb63a0eb MS |
409 | |
410 | #endif /* CONFIG_CLOCKSOURCE_WATCHDOG */ | |
5d8b34fd | 411 | |
c54a42b1 MD |
412 | /** |
413 | * clocksource_suspend - suspend the clocksource(s) | |
414 | */ | |
415 | void clocksource_suspend(void) | |
416 | { | |
417 | struct clocksource *cs; | |
418 | ||
419 | list_for_each_entry_reverse(cs, &clocksource_list, list) | |
420 | if (cs->suspend) | |
421 | cs->suspend(cs); | |
422 | } | |
423 | ||
b52f52a0 TG |
424 | /** |
425 | * clocksource_resume - resume the clocksource(s) | |
426 | */ | |
427 | void clocksource_resume(void) | |
428 | { | |
2e197586 | 429 | struct clocksource *cs; |
b52f52a0 | 430 | |
75c5158f | 431 | list_for_each_entry(cs, &clocksource_list, list) |
b52f52a0 | 432 | if (cs->resume) |
17622339 | 433 | cs->resume(cs); |
b52f52a0 TG |
434 | |
435 | clocksource_resume_watchdog(); | |
b52f52a0 TG |
436 | } |
437 | ||
7c3078b6 JW |
438 | /** |
439 | * clocksource_touch_watchdog - Update watchdog | |
440 | * | |
441 | * Update the watchdog after exception contexts such as kgdb so as not | |
7b7422a5 TG |
442 | * to incorrectly trip the watchdog. This might fail when the kernel |
443 | * was stopped in code which holds watchdog_lock. | |
7c3078b6 JW |
444 | */ |
445 | void clocksource_touch_watchdog(void) | |
446 | { | |
447 | clocksource_resume_watchdog(); | |
448 | } | |
449 | ||
d65670a7 JS |
450 | /** |
451 | * clocksource_max_adjustment- Returns max adjustment amount | |
452 | * @cs: Pointer to clocksource | |
453 | * | |
454 | */ | |
455 | static u32 clocksource_max_adjustment(struct clocksource *cs) | |
456 | { | |
457 | u64 ret; | |
458 | /* | |
88b28adf | 459 | * We won't try to correct for more than 11% adjustments (110,000 ppm), |
d65670a7 JS |
460 | */ |
461 | ret = (u64)cs->mult * 11; | |
462 | do_div(ret,100); | |
463 | return (u32)ret; | |
464 | } | |
465 | ||
98962465 | 466 | /** |
87d8b9eb SB |
467 | * clocks_calc_max_nsecs - Returns maximum nanoseconds that can be converted |
468 | * @mult: cycle to nanosecond multiplier | |
469 | * @shift: cycle to nanosecond divisor (power of two) | |
470 | * @maxadj: maximum adjustment value to mult (~11%) | |
471 | * @mask: bitmask for two's complement subtraction of non 64 bit counters | |
98962465 | 472 | */ |
87d8b9eb | 473 | u64 clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask) |
98962465 JH |
474 | { |
475 | u64 max_nsecs, max_cycles; | |
476 | ||
477 | /* | |
478 | * Calculate the maximum number of cycles that we can pass to the | |
6086e346 | 479 | * cyc2ns() function without overflowing a 64-bit result. |
98962465 | 480 | */ |
6086e346 JS |
481 | max_cycles = ULLONG_MAX; |
482 | do_div(max_cycles, mult+maxadj); | |
98962465 JH |
483 | |
484 | /* | |
485 | * The actual maximum number of cycles we can defer the clocksource is | |
87d8b9eb | 486 | * determined by the minimum of max_cycles and mask. |
d65670a7 JS |
487 | * Note: Here we subtract the maxadj to make sure we don't sleep for |
488 | * too long if there's a large negative adjustment. | |
98962465 | 489 | */ |
87d8b9eb SB |
490 | max_cycles = min(max_cycles, mask); |
491 | max_nsecs = clocksource_cyc2ns(max_cycles, mult - maxadj, shift); | |
492 | ||
493 | return max_nsecs; | |
494 | } | |
495 | ||
496 | /** | |
497 | * clocksource_max_deferment - Returns max time the clocksource can be deferred | |
498 | * @cs: Pointer to clocksource | |
499 | * | |
500 | */ | |
501 | static u64 clocksource_max_deferment(struct clocksource *cs) | |
502 | { | |
503 | u64 max_nsecs; | |
98962465 | 504 | |
87d8b9eb SB |
505 | max_nsecs = clocks_calc_max_nsecs(cs->mult, cs->shift, cs->maxadj, |
506 | cs->mask); | |
98962465 JH |
507 | /* |
508 | * To ensure that the clocksource does not wrap whilst we are idle, | |
509 | * limit the time the clocksource can be deferred by 12.5%. Please | |
510 | * note a margin of 12.5% is used because this can be computed with | |
511 | * a shift, versus say 10% which would require division. | |
512 | */ | |
b1f91966 | 513 | return max_nsecs - (max_nsecs >> 3); |
98962465 JH |
514 | } |
515 | ||
592913ec | 516 | #ifndef CONFIG_ARCH_USES_GETTIMEOFFSET |
734efb46 | 517 | |
f5a2e343 | 518 | static struct clocksource *clocksource_find_best(bool oneshot, bool skipcur) |
5d33b883 TG |
519 | { |
520 | struct clocksource *cs; | |
521 | ||
522 | if (!finished_booting || list_empty(&clocksource_list)) | |
523 | return NULL; | |
524 | ||
525 | /* | |
526 | * We pick the clocksource with the highest rating. If oneshot | |
527 | * mode is active, we pick the highres valid clocksource with | |
528 | * the best rating. | |
529 | */ | |
530 | list_for_each_entry(cs, &clocksource_list, list) { | |
f5a2e343 TG |
531 | if (skipcur && cs == curr_clocksource) |
532 | continue; | |
5d33b883 TG |
533 | if (oneshot && !(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES)) |
534 | continue; | |
535 | return cs; | |
536 | } | |
537 | return NULL; | |
538 | } | |
539 | ||
f5a2e343 | 540 | static void __clocksource_select(bool skipcur) |
734efb46 | 541 | { |
5d33b883 | 542 | bool oneshot = tick_oneshot_mode_active(); |
f1b82746 | 543 | struct clocksource *best, *cs; |
5d8b34fd | 544 | |
5d33b883 | 545 | /* Find the best suitable clocksource */ |
f5a2e343 | 546 | best = clocksource_find_best(oneshot, skipcur); |
5d33b883 | 547 | if (!best) |
f1b82746 | 548 | return; |
5d33b883 | 549 | |
f1b82746 MS |
550 | /* Check for the override clocksource. */ |
551 | list_for_each_entry(cs, &clocksource_list, list) { | |
f5a2e343 TG |
552 | if (skipcur && cs == curr_clocksource) |
553 | continue; | |
f1b82746 MS |
554 | if (strcmp(cs->name, override_name) != 0) |
555 | continue; | |
556 | /* | |
557 | * Check to make sure we don't switch to a non-highres | |
558 | * capable clocksource if the tick code is in oneshot | |
559 | * mode (highres or nohz) | |
560 | */ | |
5d33b883 | 561 | if (!(cs->flags & CLOCK_SOURCE_VALID_FOR_HRES) && oneshot) { |
f1b82746 MS |
562 | /* Override clocksource cannot be used. */ |
563 | printk(KERN_WARNING "Override clocksource %s is not " | |
564 | "HRT compatible. Cannot switch while in " | |
565 | "HRT/NOHZ mode\n", cs->name); | |
566 | override_name[0] = 0; | |
567 | } else | |
568 | /* Override clocksource can be used. */ | |
569 | best = cs; | |
570 | break; | |
571 | } | |
ba919d1c TG |
572 | |
573 | if (curr_clocksource != best && !timekeeping_notify(best)) { | |
574 | pr_info("Switched to clocksource %s\n", best->name); | |
75c5158f | 575 | curr_clocksource = best; |
75c5158f | 576 | } |
f1b82746 | 577 | } |
734efb46 | 578 | |
f5a2e343 TG |
579 | /** |
580 | * clocksource_select - Select the best clocksource available | |
581 | * | |
582 | * Private function. Must hold clocksource_mutex when called. | |
583 | * | |
584 | * Select the clocksource with the best rating, or the clocksource, | |
585 | * which is selected by userspace override. | |
586 | */ | |
587 | static void clocksource_select(void) | |
588 | { | |
589 | return __clocksource_select(false); | |
590 | } | |
591 | ||
7eaeb343 TG |
592 | static void clocksource_select_fallback(void) |
593 | { | |
594 | return __clocksource_select(true); | |
595 | } | |
596 | ||
592913ec | 597 | #else /* !CONFIG_ARCH_USES_GETTIMEOFFSET */ |
54a6bc0b TG |
598 | |
599 | static inline void clocksource_select(void) { } | |
1eaff672 | 600 | static inline void clocksource_select_fallback(void) { } |
54a6bc0b TG |
601 | |
602 | #endif | |
603 | ||
75c5158f MS |
604 | /* |
605 | * clocksource_done_booting - Called near the end of core bootup | |
606 | * | |
607 | * Hack to avoid lots of clocksource churn at boot time. | |
608 | * We use fs_initcall because we want this to start before | |
609 | * device_initcall but after subsys_initcall. | |
610 | */ | |
611 | static int __init clocksource_done_booting(void) | |
612 | { | |
ad6759fb JS |
613 | mutex_lock(&clocksource_mutex); |
614 | curr_clocksource = clocksource_default_clock(); | |
75c5158f | 615 | finished_booting = 1; |
54a6bc0b TG |
616 | /* |
617 | * Run the watchdog first to eliminate unstable clock sources | |
618 | */ | |
332962f2 | 619 | __clocksource_watchdog_kthread(); |
75c5158f | 620 | clocksource_select(); |
e6c73305 | 621 | mutex_unlock(&clocksource_mutex); |
75c5158f MS |
622 | return 0; |
623 | } | |
624 | fs_initcall(clocksource_done_booting); | |
625 | ||
92c7e002 TG |
626 | /* |
627 | * Enqueue the clocksource sorted by rating | |
734efb46 | 628 | */ |
f1b82746 | 629 | static void clocksource_enqueue(struct clocksource *cs) |
734efb46 | 630 | { |
f1b82746 MS |
631 | struct list_head *entry = &clocksource_list; |
632 | struct clocksource *tmp; | |
92c7e002 | 633 | |
f1b82746 | 634 | list_for_each_entry(tmp, &clocksource_list, list) |
92c7e002 | 635 | /* Keep track of the place, where to insert */ |
f1b82746 MS |
636 | if (tmp->rating >= cs->rating) |
637 | entry = &tmp->list; | |
638 | list_add(&cs->list, entry); | |
734efb46 JS |
639 | } |
640 | ||
d7e81c26 | 641 | /** |
852db46d | 642 | * __clocksource_updatefreq_scale - Used update clocksource with new freq |
b1b73d09 | 643 | * @cs: clocksource to be registered |
d7e81c26 JS |
644 | * @scale: Scale factor multiplied against freq to get clocksource hz |
645 | * @freq: clocksource frequency (cycles per second) divided by scale | |
646 | * | |
852db46d | 647 | * This should only be called from the clocksource->enable() method. |
d7e81c26 JS |
648 | * |
649 | * This *SHOULD NOT* be called directly! Please use the | |
852db46d | 650 | * clocksource_updatefreq_hz() or clocksource_updatefreq_khz helper functions. |
d7e81c26 | 651 | */ |
852db46d | 652 | void __clocksource_updatefreq_scale(struct clocksource *cs, u32 scale, u32 freq) |
d7e81c26 | 653 | { |
c0e299b1 | 654 | u64 sec; |
d7e81c26 | 655 | /* |
724ed53e TG |
656 | * Calc the maximum number of seconds which we can run before |
657 | * wrapping around. For clocksources which have a mask > 32bit | |
658 | * we need to limit the max sleep time to have a good | |
659 | * conversion precision. 10 minutes is still a reasonable | |
660 | * amount. That results in a shift value of 24 for a | |
661 | * clocksource with mask >= 40bit and f >= 4GHz. That maps to | |
662 | * ~ 0.06ppm granularity for NTP. We apply the same 12.5% | |
663 | * margin as we do in clocksource_max_deferment() | |
d7e81c26 | 664 | */ |
b1f91966 | 665 | sec = (cs->mask - (cs->mask >> 3)); |
724ed53e TG |
666 | do_div(sec, freq); |
667 | do_div(sec, scale); | |
668 | if (!sec) | |
669 | sec = 1; | |
670 | else if (sec > 600 && cs->mask > UINT_MAX) | |
671 | sec = 600; | |
672 | ||
d7e81c26 | 673 | clocks_calc_mult_shift(&cs->mult, &cs->shift, freq, |
724ed53e | 674 | NSEC_PER_SEC / scale, sec * scale); |
d65670a7 JS |
675 | |
676 | /* | |
677 | * for clocksources that have large mults, to avoid overflow. | |
678 | * Since mult may be adjusted by ntp, add an safety extra margin | |
679 | * | |
680 | */ | |
681 | cs->maxadj = clocksource_max_adjustment(cs); | |
682 | while ((cs->mult + cs->maxadj < cs->mult) | |
683 | || (cs->mult - cs->maxadj > cs->mult)) { | |
684 | cs->mult >>= 1; | |
685 | cs->shift--; | |
686 | cs->maxadj = clocksource_max_adjustment(cs); | |
687 | } | |
688 | ||
d7e81c26 | 689 | cs->max_idle_ns = clocksource_max_deferment(cs); |
852db46d JS |
690 | } |
691 | EXPORT_SYMBOL_GPL(__clocksource_updatefreq_scale); | |
692 | ||
693 | /** | |
694 | * __clocksource_register_scale - Used to install new clocksources | |
b1b73d09 | 695 | * @cs: clocksource to be registered |
852db46d JS |
696 | * @scale: Scale factor multiplied against freq to get clocksource hz |
697 | * @freq: clocksource frequency (cycles per second) divided by scale | |
698 | * | |
699 | * Returns -EBUSY if registration fails, zero otherwise. | |
700 | * | |
701 | * This *SHOULD NOT* be called directly! Please use the | |
702 | * clocksource_register_hz() or clocksource_register_khz helper functions. | |
703 | */ | |
704 | int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq) | |
705 | { | |
706 | ||
b595076a | 707 | /* Initialize mult/shift and max_idle_ns */ |
852db46d | 708 | __clocksource_updatefreq_scale(cs, scale, freq); |
d7e81c26 | 709 | |
be278e98 | 710 | /* Add clocksource to the clocksource list */ |
d7e81c26 JS |
711 | mutex_lock(&clocksource_mutex); |
712 | clocksource_enqueue(cs); | |
d7e81c26 | 713 | clocksource_enqueue_watchdog(cs); |
e05b2efb | 714 | clocksource_select(); |
d7e81c26 JS |
715 | mutex_unlock(&clocksource_mutex); |
716 | return 0; | |
717 | } | |
718 | EXPORT_SYMBOL_GPL(__clocksource_register_scale); | |
719 | ||
720 | ||
734efb46 | 721 | /** |
a2752549 | 722 | * clocksource_register - Used to install new clocksources |
b1b73d09 | 723 | * @cs: clocksource to be registered |
734efb46 JS |
724 | * |
725 | * Returns -EBUSY if registration fails, zero otherwise. | |
726 | */ | |
f1b82746 | 727 | int clocksource_register(struct clocksource *cs) |
734efb46 | 728 | { |
d65670a7 JS |
729 | /* calculate max adjustment for given mult/shift */ |
730 | cs->maxadj = clocksource_max_adjustment(cs); | |
731 | WARN_ONCE(cs->mult + cs->maxadj < cs->mult, | |
732 | "Clocksource %s might overflow on 11%% adjustment\n", | |
733 | cs->name); | |
734 | ||
98962465 JH |
735 | /* calculate max idle time permitted for this clocksource */ |
736 | cs->max_idle_ns = clocksource_max_deferment(cs); | |
737 | ||
75c5158f | 738 | mutex_lock(&clocksource_mutex); |
f1b82746 | 739 | clocksource_enqueue(cs); |
fb63a0eb | 740 | clocksource_enqueue_watchdog(cs); |
e05b2efb | 741 | clocksource_select(); |
75c5158f | 742 | mutex_unlock(&clocksource_mutex); |
f1b82746 | 743 | return 0; |
734efb46 | 744 | } |
a2752549 | 745 | EXPORT_SYMBOL(clocksource_register); |
734efb46 | 746 | |
d0981a1b TG |
747 | static void __clocksource_change_rating(struct clocksource *cs, int rating) |
748 | { | |
749 | list_del(&cs->list); | |
750 | cs->rating = rating; | |
751 | clocksource_enqueue(cs); | |
d0981a1b TG |
752 | } |
753 | ||
734efb46 | 754 | /** |
92c7e002 | 755 | * clocksource_change_rating - Change the rating of a registered clocksource |
b1b73d09 KK |
756 | * @cs: clocksource to be changed |
757 | * @rating: new rating | |
734efb46 | 758 | */ |
92c7e002 | 759 | void clocksource_change_rating(struct clocksource *cs, int rating) |
734efb46 | 760 | { |
75c5158f | 761 | mutex_lock(&clocksource_mutex); |
d0981a1b | 762 | __clocksource_change_rating(cs, rating); |
332962f2 | 763 | clocksource_select(); |
75c5158f | 764 | mutex_unlock(&clocksource_mutex); |
734efb46 | 765 | } |
fb63a0eb | 766 | EXPORT_SYMBOL(clocksource_change_rating); |
734efb46 | 767 | |
7eaeb343 TG |
768 | /* |
769 | * Unbind clocksource @cs. Called with clocksource_mutex held | |
770 | */ | |
771 | static int clocksource_unbind(struct clocksource *cs) | |
772 | { | |
773 | /* | |
774 | * I really can't convince myself to support this on hardware | |
775 | * designed by lobotomized monkeys. | |
776 | */ | |
777 | if (clocksource_is_watchdog(cs)) | |
778 | return -EBUSY; | |
779 | ||
780 | if (cs == curr_clocksource) { | |
781 | /* Select and try to install a replacement clock source */ | |
782 | clocksource_select_fallback(); | |
783 | if (curr_clocksource == cs) | |
784 | return -EBUSY; | |
785 | } | |
786 | clocksource_dequeue_watchdog(cs); | |
787 | list_del_init(&cs->list); | |
788 | return 0; | |
789 | } | |
790 | ||
4713e22c TG |
791 | /** |
792 | * clocksource_unregister - remove a registered clocksource | |
b1b73d09 | 793 | * @cs: clocksource to be unregistered |
4713e22c | 794 | */ |
a89c7edb | 795 | int clocksource_unregister(struct clocksource *cs) |
4713e22c | 796 | { |
a89c7edb TG |
797 | int ret = 0; |
798 | ||
75c5158f | 799 | mutex_lock(&clocksource_mutex); |
a89c7edb TG |
800 | if (!list_empty(&cs->list)) |
801 | ret = clocksource_unbind(cs); | |
75c5158f | 802 | mutex_unlock(&clocksource_mutex); |
a89c7edb | 803 | return ret; |
4713e22c | 804 | } |
fb63a0eb | 805 | EXPORT_SYMBOL(clocksource_unregister); |
4713e22c | 806 | |
2b013700 | 807 | #ifdef CONFIG_SYSFS |
734efb46 JS |
808 | /** |
809 | * sysfs_show_current_clocksources - sysfs interface for current clocksource | |
810 | * @dev: unused | |
b1b73d09 | 811 | * @attr: unused |
734efb46 JS |
812 | * @buf: char buffer to be filled with clocksource list |
813 | * | |
814 | * Provides sysfs interface for listing current clocksource. | |
815 | */ | |
816 | static ssize_t | |
d369a5d8 KS |
817 | sysfs_show_current_clocksources(struct device *dev, |
818 | struct device_attribute *attr, char *buf) | |
734efb46 | 819 | { |
5e2cb101 | 820 | ssize_t count = 0; |
734efb46 | 821 | |
75c5158f | 822 | mutex_lock(&clocksource_mutex); |
5e2cb101 | 823 | count = snprintf(buf, PAGE_SIZE, "%s\n", curr_clocksource->name); |
75c5158f | 824 | mutex_unlock(&clocksource_mutex); |
734efb46 | 825 | |
5e2cb101 | 826 | return count; |
734efb46 JS |
827 | } |
828 | ||
891292a7 | 829 | ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt) |
29b54078 TG |
830 | { |
831 | size_t ret = cnt; | |
832 | ||
833 | /* strings from sysfs write are not 0 terminated! */ | |
834 | if (!cnt || cnt >= CS_NAME_LEN) | |
835 | return -EINVAL; | |
836 | ||
837 | /* strip of \n: */ | |
838 | if (buf[cnt-1] == '\n') | |
839 | cnt--; | |
840 | if (cnt > 0) | |
841 | memcpy(dst, buf, cnt); | |
842 | dst[cnt] = 0; | |
843 | return ret; | |
844 | } | |
845 | ||
734efb46 JS |
846 | /** |
847 | * sysfs_override_clocksource - interface for manually overriding clocksource | |
848 | * @dev: unused | |
b1b73d09 | 849 | * @attr: unused |
734efb46 JS |
850 | * @buf: name of override clocksource |
851 | * @count: length of buffer | |
852 | * | |
853 | * Takes input from sysfs interface for manually overriding the default | |
b71a8eb0 | 854 | * clocksource selection. |
734efb46 | 855 | */ |
d369a5d8 KS |
856 | static ssize_t sysfs_override_clocksource(struct device *dev, |
857 | struct device_attribute *attr, | |
734efb46 JS |
858 | const char *buf, size_t count) |
859 | { | |
233bcb41 | 860 | ssize_t ret; |
734efb46 | 861 | |
75c5158f | 862 | mutex_lock(&clocksource_mutex); |
734efb46 | 863 | |
03e13cf5 | 864 | ret = sysfs_get_uname(buf, override_name, count); |
29b54078 TG |
865 | if (ret >= 0) |
866 | clocksource_select(); | |
734efb46 | 867 | |
75c5158f | 868 | mutex_unlock(&clocksource_mutex); |
734efb46 JS |
869 | |
870 | return ret; | |
871 | } | |
872 | ||
7eaeb343 TG |
873 | /** |
874 | * sysfs_unbind_current_clocksource - interface for manually unbinding clocksource | |
875 | * @dev: unused | |
876 | * @attr: unused | |
877 | * @buf: unused | |
878 | * @count: length of buffer | |
879 | * | |
880 | * Takes input from sysfs interface for manually unbinding a clocksource. | |
881 | */ | |
882 | static ssize_t sysfs_unbind_clocksource(struct device *dev, | |
883 | struct device_attribute *attr, | |
884 | const char *buf, size_t count) | |
885 | { | |
886 | struct clocksource *cs; | |
887 | char name[CS_NAME_LEN]; | |
233bcb41 | 888 | ssize_t ret; |
7eaeb343 | 889 | |
03e13cf5 | 890 | ret = sysfs_get_uname(buf, name, count); |
7eaeb343 TG |
891 | if (ret < 0) |
892 | return ret; | |
893 | ||
894 | ret = -ENODEV; | |
895 | mutex_lock(&clocksource_mutex); | |
896 | list_for_each_entry(cs, &clocksource_list, list) { | |
897 | if (strcmp(cs->name, name)) | |
898 | continue; | |
899 | ret = clocksource_unbind(cs); | |
900 | break; | |
901 | } | |
902 | mutex_unlock(&clocksource_mutex); | |
903 | ||
904 | return ret ? ret : count; | |
905 | } | |
906 | ||
734efb46 JS |
907 | /** |
908 | * sysfs_show_available_clocksources - sysfs interface for listing clocksource | |
909 | * @dev: unused | |
b1b73d09 | 910 | * @attr: unused |
734efb46 JS |
911 | * @buf: char buffer to be filled with clocksource list |
912 | * | |
913 | * Provides sysfs interface for listing registered clocksources | |
914 | */ | |
915 | static ssize_t | |
d369a5d8 KS |
916 | sysfs_show_available_clocksources(struct device *dev, |
917 | struct device_attribute *attr, | |
4a0b2b4d | 918 | char *buf) |
734efb46 | 919 | { |
2e197586 | 920 | struct clocksource *src; |
5e2cb101 | 921 | ssize_t count = 0; |
734efb46 | 922 | |
75c5158f | 923 | mutex_lock(&clocksource_mutex); |
2e197586 | 924 | list_for_each_entry(src, &clocksource_list, list) { |
cd6d95d8 TG |
925 | /* |
926 | * Don't show non-HRES clocksource if the tick code is | |
927 | * in one shot mode (highres=on or nohz=on) | |
928 | */ | |
929 | if (!tick_oneshot_mode_active() || | |
930 | (src->flags & CLOCK_SOURCE_VALID_FOR_HRES)) | |
3f68535a | 931 | count += snprintf(buf + count, |
5e2cb101 MX |
932 | max((ssize_t)PAGE_SIZE - count, (ssize_t)0), |
933 | "%s ", src->name); | |
734efb46 | 934 | } |
75c5158f | 935 | mutex_unlock(&clocksource_mutex); |
734efb46 | 936 | |
5e2cb101 MX |
937 | count += snprintf(buf + count, |
938 | max((ssize_t)PAGE_SIZE - count, (ssize_t)0), "\n"); | |
734efb46 | 939 | |
5e2cb101 | 940 | return count; |
734efb46 JS |
941 | } |
942 | ||
943 | /* | |
944 | * Sysfs setup bits: | |
945 | */ | |
d369a5d8 | 946 | static DEVICE_ATTR(current_clocksource, 0644, sysfs_show_current_clocksources, |
f5f1a24a | 947 | sysfs_override_clocksource); |
734efb46 | 948 | |
7eaeb343 TG |
949 | static DEVICE_ATTR(unbind_clocksource, 0200, NULL, sysfs_unbind_clocksource); |
950 | ||
d369a5d8 | 951 | static DEVICE_ATTR(available_clocksource, 0444, |
f5f1a24a | 952 | sysfs_show_available_clocksources, NULL); |
734efb46 | 953 | |
d369a5d8 | 954 | static struct bus_type clocksource_subsys = { |
af5ca3f4 | 955 | .name = "clocksource", |
d369a5d8 | 956 | .dev_name = "clocksource", |
734efb46 JS |
957 | }; |
958 | ||
d369a5d8 | 959 | static struct device device_clocksource = { |
734efb46 | 960 | .id = 0, |
d369a5d8 | 961 | .bus = &clocksource_subsys, |
734efb46 JS |
962 | }; |
963 | ||
ad596171 | 964 | static int __init init_clocksource_sysfs(void) |
734efb46 | 965 | { |
d369a5d8 | 966 | int error = subsys_system_register(&clocksource_subsys, NULL); |
734efb46 JS |
967 | |
968 | if (!error) | |
d369a5d8 | 969 | error = device_register(&device_clocksource); |
734efb46 | 970 | if (!error) |
d369a5d8 | 971 | error = device_create_file( |
734efb46 | 972 | &device_clocksource, |
d369a5d8 | 973 | &dev_attr_current_clocksource); |
7eaeb343 TG |
974 | if (!error) |
975 | error = device_create_file(&device_clocksource, | |
976 | &dev_attr_unbind_clocksource); | |
734efb46 | 977 | if (!error) |
d369a5d8 | 978 | error = device_create_file( |
734efb46 | 979 | &device_clocksource, |
d369a5d8 | 980 | &dev_attr_available_clocksource); |
734efb46 JS |
981 | return error; |
982 | } | |
983 | ||
984 | device_initcall(init_clocksource_sysfs); | |
2b013700 | 985 | #endif /* CONFIG_SYSFS */ |
734efb46 JS |
986 | |
987 | /** | |
988 | * boot_override_clocksource - boot clock override | |
989 | * @str: override name | |
990 | * | |
991 | * Takes a clocksource= boot argument and uses it | |
992 | * as the clocksource override name. | |
993 | */ | |
994 | static int __init boot_override_clocksource(char* str) | |
995 | { | |
75c5158f | 996 | mutex_lock(&clocksource_mutex); |
734efb46 JS |
997 | if (str) |
998 | strlcpy(override_name, str, sizeof(override_name)); | |
75c5158f | 999 | mutex_unlock(&clocksource_mutex); |
734efb46 JS |
1000 | return 1; |
1001 | } | |
1002 | ||
1003 | __setup("clocksource=", boot_override_clocksource); | |
1004 | ||
1005 | /** | |
1006 | * boot_override_clock - Compatibility layer for deprecated boot option | |
1007 | * @str: override name | |
1008 | * | |
1009 | * DEPRECATED! Takes a clock= boot argument and uses it | |
1010 | * as the clocksource override name | |
1011 | */ | |
1012 | static int __init boot_override_clock(char* str) | |
1013 | { | |
5d0cf410 JS |
1014 | if (!strcmp(str, "pmtmr")) { |
1015 | printk("Warning: clock=pmtmr is deprecated. " | |
1016 | "Use clocksource=acpi_pm.\n"); | |
1017 | return boot_override_clocksource("acpi_pm"); | |
1018 | } | |
1019 | printk("Warning! clock= boot option is deprecated. " | |
1020 | "Use clocksource=xyz\n"); | |
734efb46 JS |
1021 | return boot_override_clocksource(str); |
1022 | } | |
1023 | ||
1024 | __setup("clock=", boot_override_clock); |