]>
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 | |
24 | * o get rid of clocksource_jiffies extern | |
25 | */ | |
26 | ||
27 | #include <linux/clocksource.h> | |
28 | #include <linux/sysdev.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/module.h> | |
dc29a365 | 31 | #include <linux/sched.h> /* for spin_unlock_irq() using preempt_count() m68k */ |
79bf2bb3 | 32 | #include <linux/tick.h> |
734efb46 | 33 | |
a038a353 PO |
34 | void timecounter_init(struct timecounter *tc, |
35 | const struct cyclecounter *cc, | |
36 | u64 start_tstamp) | |
37 | { | |
38 | tc->cc = cc; | |
39 | tc->cycle_last = cc->read(cc); | |
40 | tc->nsec = start_tstamp; | |
41 | } | |
42 | EXPORT_SYMBOL(timecounter_init); | |
43 | ||
44 | /** | |
45 | * timecounter_read_delta - get nanoseconds since last call of this function | |
46 | * @tc: Pointer to time counter | |
47 | * | |
48 | * When the underlying cycle counter runs over, this will be handled | |
49 | * correctly as long as it does not run over more than once between | |
50 | * calls. | |
51 | * | |
52 | * The first call to this function for a new time counter initializes | |
53 | * the time tracking and returns an undefined result. | |
54 | */ | |
55 | static u64 timecounter_read_delta(struct timecounter *tc) | |
56 | { | |
57 | cycle_t cycle_now, cycle_delta; | |
58 | u64 ns_offset; | |
59 | ||
60 | /* read cycle counter: */ | |
61 | cycle_now = tc->cc->read(tc->cc); | |
62 | ||
63 | /* calculate the delta since the last timecounter_read_delta(): */ | |
64 | cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask; | |
65 | ||
66 | /* convert to nanoseconds: */ | |
67 | ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta); | |
68 | ||
69 | /* update time stamp of timecounter_read_delta() call: */ | |
70 | tc->cycle_last = cycle_now; | |
71 | ||
72 | return ns_offset; | |
73 | } | |
74 | ||
75 | u64 timecounter_read(struct timecounter *tc) | |
76 | { | |
77 | u64 nsec; | |
78 | ||
79 | /* increment time by nanoseconds since last call */ | |
80 | nsec = timecounter_read_delta(tc); | |
81 | nsec += tc->nsec; | |
82 | tc->nsec = nsec; | |
83 | ||
84 | return nsec; | |
85 | } | |
86 | EXPORT_SYMBOL(timecounter_read); | |
87 | ||
88 | u64 timecounter_cyc2time(struct timecounter *tc, | |
89 | cycle_t cycle_tstamp) | |
90 | { | |
91 | u64 cycle_delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask; | |
92 | u64 nsec; | |
93 | ||
94 | /* | |
95 | * Instead of always treating cycle_tstamp as more recent | |
96 | * than tc->cycle_last, detect when it is too far in the | |
97 | * future and treat it as old time stamp instead. | |
98 | */ | |
99 | if (cycle_delta > tc->cc->mask / 2) { | |
100 | cycle_delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask; | |
101 | nsec = tc->nsec - cyclecounter_cyc2ns(tc->cc, cycle_delta); | |
102 | } else { | |
103 | nsec = cyclecounter_cyc2ns(tc->cc, cycle_delta) + tc->nsec; | |
104 | } | |
105 | ||
106 | return nsec; | |
107 | } | |
108 | EXPORT_SYMBOL(timecounter_cyc2time); | |
109 | ||
734efb46 JS |
110 | /* XXX - Would like a better way for initializing curr_clocksource */ |
111 | extern struct clocksource clocksource_jiffies; | |
112 | ||
113 | /*[Clocksource internal variables]--------- | |
114 | * curr_clocksource: | |
115 | * currently selected clocksource. Initialized to clocksource_jiffies. | |
116 | * next_clocksource: | |
117 | * pending next selected clocksource. | |
118 | * clocksource_list: | |
119 | * linked list with the registered clocksources | |
120 | * clocksource_lock: | |
121 | * protects manipulations to curr_clocksource and next_clocksource | |
122 | * and the clocksource_list | |
123 | * override_name: | |
124 | * Name of the user-specified clocksource. | |
125 | */ | |
126 | static struct clocksource *curr_clocksource = &clocksource_jiffies; | |
127 | static struct clocksource *next_clocksource; | |
92c7e002 | 128 | static struct clocksource *clocksource_override; |
734efb46 JS |
129 | static LIST_HEAD(clocksource_list); |
130 | static DEFINE_SPINLOCK(clocksource_lock); | |
131 | static char override_name[32]; | |
132 | static int finished_booting; | |
133 | ||
6bb74df4 | 134 | /* clocksource_done_booting - Called near the end of core bootup |
734efb46 | 135 | * |
6bb74df4 JS |
136 | * Hack to avoid lots of clocksource churn at boot time. |
137 | * We use fs_initcall because we want this to start before | |
138 | * device_initcall but after subsys_initcall. | |
734efb46 | 139 | */ |
ad596171 | 140 | static int __init clocksource_done_booting(void) |
734efb46 JS |
141 | { |
142 | finished_booting = 1; | |
143 | return 0; | |
144 | } | |
6bb74df4 | 145 | fs_initcall(clocksource_done_booting); |
734efb46 | 146 | |
5d8b34fd TG |
147 | #ifdef CONFIG_CLOCKSOURCE_WATCHDOG |
148 | static LIST_HEAD(watchdog_list); | |
149 | static struct clocksource *watchdog; | |
150 | static struct timer_list watchdog_timer; | |
151 | static DEFINE_SPINLOCK(watchdog_lock); | |
152 | static cycle_t watchdog_last; | |
8f89441b | 153 | static unsigned long watchdog_resumed; |
b52f52a0 | 154 | |
5d8b34fd | 155 | /* |
35c35d1a | 156 | * Interval: 0.5sec Threshold: 0.0625s |
5d8b34fd TG |
157 | */ |
158 | #define WATCHDOG_INTERVAL (HZ >> 1) | |
35c35d1a | 159 | #define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4) |
5d8b34fd TG |
160 | |
161 | static void clocksource_ratewd(struct clocksource *cs, int64_t delta) | |
162 | { | |
35c35d1a | 163 | if (delta > -WATCHDOG_THRESHOLD && delta < WATCHDOG_THRESHOLD) |
5d8b34fd TG |
164 | return; |
165 | ||
166 | printk(KERN_WARNING "Clocksource %s unstable (delta = %Ld ns)\n", | |
167 | cs->name, delta); | |
168 | cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG); | |
169 | clocksource_change_rating(cs, 0); | |
5d8b34fd TG |
170 | list_del(&cs->wd_list); |
171 | } | |
172 | ||
173 | static void clocksource_watchdog(unsigned long data) | |
174 | { | |
175 | struct clocksource *cs, *tmp; | |
176 | cycle_t csnow, wdnow; | |
177 | int64_t wd_nsec, cs_nsec; | |
b52f52a0 | 178 | int resumed; |
5d8b34fd TG |
179 | |
180 | spin_lock(&watchdog_lock); | |
181 | ||
8f89441b | 182 | resumed = test_and_clear_bit(0, &watchdog_resumed); |
b52f52a0 | 183 | |
8e19608e | 184 | wdnow = watchdog->read(watchdog); |
5d8b34fd TG |
185 | wd_nsec = cyc2ns(watchdog, (wdnow - watchdog_last) & watchdog->mask); |
186 | watchdog_last = wdnow; | |
187 | ||
188 | list_for_each_entry_safe(cs, tmp, &watchdog_list, wd_list) { | |
8e19608e | 189 | csnow = cs->read(cs); |
b52f52a0 TG |
190 | |
191 | if (unlikely(resumed)) { | |
192 | cs->wd_last = csnow; | |
193 | continue; | |
194 | } | |
195 | ||
5d8b34fd TG |
196 | /* Initialized ? */ |
197 | if (!(cs->flags & CLOCK_SOURCE_WATCHDOG)) { | |
198 | if ((cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) && | |
199 | (watchdog->flags & CLOCK_SOURCE_IS_CONTINUOUS)) { | |
200 | cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; | |
79bf2bb3 TG |
201 | /* |
202 | * We just marked the clocksource as | |
203 | * highres-capable, notify the rest of the | |
204 | * system as well so that we transition | |
205 | * into high-res mode: | |
206 | */ | |
207 | tick_clock_notify(); | |
5d8b34fd TG |
208 | } |
209 | cs->flags |= CLOCK_SOURCE_WATCHDOG; | |
210 | cs->wd_last = csnow; | |
211 | } else { | |
212 | cs_nsec = cyc2ns(cs, (csnow - cs->wd_last) & cs->mask); | |
213 | cs->wd_last = csnow; | |
214 | /* Check the delta. Might remove from the list ! */ | |
215 | clocksource_ratewd(cs, cs_nsec - wd_nsec); | |
216 | } | |
217 | } | |
218 | ||
219 | if (!list_empty(&watchdog_list)) { | |
6993fc5b AK |
220 | /* |
221 | * Cycle through CPUs to check if the CPUs stay | |
222 | * synchronized to each other. | |
223 | */ | |
5db0e1e9 RR |
224 | int next_cpu = cpumask_next(raw_smp_processor_id(), |
225 | cpu_online_mask); | |
6993fc5b | 226 | |
cad0e458 | 227 | if (next_cpu >= nr_cpu_ids) |
6b954823 | 228 | next_cpu = cpumask_first(cpu_online_mask); |
6993fc5b AK |
229 | watchdog_timer.expires += WATCHDOG_INTERVAL; |
230 | add_timer_on(&watchdog_timer, next_cpu); | |
5d8b34fd TG |
231 | } |
232 | spin_unlock(&watchdog_lock); | |
233 | } | |
b52f52a0 TG |
234 | static void clocksource_resume_watchdog(void) |
235 | { | |
8f89441b | 236 | set_bit(0, &watchdog_resumed); |
b52f52a0 TG |
237 | } |
238 | ||
5d8b34fd TG |
239 | static void clocksource_check_watchdog(struct clocksource *cs) |
240 | { | |
241 | struct clocksource *cse; | |
242 | unsigned long flags; | |
243 | ||
244 | spin_lock_irqsave(&watchdog_lock, flags); | |
245 | if (cs->flags & CLOCK_SOURCE_MUST_VERIFY) { | |
246 | int started = !list_empty(&watchdog_list); | |
247 | ||
248 | list_add(&cs->wd_list, &watchdog_list); | |
249 | if (!started && watchdog) { | |
8e19608e | 250 | watchdog_last = watchdog->read(watchdog); |
5d8b34fd | 251 | watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL; |
6993fc5b | 252 | add_timer_on(&watchdog_timer, |
6b954823 | 253 | cpumask_first(cpu_online_mask)); |
5d8b34fd | 254 | } |
948ac6d7 TG |
255 | } else { |
256 | if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) | |
5d8b34fd TG |
257 | cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; |
258 | ||
259 | if (!watchdog || cs->rating > watchdog->rating) { | |
260 | if (watchdog) | |
261 | del_timer(&watchdog_timer); | |
262 | watchdog = cs; | |
898a19de | 263 | init_timer(&watchdog_timer); |
5d8b34fd TG |
264 | watchdog_timer.function = clocksource_watchdog; |
265 | ||
266 | /* Reset watchdog cycles */ | |
267 | list_for_each_entry(cse, &watchdog_list, wd_list) | |
268 | cse->flags &= ~CLOCK_SOURCE_WATCHDOG; | |
269 | /* Start if list is not empty */ | |
270 | if (!list_empty(&watchdog_list)) { | |
8e19608e | 271 | watchdog_last = watchdog->read(watchdog); |
5d8b34fd TG |
272 | watchdog_timer.expires = |
273 | jiffies + WATCHDOG_INTERVAL; | |
6993fc5b | 274 | add_timer_on(&watchdog_timer, |
6b954823 | 275 | cpumask_first(cpu_online_mask)); |
5d8b34fd TG |
276 | } |
277 | } | |
278 | } | |
279 | spin_unlock_irqrestore(&watchdog_lock, flags); | |
280 | } | |
281 | #else | |
282 | static void clocksource_check_watchdog(struct clocksource *cs) | |
283 | { | |
284 | if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) | |
285 | cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES; | |
286 | } | |
b52f52a0 TG |
287 | |
288 | static inline void clocksource_resume_watchdog(void) { } | |
5d8b34fd TG |
289 | #endif |
290 | ||
b52f52a0 TG |
291 | /** |
292 | * clocksource_resume - resume the clocksource(s) | |
293 | */ | |
294 | void clocksource_resume(void) | |
295 | { | |
2e197586 | 296 | struct clocksource *cs; |
b52f52a0 TG |
297 | unsigned long flags; |
298 | ||
299 | spin_lock_irqsave(&clocksource_lock, flags); | |
300 | ||
2e197586 | 301 | list_for_each_entry(cs, &clocksource_list, list) { |
b52f52a0 TG |
302 | if (cs->resume) |
303 | cs->resume(); | |
304 | } | |
305 | ||
306 | clocksource_resume_watchdog(); | |
307 | ||
308 | spin_unlock_irqrestore(&clocksource_lock, flags); | |
309 | } | |
310 | ||
7c3078b6 JW |
311 | /** |
312 | * clocksource_touch_watchdog - Update watchdog | |
313 | * | |
314 | * Update the watchdog after exception contexts such as kgdb so as not | |
315 | * to incorrectly trip the watchdog. | |
316 | * | |
317 | */ | |
318 | void clocksource_touch_watchdog(void) | |
319 | { | |
320 | clocksource_resume_watchdog(); | |
321 | } | |
322 | ||
734efb46 | 323 | /** |
a2752549 | 324 | * clocksource_get_next - Returns the selected clocksource |
734efb46 JS |
325 | * |
326 | */ | |
a2752549 | 327 | struct clocksource *clocksource_get_next(void) |
734efb46 JS |
328 | { |
329 | unsigned long flags; | |
330 | ||
331 | spin_lock_irqsave(&clocksource_lock, flags); | |
332 | if (next_clocksource && finished_booting) { | |
333 | curr_clocksource = next_clocksource; | |
334 | next_clocksource = NULL; | |
335 | } | |
336 | spin_unlock_irqrestore(&clocksource_lock, flags); | |
337 | ||
338 | return curr_clocksource; | |
339 | } | |
340 | ||
341 | /** | |
92c7e002 | 342 | * select_clocksource - Selects the best registered clocksource. |
734efb46 JS |
343 | * |
344 | * Private function. Must hold clocksource_lock when called. | |
345 | * | |
92c7e002 TG |
346 | * Select the clocksource with the best rating, or the clocksource, |
347 | * which is selected by userspace override. | |
734efb46 JS |
348 | */ |
349 | static struct clocksource *select_clocksource(void) | |
350 | { | |
5d8b34fd TG |
351 | struct clocksource *next; |
352 | ||
92c7e002 TG |
353 | if (list_empty(&clocksource_list)) |
354 | return NULL; | |
734efb46 | 355 | |
92c7e002 | 356 | if (clocksource_override) |
5d8b34fd TG |
357 | next = clocksource_override; |
358 | else | |
359 | next = list_entry(clocksource_list.next, struct clocksource, | |
360 | list); | |
734efb46 | 361 | |
5d8b34fd TG |
362 | if (next == curr_clocksource) |
363 | return NULL; | |
364 | ||
365 | return next; | |
734efb46 JS |
366 | } |
367 | ||
92c7e002 TG |
368 | /* |
369 | * Enqueue the clocksource sorted by rating | |
734efb46 | 370 | */ |
92c7e002 | 371 | static int clocksource_enqueue(struct clocksource *c) |
734efb46 | 372 | { |
92c7e002 | 373 | struct list_head *tmp, *entry = &clocksource_list; |
734efb46 JS |
374 | |
375 | list_for_each(tmp, &clocksource_list) { | |
92c7e002 TG |
376 | struct clocksource *cs; |
377 | ||
378 | cs = list_entry(tmp, struct clocksource, list); | |
379 | if (cs == c) | |
380 | return -EBUSY; | |
381 | /* Keep track of the place, where to insert */ | |
382 | if (cs->rating >= c->rating) | |
383 | entry = tmp; | |
734efb46 | 384 | } |
92c7e002 TG |
385 | list_add(&c->list, entry); |
386 | ||
387 | if (strlen(c->name) == strlen(override_name) && | |
388 | !strcmp(c->name, override_name)) | |
389 | clocksource_override = c; | |
734efb46 JS |
390 | |
391 | return 0; | |
392 | } | |
393 | ||
394 | /** | |
a2752549 | 395 | * clocksource_register - Used to install new clocksources |
734efb46 JS |
396 | * @t: clocksource to be registered |
397 | * | |
398 | * Returns -EBUSY if registration fails, zero otherwise. | |
399 | */ | |
a2752549 | 400 | int clocksource_register(struct clocksource *c) |
734efb46 | 401 | { |
734efb46 | 402 | unsigned long flags; |
5d8b34fd | 403 | int ret; |
734efb46 JS |
404 | |
405 | spin_lock_irqsave(&clocksource_lock, flags); | |
92c7e002 TG |
406 | ret = clocksource_enqueue(c); |
407 | if (!ret) | |
734efb46 | 408 | next_clocksource = select_clocksource(); |
734efb46 | 409 | spin_unlock_irqrestore(&clocksource_lock, flags); |
5d8b34fd TG |
410 | if (!ret) |
411 | clocksource_check_watchdog(c); | |
734efb46 JS |
412 | return ret; |
413 | } | |
a2752549 | 414 | EXPORT_SYMBOL(clocksource_register); |
734efb46 JS |
415 | |
416 | /** | |
92c7e002 | 417 | * clocksource_change_rating - Change the rating of a registered clocksource |
734efb46 | 418 | * |
734efb46 | 419 | */ |
92c7e002 | 420 | void clocksource_change_rating(struct clocksource *cs, int rating) |
734efb46 JS |
421 | { |
422 | unsigned long flags; | |
423 | ||
424 | spin_lock_irqsave(&clocksource_lock, flags); | |
92c7e002 | 425 | list_del(&cs->list); |
5d8b34fd | 426 | cs->rating = rating; |
92c7e002 | 427 | clocksource_enqueue(cs); |
734efb46 JS |
428 | next_clocksource = select_clocksource(); |
429 | spin_unlock_irqrestore(&clocksource_lock, flags); | |
430 | } | |
431 | ||
4713e22c TG |
432 | /** |
433 | * clocksource_unregister - remove a registered clocksource | |
434 | */ | |
435 | void clocksource_unregister(struct clocksource *cs) | |
436 | { | |
437 | unsigned long flags; | |
438 | ||
439 | spin_lock_irqsave(&clocksource_lock, flags); | |
440 | list_del(&cs->list); | |
441 | if (clocksource_override == cs) | |
442 | clocksource_override = NULL; | |
443 | next_clocksource = select_clocksource(); | |
444 | spin_unlock_irqrestore(&clocksource_lock, flags); | |
445 | } | |
446 | ||
2b013700 | 447 | #ifdef CONFIG_SYSFS |
734efb46 JS |
448 | /** |
449 | * sysfs_show_current_clocksources - sysfs interface for current clocksource | |
450 | * @dev: unused | |
451 | * @buf: char buffer to be filled with clocksource list | |
452 | * | |
453 | * Provides sysfs interface for listing current clocksource. | |
454 | */ | |
455 | static ssize_t | |
4a0b2b4d AK |
456 | sysfs_show_current_clocksources(struct sys_device *dev, |
457 | struct sysdev_attribute *attr, char *buf) | |
734efb46 | 458 | { |
5e2cb101 | 459 | ssize_t count = 0; |
734efb46 JS |
460 | |
461 | spin_lock_irq(&clocksource_lock); | |
5e2cb101 | 462 | count = snprintf(buf, PAGE_SIZE, "%s\n", curr_clocksource->name); |
734efb46 JS |
463 | spin_unlock_irq(&clocksource_lock); |
464 | ||
5e2cb101 | 465 | return count; |
734efb46 JS |
466 | } |
467 | ||
468 | /** | |
469 | * sysfs_override_clocksource - interface for manually overriding clocksource | |
470 | * @dev: unused | |
471 | * @buf: name of override clocksource | |
472 | * @count: length of buffer | |
473 | * | |
474 | * Takes input from sysfs interface for manually overriding the default | |
475 | * clocksource selction. | |
476 | */ | |
477 | static ssize_t sysfs_override_clocksource(struct sys_device *dev, | |
4a0b2b4d | 478 | struct sysdev_attribute *attr, |
734efb46 JS |
479 | const char *buf, size_t count) |
480 | { | |
92c7e002 | 481 | struct clocksource *ovr = NULL; |
734efb46 | 482 | size_t ret = count; |
92c7e002 TG |
483 | int len; |
484 | ||
734efb46 JS |
485 | /* strings from sysfs write are not 0 terminated! */ |
486 | if (count >= sizeof(override_name)) | |
487 | return -EINVAL; | |
488 | ||
489 | /* strip of \n: */ | |
490 | if (buf[count-1] == '\n') | |
491 | count--; | |
734efb46 JS |
492 | |
493 | spin_lock_irq(&clocksource_lock); | |
494 | ||
92c7e002 TG |
495 | if (count > 0) |
496 | memcpy(override_name, buf, count); | |
734efb46 JS |
497 | override_name[count] = 0; |
498 | ||
92c7e002 TG |
499 | len = strlen(override_name); |
500 | if (len) { | |
2e197586 MK |
501 | struct clocksource *cs; |
502 | ||
92c7e002 TG |
503 | ovr = clocksource_override; |
504 | /* try to select it: */ | |
2e197586 | 505 | list_for_each_entry(cs, &clocksource_list, list) { |
92c7e002 TG |
506 | if (strlen(cs->name) == len && |
507 | !strcmp(cs->name, override_name)) | |
508 | ovr = cs; | |
509 | } | |
510 | } | |
511 | ||
3f68535a | 512 | /* |
cd6d95d8 TG |
513 | * Check to make sure we don't switch to a non-highres capable |
514 | * clocksource if the tick code is in oneshot mode (highres or nohz) | |
3f68535a | 515 | */ |
79ef2bb0 | 516 | if (tick_oneshot_mode_active() && ovr && |
3f68535a JS |
517 | !(ovr->flags & CLOCK_SOURCE_VALID_FOR_HRES)) { |
518 | printk(KERN_WARNING "%s clocksource is not HRT compatible. " | |
cd6d95d8 | 519 | "Cannot switch while in HRT/NOHZ mode\n", ovr->name); |
3f68535a JS |
520 | ovr = NULL; |
521 | override_name[0] = 0; | |
522 | } | |
523 | ||
92c7e002 TG |
524 | /* Reselect, when the override name has changed */ |
525 | if (ovr != clocksource_override) { | |
526 | clocksource_override = ovr; | |
527 | next_clocksource = select_clocksource(); | |
528 | } | |
734efb46 JS |
529 | |
530 | spin_unlock_irq(&clocksource_lock); | |
531 | ||
532 | return ret; | |
533 | } | |
534 | ||
535 | /** | |
536 | * sysfs_show_available_clocksources - sysfs interface for listing clocksource | |
537 | * @dev: unused | |
538 | * @buf: char buffer to be filled with clocksource list | |
539 | * | |
540 | * Provides sysfs interface for listing registered clocksources | |
541 | */ | |
542 | static ssize_t | |
4a0b2b4d AK |
543 | sysfs_show_available_clocksources(struct sys_device *dev, |
544 | struct sysdev_attribute *attr, | |
545 | char *buf) | |
734efb46 | 546 | { |
2e197586 | 547 | struct clocksource *src; |
5e2cb101 | 548 | ssize_t count = 0; |
734efb46 JS |
549 | |
550 | spin_lock_irq(&clocksource_lock); | |
2e197586 | 551 | list_for_each_entry(src, &clocksource_list, list) { |
cd6d95d8 TG |
552 | /* |
553 | * Don't show non-HRES clocksource if the tick code is | |
554 | * in one shot mode (highres=on or nohz=on) | |
555 | */ | |
556 | if (!tick_oneshot_mode_active() || | |
557 | (src->flags & CLOCK_SOURCE_VALID_FOR_HRES)) | |
3f68535a | 558 | count += snprintf(buf + count, |
5e2cb101 MX |
559 | max((ssize_t)PAGE_SIZE - count, (ssize_t)0), |
560 | "%s ", src->name); | |
734efb46 JS |
561 | } |
562 | spin_unlock_irq(&clocksource_lock); | |
563 | ||
5e2cb101 MX |
564 | count += snprintf(buf + count, |
565 | max((ssize_t)PAGE_SIZE - count, (ssize_t)0), "\n"); | |
734efb46 | 566 | |
5e2cb101 | 567 | return count; |
734efb46 JS |
568 | } |
569 | ||
570 | /* | |
571 | * Sysfs setup bits: | |
572 | */ | |
4f95f81a | 573 | static SYSDEV_ATTR(current_clocksource, 0644, sysfs_show_current_clocksources, |
f5f1a24a | 574 | sysfs_override_clocksource); |
734efb46 | 575 | |
4f95f81a | 576 | static SYSDEV_ATTR(available_clocksource, 0444, |
f5f1a24a | 577 | sysfs_show_available_clocksources, NULL); |
734efb46 JS |
578 | |
579 | static struct sysdev_class clocksource_sysclass = { | |
af5ca3f4 | 580 | .name = "clocksource", |
734efb46 JS |
581 | }; |
582 | ||
583 | static struct sys_device device_clocksource = { | |
584 | .id = 0, | |
585 | .cls = &clocksource_sysclass, | |
586 | }; | |
587 | ||
ad596171 | 588 | static int __init init_clocksource_sysfs(void) |
734efb46 JS |
589 | { |
590 | int error = sysdev_class_register(&clocksource_sysclass); | |
591 | ||
592 | if (!error) | |
593 | error = sysdev_register(&device_clocksource); | |
594 | if (!error) | |
595 | error = sysdev_create_file( | |
596 | &device_clocksource, | |
597 | &attr_current_clocksource); | |
598 | if (!error) | |
599 | error = sysdev_create_file( | |
600 | &device_clocksource, | |
601 | &attr_available_clocksource); | |
602 | return error; | |
603 | } | |
604 | ||
605 | device_initcall(init_clocksource_sysfs); | |
2b013700 | 606 | #endif /* CONFIG_SYSFS */ |
734efb46 JS |
607 | |
608 | /** | |
609 | * boot_override_clocksource - boot clock override | |
610 | * @str: override name | |
611 | * | |
612 | * Takes a clocksource= boot argument and uses it | |
613 | * as the clocksource override name. | |
614 | */ | |
615 | static int __init boot_override_clocksource(char* str) | |
616 | { | |
617 | unsigned long flags; | |
618 | spin_lock_irqsave(&clocksource_lock, flags); | |
619 | if (str) | |
620 | strlcpy(override_name, str, sizeof(override_name)); | |
621 | spin_unlock_irqrestore(&clocksource_lock, flags); | |
622 | return 1; | |
623 | } | |
624 | ||
625 | __setup("clocksource=", boot_override_clocksource); | |
626 | ||
627 | /** | |
628 | * boot_override_clock - Compatibility layer for deprecated boot option | |
629 | * @str: override name | |
630 | * | |
631 | * DEPRECATED! Takes a clock= boot argument and uses it | |
632 | * as the clocksource override name | |
633 | */ | |
634 | static int __init boot_override_clock(char* str) | |
635 | { | |
5d0cf410 JS |
636 | if (!strcmp(str, "pmtmr")) { |
637 | printk("Warning: clock=pmtmr is deprecated. " | |
638 | "Use clocksource=acpi_pm.\n"); | |
639 | return boot_override_clocksource("acpi_pm"); | |
640 | } | |
641 | printk("Warning! clock= boot option is deprecated. " | |
642 | "Use clocksource=xyz\n"); | |
734efb46 JS |
643 | return boot_override_clocksource(str); |
644 | } | |
645 | ||
646 | __setup("clock=", boot_override_clock); |