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>
24 struct hrtimer_clock_base;
25 struct hrtimer_cpu_base;
28 * Mode arguments of xxx_hrtimer functions:
31 HRTIMER_MODE_ABS, /* Time value is absolute */
32 HRTIMER_MODE_REL, /* Time value is relative to now */
36 * Return values for the callback function
38 enum hrtimer_restart {
39 HRTIMER_NORESTART, /* Timer is not restarted */
40 HRTIMER_RESTART, /* Timer must be restarted */
44 * struct hrtimer - the basic hrtimer structure
45 * @node: red black tree node for time ordered insertion
46 * @expires: the absolute expiry time in the hrtimers internal
47 * representation. The time is related to the clock on
48 * which the timer is based.
49 * @function: timer expiry callback function
50 * @base: pointer to the timer base (per cpu and per clock)
52 * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
57 enum hrtimer_restart (*function)(struct hrtimer *);
58 struct hrtimer_clock_base *base;
62 * struct hrtimer_sleeper - simple sleeper structure
63 * @timer: embedded timer structure
64 * @task: task to wake up
66 * task is set to NULL, when the timer expires.
68 struct hrtimer_sleeper {
70 struct task_struct *task;
74 * struct hrtimer_base - the timer base for a specific clock
75 * @index: clock type index for per_cpu support when moving a
76 * timer to a base on another cpu.
77 * @active: red black tree root node for the active timers
78 * @first: pointer to the timer node which expires first
79 * @resolution: the resolution of the clock, in nanoseconds
80 * @get_time: function to retrieve the current time of the clock
81 * @get_softirq_time: function to retrieve the current time from the softirq
82 * @softirq_time: the time when running the hrtimer queue in the softirq
84 struct hrtimer_clock_base {
85 struct hrtimer_cpu_base *cpu_base;
87 struct rb_root active;
88 struct rb_node *first;
90 ktime_t (*get_time)(void);
91 ktime_t (*get_softirq_time)(void);
95 #define HRTIMER_MAX_CLOCK_BASES 2
98 * struct hrtimer_cpu_base - the per cpu clock bases
99 * @lock: lock protecting the base and associated clock bases
101 * @lock_key: the lock_class_key for use with lockdep
102 * @clock_base: array of clock bases for this cpu
103 * @curr_timer: the timer which is executing a callback right now
105 struct hrtimer_cpu_base {
107 struct lock_class_key lock_key;
108 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
109 struct hrtimer *curr_timer;
113 * clock_was_set() is a NOP for non- high-resolution systems. The
114 * time-sorted order guarantees that a timer does not expire early and
115 * is expired in the next softirq when the clock was advanced.
117 #define clock_was_set() do { } while (0)
119 /* Exported timer functions: */
121 /* Initialize timers: */
122 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
123 enum hrtimer_mode mode);
125 /* Basic timer operations: */
126 extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
127 const enum hrtimer_mode mode);
128 extern int hrtimer_cancel(struct hrtimer *timer);
129 extern int hrtimer_try_to_cancel(struct hrtimer *timer);
131 static inline int hrtimer_restart(struct hrtimer *timer)
133 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
137 extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
138 extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
140 #ifdef CONFIG_NO_IDLE_HZ
141 extern ktime_t hrtimer_get_next_event(void);
144 static inline int hrtimer_active(const struct hrtimer *timer)
146 return rb_parent(&timer->node) != &timer->node;
149 /* Forward a hrtimer so it expires after now: */
151 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
154 extern long hrtimer_nanosleep(struct timespec *rqtp,
155 struct timespec __user *rmtp,
156 const enum hrtimer_mode mode,
157 const clockid_t clockid);
158 extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
160 extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
161 struct task_struct *tsk);
163 /* Soft interrupt function to run the hrtimer queues: */
164 extern void hrtimer_run_queues(void);
166 /* Resume notification */
167 void hrtimer_notify_resume(void);
169 /* Bootup initialization: */
170 extern void __init hrtimers_init(void);