Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * include/linux/hrtimer.h |
| 3 | * |
| 4 | * hrtimers - High-resolution kernel timers |
| 5 | * |
| 6 | * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de> |
| 7 | * Copyright(C) 2005, Red Hat, Inc., Ingo Molnar |
| 8 | * |
| 9 | * data type definitions, declarations, prototypes |
| 10 | * |
| 11 | * Started by: Thomas Gleixner and Ingo Molnar |
| 12 | * |
| 13 | * For licencing details see kernel-base/COPYING |
| 14 | */ |
| 15 | #ifndef _LINUX_HRTIMER_H |
| 16 | #define _LINUX_HRTIMER_H |
| 17 | |
| 18 | #include <linux/rbtree.h> |
| 19 | #include <linux/ktime.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/wait.h> |
| 23 | |
| 24 | /* |
| 25 | * Mode arguments of xxx_hrtimer functions: |
| 26 | */ |
| 27 | enum hrtimer_mode { |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame^] | 28 | HRTIMER_MODE_ABS, /* Time value is absolute */ |
| 29 | HRTIMER_MODE_REL, /* Time value is relative to now */ |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 30 | }; |
| 31 | |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame^] | 32 | /* |
| 33 | * Return values for the callback function |
| 34 | */ |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 35 | enum hrtimer_restart { |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame^] | 36 | HRTIMER_NORESTART, /* Timer is not restarted */ |
| 37 | HRTIMER_RESTART, /* Timer must be restarted */ |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 40 | struct hrtimer_base; |
| 41 | |
| 42 | /** |
| 43 | * struct hrtimer - the basic hrtimer structure |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 44 | * @node: red black tree node for time ordered insertion |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 45 | * @expires: the absolute expiry time in the hrtimers internal |
| 46 | * representation. The time is related to the clock on |
| 47 | * which the timer is based. |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 48 | * @function: timer expiry callback function |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 49 | * @base: pointer to the timer base (per cpu and per clock) |
| 50 | * |
| 51 | * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE() |
| 52 | */ |
| 53 | struct hrtimer { |
| 54 | struct rb_node node; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 55 | ktime_t expires; |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame^] | 56 | enum hrtimer_restart (*function)(struct hrtimer *); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 57 | struct hrtimer_base *base; |
| 58 | }; |
| 59 | |
| 60 | /** |
Thomas Gleixner | 00362e3 | 2006-03-31 02:31:17 -0800 | [diff] [blame] | 61 | * struct hrtimer_sleeper - simple sleeper structure |
Thomas Gleixner | 00362e3 | 2006-03-31 02:31:17 -0800 | [diff] [blame] | 62 | * @timer: embedded timer structure |
| 63 | * @task: task to wake up |
| 64 | * |
| 65 | * task is set to NULL, when the timer expires. |
| 66 | */ |
| 67 | struct hrtimer_sleeper { |
| 68 | struct hrtimer timer; |
| 69 | struct task_struct *task; |
| 70 | }; |
| 71 | |
| 72 | /** |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 73 | * struct hrtimer_base - the timer base for a specific clock |
Thomas Gleixner | 92127c7 | 2006-03-26 01:38:05 -0800 | [diff] [blame] | 74 | * @index: clock type index for per_cpu support when moving a timer |
| 75 | * to a base on another cpu. |
| 76 | * @lock: lock protecting the base and associated timers |
| 77 | * @active: red black tree root node for the active timers |
| 78 | * @first: pointer to the timer node which expires first |
| 79 | * @resolution: the resolution of the clock, in nanoseconds |
| 80 | * @get_time: function to retrieve the current time of the clock |
Martin Waitz | a580290 | 2006-04-02 13:59:55 +0200 | [diff] [blame] | 81 | * @get_softirq_time: function to retrieve the current time from the softirq |
Thomas Gleixner | 92127c7 | 2006-03-26 01:38:05 -0800 | [diff] [blame] | 82 | * @curr_timer: the timer which is executing a callback right now |
| 83 | * @softirq_time: the time when running the hrtimer queue in the softirq |
Henrik Kretzschmar | 6dba283 | 2006-09-06 00:03:40 -0700 | [diff] [blame] | 84 | * @lock_key: the lock_class_key for use with lockdep |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 85 | */ |
| 86 | struct hrtimer_base { |
| 87 | clockid_t index; |
| 88 | spinlock_t lock; |
| 89 | struct rb_root active; |
Thomas Gleixner | 288867e | 2006-01-12 11:25:54 +0100 | [diff] [blame] | 90 | struct rb_node *first; |
Thomas Gleixner | e278763 | 2006-01-12 11:36:14 +0100 | [diff] [blame] | 91 | ktime_t resolution; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 92 | ktime_t (*get_time)(void); |
Thomas Gleixner | 92127c7 | 2006-03-26 01:38:05 -0800 | [diff] [blame] | 93 | ktime_t (*get_softirq_time)(void); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 94 | struct hrtimer *curr_timer; |
Thomas Gleixner | 92127c7 | 2006-03-26 01:38:05 -0800 | [diff] [blame] | 95 | ktime_t softirq_time; |
Ingo Molnar | 5436552 | 2006-07-03 00:25:11 -0700 | [diff] [blame] | 96 | struct lock_class_key lock_key; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Thomas Gleixner | becf8b5 | 2006-01-09 20:52:38 -0800 | [diff] [blame] | 99 | /* |
| 100 | * clock_was_set() is a NOP for non- high-resolution systems. The |
| 101 | * time-sorted order guarantees that a timer does not expire early and |
| 102 | * is expired in the next softirq when the clock was advanced. |
| 103 | */ |
| 104 | #define clock_was_set() do { } while (0) |
| 105 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 106 | /* Exported timer functions: */ |
| 107 | |
| 108 | /* Initialize timers: */ |
George Anzinger | 7978672c | 2006-02-01 03:05:11 -0800 | [diff] [blame] | 109 | extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, |
| 110 | enum hrtimer_mode mode); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 111 | |
| 112 | /* Basic timer operations: */ |
| 113 | extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, |
| 114 | const enum hrtimer_mode mode); |
| 115 | extern int hrtimer_cancel(struct hrtimer *timer); |
| 116 | extern int hrtimer_try_to_cancel(struct hrtimer *timer); |
| 117 | |
Thomas Gleixner | c9cb2e3 | 2007-02-16 01:27:49 -0800 | [diff] [blame^] | 118 | static inline int hrtimer_restart(struct hrtimer *timer) |
| 119 | { |
| 120 | return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS); |
| 121 | } |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 122 | |
| 123 | /* Query timers: */ |
| 124 | extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer); |
| 125 | extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp); |
| 126 | |
Tony Lindgren | 6923974 | 2006-03-06 15:42:45 -0800 | [diff] [blame] | 127 | #ifdef CONFIG_NO_IDLE_HZ |
| 128 | extern ktime_t hrtimer_get_next_event(void); |
| 129 | #endif |
| 130 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 131 | static inline int hrtimer_active(const struct hrtimer *timer) |
| 132 | { |
David Woodhouse | ed198cb | 2006-04-22 02:38:50 +0100 | [diff] [blame] | 133 | return rb_parent(&timer->node) != &timer->node; |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* Forward a hrtimer so it expires after now: */ |
Roman Zippel | 44f2147 | 2006-03-26 01:38:06 -0800 | [diff] [blame] | 137 | extern unsigned long |
| 138 | hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval); |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 139 | |
Thomas Gleixner | 10c94ec | 2006-01-09 20:52:35 -0800 | [diff] [blame] | 140 | /* Precise sleep: */ |
| 141 | extern long hrtimer_nanosleep(struct timespec *rqtp, |
| 142 | struct timespec __user *rmtp, |
| 143 | const enum hrtimer_mode mode, |
| 144 | const clockid_t clockid); |
Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 145 | extern long hrtimer_nanosleep_restart(struct restart_block *restart_block); |
Thomas Gleixner | 10c94ec | 2006-01-09 20:52:35 -0800 | [diff] [blame] | 146 | |
Thomas Gleixner | 00362e3 | 2006-03-31 02:31:17 -0800 | [diff] [blame] | 147 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, |
| 148 | struct task_struct *tsk); |
| 149 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 150 | /* Soft interrupt function to run the hrtimer queues: */ |
| 151 | extern void hrtimer_run_queues(void); |
| 152 | |
John Stultz | 411187f | 2007-02-16 01:27:30 -0800 | [diff] [blame] | 153 | /* Resume notification */ |
| 154 | void hrtimer_notify_resume(void); |
| 155 | |
Thomas Gleixner | c0a3132 | 2006-01-09 20:52:32 -0800 | [diff] [blame] | 156 | /* Bootup initialization: */ |
| 157 | extern void __init hrtimers_init(void); |
| 158 | |
| 159 | #endif |