1
2#ifndef _LINUX_TIMER_H
3#define _LINUX_TIMER_H
4
5#include <linux/list.h>
6#include <linux/ktime.h>
7#include <linux/stddef.h>
8#include <linux/debugobjects.h>
9#include <linux/stringify.h>
10
11struct timer_list {
12
13
14
15
16 struct hlist_node entry;
17 unsigned long expires;
18 void (*function)(struct timer_list *);
19 u32 flags;
20
21#ifdef CONFIG_LOCKDEP
22 struct lockdep_map lockdep_map;
23#endif
24};
25
26#ifdef CONFIG_LOCKDEP
27
28
29
30
31
32
33#define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) \
34 .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn),
35#else
36#define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn)
37#endif
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64#define TIMER_CPUMASK 0x0003FFFF
65#define TIMER_MIGRATING 0x00040000
66#define TIMER_BASEMASK (TIMER_CPUMASK | TIMER_MIGRATING)
67#define TIMER_DEFERRABLE 0x00080000
68#define TIMER_PINNED 0x00100000
69#define TIMER_IRQSAFE 0x00200000
70#define TIMER_INIT_FLAGS (TIMER_DEFERRABLE | TIMER_PINNED | TIMER_IRQSAFE)
71#define TIMER_ARRAYSHIFT 22
72#define TIMER_ARRAYMASK 0xFFC00000
73
74#define TIMER_TRACE_FLAGMASK (TIMER_MIGRATING | TIMER_DEFERRABLE | TIMER_PINNED | TIMER_IRQSAFE)
75
76#define __TIMER_INITIALIZER(_function, _flags) { \
77 .entry = { .next = TIMER_ENTRY_STATIC }, \
78 .function = (_function), \
79 .flags = (_flags), \
80 __TIMER_LOCKDEP_MAP_INITIALIZER( \
81 __FILE__ ":" __stringify(__LINE__)) \
82 }
83
84#define DEFINE_TIMER(_name, _function) \
85 struct timer_list _name = \
86 __TIMER_INITIALIZER(_function, 0)
87
88
89
90
91void init_timer_key(struct timer_list *timer,
92 void (*func)(struct timer_list *), unsigned int flags,
93 const char *name, struct lock_class_key *key);
94
95#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
96extern void init_timer_on_stack_key(struct timer_list *timer,
97 void (*func)(struct timer_list *),
98 unsigned int flags, const char *name,
99 struct lock_class_key *key);
100#else
101static inline void init_timer_on_stack_key(struct timer_list *timer,
102 void (*func)(struct timer_list *),
103 unsigned int flags,
104 const char *name,
105 struct lock_class_key *key)
106{
107 init_timer_key(timer, func, flags, name, key);
108}
109#endif
110
111#ifdef CONFIG_LOCKDEP
112#define __init_timer(_timer, _fn, _flags) \
113 do { \
114 static struct lock_class_key __key; \
115 init_timer_key((_timer), (_fn), (_flags), #_timer, &__key);\
116 } while (0)
117
118#define __init_timer_on_stack(_timer, _fn, _flags) \
119 do { \
120 static struct lock_class_key __key; \
121 init_timer_on_stack_key((_timer), (_fn), (_flags), \
122 #_timer, &__key); \
123 } while (0)
124#else
125#define __init_timer(_timer, _fn, _flags) \
126 init_timer_key((_timer), (_fn), (_flags), NULL, NULL)
127#define __init_timer_on_stack(_timer, _fn, _flags) \
128 init_timer_on_stack_key((_timer), (_fn), (_flags), NULL, NULL)
129#endif
130
131
132
133
134
135
136
137
138
139
140
141#define timer_setup(timer, callback, flags) \
142 __init_timer((timer), (callback), (flags))
143
144#define timer_setup_on_stack(timer, callback, flags) \
145 __init_timer_on_stack((timer), (callback), (flags))
146
147#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
148extern void destroy_timer_on_stack(struct timer_list *timer);
149#else
150static inline void destroy_timer_on_stack(struct timer_list *timer) { }
151#endif
152
153#define from_timer(var, callback_timer, timer_fieldname) \
154 container_of(callback_timer, typeof(*var), timer_fieldname)
155
156
157
158
159
160
161
162
163
164
165
166static inline int timer_pending(const struct timer_list * timer)
167{
168 return !hlist_unhashed_lockless(&timer->entry);
169}
170
171extern void add_timer_on(struct timer_list *timer, int cpu);
172extern int del_timer(struct timer_list * timer);
173extern int mod_timer(struct timer_list *timer, unsigned long expires);
174extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
175extern int timer_reduce(struct timer_list *timer, unsigned long expires);
176
177
178
179
180
181#define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1)
182
183extern void add_timer(struct timer_list *timer);
184
185extern int try_to_del_timer_sync(struct timer_list *timer);
186
187#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT)
188 extern int del_timer_sync(struct timer_list *timer);
189#else
190# define del_timer_sync(t) del_timer(t)
191#endif
192
193#define del_singleshot_timer_sync(t) del_timer_sync(t)
194
195extern void init_timers(void);
196struct hrtimer;
197extern enum hrtimer_restart it_real_fn(struct hrtimer *);
198
199#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
200struct ctl_table;
201
202extern unsigned int sysctl_timer_migration;
203int timer_migration_handler(struct ctl_table *table, int write,
204 void *buffer, size_t *lenp, loff_t *ppos);
205#endif
206
207unsigned long __round_jiffies(unsigned long j, int cpu);
208unsigned long __round_jiffies_relative(unsigned long j, int cpu);
209unsigned long round_jiffies(unsigned long j);
210unsigned long round_jiffies_relative(unsigned long j);
211
212unsigned long __round_jiffies_up(unsigned long j, int cpu);
213unsigned long __round_jiffies_up_relative(unsigned long j, int cpu);
214unsigned long round_jiffies_up(unsigned long j);
215unsigned long round_jiffies_up_relative(unsigned long j);
216
217#ifdef CONFIG_HOTPLUG_CPU
218int timers_prepare_cpu(unsigned int cpu);
219int timers_dead_cpu(unsigned int cpu);
220#else
221#define timers_prepare_cpu NULL
222#define timers_dead_cpu NULL
223#endif
224
225#endif
226