aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/hrtimer.h
diff options
context:
space:
mode:
authorRussell King <rmk@dyn-67.arm.linux.org.uk>2007-02-20 14:13:30 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2007-02-20 14:13:30 -0500
commit5a84d159061d914c8dd4aa372ac6e9529c2be453 (patch)
tree9b08af78085334af44414adafe0096276f8fe0ff /include/linux/hrtimer.h
parente80a0e6e7ccdf64575d4384cb4172860422f5b81 (diff)
parent7d477a04a619e90ee08724e8f2d8803c6bdfcef8 (diff)
Merge ARM fixes
Diffstat (limited to 'include/linux/hrtimer.h')
-rw-r--r--include/linux/hrtimer.h260
1 files changed, 235 insertions, 25 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index fca93025ab51..37f9279192a9 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -21,22 +21,72 @@
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/wait.h> 22#include <linux/wait.h>
23 23
24struct hrtimer_clock_base;
25struct hrtimer_cpu_base;
26
24/* 27/*
25 * Mode arguments of xxx_hrtimer functions: 28 * Mode arguments of xxx_hrtimer functions:
26 */ 29 */
27enum hrtimer_mode { 30enum hrtimer_mode {
28 HRTIMER_ABS, /* Time value is absolute */ 31 HRTIMER_MODE_ABS, /* Time value is absolute */
29 HRTIMER_REL, /* Time value is relative to now */ 32 HRTIMER_MODE_REL, /* Time value is relative to now */
30}; 33};
31 34
35/*
36 * Return values for the callback function
37 */
32enum hrtimer_restart { 38enum hrtimer_restart {
33 HRTIMER_NORESTART, 39 HRTIMER_NORESTART, /* Timer is not restarted */
34 HRTIMER_RESTART, 40 HRTIMER_RESTART, /* Timer must be restarted */
35}; 41};
36 42
37#define HRTIMER_INACTIVE ((void *)1UL) 43/*
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_NO_SOFTIRQ: Callback must run in softirq context
51 * Special mode for tick emultation
52 */
53enum hrtimer_cb_mode {
54 HRTIMER_CB_SOFTIRQ,
55 HRTIMER_CB_IRQSAFE,
56 HRTIMER_CB_IRQSAFE_NO_RESTART,
57 HRTIMER_CB_IRQSAFE_NO_SOFTIRQ,
58};
38 59
39struct hrtimer_base; 60/*
61 * Values to track state of the timer
62 *
63 * Possible states:
64 *
65 * 0x00 inactive
66 * 0x01 enqueued into rbtree
67 * 0x02 callback function running
68 * 0x04 callback pending (high resolution mode)
69 *
70 * Special case:
71 * 0x03 callback function running and enqueued
72 * (was requeued on another CPU)
73 * 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
75 * queued a signal. Between dropping the lock which protects the posix timer
76 * and reacquiring the base lock of the hrtimer, another CPU can deliver the
77 * signal and rearm the timer. We have to preserve the callback running state,
78 * as otherwise the timer could be removed before the softirq code finishes the
79 * the handling of the timer.
80 *
81 * The HRTIMER_STATE_ENQUEUE bit is always or'ed to the current state to
82 * preserve the HRTIMER_STATE_CALLBACK bit in the above scenario.
83 *
84 * All state transitions are protected by cpu_base->lock.
85 */
86#define HRTIMER_STATE_INACTIVE 0x00
87#define HRTIMER_STATE_ENQUEUED 0x01
88#define HRTIMER_STATE_CALLBACK 0x02
89#define HRTIMER_STATE_PENDING 0x04
40 90
41/** 91/**
42 * struct hrtimer - the basic hrtimer structure 92 * struct hrtimer - the basic hrtimer structure
@@ -46,14 +96,34 @@ struct hrtimer_base;
46 * which the timer is based. 96 * which the timer is based.
47 * @function: timer expiry callback function 97 * @function: timer expiry callback function
48 * @base: pointer to the timer base (per cpu and per clock) 98 * @base: pointer to the timer base (per cpu and per clock)
99 * @state: state information (See bit values above)
100 * @cb_mode: high resolution timer feature to select the callback execution
101 * mode
102 * @cb_entry: list head to enqueue an expired timer into the callback list
103 * @start_site: timer statistics field to store the site where the timer
104 * was started
105 * @start_comm: timer statistics field to store the name of the process which
106 * started the timer
107 * @start_pid: timer statistics field to store the pid of the task which
108 * started the timer
49 * 109 *
50 * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE() 110 * The hrtimer structure must be initialized by hrtimer_init()
51 */ 111 */
52struct hrtimer { 112struct hrtimer {
53 struct rb_node node; 113 struct rb_node node;
54 ktime_t expires; 114 ktime_t expires;
55 int (*function)(struct hrtimer *); 115 enum hrtimer_restart (*function)(struct hrtimer *);
56 struct hrtimer_base *base; 116 struct hrtimer_clock_base *base;
117 unsigned long state;
118#ifdef CONFIG_HIGH_RES_TIMERS
119 enum hrtimer_cb_mode cb_mode;
120 struct list_head cb_entry;
121#endif
122#ifdef CONFIG_TIMER_STATS
123 void *start_site;
124 char start_comm[16];
125 int start_pid;
126#endif
57}; 127};
58 128
59/** 129/**
@@ -70,37 +140,114 @@ struct hrtimer_sleeper {
70 140
71/** 141/**
72 * struct hrtimer_base - the timer base for a specific clock 142 * struct hrtimer_base - the timer base for a specific clock
73 * @index: clock type index for per_cpu support when moving a timer 143 * @index: clock type index for per_cpu support when moving a
74 * to a base on another cpu. 144 * timer 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 145 * @active: red black tree root node for the active timers
77 * @first: pointer to the timer node which expires first 146 * @first: pointer to the timer node which expires first
78 * @resolution: the resolution of the clock, in nanoseconds 147 * @resolution: the resolution of the clock, in nanoseconds
79 * @get_time: function to retrieve the current time of the clock 148 * @get_time: function to retrieve the current time of the clock
80 * @get_softirq_time: function to retrieve the current time from the softirq 149 * @get_softirq_time: function to retrieve the current time from the softirq
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 150 * @softirq_time: the time when running the hrtimer queue in the softirq
83 * @lock_key: the lock_class_key for use with lockdep 151 * @cb_pending: list of timers where the callback is pending
152 * @offset: offset of this clock to the monotonic base
153 * @reprogram: function to reprogram the timer event
84 */ 154 */
85struct hrtimer_base { 155struct hrtimer_clock_base {
156 struct hrtimer_cpu_base *cpu_base;
86 clockid_t index; 157 clockid_t index;
87 spinlock_t lock;
88 struct rb_root active; 158 struct rb_root active;
89 struct rb_node *first; 159 struct rb_node *first;
90 ktime_t resolution; 160 ktime_t resolution;
91 ktime_t (*get_time)(void); 161 ktime_t (*get_time)(void);
92 ktime_t (*get_softirq_time)(void); 162 ktime_t (*get_softirq_time)(void);
93 struct hrtimer *curr_timer;
94 ktime_t softirq_time; 163 ktime_t softirq_time;
95 struct lock_class_key lock_key; 164#ifdef CONFIG_HIGH_RES_TIMERS
165 ktime_t offset;
166 int (*reprogram)(struct hrtimer *t,
167 struct hrtimer_clock_base *b,
168 ktime_t n);
169#endif
170};
171
172#define HRTIMER_MAX_CLOCK_BASES 2
173
174/*
175 * struct hrtimer_cpu_base - the per cpu clock bases
176 * @lock: lock protecting the base and associated clock bases
177 * and timers
178 * @lock_key: the lock_class_key for use with lockdep
179 * @clock_base: array of clock bases for this cpu
180 * @curr_timer: the timer which is executing a callback right now
181 * @expires_next: absolute time of the next event which was scheduled
182 * via clock_set_next_event()
183 * @hres_active: State of high resolution mode
184 * @check_clocks: Indictator, when set evaluate time source and clock
185 * event devices whether high resolution mode can be
186 * activated.
187 * @cb_pending: Expired timers are moved from the rbtree to this
188 * list in the timer interrupt. The list is processed
189 * in the softirq.
190 * @nr_events: Total number of timer interrupt events
191 */
192struct hrtimer_cpu_base {
193 spinlock_t lock;
194 struct lock_class_key lock_key;
195 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
196#ifdef CONFIG_HIGH_RES_TIMERS
197 ktime_t expires_next;
198 int hres_active;
199 struct list_head cb_pending;
200 unsigned long nr_events;
201#endif
96}; 202};
97 203
204#ifdef CONFIG_HIGH_RES_TIMERS
205struct clock_event_device;
206
207extern void clock_was_set(void);
208extern void hrtimer_interrupt(struct clock_event_device *dev);
209
210/*
211 * In high resolution mode the time reference must be read accurate
212 */
213static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
214{
215 return timer->base->get_time();
216}
217
218/*
219 * The resolution of the clocks. The resolution value is returned in
220 * the clock_getres() system call to give application programmers an
221 * idea of the (in)accuracy of timers. Timer values are rounded up to
222 * this resolution values.
223 */
224# define KTIME_HIGH_RES (ktime_t) { .tv64 = 1 }
225# define KTIME_MONOTONIC_RES KTIME_HIGH_RES
226
227#else
228
229# define KTIME_MONOTONIC_RES KTIME_LOW_RES
230
98/* 231/*
99 * clock_was_set() is a NOP for non- high-resolution systems. The 232 * 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 233 * time-sorted order guarantees that a timer does not expire early and
101 * is expired in the next softirq when the clock was advanced. 234 * is expired in the next softirq when the clock was advanced.
102 */ 235 */
103#define clock_was_set() do { } while (0) 236static inline void clock_was_set(void) { }
237
238/*
239 * In non high resolution mode the time reference is taken from
240 * the base softirq time variable.
241 */
242static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
243{
244 return timer->base->softirq_time;
245}
246
247#endif
248
249extern ktime_t ktime_get(void);
250extern ktime_t ktime_get_real(void);
104 251
105/* Exported timer functions: */ 252/* Exported timer functions: */
106 253
@@ -114,19 +261,33 @@ extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
114extern int hrtimer_cancel(struct hrtimer *timer); 261extern int hrtimer_cancel(struct hrtimer *timer);
115extern int hrtimer_try_to_cancel(struct hrtimer *timer); 262extern int hrtimer_try_to_cancel(struct hrtimer *timer);
116 263
117#define hrtimer_restart(timer) hrtimer_start((timer), (timer)->expires, HRTIMER_ABS) 264static inline int hrtimer_restart(struct hrtimer *timer)
265{
266 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
267}
118 268
119/* Query timers: */ 269/* Query timers: */
120extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer); 270extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
121extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp); 271extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
122 272
123#ifdef CONFIG_NO_IDLE_HZ
124extern ktime_t hrtimer_get_next_event(void); 273extern ktime_t hrtimer_get_next_event(void);
125#endif
126 274
275/*
276 * A timer is active, when it is enqueued into the rbtree or the callback
277 * function is running.
278 */
127static inline int hrtimer_active(const struct hrtimer *timer) 279static inline int hrtimer_active(const struct hrtimer *timer)
128{ 280{
129 return rb_parent(&timer->node) != &timer->node; 281 return timer->state != HRTIMER_STATE_INACTIVE;
282}
283
284/*
285 * Helper function to check, whether the timer is on one of the queues
286 */
287static inline int hrtimer_is_queued(struct hrtimer *timer)
288{
289 return timer->state &
290 (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
130} 291}
131 292
132/* Forward a hrtimer so it expires after now: */ 293/* Forward a hrtimer so it expires after now: */
@@ -149,4 +310,53 @@ extern void hrtimer_run_queues(void);
149/* Bootup initialization: */ 310/* Bootup initialization: */
150extern void __init hrtimers_init(void); 311extern void __init hrtimers_init(void);
151 312
313#if BITS_PER_LONG < 64
314extern unsigned long ktime_divns(const ktime_t kt, s64 div);
315#else /* BITS_PER_LONG < 64 */
316# define ktime_divns(kt, div) (unsigned long)((kt).tv64 / (div))
317#endif
318
319/* Show pending timers: */
320extern void sysrq_timer_list_show(void);
321
322/*
323 * Timer-statistics info:
324 */
325#ifdef CONFIG_TIMER_STATS
326
327extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
328 void *timerf, char * comm);
329
330static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
331{
332 timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
333 timer->function, timer->start_comm);
334}
335
336extern void __timer_stats_hrtimer_set_start_info(struct hrtimer *timer,
337 void *addr);
338
339static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
340{
341 __timer_stats_hrtimer_set_start_info(timer, __builtin_return_address(0));
342}
343
344static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer)
345{
346 timer->start_site = NULL;
347}
348#else
349static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
350{
351}
352
353static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
354{
355}
356
357static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer)
358{
359}
360#endif
361
152#endif 362#endif