hrtimer: remove hrtimer_clock_base::get_softirq_time()
[deliverable/linux.git] / include / linux / hrtimer.h
CommitLineData
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
3c8aa39d
TG
24struct hrtimer_clock_base;
25struct hrtimer_cpu_base;
26
c0a31329
TG
27/*
28 * Mode arguments of xxx_hrtimer functions:
29 */
30enum hrtimer_mode {
c9cb2e3d
TG
31 HRTIMER_MODE_ABS, /* Time value is absolute */
32 HRTIMER_MODE_REL, /* Time value is relative to now */
c0a31329
TG
33};
34
c9cb2e3d
TG
35/*
36 * Return values for the callback function
37 */
c0a31329 38enum hrtimer_restart {
c9cb2e3d
TG
39 HRTIMER_NORESTART, /* Timer is not restarted */
40 HRTIMER_RESTART, /* Timer must be restarted */
c0a31329
TG
41};
42
303e967f 43/*
54cdfdb4
TG
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
8437fdc7 50 * HRTIMER_CB_IRQSAFE_NO_SOFTIRQ: Callback must run in hardirq context
54cdfdb4
TG
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};
59
60/*
61 * Values to track state of the timer
303e967f
TG
62 *
63 * Possible states:
64 *
65 * 0x00 inactive
66 * 0x01 enqueued into rbtree
67 * 0x02 callback function running
54cdfdb4
TG
68 * 0x04 callback pending (high resolution mode)
69 *
70 * Special case:
303e967f
TG
71 * 0x03 callback function running and enqueued
72 * (was requeued on another CPU)
303e967f
TG
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 *
3eb05676 81 * The HRTIMER_STATE_ENQUEUED bit is always or'ed to the current state to
303e967f
TG
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
54cdfdb4 89#define HRTIMER_STATE_PENDING 0x04
303e967f 90
c0a31329
TG
91/**
92 * struct hrtimer - the basic hrtimer structure
c0a31329 93 * @node: red black tree node for time ordered insertion
c0a31329
TG
94 * @expires: the absolute expiry time in the hrtimers internal
95 * representation. The time is related to the clock on
96 * which the timer is based.
c0a31329 97 * @function: timer expiry callback function
c0a31329 98 * @base: pointer to the timer base (per cpu and per clock)
303e967f 99 * @state: state information (See bit values above)
54cdfdb4
TG
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
c0a31329 109 *
54cdfdb4 110 * The hrtimer structure must be initialized by hrtimer_init()
c0a31329
TG
111 */
112struct hrtimer {
3c8aa39d
TG
113 struct rb_node node;
114 ktime_t expires;
115 enum hrtimer_restart (*function)(struct hrtimer *);
116 struct hrtimer_clock_base *base;
303e967f 117 unsigned long state;
54cdfdb4
TG
118 enum hrtimer_cb_mode cb_mode;
119 struct list_head cb_entry;
82f67cd9
IM
120#ifdef CONFIG_TIMER_STATS
121 void *start_site;
122 char start_comm[16];
123 int start_pid;
124#endif
c0a31329
TG
125};
126
00362e33
TG
127/**
128 * struct hrtimer_sleeper - simple sleeper structure
00362e33
TG
129 * @timer: embedded timer structure
130 * @task: task to wake up
131 *
132 * task is set to NULL, when the timer expires.
133 */
134struct hrtimer_sleeper {
135 struct hrtimer timer;
136 struct task_struct *task;
137};
138
c0a31329 139/**
d1d67174 140 * struct hrtimer_clock_base - the timer base for a specific clock
05fb6bf0 141 * @cpu_base: per cpu clock base
3c8aa39d
TG
142 * @index: clock type index for per_cpu support when moving a
143 * timer to a base on another cpu.
92127c7a
TG
144 * @active: red black tree root node for the active timers
145 * @first: pointer to the timer node which expires first
146 * @resolution: the resolution of the clock, in nanoseconds
147 * @get_time: function to retrieve the current time of the clock
92127c7a 148 * @softirq_time: the time when running the hrtimer queue in the softirq
54cdfdb4
TG
149 * @offset: offset of this clock to the monotonic base
150 * @reprogram: function to reprogram the timer event
c0a31329 151 */
3c8aa39d
TG
152struct hrtimer_clock_base {
153 struct hrtimer_cpu_base *cpu_base;
c0a31329 154 clockid_t index;
c0a31329 155 struct rb_root active;
288867ec 156 struct rb_node *first;
e2787630 157 ktime_t resolution;
c0a31329 158 ktime_t (*get_time)(void);
92127c7a 159 ktime_t softirq_time;
54cdfdb4
TG
160#ifdef CONFIG_HIGH_RES_TIMERS
161 ktime_t offset;
162 int (*reprogram)(struct hrtimer *t,
163 struct hrtimer_clock_base *b,
164 ktime_t n);
165#endif
3c8aa39d
TG
166};
167
168#define HRTIMER_MAX_CLOCK_BASES 2
169
170/*
171 * struct hrtimer_cpu_base - the per cpu clock bases
172 * @lock: lock protecting the base and associated clock bases
173 * and timers
3c8aa39d
TG
174 * @clock_base: array of clock bases for this cpu
175 * @curr_timer: the timer which is executing a callback right now
54cdfdb4
TG
176 * @expires_next: absolute time of the next event which was scheduled
177 * via clock_set_next_event()
178 * @hres_active: State of high resolution mode
179 * @check_clocks: Indictator, when set evaluate time source and clock
180 * event devices whether high resolution mode can be
181 * activated.
182 * @cb_pending: Expired timers are moved from the rbtree to this
183 * list in the timer interrupt. The list is processed
184 * in the softirq.
185 * @nr_events: Total number of timer interrupt events
3c8aa39d
TG
186 */
187struct hrtimer_cpu_base {
188 spinlock_t lock;
3c8aa39d 189 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
d3d74453 190 struct list_head cb_pending;
54cdfdb4
TG
191#ifdef CONFIG_HIGH_RES_TIMERS
192 ktime_t expires_next;
193 int hres_active;
54cdfdb4
TG
194 unsigned long nr_events;
195#endif
c0a31329
TG
196};
197
54cdfdb4
TG
198#ifdef CONFIG_HIGH_RES_TIMERS
199struct clock_event_device;
200
201extern void clock_was_set(void);
995f054f 202extern void hres_timers_resume(void);
54cdfdb4
TG
203extern void hrtimer_interrupt(struct clock_event_device *dev);
204
205/*
206 * In high resolution mode the time reference must be read accurate
207 */
208static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
209{
210 return timer->base->get_time();
211}
212
8f4d37ec
PZ
213static inline int hrtimer_is_hres_active(struct hrtimer *timer)
214{
215 return timer->base->cpu_base->hres_active;
216}
217
54cdfdb4
TG
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 */
151db1fc
TB
224# define HIGH_RES_NSEC 1
225# define KTIME_HIGH_RES (ktime_t) { .tv64 = HIGH_RES_NSEC }
226# define MONOTONIC_RES_NSEC HIGH_RES_NSEC
54cdfdb4
TG
227# define KTIME_MONOTONIC_RES KTIME_HIGH_RES
228
229#else
230
151db1fc 231# define MONOTONIC_RES_NSEC LOW_RES_NSEC
54cdfdb4
TG
232# define KTIME_MONOTONIC_RES KTIME_LOW_RES
233
becf8b5d
TG
234/*
235 * clock_was_set() is a NOP for non- high-resolution systems. The
236 * time-sorted order guarantees that a timer does not expire early and
237 * is expired in the next softirq when the clock was advanced.
238 */
54cdfdb4
TG
239static inline void clock_was_set(void) { }
240
995f054f
IM
241static inline void hres_timers_resume(void) { }
242
54cdfdb4
TG
243/*
244 * In non high resolution mode the time reference is taken from
245 * the base softirq time variable.
246 */
247static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
248{
249 return timer->base->softirq_time;
250}
251
8f4d37ec
PZ
252static inline int hrtimer_is_hres_active(struct hrtimer *timer)
253{
254 return 0;
255}
54cdfdb4
TG
256#endif
257
d316c57f
TG
258extern ktime_t ktime_get(void);
259extern ktime_t ktime_get_real(void);
becf8b5d 260
c0a31329
TG
261/* Exported timer functions: */
262
263/* Initialize timers: */
7978672c
GA
264extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
265 enum hrtimer_mode mode);
c0a31329 266
237fc6e7
TG
267#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
268extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
269 enum hrtimer_mode mode);
270
271extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
272#else
273static inline void hrtimer_init_on_stack(struct hrtimer *timer,
274 clockid_t which_clock,
275 enum hrtimer_mode mode)
276{
277 hrtimer_init(timer, which_clock, mode);
278}
279static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
280#endif
281
c0a31329
TG
282/* Basic timer operations: */
283extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
284 const enum hrtimer_mode mode);
285extern int hrtimer_cancel(struct hrtimer *timer);
286extern int hrtimer_try_to_cancel(struct hrtimer *timer);
287
c9cb2e3d
TG
288static inline int hrtimer_restart(struct hrtimer *timer)
289{
290 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
291}
c0a31329
TG
292
293/* Query timers: */
294extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
295extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
296
69239749 297extern ktime_t hrtimer_get_next_event(void);
69239749 298
303e967f
TG
299/*
300 * A timer is active, when it is enqueued into the rbtree or the callback
301 * function is running.
302 */
c0a31329
TG
303static inline int hrtimer_active(const struct hrtimer *timer)
304{
303e967f 305 return timer->state != HRTIMER_STATE_INACTIVE;
c0a31329
TG
306}
307
54cdfdb4
TG
308/*
309 * Helper function to check, whether the timer is on one of the queues
310 */
311static inline int hrtimer_is_queued(struct hrtimer *timer)
312{
313 return timer->state &
314 (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
315}
316
4346f654
OH
317/*
318 * Helper function to check, whether the timer is running the callback
319 * function
320 */
321static inline int hrtimer_callback_running(struct hrtimer *timer)
322{
323 return timer->state & HRTIMER_STATE_CALLBACK;
324}
325
c0a31329 326/* Forward a hrtimer so it expires after now: */
4d672e7a 327extern u64
44f21475 328hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
c0a31329 329
5e05ad7d 330/* Forward a hrtimer so it expires after the hrtimer's current now */
4d672e7a
DL
331static inline u64 hrtimer_forward_now(struct hrtimer *timer,
332 ktime_t interval)
5e05ad7d
DL
333{
334 return hrtimer_forward(timer, timer->base->get_time(), interval);
335}
336
10c94ec1
TG
337/* Precise sleep: */
338extern long hrtimer_nanosleep(struct timespec *rqtp,
080344b9 339 struct timespec __user *rmtp,
10c94ec1
TG
340 const enum hrtimer_mode mode,
341 const clockid_t clockid);
1711ef38 342extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
10c94ec1 343
00362e33
TG
344extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
345 struct task_struct *tsk);
346
c0a31329
TG
347/* Soft interrupt function to run the hrtimer queues: */
348extern void hrtimer_run_queues(void);
d3d74453 349extern void hrtimer_run_pending(void);
c0a31329
TG
350
351/* Bootup initialization: */
352extern void __init hrtimers_init(void);
353
79bf2bb3 354#if BITS_PER_LONG < 64
4d672e7a 355extern u64 ktime_divns(const ktime_t kt, s64 div);
79bf2bb3 356#else /* BITS_PER_LONG < 64 */
4d672e7a 357# define ktime_divns(kt, div) (u64)((kt).tv64 / (div))
79bf2bb3
TG
358#endif
359
88ad0bf6
IM
360/* Show pending timers: */
361extern void sysrq_timer_list_show(void);
362
82f67cd9
IM
363/*
364 * Timer-statistics info:
365 */
366#ifdef CONFIG_TIMER_STATS
367
368extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
c5c061b8
VP
369 void *timerf, char *comm,
370 unsigned int timer_flag);
82f67cd9
IM
371
372static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
373{
374 timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
c5c061b8 375 timer->function, timer->start_comm, 0);
82f67cd9
IM
376}
377
378extern void __timer_stats_hrtimer_set_start_info(struct hrtimer *timer,
379 void *addr);
380
381static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
382{
383 __timer_stats_hrtimer_set_start_info(timer, __builtin_return_address(0));
384}
385
386static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer)
387{
388 timer->start_site = NULL;
389}
390#else
391static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
392{
393}
394
395static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
396{
397}
398
399static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer)
400{
401}
402#endif
403
c0a31329 404#endif
This page took 0.426942 seconds and 5 git commands to generate.