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.h115
1 files changed, 103 insertions, 12 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 2f245fe63bda..2b3645b1acf4 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;
@@ -101,9 +103,14 @@ enum hrtimer_cb_mode {
101/** 103/**
102 * struct hrtimer - the basic hrtimer structure 104 * struct hrtimer - the basic hrtimer structure
103 * @node: red black tree node for time ordered insertion 105 * @node: red black tree node for time ordered insertion
104 * @expires: the absolute expiry time in the hrtimers internal 106 * @_expires: the absolute expiry time in the hrtimers internal
105 * representation. The time is related to the clock on 107 * representation. The time is related to the clock on
106 * which the timer is based. 108 * which the timer is based. Is setup by adding
109 * slack to the _softexpires value. For non range timers
110 * identical to _softexpires.
111 * @_softexpires: the absolute earliest expiry time of the hrtimer.
112 * The time which was given as expiry time when the timer
113 * was armed.
107 * @function: timer expiry callback function 114 * @function: timer expiry callback function
108 * @base: pointer to the timer base (per cpu and per clock) 115 * @base: pointer to the timer base (per cpu and per clock)
109 * @state: state information (See bit values above) 116 * @state: state information (See bit values above)
@@ -121,16 +128,17 @@ enum hrtimer_cb_mode {
121 */ 128 */
122struct hrtimer { 129struct hrtimer {
123 struct rb_node node; 130 struct rb_node node;
124 ktime_t expires; 131 ktime_t _expires;
132 ktime_t _softexpires;
125 enum hrtimer_restart (*function)(struct hrtimer *); 133 enum hrtimer_restart (*function)(struct hrtimer *);
126 struct hrtimer_clock_base *base; 134 struct hrtimer_clock_base *base;
127 unsigned long state; 135 unsigned long state;
128 enum hrtimer_cb_mode cb_mode;
129 struct list_head cb_entry; 136 struct list_head cb_entry;
137 enum hrtimer_cb_mode cb_mode;
130#ifdef CONFIG_TIMER_STATS 138#ifdef CONFIG_TIMER_STATS
139 int start_pid;
131 void *start_site; 140 void *start_site;
132 char start_comm[16]; 141 char start_comm[16];
133 int start_pid;
134#endif 142#endif
135}; 143};
136 144
@@ -155,10 +163,8 @@ struct hrtimer_sleeper {
155 * @first: pointer to the timer node which expires first 163 * @first: pointer to the timer node which expires first
156 * @resolution: the resolution of the clock, in nanoseconds 164 * @resolution: the resolution of the clock, in nanoseconds
157 * @get_time: function to retrieve the current time of the clock 165 * @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 166 * @softirq_time: the time when running the hrtimer queue in the softirq
160 * @offset: offset of this clock to the monotonic base 167 * @offset: offset of this clock to the monotonic base
161 * @reprogram: function to reprogram the timer event
162 */ 168 */
163struct hrtimer_clock_base { 169struct hrtimer_clock_base {
164 struct hrtimer_cpu_base *cpu_base; 170 struct hrtimer_cpu_base *cpu_base;
@@ -167,13 +173,9 @@ struct hrtimer_clock_base {
167 struct rb_node *first; 173 struct rb_node *first;
168 ktime_t resolution; 174 ktime_t resolution;
169 ktime_t (*get_time)(void); 175 ktime_t (*get_time)(void);
170 ktime_t (*get_softirq_time)(void);
171 ktime_t softirq_time; 176 ktime_t softirq_time;
172#ifdef CONFIG_HIGH_RES_TIMERS 177#ifdef CONFIG_HIGH_RES_TIMERS
173 ktime_t offset; 178 ktime_t offset;
174 int (*reprogram)(struct hrtimer *t,
175 struct hrtimer_clock_base *b,
176 ktime_t n);
177#endif 179#endif
178}; 180};
179 181
@@ -207,6 +209,71 @@ struct hrtimer_cpu_base {
207#endif 209#endif
208}; 210};
209 211
212static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time)
213{
214 timer->_expires = time;
215 timer->_softexpires = time;
216}
217
218static inline void hrtimer_set_expires_range(struct hrtimer *timer, ktime_t time, ktime_t delta)
219{
220 timer->_softexpires = time;
221 timer->_expires = ktime_add_safe(time, delta);
222}
223
224static inline void hrtimer_set_expires_range_ns(struct hrtimer *timer, ktime_t time, unsigned long delta)
225{
226 timer->_softexpires = time;
227 timer->_expires = ktime_add_safe(time, ns_to_ktime(delta));
228}
229
230static inline void hrtimer_set_expires_tv64(struct hrtimer *timer, s64 tv64)
231{
232 timer->_expires.tv64 = tv64;
233 timer->_softexpires.tv64 = tv64;
234}
235
236static inline void hrtimer_add_expires(struct hrtimer *timer, ktime_t time)
237{
238 timer->_expires = ktime_add_safe(timer->_expires, time);
239 timer->_softexpires = ktime_add_safe(timer->_softexpires, time);
240}
241
242static inline void hrtimer_add_expires_ns(struct hrtimer *timer, unsigned long ns)
243{
244 timer->_expires = ktime_add_ns(timer->_expires, ns);
245 timer->_softexpires = ktime_add_ns(timer->_softexpires, ns);
246}
247
248static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer)
249{
250 return timer->_expires;
251}
252
253static inline ktime_t hrtimer_get_softexpires(const struct hrtimer *timer)
254{
255 return timer->_softexpires;
256}
257
258static inline s64 hrtimer_get_expires_tv64(const struct hrtimer *timer)
259{
260 return timer->_expires.tv64;
261}
262static inline s64 hrtimer_get_softexpires_tv64(const struct hrtimer *timer)
263{
264 return timer->_softexpires.tv64;
265}
266
267static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer)
268{
269 return ktime_to_ns(timer->_expires);
270}
271
272static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer)
273{
274 return ktime_sub(timer->_expires, timer->base->get_time());
275}
276
210#ifdef CONFIG_HIGH_RES_TIMERS 277#ifdef CONFIG_HIGH_RES_TIMERS
211struct clock_event_device; 278struct clock_event_device;
212 279
@@ -227,6 +294,8 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
227 return timer->base->cpu_base->hres_active; 294 return timer->base->cpu_base->hres_active;
228} 295}
229 296
297extern void hrtimer_peek_ahead_timers(void);
298
230/* 299/*
231 * The resolution of the clocks. The resolution value is returned in 300 * The resolution of the clocks. The resolution value is returned in
232 * the clock_getres() system call to give application programmers an 301 * the clock_getres() system call to give application programmers an
@@ -249,6 +318,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
249 * is expired in the next softirq when the clock was advanced. 318 * is expired in the next softirq when the clock was advanced.
250 */ 319 */
251static inline void clock_was_set(void) { } 320static inline void clock_was_set(void) { }
321static inline void hrtimer_peek_ahead_timers(void) { }
252 322
253static inline void hres_timers_resume(void) { } 323static inline void hres_timers_resume(void) { }
254 324
@@ -270,6 +340,10 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
270extern ktime_t ktime_get(void); 340extern ktime_t ktime_get(void);
271extern ktime_t ktime_get_real(void); 341extern ktime_t ktime_get_real(void);
272 342
343
344DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
345
346
273/* Exported timer functions: */ 347/* Exported timer functions: */
274 348
275/* Initialize timers: */ 349/* Initialize timers: */
@@ -294,12 +368,25 @@ static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
294/* Basic timer operations: */ 368/* Basic timer operations: */
295extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, 369extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
296 const enum hrtimer_mode mode); 370 const enum hrtimer_mode mode);
371extern int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
372 unsigned long range_ns, const enum hrtimer_mode mode);
297extern int hrtimer_cancel(struct hrtimer *timer); 373extern int hrtimer_cancel(struct hrtimer *timer);
298extern int hrtimer_try_to_cancel(struct hrtimer *timer); 374extern int hrtimer_try_to_cancel(struct hrtimer *timer);
299 375
376static inline int hrtimer_start_expires(struct hrtimer *timer,
377 enum hrtimer_mode mode)
378{
379 unsigned long delta;
380 ktime_t soft, hard;
381 soft = hrtimer_get_softexpires(timer);
382 hard = hrtimer_get_expires(timer);
383 delta = ktime_to_ns(ktime_sub(hard, soft));
384 return hrtimer_start_range_ns(timer, soft, delta, mode);
385}
386
300static inline int hrtimer_restart(struct hrtimer *timer) 387static inline int hrtimer_restart(struct hrtimer *timer)
301{ 388{
302 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS); 389 return hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
303} 390}
304 391
305/* Query timers: */ 392/* Query timers: */
@@ -356,6 +443,10 @@ extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
356extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, 443extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
357 struct task_struct *tsk); 444 struct task_struct *tsk);
358 445
446extern int schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
447 const enum hrtimer_mode mode);
448extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode);
449
359/* Soft interrupt function to run the hrtimer queues: */ 450/* Soft interrupt function to run the hrtimer queues: */
360extern void hrtimer_run_queues(void); 451extern void hrtimer_run_queues(void);
361extern void hrtimer_run_pending(void); 452extern void hrtimer_run_pending(void);