[hrtimer] Remove listhead from hrtimer struct
[linux-2.6-block.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 {
28 HRTIMER_ABS, /* Time value is absolute */
29 HRTIMER_REL, /* Time value is relative to now */
30};
31
32enum hrtimer_restart {
33 HRTIMER_NORESTART,
34 HRTIMER_RESTART,
35};
36
37/*
38 * Timer states:
39 */
40enum hrtimer_state {
41 HRTIMER_INACTIVE, /* Timer is inactive */
42 HRTIMER_EXPIRED, /* Timer is expired */
43 HRTIMER_PENDING, /* Timer is pending */
44};
45
46struct hrtimer_base;
47
48/**
49 * struct hrtimer - the basic hrtimer structure
50 *
51 * @node: red black tree node for time ordered insertion
c0a31329
TG
52 * @expires: the absolute expiry time in the hrtimers internal
53 * representation. The time is related to the clock on
54 * which the timer is based.
55 * @state: state of the timer
56 * @function: timer expiry callback function
57 * @data: argument for the callback function
58 * @base: pointer to the timer base (per cpu and per clock)
59 *
60 * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
61 */
62struct hrtimer {
63 struct rb_node node;
c0a31329
TG
64 ktime_t expires;
65 enum hrtimer_state state;
66 int (*function)(void *);
67 void *data;
68 struct hrtimer_base *base;
69};
70
71/**
72 * struct hrtimer_base - the timer base for a specific clock
73 *
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
288867ec 78 * @first: pointer to the timer node which expires first
c0a31329
TG
79 * @resolution: the resolution of the clock, in nanoseconds
80 * @get_time: function to retrieve the current time of the clock
81 * @curr_timer: the timer which is executing a callback right now
82 */
83struct hrtimer_base {
84 clockid_t index;
85 spinlock_t lock;
86 struct rb_root active;
288867ec 87 struct rb_node *first;
c0a31329
TG
88 unsigned long resolution;
89 ktime_t (*get_time)(void);
90 struct hrtimer *curr_timer;
91};
92
becf8b5d
TG
93/*
94 * clock_was_set() is a NOP for non- high-resolution systems. The
95 * time-sorted order guarantees that a timer does not expire early and
96 * is expired in the next softirq when the clock was advanced.
97 */
98#define clock_was_set() do { } while (0)
99
c0a31329
TG
100/* Exported timer functions: */
101
102/* Initialize timers: */
103extern void hrtimer_init(struct hrtimer *timer, const clockid_t which_clock);
104extern void hrtimer_rebase(struct hrtimer *timer, const clockid_t which_clock);
105
106
107/* Basic timer operations: */
108extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
109 const enum hrtimer_mode mode);
110extern int hrtimer_cancel(struct hrtimer *timer);
111extern int hrtimer_try_to_cancel(struct hrtimer *timer);
112
113#define hrtimer_restart(timer) hrtimer_start((timer), (timer)->expires, HRTIMER_ABS)
114
115/* Query timers: */
116extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
117extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
118
119static inline int hrtimer_active(const struct hrtimer *timer)
120{
121 return timer->state == HRTIMER_PENDING;
122}
123
124/* Forward a hrtimer so it expires after now: */
125extern unsigned long hrtimer_forward(struct hrtimer *timer,
126 const ktime_t interval);
127
10c94ec1
TG
128/* Precise sleep: */
129extern long hrtimer_nanosleep(struct timespec *rqtp,
130 struct timespec __user *rmtp,
131 const enum hrtimer_mode mode,
132 const clockid_t clockid);
133
c0a31329
TG
134/* Soft interrupt function to run the hrtimer queues: */
135extern void hrtimer_run_queues(void);
136
137/* Bootup initialization: */
138extern void __init hrtimers_init(void);
139
140#endif