]>
Commit | Line | Data |
---|---|---|
c0a31329 TG |
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 | ||
b75f7a51 | 37 | #define HRTIMER_INACTIVE ((void *)1UL) |
c0a31329 TG |
38 | |
39 | struct hrtimer_base; | |
40 | ||
41 | /** | |
42 | * struct hrtimer - the basic hrtimer structure | |
c0a31329 | 43 | * @node: red black tree node for time ordered insertion |
c0a31329 TG |
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. | |
c0a31329 | 47 | * @function: timer expiry callback function |
c0a31329 TG |
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; | |
c0a31329 | 54 | ktime_t expires; |
05cfb614 | 55 | int (*function)(struct hrtimer *); |
c0a31329 TG |
56 | struct hrtimer_base *base; |
57 | }; | |
58 | ||
00362e33 TG |
59 | /** |
60 | * struct hrtimer_sleeper - simple sleeper structure | |
00362e33 TG |
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 | ||
c0a31329 TG |
71 | /** |
72 | * struct hrtimer_base - the timer base for a specific clock | |
92127c7a TG |
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 | |
a580290c | 80 | * @get_softirq_time: function to retrieve the current time from the softirq |
92127c7a TG |
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 | |
c0a31329 TG |
83 | */ |
84 | struct hrtimer_base { | |
85 | clockid_t index; | |
86 | spinlock_t lock; | |
87 | struct rb_root active; | |
288867ec | 88 | struct rb_node *first; |
e2787630 | 89 | ktime_t resolution; |
c0a31329 | 90 | ktime_t (*get_time)(void); |
92127c7a | 91 | ktime_t (*get_softirq_time)(void); |
c0a31329 | 92 | struct hrtimer *curr_timer; |
92127c7a | 93 | ktime_t softirq_time; |
54365524 | 94 | struct lock_class_key lock_key; |
c0a31329 TG |
95 | }; |
96 | ||
becf8b5d TG |
97 | /* |
98 | * clock_was_set() is a NOP for non- high-resolution systems. The | |
99 | * time-sorted order guarantees that a timer does not expire early and | |
100 | * is expired in the next softirq when the clock was advanced. | |
101 | */ | |
102 | #define clock_was_set() do { } while (0) | |
103 | ||
c0a31329 TG |
104 | /* Exported timer functions: */ |
105 | ||
106 | /* Initialize timers: */ | |
7978672c GA |
107 | extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, |
108 | enum hrtimer_mode mode); | |
c0a31329 TG |
109 | |
110 | /* Basic timer operations: */ | |
111 | extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, | |
112 | const enum hrtimer_mode mode); | |
113 | extern int hrtimer_cancel(struct hrtimer *timer); | |
114 | extern int hrtimer_try_to_cancel(struct hrtimer *timer); | |
115 | ||
116 | #define hrtimer_restart(timer) hrtimer_start((timer), (timer)->expires, HRTIMER_ABS) | |
117 | ||
118 | /* Query timers: */ | |
119 | extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer); | |
120 | extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp); | |
121 | ||
69239749 TL |
122 | #ifdef CONFIG_NO_IDLE_HZ |
123 | extern ktime_t hrtimer_get_next_event(void); | |
124 | #endif | |
125 | ||
c0a31329 TG |
126 | static inline int hrtimer_active(const struct hrtimer *timer) |
127 | { | |
ed198cb4 | 128 | return rb_parent(&timer->node) != &timer->node; |
c0a31329 TG |
129 | } |
130 | ||
131 | /* Forward a hrtimer so it expires after now: */ | |
44f21475 RZ |
132 | extern unsigned long |
133 | hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval); | |
c0a31329 | 134 | |
10c94ec1 TG |
135 | /* Precise sleep: */ |
136 | extern long hrtimer_nanosleep(struct timespec *rqtp, | |
137 | struct timespec __user *rmtp, | |
138 | const enum hrtimer_mode mode, | |
139 | const clockid_t clockid); | |
140 | ||
00362e33 TG |
141 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, |
142 | struct task_struct *tsk); | |
143 | ||
c0a31329 TG |
144 | /* Soft interrupt function to run the hrtimer queues: */ |
145 | extern void hrtimer_run_queues(void); | |
146 | ||
147 | /* Bootup initialization: */ | |
148 | extern void __init hrtimers_init(void); | |
149 | ||
150 | #endif |