]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/hrtimer.h
[PATCH] hrtimers: namespace and enum cleanup
[mirror_ubuntu-bionic-kernel.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
24/*
25 * Mode arguments of xxx_hrtimer functions:
26 */
27enum hrtimer_mode {
c9cb2e3d
TG
28 HRTIMER_MODE_ABS, /* Time value is absolute */
29 HRTIMER_MODE_REL, /* Time value is relative to now */
c0a31329
TG
30};
31
c9cb2e3d
TG
32/*
33 * Return values for the callback function
34 */
c0a31329 35enum hrtimer_restart {
c9cb2e3d
TG
36 HRTIMER_NORESTART, /* Timer is not restarted */
37 HRTIMER_RESTART, /* Timer must be restarted */
c0a31329
TG
38};
39
c0a31329
TG
40struct hrtimer_base;
41
42/**
43 * struct hrtimer - the basic hrtimer structure
c0a31329 44 * @node: red black tree node for time ordered insertion
c0a31329
TG
45 * @expires: the absolute expiry time in the hrtimers internal
46 * representation. The time is related to the clock on
47 * which the timer is based.
c0a31329 48 * @function: timer expiry callback function
c0a31329
TG
49 * @base: pointer to the timer base (per cpu and per clock)
50 *
51 * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
52 */
53struct hrtimer {
54 struct rb_node node;
c0a31329 55 ktime_t expires;
c9cb2e3d 56 enum hrtimer_restart (*function)(struct hrtimer *);
c0a31329
TG
57 struct hrtimer_base *base;
58};
59
00362e33
TG
60/**
61 * struct hrtimer_sleeper - simple sleeper structure
00362e33
TG
62 * @timer: embedded timer structure
63 * @task: task to wake up
64 *
65 * task is set to NULL, when the timer expires.
66 */
67struct hrtimer_sleeper {
68 struct hrtimer timer;
69 struct task_struct *task;
70};
71
c0a31329
TG
72/**
73 * struct hrtimer_base - the timer base for a specific clock
92127c7a
TG
74 * @index: clock type index for per_cpu support when moving a timer
75 * to a base on another cpu.
76 * @lock: lock protecting the base and associated timers
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
a580290c 81 * @get_softirq_time: function to retrieve the current time from the softirq
92127c7a
TG
82 * @curr_timer: the timer which is executing a callback right now
83 * @softirq_time: the time when running the hrtimer queue in the softirq
6dba2837 84 * @lock_key: the lock_class_key for use with lockdep
c0a31329
TG
85 */
86struct hrtimer_base {
87 clockid_t index;
88 spinlock_t lock;
89 struct rb_root active;
288867ec 90 struct rb_node *first;
e2787630 91 ktime_t resolution;
c0a31329 92 ktime_t (*get_time)(void);
92127c7a 93 ktime_t (*get_softirq_time)(void);
c0a31329 94 struct hrtimer *curr_timer;
92127c7a 95 ktime_t softirq_time;
54365524 96 struct lock_class_key lock_key;
c0a31329
TG
97};
98
becf8b5d
TG
99/*
100 * clock_was_set() is a NOP for non- high-resolution systems. The
101 * time-sorted order guarantees that a timer does not expire early and
102 * is expired in the next softirq when the clock was advanced.
103 */
104#define clock_was_set() do { } while (0)
105
c0a31329
TG
106/* Exported timer functions: */
107
108/* Initialize timers: */
7978672c
GA
109extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
110 enum hrtimer_mode mode);
c0a31329
TG
111
112/* Basic timer operations: */
113extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
114 const enum hrtimer_mode mode);
115extern int hrtimer_cancel(struct hrtimer *timer);
116extern int hrtimer_try_to_cancel(struct hrtimer *timer);
117
c9cb2e3d
TG
118static inline int hrtimer_restart(struct hrtimer *timer)
119{
120 return hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
121}
c0a31329
TG
122
123/* Query timers: */
124extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
125extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
126
69239749
TL
127#ifdef CONFIG_NO_IDLE_HZ
128extern ktime_t hrtimer_get_next_event(void);
129#endif
130
c0a31329
TG
131static inline int hrtimer_active(const struct hrtimer *timer)
132{
ed198cb4 133 return rb_parent(&timer->node) != &timer->node;
c0a31329
TG
134}
135
136/* Forward a hrtimer so it expires after now: */
44f21475
RZ
137extern unsigned long
138hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
c0a31329 139
10c94ec1
TG
140/* Precise sleep: */
141extern long hrtimer_nanosleep(struct timespec *rqtp,
142 struct timespec __user *rmtp,
143 const enum hrtimer_mode mode,
144 const clockid_t clockid);
1711ef38 145extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
10c94ec1 146
00362e33
TG
147extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
148 struct task_struct *tsk);
149
c0a31329
TG
150/* Soft interrupt function to run the hrtimer queues: */
151extern void hrtimer_run_queues(void);
152
411187fb
JS
153/* Resume notification */
154void hrtimer_notify_resume(void);
155
c0a31329
TG
156/* Bootup initialization: */
157extern void __init hrtimers_init(void);
158
159#endif