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.h138
1 files changed, 117 insertions, 21 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 6d93dce61cbb..3eba43878dcb 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;
@@ -44,17 +46,20 @@ enum hrtimer_restart {
44 * hrtimer callback modes: 46 * hrtimer callback modes:
45 * 47 *
46 * HRTIMER_CB_SOFTIRQ: Callback must run in softirq context 48 * HRTIMER_CB_SOFTIRQ: Callback must run in softirq context
47 * HRTIMER_CB_IRQSAFE: Callback may run in hardirq context 49 * HRTIMER_CB_IRQSAFE_PERCPU: Callback must run in hardirq context
48 * HRTIMER_CB_IRQSAFE_NO_RESTART: Callback may run in hardirq context and 50 * Special mode for tick emulation and
49 * does not restart the timer 51 * scheduler timer. Such timers are per
50 * HRTIMER_CB_IRQSAFE_NO_SOFTIRQ: Callback must run in hardirq context 52 * cpu and not allowed to be migrated on
51 * Special mode for tick emultation 53 * cpu unplug.
54 * HRTIMER_CB_IRQSAFE_UNLOCKED: Callback should run in hardirq context
55 * with timer->base lock unlocked
56 * used for timers which call wakeup to
57 * avoid lock order problems with rq->lock
52 */ 58 */
53enum hrtimer_cb_mode { 59enum hrtimer_cb_mode {
54 HRTIMER_CB_SOFTIRQ, 60 HRTIMER_CB_SOFTIRQ,
55 HRTIMER_CB_IRQSAFE, 61 HRTIMER_CB_IRQSAFE_PERCPU,
56 HRTIMER_CB_IRQSAFE_NO_RESTART, 62 HRTIMER_CB_IRQSAFE_UNLOCKED,
57 HRTIMER_CB_IRQSAFE_NO_SOFTIRQ,
58}; 63};
59 64
60/* 65/*
@@ -67,9 +72,10 @@ enum hrtimer_cb_mode {
67 * 0x02 callback function running 72 * 0x02 callback function running
68 * 0x04 callback pending (high resolution mode) 73 * 0x04 callback pending (high resolution mode)
69 * 74 *
70 * Special case: 75 * Special cases:
71 * 0x03 callback function running and enqueued 76 * 0x03 callback function running and enqueued
72 * (was requeued on another CPU) 77 * (was requeued on another CPU)
78 * 0x09 timer was migrated on CPU hotunplug
73 * The "callback function running and enqueued" status is only possible on 79 * The "callback function running and enqueued" status is only possible on
74 * SMP. It happens for example when a posix timer expired and the callback 80 * SMP. It happens for example when a posix timer expired and the callback
75 * queued a signal. Between dropping the lock which protects the posix timer 81 * queued a signal. Between dropping the lock which protects the posix timer
@@ -87,13 +93,19 @@ enum hrtimer_cb_mode {
87#define HRTIMER_STATE_ENQUEUED 0x01 93#define HRTIMER_STATE_ENQUEUED 0x01
88#define HRTIMER_STATE_CALLBACK 0x02 94#define HRTIMER_STATE_CALLBACK 0x02
89#define HRTIMER_STATE_PENDING 0x04 95#define HRTIMER_STATE_PENDING 0x04
96#define HRTIMER_STATE_MIGRATE 0x08
90 97
91/** 98/**
92 * struct hrtimer - the basic hrtimer structure 99 * struct hrtimer - the basic hrtimer structure
93 * @node: red black tree node for time ordered insertion 100 * @node: red black tree node for time ordered insertion
94 * @expires: the absolute expiry time in the hrtimers internal 101 * @_expires: the absolute expiry time in the hrtimers internal
95 * representation. The time is related to the clock on 102 * representation. The time is related to the clock on
96 * which the timer is based. 103 * which the timer is based. Is setup by adding
104 * slack to the _softexpires value. For non range timers
105 * identical to _softexpires.
106 * @_softexpires: the absolute earliest expiry time of the hrtimer.
107 * The time which was given as expiry time when the timer
108 * was armed.
97 * @function: timer expiry callback function 109 * @function: timer expiry callback function
98 * @base: pointer to the timer base (per cpu and per clock) 110 * @base: pointer to the timer base (per cpu and per clock)
99 * @state: state information (See bit values above) 111 * @state: state information (See bit values above)
@@ -111,16 +123,17 @@ enum hrtimer_cb_mode {
111 */ 123 */
112struct hrtimer { 124struct hrtimer {
113 struct rb_node node; 125 struct rb_node node;
114 ktime_t expires; 126 ktime_t _expires;
127 ktime_t _softexpires;
115 enum hrtimer_restart (*function)(struct hrtimer *); 128 enum hrtimer_restart (*function)(struct hrtimer *);
116 struct hrtimer_clock_base *base; 129 struct hrtimer_clock_base *base;
117 unsigned long state; 130 unsigned long state;
118 enum hrtimer_cb_mode cb_mode;
119 struct list_head cb_entry; 131 struct list_head cb_entry;
132 enum hrtimer_cb_mode cb_mode;
120#ifdef CONFIG_TIMER_STATS 133#ifdef CONFIG_TIMER_STATS
134 int start_pid;
121 void *start_site; 135 void *start_site;
122 char start_comm[16]; 136 char start_comm[16];
123 int start_pid;
124#endif 137#endif
125}; 138};
126 139
@@ -145,10 +158,8 @@ struct hrtimer_sleeper {
145 * @first: pointer to the timer node which expires first 158 * @first: pointer to the timer node which expires first
146 * @resolution: the resolution of the clock, in nanoseconds 159 * @resolution: the resolution of the clock, in nanoseconds
147 * @get_time: function to retrieve the current time of the clock 160 * @get_time: function to retrieve the current time of the clock
148 * @get_softirq_time: function to retrieve the current time from the softirq
149 * @softirq_time: the time when running the hrtimer queue in the softirq 161 * @softirq_time: the time when running the hrtimer queue in the softirq
150 * @offset: offset of this clock to the monotonic base 162 * @offset: offset of this clock to the monotonic base
151 * @reprogram: function to reprogram the timer event
152 */ 163 */
153struct hrtimer_clock_base { 164struct hrtimer_clock_base {
154 struct hrtimer_cpu_base *cpu_base; 165 struct hrtimer_cpu_base *cpu_base;
@@ -157,13 +168,9 @@ struct hrtimer_clock_base {
157 struct rb_node *first; 168 struct rb_node *first;
158 ktime_t resolution; 169 ktime_t resolution;
159 ktime_t (*get_time)(void); 170 ktime_t (*get_time)(void);
160 ktime_t (*get_softirq_time)(void);
161 ktime_t softirq_time; 171 ktime_t softirq_time;
162#ifdef CONFIG_HIGH_RES_TIMERS 172#ifdef CONFIG_HIGH_RES_TIMERS
163 ktime_t offset; 173 ktime_t offset;
164 int (*reprogram)(struct hrtimer *t,
165 struct hrtimer_clock_base *b,
166 ktime_t n);
167#endif 174#endif
168}; 175};
169 176
@@ -197,6 +204,71 @@ struct hrtimer_cpu_base {
197#endif 204#endif
198}; 205};
199 206
207static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time)
208{
209 timer->_expires = time;
210 timer->_softexpires = time;
211}
212
213static inline void hrtimer_set_expires_range(struct hrtimer *timer, ktime_t time, ktime_t delta)
214{
215 timer->_softexpires = time;
216 timer->_expires = ktime_add_safe(time, delta);
217}
218
219static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t time, unsigned long delta)
220{
221 timer->_softexpires = time;
222 timer->_expires = ktime_add_safe(time, ns_to_ktime(delta));
223}
224
225static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64)
226{
227 timer->_expires.tv64 = tv64;
228 timer->_softexpires.tv64 = tv64;
229}
230
231static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time)
232{
233 timer->_expires = ktime_add_safe(timer->_expires, time);
234 timer->_softexpires = ktime_add_safe(timer->_softexpires, time);
235}
236
237static inline void hrtimer_add_expires_ns(struct hrtimer *timer, u64 ns)
238{
239 timer->_expires = ktime_add_ns(timer->_expires, ns);
240 timer->_softexpires = ktime_add_ns(timer->_softexpires, ns);
241}
242
243static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer)
244{
245 return timer->_expires;
246}
247
248static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer)
249{
250 return timer->_softexpires;
251}
252
253static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer)
254{
255 return timer->_expires.tv64;
256}
257static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer)
258{
259 return timer->_softexpires.tv64;
260}
261
262static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer)
263{
264 return ktime_to_ns(timer->_expires);
265}
266
267static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer)
268{
269 return ktime_sub(timer->_expires, timer->base->get_time());
270}
271
200#ifdef CONFIG_HIGH_RES_TIMERS 272#ifdef CONFIG_HIGH_RES_TIMERS
201struct clock_event_device; 273struct clock_event_device;
202 274
@@ -217,6 +289,8 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
217 return timer->base->cpu_base->hres_active; 289 return timer->base->cpu_base->hres_active;
218} 290}
219 291
292extern void hrtimer_peek_ahead_timers(void);
293
220/* 294/*
221 * The resolution of the clocks. The resolution value is returned in 295 * The resolution of the clocks. The resolution value is returned in
222 * the clock_getres() system call to give application programmers an 296 * the clock_getres() system call to give application programmers an
@@ -239,6 +313,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
239 * is expired in the next softirq when the clock was advanced. 313 * is expired in the next softirq when the clock was advanced.
240 */ 314 */
241static inline void clock_was_set(void) { } 315static inline void clock_was_set(void) { }
316static inline void hrtimer_peek_ahead_timers(void) { }
242 317
243static inline void hres_timers_resume(void) { } 318static inline void hres_timers_resume(void) { }
244 319
@@ -260,6 +335,10 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
260extern ktime_t ktime_get(void); 335extern ktime_t ktime_get(void);
261extern ktime_t ktime_get_real(void); 336extern ktime_t ktime_get_real(void);
262 337
338
339DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
340
341
263/* Exported timer functions: */ 342/* Exported timer functions: */
264 343
265/* Initialize timers: */ 344/* Initialize timers: */
@@ -284,12 +363,25 @@ static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
284/* Basic timer operations: */ 363/* Basic timer operations: */
285extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, 364extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
286 const enum hrtimer_mode mode); 365 const enum hrtimer_mode mode);
366extern int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
367 unsigned long range_ns, const enum hrtimer_mode mode);
287extern int hrtimer_cancel(struct hrtimer *timer); 368extern int hrtimer_cancel(struct hrtimer *timer);
288extern int hrtimer_try_to_cancel(struct hrtimer *timer); 369extern int hrtimer_try_to_cancel(struct hrtimer *timer);
289 370
371static inline int hrtimer_start_expires(struct hrtimer *timer,
372 enum hrtimer_mode mode)
373{
374 unsigned long delta;
375 ktime_t soft, hard;
376 soft = hrtimer_get_softexpires(timer);
377 hard = hrtimer_get_expires(timer);
378 delta = ktime_to_ns(ktime_sub(hard, soft));
379 return hrtimer_start_range_ns(timer, soft, delta, mode);
380}
381
290static inline int hrtimer_restart(struct hrtimer *timer) 382static inline int hrtimer_restart(struct hrtimer *timer)
291{ 383{
292 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS); 384 return hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
293} 385}
294 386
295/* Query timers: */ 387/* Query timers: */
@@ -346,6 +438,10 @@ extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
346extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, 438extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
347 struct task_struct *tsk); 439 struct task_struct *tsk);
348 440
441extern int schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
442 const enum hrtimer_mode mode);
443extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode);
444
349/* Soft interrupt function to run the hrtimer queues: */ 445/* Soft interrupt function to run the hrtimer queues: */
350extern void hrtimer_run_queues(void); 446extern void hrtimer_run_queues(void);
351extern void hrtimer_run_pending(void); 447extern void hrtimer_run_pending(void);