blob: f57cc7bd7008e0e6dc4fb1a81d56e1b6710622b2 [file] [log] [blame]
Thomas Gleixnerc0a31322006-01-09 20:52:32 -08001/*
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
Roman Zippelb75f7a52006-03-26 01:38:09 -080037#define HRTIMER_INACTIVE ((void *)1UL)
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080038
39struct hrtimer_base;
40
41/**
42 * struct hrtimer - the basic hrtimer structure
43 *
44 * @node: red black tree node for time ordered insertion
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080045 * @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.
48 * @state: state of the timer
49 * @function: timer expiry callback function
50 * @data: argument for the callback function
51 * @base: pointer to the timer base (per cpu and per clock)
52 *
53 * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
54 */
55struct hrtimer {
56 struct rb_node node;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080057 ktime_t expires;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080058 int (*function)(void *);
59 void *data;
60 struct hrtimer_base *base;
61};
62
63/**
64 * struct hrtimer_base - the timer base for a specific clock
65 *
Thomas Gleixner92127c72006-03-26 01:38:05 -080066 * @index: clock type index for per_cpu support when moving a timer
67 * to a base on another cpu.
68 * @lock: lock protecting the base and associated timers
69 * @active: red black tree root node for the active timers
70 * @first: pointer to the timer node which expires first
71 * @resolution: the resolution of the clock, in nanoseconds
72 * @get_time: function to retrieve the current time of the clock
73 * @get_sofirq_time: function to retrieve the current time from the softirq
74 * @curr_timer: the timer which is executing a callback right now
75 * @softirq_time: the time when running the hrtimer queue in the softirq
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080076 */
77struct hrtimer_base {
78 clockid_t index;
79 spinlock_t lock;
80 struct rb_root active;
Thomas Gleixner288867e2006-01-12 11:25:54 +010081 struct rb_node *first;
Thomas Gleixnere2787632006-01-12 11:36:14 +010082 ktime_t resolution;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080083 ktime_t (*get_time)(void);
Thomas Gleixner92127c72006-03-26 01:38:05 -080084 ktime_t (*get_softirq_time)(void);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080085 struct hrtimer *curr_timer;
Thomas Gleixner92127c72006-03-26 01:38:05 -080086 ktime_t softirq_time;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080087};
88
Thomas Gleixnerbecf8b52006-01-09 20:52:38 -080089/*
90 * clock_was_set() is a NOP for non- high-resolution systems. The
91 * time-sorted order guarantees that a timer does not expire early and
92 * is expired in the next softirq when the clock was advanced.
93 */
94#define clock_was_set() do { } while (0)
95
Thomas Gleixnerc0a31322006-01-09 20:52:32 -080096/* Exported timer functions: */
97
98/* Initialize timers: */
George Anzinger79786722006-02-01 03:05:11 -080099extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
100 enum hrtimer_mode mode);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800101
102/* Basic timer operations: */
103extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
104 const enum hrtimer_mode mode);
105extern int hrtimer_cancel(struct hrtimer *timer);
106extern int hrtimer_try_to_cancel(struct hrtimer *timer);
107
108#define hrtimer_restart(timer) hrtimer_start((timer), (timer)->expires, HRTIMER_ABS)
109
110/* Query timers: */
111extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
112extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
113
Tony Lindgren69239742006-03-06 15:42:45 -0800114#ifdef CONFIG_NO_IDLE_HZ
115extern ktime_t hrtimer_get_next_event(void);
116#endif
117
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800118static inline int hrtimer_active(const struct hrtimer *timer)
119{
Roman Zippelb75f7a52006-03-26 01:38:09 -0800120 return timer->node.rb_parent != HRTIMER_INACTIVE;
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800121}
122
123/* Forward a hrtimer so it expires after now: */
Roman Zippel44f21472006-03-26 01:38:06 -0800124extern unsigned long
125hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800126
Thomas Gleixner10c94ec2006-01-09 20:52:35 -0800127/* Precise sleep: */
128extern long hrtimer_nanosleep(struct timespec *rqtp,
129 struct timespec __user *rmtp,
130 const enum hrtimer_mode mode,
131 const clockid_t clockid);
132
Thomas Gleixnerc0a31322006-01-09 20:52:32 -0800133/* Soft interrupt function to run the hrtimer queues: */
134extern void hrtimer_run_queues(void);
135
136/* Bootup initialization: */
137extern void __init hrtimers_init(void);
138
139#endif