aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/hrtimer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/hrtimer.h')
-rw-r--r--include/linux/hrtimer.h152
1 files changed, 104 insertions, 48 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 2f245fe63bd..bd37078c2d7 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -20,6 +20,8 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/wait.h> 22#include <linux/wait.h>
23#include <linux/percpu.h>
24
23 25
24struct hrtimer_clock_base; 26struct hrtimer_clock_base;
25struct hrtimer_cpu_base; 27struct hrtimer_cpu_base;
@@ -41,31 +43,6 @@ enum hrtimer_restart {
41}; 43};
42 44
43/* 45/*
44 * hrtimer callback modes:
45 *
46 * HRTIMER_CB_SOFTIRQ: Callback must run in softirq context
47 * HRTIMER_CB_IRQSAFE: Callback may run in hardirq context
48 * HRTIMER_CB_IRQSAFE_NO_RESTART: Callback may run in hardirq context and
49 * does not restart the timer
50 * HRTIMER_CB_IRQSAFE_PERCPU: Callback must run in hardirq context
51 * Special mode for tick emulation and
52 * scheduler timer. Such timers are per
53 * cpu and not allowed to be migrated on
54 * cpu unplug.
55 * HRTIMER_CB_IRQSAFE_UNLOCKED: Callback should run in hardirq context
56 * with timer->base lock unlocked
57 * used for timers which call wakeup to
58 * avoid lock order problems with rq->lock
59 */
60enum hrtimer_cb_mode {
61 HRTIMER_CB_SOFTIRQ,
62 HRTIMER_CB_IRQSAFE,
63 HRTIMER_CB_IRQSAFE_NO_RESTART,
64 HRTIMER_CB_IRQSAFE_PERCPU,
65 HRTIMER_CB_IRQSAFE_UNLOCKED,
66};
67
68/*
69 * Values to track state of the timer 46 * Values to track state of the timer
70 * 47 *
71 * Possible states: 48 * Possible states:
@@ -73,7 +50,6 @@ enum hrtimer_cb_mode {
73 * 0x00 inactive 50 * 0x00 inactive
74 * 0x01 enqueued into rbtree 51 * 0x01 enqueued into rbtree
75 * 0x02 callback function running 52 * 0x02 callback function running
76 * 0x04 callback pending (high resolution mode)
77 * 53 *
78 * Special cases: 54 * Special cases:
79 * 0x03 callback function running and enqueued 55 * 0x03 callback function running and enqueued
@@ -95,20 +71,22 @@ enum hrtimer_cb_mode {
95#define HRTIMER_STATE_INACTIVE 0x00 71#define HRTIMER_STATE_INACTIVE 0x00
96#define HRTIMER_STATE_ENQUEUED 0x01 72#define HRTIMER_STATE_ENQUEUED 0x01
97#define HRTIMER_STATE_CALLBACK 0x02 73#define HRTIMER_STATE_CALLBACK 0x02
98#define HRTIMER_STATE_PENDING 0x04 74#define HRTIMER_STATE_MIGRATE 0x04
99#define HRTIMER_STATE_MIGRATE 0x08
100 75
101/** 76/**
102 * struct hrtimer - the basic hrtimer structure 77 * struct hrtimer - the basic hrtimer structure
103 * @node: red black tree node for time ordered insertion 78 * @node: red black tree node for time ordered insertion
104 * @expires: the absolute expiry time in the hrtimers internal 79 * @_expires: the absolute expiry time in the hrtimers internal
105 * representation. The time is related to the clock on 80 * representation. The time is related to the clock on
106 * which the timer is based. 81 * which the timer is based. Is setup by adding
82 * slack to the _softexpires value. For non range timers
83 * identical to _softexpires.
84 * @_softexpires: the absolute earliest expiry time of the hrtimer.
85 * The time which was given as expiry time when the timer
86 * was armed.
107 * @function: timer expiry callback function 87 * @function: timer expiry callback function
108 * @base: pointer to the timer base (per cpu and per clock) 88 * @base: pointer to the timer base (per cpu and per clock)
109 * @state: state information (See bit values above) 89 * @state: state information (See bit values above)
110 * @cb_mode: high resolution timer feature to select the callback execution
111 * mode
112 * @cb_entry: list head to enqueue an expired timer into the callback list 90 * @cb_entry: list head to enqueue an expired timer into the callback list
113 * @start_site: timer statistics field to store the site where the timer 91 * @start_site: timer statistics field to store the site where the timer
114 * was started 92 * was started
@@ -121,16 +99,16 @@ enum hrtimer_cb_mode {
121 */ 99 */
122struct hrtimer { 100struct hrtimer {
123 struct rb_node node; 101 struct rb_node node;
124 ktime_t expires; 102 ktime_t _expires;
103 ktime_t _softexpires;
125 enum hrtimer_restart (*function)(struct hrtimer *); 104 enum hrtimer_restart (*function)(struct hrtimer *);
126 struct hrtimer_clock_base *base; 105 struct hrtimer_clock_base *base;
127 unsigned long state; 106 unsigned long state;
128 enum hrtimer_cb_mode cb_mode;
129 struct list_head cb_entry; 107 struct list_head cb_entry;
130#ifdef CONFIG_TIMER_STATS 108#ifdef CONFIG_TIMER_STATS
109 int start_pid;
131 void *start_site; 110 void *start_site;
132 char start_comm[16]; 111 char start_comm[16];
133 int start_pid;
134#endif 112#endif
135}; 113};
136 114
@@ -155,10 +133,8 @@ struct hrtimer_sleeper {
155 * @first: pointer to the timer node which expires first 133 * @first: pointer to the timer node which expires first
156 * @resolution: the resolution of the clock, in nanoseconds 134 * @resolution: the resolution of the clock, in nanoseconds
157 * @get_time: function to retrieve the current time of the clock 135 * @get_time: function to retrieve the current time of the clock
158 * @get_softirq_time: function to retrieve the current time from the softirq
159 * @softirq_time: the time when running the hrtimer queue in the softirq 136 * @softirq_time: the time when running the hrtimer queue in the softirq
160 * @offset: offset of this clock to the monotonic base 137 * @offset: offset of this clock to the monotonic base
161 * @reprogram: function to reprogram the timer event
162 */ 138 */
163struct hrtimer_clock_base { 139struct hrtimer_clock_base {
164 struct hrtimer_cpu_base *cpu_base; 140 struct hrtimer_cpu_base *cpu_base;
@@ -167,13 +143,9 @@ struct hrtimer_clock_base {
167 struct rb_node *first; 143 struct rb_node *first;
168 ktime_t resolution; 144 ktime_t resolution;
169 ktime_t (*get_time)(void); 145 ktime_t (*get_time)(void);
170 ktime_t (*get_softirq_time)(void);
171 ktime_t softirq_time; 146 ktime_t softirq_time;
172#ifdef CONFIG_HIGH_RES_TIMERS 147#ifdef CONFIG_HIGH_RES_TIMERS
173 ktime_t offset; 148 ktime_t offset;
174 int (*reprogram)(struct hrtimer *t,
175 struct hrtimer_clock_base *b,
176 ktime_t n);
177#endif 149#endif
178}; 150};
179 151
@@ -191,15 +163,11 @@ struct hrtimer_clock_base {
191 * @check_clocks: Indictator, when set evaluate time source and clock 163 * @check_clocks: Indictator, when set evaluate time source and clock
192 * event devices whether high resolution mode can be 164 * event devices whether high resolution mode can be
193 * activated. 165 * activated.
194 * @cb_pending: Expired timers are moved from the rbtree to this
195 * list in the timer interrupt. The list is processed
196 * in the softirq.
197 * @nr_events: Total number of timer interrupt events 166 * @nr_events: Total number of timer interrupt events
198 */ 167 */
199struct hrtimer_cpu_base { 168struct hrtimer_cpu_base {
200 spinlock_t lock; 169 spinlock_t lock;
201 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES]; 170 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
202 struct list_head cb_pending;
203#ifdef CONFIG_HIGH_RES_TIMERS 171#ifdef CONFIG_HIGH_RES_TIMERS
204 ktime_t expires_next; 172 ktime_t expires_next;
205 int hres_active; 173 int hres_active;
@@ -207,6 +175,71 @@ struct hrtimer_cpu_base {
207#endif 175#endif
208}; 176};
209 177
178static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time)
179{
180 timer->_expires = time;
181 timer->_softexpires = time;
182}
183
184static inline void hrtimer_set_expires_range(struct hrtimer *timer, ktime_t time, ktime_t delta)
185{
186 timer->_softexpires = time;
187 timer->_expires = ktime_add_safe(time, delta);
188}
189
190static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t time, unsigned long delta)
191{
192 timer->_softexpires = time;
193 timer->_expires = ktime_add_safe(time, ns_to_ktime(delta));
194}
195
196static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64)
197{
198 timer->_expires.tv64 = tv64;
199 timer->_softexpires.tv64 = tv64;
200}
201
202static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time)
203{
204 timer->_expires = ktime_add_safe(timer->_expires, time);
205 timer->_softexpires = ktime_add_safe(timer->_softexpires, time);
206}
207
208static inline void hrtimer_add_expires_ns(struct hrtimer *timer, u64 ns)
209{
210 timer->_expires = ktime_add_ns(timer->_expires, ns);
211 timer->_softexpires = ktime_add_ns(timer->_softexpires, ns);
212}
213
214static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer)
215{
216 return timer->_expires;
217}
218
219static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer)
220{
221 return timer->_softexpires;
222}
223
224static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer)
225{
226 return timer->_expires.tv64;
227}
228static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer)
229{
230 return timer->_softexpires.tv64;
231}
232
233static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer)
234{
235 return ktime_to_ns(timer->_expires);
236}
237
238static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer)
239{
240 return ktime_sub(timer->_expires, timer->base->get_time());
241}
242
210#ifdef CONFIG_HIGH_RES_TIMERS 243#ifdef CONFIG_HIGH_RES_TIMERS
211struct clock_event_device; 244struct clock_event_device;
212 245
@@ -227,6 +260,8 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
227 return timer->base->cpu_base->hres_active; 260 return timer->base->cpu_base->hres_active;
228} 261}
229 262
263extern void hrtimer_peek_ahead_timers(void);
264
230/* 265/*
231 * The resolution of the clocks. The resolution value is returned in 266 * The resolution of the clocks. The resolution value is returned in
232 * the clock_getres() system call to give application programmers an 267 * the clock_getres() system call to give application programmers an
@@ -249,6 +284,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
249 * is expired in the next softirq when the clock was advanced. 284 * is expired in the next softirq when the clock was advanced.
250 */ 285 */
251static inline void clock_was_set(void) { } 286static inline void clock_was_set(void) { }
287static inline void hrtimer_peek_ahead_timers(void) { }
252 288
253static inline void hres_timers_resume(void) { } 289static inline void hres_timers_resume(void) { }
254 290
@@ -270,6 +306,10 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
270extern ktime_t ktime_get(void); 306extern ktime_t ktime_get(void);
271extern ktime_t ktime_get_real(void); 307extern ktime_t ktime_get_real(void);
272 308
309
310DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
311
312
273/* Exported timer functions: */ 313/* Exported timer functions: */
274 314
275/* Initialize timers: */ 315/* Initialize timers: */
@@ -294,12 +334,25 @@ static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
294/* Basic timer operations: */ 334/* Basic timer operations: */
295extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, 335extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
296 const enum hrtimer_mode mode); 336 const enum hrtimer_mode mode);
337extern int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
338 unsigned long range_ns, const enum hrtimer_mode mode);
297extern int hrtimer_cancel(struct hrtimer *timer); 339extern int hrtimer_cancel(struct hrtimer *timer);
298extern int hrtimer_try_to_cancel(struct hrtimer *timer); 340extern int hrtimer_try_to_cancel(struct hrtimer *timer);
299 341
342static inline int hrtimer_start_expires(struct hrtimer *timer,
343 enum hrtimer_mode mode)
344{
345 unsigned long delta;
346 ktime_t soft, hard;
347 soft = hrtimer_get_softexpires(timer);
348 hard = hrtimer_get_expires(timer);
349 delta = ktime_to_ns(ktime_sub(hard, soft));
350 return hrtimer_start_range_ns(timer, soft, delta, mode);
351}
352
300static inline int hrtimer_restart(struct hrtimer *timer) 353static inline int hrtimer_restart(struct hrtimer *timer)
301{ 354{
302 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS); 355 return hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
303} 356}
304 357
305/* Query timers: */ 358/* Query timers: */
@@ -322,8 +375,7 @@ static inline int hrtimer_active(const struct hrtimer *timer)
322 */ 375 */
323static inline int hrtimer_is_queued(struct hrtimer *timer) 376static inline int hrtimer_is_queued(struct hrtimer *timer)
324{ 377{
325 return timer->state & 378 return timer->state & HRTIMER_STATE_ENQUEUED;
326 (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
327} 379}
328 380
329/* 381/*
@@ -356,6 +408,10 @@ extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
356extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, 408extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
357 struct task_struct *tsk); 409 struct task_struct *tsk);
358 410
411extern int schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
412 const enum hrtimer_mode mode);
413extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode);
414
359/* Soft interrupt function to run the hrtimer queues: */ 415/* Soft interrupt function to run the hrtimer queues: */
360extern void hrtimer_run_queues(void); 416extern void hrtimer_run_queues(void);
361extern void hrtimer_run_pending(void); 417extern void hrtimer_run_pending(void);