2 * include/linux/hrtimer.h
4 * hrtimers - High-resolution kernel timers
6 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
7 * Copyright(C) 2005, Red Hat, Inc., Ingo Molnar
9 * data type definitions, declarations, prototypes
11 * Started by: Thomas Gleixner and Ingo Molnar
13 * For licencing details see kernel-base/COPYING
15 #ifndef _LINUX_HRTIMER_H
16 #define _LINUX_HRTIMER_H
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>
25 * Mode arguments of xxx_hrtimer functions:
28 HRTIMER_ABS
, /* Time value is absolute */
29 HRTIMER_REL
, /* Time value is relative to now */
32 enum hrtimer_restart
{
37 #define HRTIMER_INACTIVE ((void *)1UL)
42 * struct hrtimer - the basic hrtimer structure
43 * @node: red black tree node for time ordered insertion
44 * @expires: the absolute expiry time in the hrtimers internal
45 * representation. The time is related to the clock on
46 * which the timer is based.
47 * @function: timer expiry callback function
48 * @base: pointer to the timer base (per cpu and per clock)
50 * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
55 int (*function
)(struct hrtimer
*);
56 struct hrtimer_base
*base
;
60 * struct hrtimer_sleeper - simple sleeper structure
61 * @timer: embedded timer structure
62 * @task: task to wake up
64 * task is set to NULL, when the timer expires.
66 struct hrtimer_sleeper
{
68 struct task_struct
*task
;
72 * struct hrtimer_base - the timer base for a specific clock
73 * @index: clock type index for per_cpu support when moving a timer
74 * 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
77 * @first: pointer to the timer node which expires first
78 * @resolution: the resolution of the clock, in nanoseconds
79 * @get_time: function to retrieve the current time of the clock
80 * @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
83 * @lock_key: the lock_class_key for use with lockdep
88 struct rb_root active
;
89 struct rb_node
*first
;
91 ktime_t (*get_time
)(void);
92 ktime_t (*get_softirq_time
)(void);
93 struct hrtimer
*curr_timer
;
95 struct lock_class_key lock_key
;
99 * 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
101 * is expired in the next softirq when the clock was advanced.
103 #define clock_was_set() do { } while (0)
105 /* Exported timer functions: */
107 /* Initialize timers: */
108 extern void hrtimer_init(struct hrtimer
*timer
, clockid_t which_clock
,
109 enum hrtimer_mode mode
);
111 /* Basic timer operations: */
112 extern int hrtimer_start(struct hrtimer
*timer
, ktime_t tim
,
113 const enum hrtimer_mode mode
);
114 extern int hrtimer_cancel(struct hrtimer
*timer
);
115 extern int hrtimer_try_to_cancel(struct hrtimer
*timer
);
117 #define hrtimer_restart(timer) hrtimer_start((timer), (timer)->expires, HRTIMER_ABS)
120 extern ktime_t
hrtimer_get_remaining(const struct hrtimer
*timer
);
121 extern int hrtimer_get_res(const clockid_t which_clock
, struct timespec
*tp
);
123 #ifdef CONFIG_NO_IDLE_HZ
124 extern ktime_t
hrtimer_get_next_event(void);
127 static inline int hrtimer_active(const struct hrtimer
*timer
)
129 return rb_parent(&timer
->node
) != &timer
->node
;
132 /* Forward a hrtimer so it expires after now: */
134 hrtimer_forward(struct hrtimer
*timer
, ktime_t now
, ktime_t interval
);
137 extern long hrtimer_nanosleep(struct timespec
*rqtp
,
138 struct timespec __user
*rmtp
,
139 const enum hrtimer_mode mode
,
140 const clockid_t clockid
);
141 extern long hrtimer_nanosleep_restart(struct restart_block
*restart_block
);
143 extern void hrtimer_init_sleeper(struct hrtimer_sleeper
*sl
,
144 struct task_struct
*tsk
);
146 /* Soft interrupt function to run the hrtimer queues: */
147 extern void hrtimer_run_queues(void);
149 /* Bootup initialization: */
150 extern void __init
hrtimers_init(void);