blob: e04ef38ea3beac27a9893fb2019b990ef3d3b1dd [file] [log] [blame]
Thomas Gleixnerc0a31322006-01-09 20:52:32 -08001/*
2 * linux/kernel/hrtimer.c
3 *
Thomas Gleixner3c8aa392007-02-16 01:27:50 -08004 * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -08005 * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
6 * Copyright(C) 2006-2007 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
Thomas Gleixnerc0a31322006-01-09 20:52:32 -08007 *
8 * High-resolution kernel timers
9 *
10 * In contrast to the low-resolution timeout API implemented in
11 * kernel/timer.c, hrtimers provide finer resolution and accuracy
12 * depending on system configuration and capabilities.
13 *
14 * These timers are currently used for:
15 * - itimers
16 * - POSIX timers
17 * - nanosleep
18 * - precise in-kernel timing
19 *
20 * Started by: Thomas Gleixner and Ingo Molnar
21 *
22 * Credits:
23 * based on kernel/timer.c
24 *
Thomas Gleixner66188fa2006-02-01 03:05:13 -080025 * Help, testing, suggestions, bugfixes, improvements were
26 * provided by:
27 *
28 * George Anzinger, Andrew Morton, Steven Rostedt, Roman Zippel
29 * et. al.
30 *
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080031 * For licencing details see kernel-base/COPYING
32 */
33
34#include <linux/cpu.h>
35#include <linux/module.h>
36#include <linux/percpu.h>
37#include <linux/hrtimer.h>
38#include <linux/notifier.h>
39#include <linux/syscalls.h>
40#include <linux/interrupt.h>
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080041#include <linux/tick.h>
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080042
43#include <asm/uaccess.h>
44
45/**
46 * ktime_get - get the monotonic time in ktime_t format
47 *
48 * returns the time in ktime_t format
49 */
Thomas Gleixnerd316c572007-02-16 01:28:00 -080050ktime_t ktime_get(void)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080051{
52 struct timespec now;
53
54 ktime_get_ts(&now);
55
56 return timespec_to_ktime(now);
57}
58
59/**
60 * ktime_get_real - get the real (wall-) time in ktime_t format
61 *
62 * returns the time in ktime_t format
63 */
Thomas Gleixnerd316c572007-02-16 01:28:00 -080064ktime_t ktime_get_real(void)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080065{
66 struct timespec now;
67
68 getnstimeofday(&now);
69
70 return timespec_to_ktime(now);
71}
72
73EXPORT_SYMBOL_GPL(ktime_get_real);
74
75/*
76 * The timer bases:
George Anzinger7978672c2006-02-01 03:05:11 -080077 *
78 * Note: If we want to add new timer bases, we have to skip the two
79 * clock ids captured by the cpu-timers. We do this by holding empty
80 * entries rather than doing math adjustment of the clock ids.
81 * This ensures that we capture erroneous accesses to these clock ids
82 * rather than moving them into the range of valid clock id's.
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080083 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -080084static DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080085{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -080086
87 .clock_base =
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080088 {
Thomas Gleixner3c8aa392007-02-16 01:27:50 -080089 {
90 .index = CLOCK_REALTIME,
91 .get_time = &ktime_get_real,
92 .resolution = KTIME_REALTIME_RES,
93 },
94 {
95 .index = CLOCK_MONOTONIC,
96 .get_time = &ktime_get,
97 .resolution = KTIME_MONOTONIC_RES,
98 },
99 }
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800100};
101
102/**
103 * ktime_get_ts - get the monotonic clock in timespec format
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800104 * @ts: pointer to timespec variable
105 *
106 * The function calculates the monotonic clock from the realtime
107 * clock and the wall_to_monotonic offset and stores the result
Robert P. J. Day72fd4a32007-02-10 01:45:59 -0800108 * in normalized timespec format in the variable pointed to by @ts.
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800109 */
110void ktime_get_ts(struct timespec *ts)
111{
112 struct timespec tomono;
113 unsigned long seq;
114
115 do {
116 seq = read_seqbegin(&xtime_lock);
117 getnstimeofday(ts);
118 tomono = wall_to_monotonic;
119
120 } while (read_seqretry(&xtime_lock, seq));
121
122 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
123 ts->tv_nsec + tomono.tv_nsec);
124}
Matt Helsley69778e32006-01-09 20:52:39 -0800125EXPORT_SYMBOL_GPL(ktime_get_ts);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800126
127/*
Thomas Gleixner92127c72006-03-26 01:38:05 -0800128 * Get the coarse grained time at the softirq based on xtime and
129 * wall_to_monotonic.
130 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800131static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
Thomas Gleixner92127c72006-03-26 01:38:05 -0800132{
133 ktime_t xtim, tomono;
john stultzf4304ab2007-02-16 01:27:26 -0800134 struct timespec xts;
Thomas Gleixner92127c72006-03-26 01:38:05 -0800135 unsigned long seq;
136
137 do {
138 seq = read_seqbegin(&xtime_lock);
john stultzf4304ab2007-02-16 01:27:26 -0800139#ifdef CONFIG_NO_HZ
140 getnstimeofday(&xts);
141#else
142 xts = xtime;
143#endif
Thomas Gleixner92127c72006-03-26 01:38:05 -0800144 } while (read_seqretry(&xtime_lock, seq));
145
john stultzf4304ab2007-02-16 01:27:26 -0800146 xtim = timespec_to_ktime(xts);
147 tomono = timespec_to_ktime(wall_to_monotonic);
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800148 base->clock_base[CLOCK_REALTIME].softirq_time = xtim;
149 base->clock_base[CLOCK_MONOTONIC].softirq_time =
150 ktime_add(xtim, tomono);
Thomas Gleixner92127c72006-03-26 01:38:05 -0800151}
152
153/*
Thomas Gleixner303e9672007-02-16 01:27:51 -0800154 * Helper function to check, whether the timer is on one of the queues
155 */
156static inline int hrtimer_is_queued(struct hrtimer *timer)
157{
158 return timer->state & HRTIMER_STATE_ENQUEUED;
159}
160
161/*
162 * Helper function to check, whether the timer is running the callback
163 * function
164 */
165static inline int hrtimer_callback_running(struct hrtimer *timer)
166{
167 return timer->state & HRTIMER_STATE_CALLBACK;
168}
169
170/*
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800171 * Functions and macros which are different for UP/SMP systems are kept in a
172 * single place
173 */
174#ifdef CONFIG_SMP
175
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800176/*
177 * We are using hashed locking: holding per_cpu(hrtimer_bases)[n].lock
178 * means that all timers which are tied to this base via timer->base are
179 * locked, and the base itself is locked too.
180 *
181 * So __run_timers/migrate_timers can safely modify all timers which could
182 * be found on the lists/queues.
183 *
184 * When the timer's base is locked, and the timer removed from list, it is
185 * possible to set timer->base = NULL and drop the lock: the timer remains
186 * locked.
187 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800188static
189struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
190 unsigned long *flags)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800191{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800192 struct hrtimer_clock_base *base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800193
194 for (;;) {
195 base = timer->base;
196 if (likely(base != NULL)) {
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800197 spin_lock_irqsave(&base->cpu_base->lock, *flags);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800198 if (likely(base == timer->base))
199 return base;
200 /* The timer has migrated to another CPU: */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800201 spin_unlock_irqrestore(&base->cpu_base->lock, *flags);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800202 }
203 cpu_relax();
204 }
205}
206
207/*
208 * Switch the timer base to the current CPU when possible.
209 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800210static inline struct hrtimer_clock_base *
211switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800212{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800213 struct hrtimer_clock_base *new_base;
214 struct hrtimer_cpu_base *new_cpu_base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800215
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800216 new_cpu_base = &__get_cpu_var(hrtimer_bases);
217 new_base = &new_cpu_base->clock_base[base->index];
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800218
219 if (base != new_base) {
220 /*
221 * We are trying to schedule the timer on the local CPU.
222 * However we can't change timer's base while it is running,
223 * so we keep it on the same CPU. No hassle vs. reprogramming
224 * the event source in the high resolution case. The softirq
225 * code will take care of this when the timer function has
226 * completed. There is no conflict as we hold the lock until
227 * the timer is enqueued.
228 */
Thomas Gleixner5cfb6de2007-02-16 01:27:52 -0800229 if (unlikely(timer->state & HRTIMER_STATE_CALLBACK))
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800230 return base;
231
232 /* See the comment in lock_timer_base() */
233 timer->base = NULL;
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800234 spin_unlock(&base->cpu_base->lock);
235 spin_lock(&new_base->cpu_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800236 timer->base = new_base;
237 }
238 return new_base;
239}
240
241#else /* CONFIG_SMP */
242
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800243static inline struct hrtimer_clock_base *
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800244lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
245{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800246 struct hrtimer_clock_base *base = timer->base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800247
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800248 spin_lock_irqsave(&base->cpu_base->lock, *flags);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800249
250 return base;
251}
252
253#define switch_hrtimer_base(t, b) (b)
254
255#endif /* !CONFIG_SMP */
256
257/*
258 * Functions for the union type storage format of ktime_t which are
259 * too large for inlining:
260 */
261#if BITS_PER_LONG < 64
262# ifndef CONFIG_KTIME_SCALAR
263/**
264 * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800265 * @kt: addend
266 * @nsec: the scalar nsec value to add
267 *
268 * Returns the sum of kt and nsec in ktime_t format
269 */
270ktime_t ktime_add_ns(const ktime_t kt, u64 nsec)
271{
272 ktime_t tmp;
273
274 if (likely(nsec < NSEC_PER_SEC)) {
275 tmp.tv64 = nsec;
276 } else {
277 unsigned long rem = do_div(nsec, NSEC_PER_SEC);
278
279 tmp = ktime_set((long)nsec, rem);
280 }
281
282 return ktime_add(kt, tmp);
283}
284
285#else /* CONFIG_KTIME_SCALAR */
286
287# endif /* !CONFIG_KTIME_SCALAR */
288
289/*
290 * Divide a ktime value by a nanosecond value
291 */
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800292unsigned long ktime_divns(const ktime_t kt, s64 div)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800293{
294 u64 dclc, inc, dns;
295 int sft = 0;
296
297 dclc = dns = ktime_to_ns(kt);
298 inc = div;
299 /* Make sure the divisor is less than 2^32: */
300 while (div >> 32) {
301 sft++;
302 div >>= 1;
303 }
304 dclc >>= sft;
305 do_div(dclc, (unsigned long) div);
306
307 return (unsigned long) dclc;
308}
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800309#endif /* BITS_PER_LONG >= 64 */
310
311/*
312 * Counterpart to lock_timer_base above:
313 */
314static inline
315void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
316{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800317 spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800318}
319
320/**
321 * hrtimer_forward - forward the timer expiry
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800322 * @timer: hrtimer to forward
Roman Zippel44f21472006-03-26 01:38:06 -0800323 * @now: forward past this time
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800324 * @interval: the interval to forward
325 *
326 * Forward the timer expiry so it will expire in the future.
Jonathan Corbet8dca6f32006-01-16 15:58:55 -0700327 * Returns the number of overruns.
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800328 */
329unsigned long
Roman Zippel44f21472006-03-26 01:38:06 -0800330hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800331{
332 unsigned long orun = 1;
Roman Zippel44f21472006-03-26 01:38:06 -0800333 ktime_t delta;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800334
335 delta = ktime_sub(now, timer->expires);
336
337 if (delta.tv64 < 0)
338 return 0;
339
Thomas Gleixnerc9db4fa2006-01-12 11:47:34 +0100340 if (interval.tv64 < timer->base->resolution.tv64)
341 interval.tv64 = timer->base->resolution.tv64;
342
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800343 if (unlikely(delta.tv64 >= interval.tv64)) {
Roman Zippeldf869b62006-03-26 01:38:11 -0800344 s64 incr = ktime_to_ns(interval);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800345
346 orun = ktime_divns(delta, incr);
347 timer->expires = ktime_add_ns(timer->expires, incr * orun);
348 if (timer->expires.tv64 > now.tv64)
349 return orun;
350 /*
351 * This (and the ktime_add() below) is the
352 * correction for exact:
353 */
354 orun++;
355 }
356 timer->expires = ktime_add(timer->expires, interval);
357
358 return orun;
359}
360
361/*
362 * enqueue_hrtimer - internal function to (re)start a timer
363 *
364 * The timer is inserted in expiry order. Insertion into the
365 * red black tree is O(log(n)). Must hold the base lock.
366 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800367static void enqueue_hrtimer(struct hrtimer *timer,
368 struct hrtimer_clock_base *base)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800369{
370 struct rb_node **link = &base->active.rb_node;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800371 struct rb_node *parent = NULL;
372 struct hrtimer *entry;
373
374 /*
375 * Find the right place in the rbtree:
376 */
377 while (*link) {
378 parent = *link;
379 entry = rb_entry(parent, struct hrtimer, node);
380 /*
381 * We dont care about collisions. Nodes with
382 * the same expiry time stay together.
383 */
384 if (timer->expires.tv64 < entry->expires.tv64)
385 link = &(*link)->rb_left;
Thomas Gleixner288867e2006-01-12 11:25:54 +0100386 else
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800387 link = &(*link)->rb_right;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800388 }
389
390 /*
Thomas Gleixner288867e2006-01-12 11:25:54 +0100391 * Insert the timer to the rbtree and check whether it
392 * replaces the first pending timer
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800393 */
394 rb_link_node(&timer->node, parent, link);
395 rb_insert_color(&timer->node, &base->active);
Thomas Gleixner303e9672007-02-16 01:27:51 -0800396 /*
397 * HRTIMER_STATE_ENQUEUED is or'ed to the current state to preserve the
398 * state of a possibly running callback.
399 */
400 timer->state |= HRTIMER_STATE_ENQUEUED;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800401
Thomas Gleixner288867e2006-01-12 11:25:54 +0100402 if (!base->first || timer->expires.tv64 <
403 rb_entry(base->first, struct hrtimer, node)->expires.tv64)
404 base->first = &timer->node;
405}
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800406
407/*
408 * __remove_hrtimer - internal function to remove a timer
409 *
410 * Caller must hold the base lock.
411 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800412static void __remove_hrtimer(struct hrtimer *timer,
Thomas Gleixner303e9672007-02-16 01:27:51 -0800413 struct hrtimer_clock_base *base,
414 unsigned long newstate)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800415{
416 /*
Thomas Gleixner288867e2006-01-12 11:25:54 +0100417 * Remove the timer from the rbtree and replace the
418 * first entry pointer if necessary.
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800419 */
Thomas Gleixner288867e2006-01-12 11:25:54 +0100420 if (base->first == &timer->node)
421 base->first = rb_next(&timer->node);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800422 rb_erase(&timer->node, &base->active);
Thomas Gleixner303e9672007-02-16 01:27:51 -0800423 timer->state = newstate;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800424}
425
426/*
427 * remove hrtimer, called with base lock held
428 */
429static inline int
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800430remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800431{
Thomas Gleixner303e9672007-02-16 01:27:51 -0800432 if (hrtimer_is_queued(timer)) {
433 __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800434 return 1;
435 }
436 return 0;
437}
438
439/**
440 * hrtimer_start - (re)start an relative timer on the current CPU
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800441 * @timer: the timer to be added
442 * @tim: expiry time
443 * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)
444 *
445 * Returns:
446 * 0 on success
447 * 1 when the timer was active
448 */
449int
450hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
451{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800452 struct hrtimer_clock_base *base, *new_base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800453 unsigned long flags;
454 int ret;
455
456 base = lock_hrtimer_base(timer, &flags);
457
458 /* Remove an active timer from the queue: */
459 ret = remove_hrtimer(timer, base);
460
461 /* Switch the timer base, if necessary: */
462 new_base = switch_hrtimer_base(timer, base);
463
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800464 if (mode == HRTIMER_MODE_REL) {
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800465 tim = ktime_add(tim, new_base->get_time());
Ingo Molnar06027bd2006-02-14 13:53:15 -0800466 /*
467 * CONFIG_TIME_LOW_RES is a temporary way for architectures
468 * to signal that they simply return xtime in
469 * do_gettimeoffset(). In this case we want to round up by
470 * resolution when starting a relative timer, to avoid short
471 * timeouts. This will go away with the GTOD framework.
472 */
473#ifdef CONFIG_TIME_LOW_RES
474 tim = ktime_add(tim, base->resolution);
475#endif
476 }
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800477 timer->expires = tim;
478
479 enqueue_hrtimer(timer, new_base);
480
481 unlock_hrtimer_base(timer, &flags);
482
483 return ret;
484}
Stephen Hemminger8d16b762006-05-30 21:26:09 -0700485EXPORT_SYMBOL_GPL(hrtimer_start);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800486
487/**
488 * hrtimer_try_to_cancel - try to deactivate a timer
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800489 * @timer: hrtimer to stop
490 *
491 * Returns:
492 * 0 when the timer was not active
493 * 1 when the timer was active
494 * -1 when the timer is currently excuting the callback function and
Randy Dunlapfa9799e2006-06-25 05:49:15 -0700495 * cannot be stopped
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800496 */
497int hrtimer_try_to_cancel(struct hrtimer *timer)
498{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800499 struct hrtimer_clock_base *base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800500 unsigned long flags;
501 int ret = -1;
502
503 base = lock_hrtimer_base(timer, &flags);
504
Thomas Gleixner303e9672007-02-16 01:27:51 -0800505 if (!hrtimer_callback_running(timer))
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800506 ret = remove_hrtimer(timer, base);
507
508 unlock_hrtimer_base(timer, &flags);
509
510 return ret;
511
512}
Stephen Hemminger8d16b762006-05-30 21:26:09 -0700513EXPORT_SYMBOL_GPL(hrtimer_try_to_cancel);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800514
515/**
516 * hrtimer_cancel - cancel a timer and wait for the handler to finish.
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800517 * @timer: the timer to be cancelled
518 *
519 * Returns:
520 * 0 when the timer was not active
521 * 1 when the timer was active
522 */
523int hrtimer_cancel(struct hrtimer *timer)
524{
525 for (;;) {
526 int ret = hrtimer_try_to_cancel(timer);
527
528 if (ret >= 0)
529 return ret;
Joe Korty5ef37b12006-04-10 22:54:13 -0700530 cpu_relax();
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800531 }
532}
Stephen Hemminger8d16b762006-05-30 21:26:09 -0700533EXPORT_SYMBOL_GPL(hrtimer_cancel);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800534
535/**
536 * hrtimer_get_remaining - get remaining time for the timer
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800537 * @timer: the timer to read
538 */
539ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
540{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800541 struct hrtimer_clock_base *base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800542 unsigned long flags;
543 ktime_t rem;
544
545 base = lock_hrtimer_base(timer, &flags);
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800546 rem = ktime_sub(timer->expires, base->get_time());
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800547 unlock_hrtimer_base(timer, &flags);
548
549 return rem;
550}
Stephen Hemminger8d16b762006-05-30 21:26:09 -0700551EXPORT_SYMBOL_GPL(hrtimer_get_remaining);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800552
Thomas Gleixnerfd064b92007-02-16 01:27:47 -0800553#if defined(CONFIG_NO_IDLE_HZ) || defined(CONFIG_NO_HZ)
Tony Lindgren69239742006-03-06 15:42:45 -0800554/**
555 * hrtimer_get_next_event - get the time until next expiry event
556 *
557 * Returns the delta to the next expiry event or KTIME_MAX if no timer
558 * is pending.
559 */
560ktime_t hrtimer_get_next_event(void)
561{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800562 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
563 struct hrtimer_clock_base *base = cpu_base->clock_base;
Tony Lindgren69239742006-03-06 15:42:45 -0800564 ktime_t delta, mindelta = { .tv64 = KTIME_MAX };
565 unsigned long flags;
566 int i;
567
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800568 spin_lock_irqsave(&cpu_base->lock, flags);
569
570 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
Tony Lindgren69239742006-03-06 15:42:45 -0800571 struct hrtimer *timer;
572
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800573 if (!base->first)
Tony Lindgren69239742006-03-06 15:42:45 -0800574 continue;
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800575
Tony Lindgren69239742006-03-06 15:42:45 -0800576 timer = rb_entry(base->first, struct hrtimer, node);
577 delta.tv64 = timer->expires.tv64;
Tony Lindgren69239742006-03-06 15:42:45 -0800578 delta = ktime_sub(delta, base->get_time());
579 if (delta.tv64 < mindelta.tv64)
580 mindelta.tv64 = delta.tv64;
581 }
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800582
583 spin_unlock_irqrestore(&cpu_base->lock, flags);
584
Tony Lindgren69239742006-03-06 15:42:45 -0800585 if (mindelta.tv64 < 0)
586 mindelta.tv64 = 0;
587 return mindelta;
588}
589#endif
590
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800591/**
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800592 * hrtimer_init - initialize a timer to the given clock
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800593 * @timer: the timer to be initialized
594 * @clock_id: the clock to be used
George Anzinger7978672c2006-02-01 03:05:11 -0800595 * @mode: timer mode abs/rel
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800596 */
George Anzinger7978672c2006-02-01 03:05:11 -0800597void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
598 enum hrtimer_mode mode)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800599{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800600 struct hrtimer_cpu_base *cpu_base;
George Anzinger7978672c2006-02-01 03:05:11 -0800601
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800602 memset(timer, 0, sizeof(struct hrtimer));
George Anzinger7978672c2006-02-01 03:05:11 -0800603
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800604 cpu_base = &__raw_get_cpu_var(hrtimer_bases);
George Anzinger7978672c2006-02-01 03:05:11 -0800605
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800606 if (clock_id == CLOCK_REALTIME && mode != HRTIMER_MODE_ABS)
George Anzinger7978672c2006-02-01 03:05:11 -0800607 clock_id = CLOCK_MONOTONIC;
608
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800609 timer->base = &cpu_base->clock_base[clock_id];
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800610}
Stephen Hemminger8d16b762006-05-30 21:26:09 -0700611EXPORT_SYMBOL_GPL(hrtimer_init);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800612
613/**
614 * hrtimer_get_res - get the timer resolution for a clock
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800615 * @which_clock: which clock to query
616 * @tp: pointer to timespec variable to store the resolution
617 *
Robert P. J. Day72fd4a32007-02-10 01:45:59 -0800618 * Store the resolution of the clock selected by @which_clock in the
619 * variable pointed to by @tp.
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800620 */
621int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
622{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800623 struct hrtimer_cpu_base *cpu_base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800624
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800625 cpu_base = &__raw_get_cpu_var(hrtimer_bases);
626 *tp = ktime_to_timespec(cpu_base->clock_base[which_clock].resolution);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800627
628 return 0;
629}
Stephen Hemminger8d16b762006-05-30 21:26:09 -0700630EXPORT_SYMBOL_GPL(hrtimer_get_res);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800631
632/*
633 * Expire the per base hrtimer-queue:
634 */
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800635static inline void run_hrtimer_queue(struct hrtimer_cpu_base *cpu_base,
636 int index)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800637{
Thomas Gleixner288867e2006-01-12 11:25:54 +0100638 struct rb_node *node;
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800639 struct hrtimer_clock_base *base = &cpu_base->clock_base[index];
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800640
Dimitri Sivanich3055add2006-03-31 02:31:20 -0800641 if (!base->first)
642 return;
643
Thomas Gleixner92127c72006-03-26 01:38:05 -0800644 if (base->get_softirq_time)
645 base->softirq_time = base->get_softirq_time();
646
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800647 spin_lock_irq(&cpu_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800648
Thomas Gleixner288867e2006-01-12 11:25:54 +0100649 while ((node = base->first)) {
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800650 struct hrtimer *timer;
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800651 enum hrtimer_restart (*fn)(struct hrtimer *);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800652 int restart;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800653
Thomas Gleixner288867e2006-01-12 11:25:54 +0100654 timer = rb_entry(node, struct hrtimer, node);
Thomas Gleixner92127c72006-03-26 01:38:05 -0800655 if (base->softirq_time.tv64 <= timer->expires.tv64)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800656 break;
657
658 fn = timer->function;
Thomas Gleixner303e9672007-02-16 01:27:51 -0800659 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK);
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800660 spin_unlock_irq(&cpu_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800661
Roman Zippel05cfb612006-03-26 01:38:12 -0800662 restart = fn(timer);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800663
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800664 spin_lock_irq(&cpu_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800665
Thomas Gleixner303e9672007-02-16 01:27:51 -0800666 timer->state &= ~HRTIMER_STATE_CALLBACK;
Roman Zippelb75f7a52006-03-26 01:38:09 -0800667 if (restart != HRTIMER_NORESTART) {
668 BUG_ON(hrtimer_active(timer));
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800669 enqueue_hrtimer(timer, base);
Roman Zippelb75f7a52006-03-26 01:38:09 -0800670 }
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800671 }
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800672 spin_unlock_irq(&cpu_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800673}
674
675/*
676 * Called from timer softirq every jiffy, expire hrtimers:
677 */
678void hrtimer_run_queues(void)
679{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800680 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800681 int i;
682
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800683 /*
684 * This _is_ ugly: We have to check in the softirq context,
685 * whether we can switch to highres and / or nohz mode. The
686 * clocksource switch happens in the timer interrupt with
687 * xtime_lock held. Notification from there only sets the
688 * check bit in the tick_oneshot code, otherwise we might
689 * deadlock vs. xtime_lock.
690 */
691 tick_check_oneshot_change(1);
692
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800693 hrtimer_get_softirq_time(cpu_base);
Thomas Gleixner92127c72006-03-26 01:38:05 -0800694
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800695 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
696 run_hrtimer_queue(cpu_base, i);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800697}
698
699/*
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800700 * Sleep related functions:
701 */
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800702static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
Thomas Gleixner00362e32006-03-31 02:31:17 -0800703{
704 struct hrtimer_sleeper *t =
705 container_of(timer, struct hrtimer_sleeper, timer);
706 struct task_struct *task = t->task;
707
708 t->task = NULL;
709 if (task)
710 wake_up_process(task);
711
712 return HRTIMER_NORESTART;
713}
714
Ingo Molnar36c8b582006-07-03 00:25:41 -0700715void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
Thomas Gleixner00362e32006-03-31 02:31:17 -0800716{
717 sl->timer.function = hrtimer_wakeup;
718 sl->task = task;
719}
720
Thomas Gleixner669d7862006-03-31 02:31:19 -0800721static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800722{
Thomas Gleixner669d7862006-03-31 02:31:19 -0800723 hrtimer_init_sleeper(t, current);
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800724
Roman Zippel432569b2006-03-26 01:38:08 -0800725 do {
726 set_current_state(TASK_INTERRUPTIBLE);
727 hrtimer_start(&t->timer, t->timer.expires, mode);
728
729 schedule();
730
Thomas Gleixner669d7862006-03-31 02:31:19 -0800731 hrtimer_cancel(&t->timer);
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800732 mode = HRTIMER_MODE_ABS;
Roman Zippel432569b2006-03-26 01:38:08 -0800733
Thomas Gleixner669d7862006-03-31 02:31:19 -0800734 } while (t->task && !signal_pending(current));
735
736 return t->task == NULL;
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800737}
738
Toyo Abe1711ef32006-09-29 02:00:28 -0700739long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800740{
Thomas Gleixner669d7862006-03-31 02:31:19 -0800741 struct hrtimer_sleeper t;
Ingo Molnarea13dbc2006-01-16 10:59:41 +0100742 struct timespec __user *rmtp;
743 struct timespec tu;
Roman Zippel432569b2006-03-26 01:38:08 -0800744 ktime_t time;
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800745
746 restart->fn = do_no_restart_syscall;
747
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800748 hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS);
Toyo Abe1711ef32006-09-29 02:00:28 -0700749 t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2;
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800750
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800751 if (do_nanosleep(&t, HRTIMER_MODE_ABS))
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800752 return 0;
753
Toyo Abe1711ef32006-09-29 02:00:28 -0700754 rmtp = (struct timespec __user *) restart->arg1;
Roman Zippel432569b2006-03-26 01:38:08 -0800755 if (rmtp) {
756 time = ktime_sub(t.timer.expires, t.timer.base->get_time());
757 if (time.tv64 <= 0)
758 return 0;
759 tu = ktime_to_timespec(time);
760 if (copy_to_user(rmtp, &tu, sizeof(tu)))
761 return -EFAULT;
762 }
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800763
Toyo Abe1711ef32006-09-29 02:00:28 -0700764 restart->fn = hrtimer_nanosleep_restart;
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800765
766 /* The other values in restart are already filled in */
767 return -ERESTART_RESTARTBLOCK;
768}
769
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800770long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
771 const enum hrtimer_mode mode, const clockid_t clockid)
772{
773 struct restart_block *restart;
Thomas Gleixner669d7862006-03-31 02:31:19 -0800774 struct hrtimer_sleeper t;
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800775 struct timespec tu;
776 ktime_t rem;
777
Roman Zippel432569b2006-03-26 01:38:08 -0800778 hrtimer_init(&t.timer, clockid, mode);
779 t.timer.expires = timespec_to_ktime(*rqtp);
780 if (do_nanosleep(&t, mode))
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800781 return 0;
782
George Anzinger7978672c2006-02-01 03:05:11 -0800783 /* Absolute timers do not update the rmtp value and restart: */
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800784 if (mode == HRTIMER_MODE_ABS)
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800785 return -ERESTARTNOHAND;
786
Roman Zippel432569b2006-03-26 01:38:08 -0800787 if (rmtp) {
788 rem = ktime_sub(t.timer.expires, t.timer.base->get_time());
789 if (rem.tv64 <= 0)
790 return 0;
791 tu = ktime_to_timespec(rem);
792 if (copy_to_user(rmtp, &tu, sizeof(tu)))
793 return -EFAULT;
794 }
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800795
796 restart = &current_thread_info()->restart_block;
Toyo Abe1711ef32006-09-29 02:00:28 -0700797 restart->fn = hrtimer_nanosleep_restart;
798 restart->arg0 = (unsigned long) t.timer.base->index;
799 restart->arg1 = (unsigned long) rmtp;
800 restart->arg2 = t.timer.expires.tv64 & 0xFFFFFFFF;
801 restart->arg3 = t.timer.expires.tv64 >> 32;
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800802
803 return -ERESTART_RESTARTBLOCK;
804}
805
Thomas Gleixner6ba1b912006-01-09 20:52:36 -0800806asmlinkage long
807sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
808{
809 struct timespec tu;
810
811 if (copy_from_user(&tu, rqtp, sizeof(tu)))
812 return -EFAULT;
813
814 if (!timespec_valid(&tu))
815 return -EINVAL;
816
Thomas Gleixnerc9cb2e32007-02-16 01:27:49 -0800817 return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
Thomas Gleixner6ba1b912006-01-09 20:52:36 -0800818}
819
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800820/*
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800821 * Functions related to boot-time initialization:
822 */
823static void __devinit init_hrtimers_cpu(int cpu)
824{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800825 struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800826 int i;
827
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800828 spin_lock_init(&cpu_base->lock);
829 lockdep_set_class(&cpu_base->lock, &cpu_base->lock_key);
830
831 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
832 cpu_base->clock_base[i].cpu_base = cpu_base;
833
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800834}
835
836#ifdef CONFIG_HOTPLUG_CPU
837
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800838static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
839 struct hrtimer_clock_base *new_base)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800840{
841 struct hrtimer *timer;
842 struct rb_node *node;
843
844 while ((node = rb_first(&old_base->active))) {
845 timer = rb_entry(node, struct hrtimer, node);
Thomas Gleixner303e9672007-02-16 01:27:51 -0800846 BUG_ON(timer->state & HRTIMER_STATE_CALLBACK);
847 __remove_hrtimer(timer, old_base, HRTIMER_STATE_INACTIVE);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800848 timer->base = new_base;
849 enqueue_hrtimer(timer, new_base);
850 }
851}
852
853static void migrate_hrtimers(int cpu)
854{
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800855 struct hrtimer_cpu_base *old_base, *new_base;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800856 int i;
857
858 BUG_ON(cpu_online(cpu));
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800859 old_base = &per_cpu(hrtimer_bases, cpu);
860 new_base = &get_cpu_var(hrtimer_bases);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800861
862 local_irq_disable();
863
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800864 spin_lock(&new_base->lock);
865 spin_lock(&old_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800866
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800867 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800868 migrate_hrtimer_list(&old_base->clock_base[i],
869 &new_base->clock_base[i]);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800870 }
Thomas Gleixner3c8aa392007-02-16 01:27:50 -0800871 spin_unlock(&old_base->lock);
872 spin_unlock(&new_base->lock);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800873
874 local_irq_enable();
875 put_cpu_var(hrtimer_bases);
876}
877#endif /* CONFIG_HOTPLUG_CPU */
878
Chandra Seetharaman8c78f302006-07-30 03:03:35 -0700879static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800880 unsigned long action, void *hcpu)
881{
882 long cpu = (long)hcpu;
883
884 switch (action) {
885
886 case CPU_UP_PREPARE:
887 init_hrtimers_cpu(cpu);
888 break;
889
890#ifdef CONFIG_HOTPLUG_CPU
891 case CPU_DEAD:
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800892 clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &cpu);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800893 migrate_hrtimers(cpu);
894 break;
895#endif
896
897 default:
898 break;
899 }
900
901 return NOTIFY_OK;
902}
903
Chandra Seetharaman8c78f302006-07-30 03:03:35 -0700904static struct notifier_block __cpuinitdata hrtimers_nb = {
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800905 .notifier_call = hrtimer_cpu_notify,
906};
907
908void __init hrtimers_init(void)
909{
910 hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
911 (void *)(long)smp_processor_id());
912 register_cpu_notifier(&hrtimers_nb);
913}
914