Merge branch 'x86-fpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / timer.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_TIMER_H
2#define _LINUX_TIMER_H
3
1da177e4 4#include <linux/list.h>
82f67cd9 5#include <linux/ktime.h>
1da177e4 6#include <linux/stddef.h>
c6f3a97f 7#include <linux/debugobjects.h>
6f2b9b9a 8#include <linux/stringify.h>
1da177e4 9
a6fa8e5a 10struct tvec_base;
1da177e4
LT
11
12struct timer_list {
13 struct list_head entry;
14 unsigned long expires;
15
1da177e4
LT
16 void (*function)(unsigned long);
17 unsigned long data;
18
a6fa8e5a 19 struct tvec_base *base;
82f67cd9
IM
20#ifdef CONFIG_TIMER_STATS
21 void *start_site;
22 char start_comm[16];
23 int start_pid;
24#endif
6f2b9b9a
JB
25#ifdef CONFIG_LOCKDEP
26 struct lockdep_map lockdep_map;
27#endif
1da177e4
LT
28};
29
a6fa8e5a 30extern struct tvec_base boot_tvec_bases;
55c888d6 31
6f2b9b9a
JB
32#ifdef CONFIG_LOCKDEP
33/*
34 * NB: because we have to copy the lockdep_map, setting the lockdep_map key
35 * (second argument) here is required, otherwise it could be initialised to
36 * the copy of the lockdep_map later! We use the pointer to and the string
37 * "<file>:<line>" as the key resp. the name of the lockdep_map.
38 */
39#define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) \
40 .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn),
41#else
42#define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn)
43#endif
44
1da177e4 45#define TIMER_INITIALIZER(_function, _expires, _data) { \
c6f3a97f 46 .entry = { .prev = TIMER_ENTRY_STATIC }, \
1da177e4
LT
47 .function = (_function), \
48 .expires = (_expires), \
49 .data = (_data), \
3691c519 50 .base = &boot_tvec_bases, \
6f2b9b9a
JB
51 __TIMER_LOCKDEP_MAP_INITIALIZER( \
52 __FILE__ ":" __stringify(__LINE__)) \
1da177e4
LT
53 }
54
8d06afab
IM
55#define DEFINE_TIMER(_name, _function, _expires, _data) \
56 struct timer_list _name = \
57 TIMER_INITIALIZER(_function, _expires, _data)
58
6f2b9b9a
JB
59void init_timer_key(struct timer_list *timer,
60 const char *name,
61 struct lock_class_key *key);
62void init_timer_deferrable_key(struct timer_list *timer,
63 const char *name,
64 struct lock_class_key *key);
65
66#ifdef CONFIG_LOCKDEP
67#define init_timer(timer) \
68 do { \
69 static struct lock_class_key __key; \
70 init_timer_key((timer), #timer, &__key); \
71 } while (0)
72
73#define init_timer_deferrable(timer) \
74 do { \
75 static struct lock_class_key __key; \
76 init_timer_deferrable_key((timer), #timer, &__key); \
77 } while (0)
78
79#define init_timer_on_stack(timer) \
80 do { \
81 static struct lock_class_key __key; \
82 init_timer_on_stack_key((timer), #timer, &__key); \
83 } while (0)
84
85#define setup_timer(timer, fn, data) \
86 do { \
87 static struct lock_class_key __key; \
88 setup_timer_key((timer), #timer, &__key, (fn), (data));\
89 } while (0)
90
91#define setup_timer_on_stack(timer, fn, data) \
92 do { \
93 static struct lock_class_key __key; \
94 setup_timer_on_stack_key((timer), #timer, &__key, \
95 (fn), (data)); \
96 } while (0)
97#else
98#define init_timer(timer)\
99 init_timer_key((timer), NULL, NULL)
100#define init_timer_deferrable(timer)\
101 init_timer_deferrable_key((timer), NULL, NULL)
102#define init_timer_on_stack(timer)\
103 init_timer_on_stack_key((timer), NULL, NULL)
104#define setup_timer(timer, fn, data)\
105 setup_timer_key((timer), NULL, NULL, (fn), (data))
106#define setup_timer_on_stack(timer, fn, data)\
107 setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data))
108#endif
1da177e4 109
c6f3a97f 110#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
6f2b9b9a
JB
111extern void init_timer_on_stack_key(struct timer_list *timer,
112 const char *name,
113 struct lock_class_key *key);
c6f3a97f
TG
114extern void destroy_timer_on_stack(struct timer_list *timer);
115#else
116static inline void destroy_timer_on_stack(struct timer_list *timer) { }
6f2b9b9a
JB
117static inline void init_timer_on_stack_key(struct timer_list *timer,
118 const char *name,
119 struct lock_class_key *key)
c6f3a97f 120{
6f2b9b9a 121 init_timer_key(timer, name, key);
c6f3a97f
TG
122}
123#endif
124
6f2b9b9a
JB
125static inline void setup_timer_key(struct timer_list * timer,
126 const char *name,
127 struct lock_class_key *key,
a8db2db1
ON
128 void (*function)(unsigned long),
129 unsigned long data)
130{
131 timer->function = function;
132 timer->data = data;
6f2b9b9a 133 init_timer_key(timer, name, key);
a8db2db1
ON
134}
135
6f2b9b9a
JB
136static inline void setup_timer_on_stack_key(struct timer_list *timer,
137 const char *name,
138 struct lock_class_key *key,
c6f3a97f
TG
139 void (*function)(unsigned long),
140 unsigned long data)
141{
142 timer->function = function;
143 timer->data = data;
6f2b9b9a 144 init_timer_on_stack_key(timer, name, key);
c6f3a97f
TG
145}
146
45f8bde0 147/**
1da177e4
LT
148 * timer_pending - is a timer pending?
149 * @timer: the timer in question
150 *
151 * timer_pending will tell whether a given timer is currently pending,
152 * or not. Callers must ensure serialization wrt. other operations done
153 * to this timer, eg. interrupt contexts, or other CPUs on SMP.
154 *
155 * return value: 1 if the timer is pending, 0 if not.
156 */
157static inline int timer_pending(const struct timer_list * timer)
158{
55c888d6 159 return timer->entry.next != NULL;
1da177e4
LT
160}
161
162extern void add_timer_on(struct timer_list *timer, int cpu);
163extern int del_timer(struct timer_list * timer);
1da177e4 164extern int mod_timer(struct timer_list *timer, unsigned long expires);
74019224 165extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
1da177e4 166
eaad084b
TG
167/*
168 * The jiffies value which is added to now, when there is no timer
169 * in the timer wheel:
170 */
171#define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1)
172
fd064b9b
TG
173/*
174 * Return when the next timer-wheel timeout occurs (in absolute jiffies),
175 * locks the timer base:
176 */
1da177e4 177extern unsigned long next_timer_interrupt(void);
fd064b9b
TG
178/*
179 * Return when the next timer-wheel timeout occurs (in absolute jiffies),
180 * locks the timer base and does the comparison against the given
181 * jiffie.
182 */
183extern unsigned long get_next_timer_interrupt(unsigned long now);
1da177e4 184
82f67cd9
IM
185/*
186 * Timer-statistics info:
187 */
188#ifdef CONFIG_TIMER_STATS
189
c5c061b8
VP
190#define TIMER_STATS_FLAG_DEFERRABLE 0x1
191
82f67cd9
IM
192extern void init_timer_stats(void);
193
194extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
c5c061b8
VP
195 void *timerf, char *comm,
196 unsigned int timer_flag);
82f67cd9
IM
197
198extern void __timer_stats_timer_set_start_info(struct timer_list *timer,
199 void *addr);
200
201static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
202{
203 __timer_stats_timer_set_start_info(timer, __builtin_return_address(0));
204}
205
206static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
207{
208 timer->start_site = NULL;
209}
210#else
211static inline void init_timer_stats(void)
212{
213}
214
82f67cd9
IM
215static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
216{
217}
218
219static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
220{
221}
222#endif
223
74019224 224extern void add_timer(struct timer_list *timer);
1da177e4
LT
225
226#ifdef CONFIG_SMP
fd450b73 227 extern int try_to_del_timer_sync(struct timer_list *timer);
1da177e4 228 extern int del_timer_sync(struct timer_list *timer);
1da177e4 229#else
fd450b73
ON
230# define try_to_del_timer_sync(t) del_timer(t)
231# define del_timer_sync(t) del_timer(t)
1da177e4
LT
232#endif
233
55c888d6
ON
234#define del_singleshot_timer_sync(t) del_timer_sync(t)
235
1da177e4
LT
236extern void init_timers(void);
237extern void run_local_timers(void);
05cfb614 238struct hrtimer;
c9cb2e3d 239extern enum hrtimer_restart it_real_fn(struct hrtimer *);
1da177e4 240
4c36a5de
AV
241unsigned long __round_jiffies(unsigned long j, int cpu);
242unsigned long __round_jiffies_relative(unsigned long j, int cpu);
243unsigned long round_jiffies(unsigned long j);
244unsigned long round_jiffies_relative(unsigned long j);
245
9c133c46
AS
246unsigned long __round_jiffies_up(unsigned long j, int cpu);
247unsigned long __round_jiffies_up_relative(unsigned long j, int cpu);
248unsigned long round_jiffies_up(unsigned long j);
249unsigned long round_jiffies_up_relative(unsigned long j);
250
1da177e4 251#endif