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