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