1
2
3
4
5
6
7
8
9
10
11
12
13
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
24struct hrtimer_clock_base;
25struct hrtimer_cpu_base;
26
27
28
29
30enum hrtimer_mode {
31 HRTIMER_MODE_ABS,
32 HRTIMER_MODE_REL,
33};
34
35
36
37
38enum hrtimer_restart {
39 HRTIMER_NORESTART,
40 HRTIMER_RESTART,
41};
42
43
44
45
46
47
48
49
50
51
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112struct hrtimer {
113 struct rb_node node;
114 ktime_t expires;
115 enum hrtimer_restart (*function)(struct hrtimer *);
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
127};
128
129
130
131
132
133
134
135
136struct hrtimer_sleeper {
137 struct hrtimer timer;
138 struct task_struct *task;
139};
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156struct hrtimer_clock_base {
157 struct hrtimer_cpu_base *cpu_base;
158 clockid_t index;
159 struct rb_root active;
160 struct rb_node *first;
161 ktime_t resolution;
162 ktime_t (*get_time)(void);
163 ktime_t (*get_softirq_time)(void);
164 ktime_t softirq_time;
165#ifdef CONFIG_HIGH_RES_TIMERS
166 ktime_t offset;
167 int (*reprogram)(struct hrtimer *t,
168 struct hrtimer_clock_base *b,
169 ktime_t n);
170#endif
171};
172
173#define HRTIMER_MAX_CLOCK_BASES 2
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193struct hrtimer_cpu_base {
194 spinlock_t lock;
195 struct lock_class_key lock_key;
196 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
197#ifdef CONFIG_HIGH_RES_TIMERS
198 ktime_t expires_next;
199 int hres_active;
200 struct list_head cb_pending;
201 unsigned long nr_events;
202#endif
203};
204
205#ifdef CONFIG_HIGH_RES_TIMERS
206struct clock_event_device;
207
208extern void clock_was_set(void);
209extern void hres_timers_resume(void);
210extern void hrtimer_interrupt(struct clock_event_device *dev);
211
212
213
214
215static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
216{
217 return timer->base->get_time();
218}
219
220
221
222
223
224
225
226# define KTIME_HIGH_RES (ktime_t) { .tv64 = 1 }
227# define KTIME_MONOTONIC_RES KTIME_HIGH_RES
228
229#else
230
231# define KTIME_MONOTONIC_RES KTIME_LOW_RES
232
233
234
235
236
237
238static inline void clock_was_set(void) { }
239
240static inline void hres_timers_resume(void) { }
241
242
243
244
245
246static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
247{
248 return timer->base->softirq_time;
249}
250
251#endif
252
253extern ktime_t ktime_get(void);
254extern ktime_t ktime_get_real(void);
255
256
257
258
259extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
260 enum hrtimer_mode mode);
261
262
263extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
264 const enum hrtimer_mode mode);
265extern int hrtimer_cancel(struct hrtimer *timer);
266extern int hrtimer_try_to_cancel(struct hrtimer *timer);
267
268static inline int hrtimer_restart(struct hrtimer *timer)
269{
270 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
271}
272
273
274extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
275extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
276
277extern ktime_t hrtimer_get_next_event(void);
278
279
280
281
282
283static inline int hrtimer_active(const struct hrtimer *timer)
284{
285 return timer->state != HRTIMER_STATE_INACTIVE;
286}
287
288
289
290
291static inline int hrtimer_is_queued(struct hrtimer *timer)
292{
293 return timer->state &
294 (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
295}
296
297
298extern unsigned long
299hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
300
301
302extern long hrtimer_nanosleep(struct timespec *rqtp,
303 struct timespec *rmtp,
304 const enum hrtimer_mode mode,
305 const clockid_t clockid);
306extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
307
308extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
309 struct task_struct *tsk);
310
311
312extern void hrtimer_run_queues(void);
313
314
315extern void __init hrtimers_init(void);
316
317#if BITS_PER_LONG < 64
318extern unsigned long ktime_divns(const ktime_t kt, s64 div);
319#else
320# define ktime_divns(kt, div) (unsigned long)((kt).tv64 / (div))
321#endif
322
323
324extern void sysrq_timer_list_show(void);
325
326
327
328
329#ifdef CONFIG_TIMER_STATS
330
331extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
332 void *timerf, char *comm,
333 unsigned int timer_flag);
334
335static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
336{
337 timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
338 timer->function, timer->start_comm, 0);
339}
340
341extern void __timer_stats_hrtimer_set_start_info(struct hrtimer *timer,
342 void *addr);
343
344static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
345{
346 __timer_stats_hrtimer_set_start_info(timer, __builtin_return_address(0));
347}
348
349static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer)
350{
351 timer->start_site = NULL;
352}
353#else
354static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
355{
356}
357
358static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
359{
360}
361
362static inline void timer_stats_hrtimer_clear_start_info(struct hrtimer *timer)
363{
364}
365#endif
366
367#endif
368