4 #include <linux/list.h>
5 #include <linux/ktime.h>
6 #include <linux/stddef.h>
7 #include <linux/debugobjects.h>
8 #include <linux/stringify.h>
14 * All fields that change during normal runtime grouped to the
17 struct hlist_node entry;
18 unsigned long expires;
19 void (*function)(unsigned long);
25 struct lockdep_map lockdep_map;
31 * NB: because we have to copy the lockdep_map, setting the lockdep_map key
32 * (second argument) here is required, otherwise it could be initialised to
33 * the copy of the lockdep_map later! We use the pointer to and the string
34 * "<file>:<line>" as the key resp. the name of the lockdep_map.
36 #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) \
37 .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn),
39 #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn)
43 * A deferrable timer will work normally when the system is busy, but
44 * will not cause a CPU to come out of idle just to service it; instead,
45 * the timer will be serviced when the CPU eventually wakes up with a
46 * subsequent non-deferrable timer.
48 * An irqsafe timer is executed with IRQ disabled and it's safe to wait for
49 * the completion of the running instance from IRQ handlers, for example,
50 * by calling del_timer_sync().
52 * Note: The irq disabled callback execution is a special case for
53 * workqueue locking issues. It's not meant for executing random crap
54 * with interrupts disabled. Abuse is monitored!
56 #define TIMER_CPUMASK 0x0007FFFF
57 #define TIMER_MIGRATING 0x00080000
58 #define TIMER_BASEMASK (TIMER_CPUMASK | TIMER_MIGRATING)
59 #define TIMER_DEFERRABLE 0x00100000
60 #define TIMER_IRQSAFE 0x00200000
61 #define TIMER_PINNED_ON_CPU 0x00400000
63 #define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \
64 .entry = { .next = TIMER_ENTRY_STATIC }, \
65 .function = (_function), \
66 .expires = (_expires), \
70 __TIMER_LOCKDEP_MAP_INITIALIZER( \
71 __FILE__ ":" __stringify(__LINE__)) \
74 #define TIMER_INITIALIZER(_function, _expires, _data) \
75 __TIMER_INITIALIZER((_function), (_expires), (_data), 0)
77 #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) \
78 __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE)
80 #define DEFINE_TIMER(_name, _function, _expires, _data) \
81 struct timer_list _name = \
82 TIMER_INITIALIZER(_function, _expires, _data)
84 void init_timer_key(struct timer_list *timer, unsigned int flags,
85 const char *name, struct lock_class_key *key);
87 #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
88 extern void init_timer_on_stack_key(struct timer_list *timer,
89 unsigned int flags, const char *name,
90 struct lock_class_key *key);
91 extern void destroy_timer_on_stack(struct timer_list *timer);
93 static inline void destroy_timer_on_stack(struct timer_list *timer) { }
94 static inline void init_timer_on_stack_key(struct timer_list *timer,
95 unsigned int flags, const char *name,
96 struct lock_class_key *key)
98 init_timer_key(timer, flags, name, key);
102 #ifdef CONFIG_LOCKDEP
103 #define __init_timer(_timer, _flags) \
105 static struct lock_class_key __key; \
106 init_timer_key((_timer), (_flags), #_timer, &__key); \
109 #define __init_timer_on_stack(_timer, _flags) \
111 static struct lock_class_key __key; \
112 init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \
115 #define __init_timer(_timer, _flags) \
116 init_timer_key((_timer), (_flags), NULL, NULL)
117 #define __init_timer_on_stack(_timer, _flags) \
118 init_timer_on_stack_key((_timer), (_flags), NULL, NULL)
121 #define init_timer(timer) \
122 __init_timer((timer), 0)
123 #define init_timer_deferrable(timer) \
124 __init_timer((timer), TIMER_DEFERRABLE)
125 #define init_timer_on_stack(timer) \
126 __init_timer_on_stack((timer), 0)
128 #define __setup_timer(_timer, _fn, _data, _flags) \
130 __init_timer((_timer), (_flags)); \
131 (_timer)->function = (_fn); \
132 (_timer)->data = (_data); \
135 #define __setup_timer_on_stack(_timer, _fn, _data, _flags) \
137 __init_timer_on_stack((_timer), (_flags)); \
138 (_timer)->function = (_fn); \
139 (_timer)->data = (_data); \
142 #define setup_timer(timer, fn, data) \
143 __setup_timer((timer), (fn), (data), 0)
144 #define setup_timer_on_stack(timer, fn, data) \
145 __setup_timer_on_stack((timer), (fn), (data), 0)
146 #define setup_deferrable_timer_on_stack(timer, fn, data) \
147 __setup_timer_on_stack((timer), (fn), (data), TIMER_DEFERRABLE)
150 * timer_pending - is a timer pending?
151 * @timer: the timer in question
153 * timer_pending will tell whether a given timer is currently pending,
154 * or not. Callers must ensure serialization wrt. other operations done
155 * to this timer, eg. interrupt contexts, or other CPUs on SMP.
157 * return value: 1 if the timer is pending, 0 if not.
159 static inline int timer_pending(const struct timer_list * timer)
161 return timer->entry.pprev != NULL;
164 extern void add_timer_on(struct timer_list *timer, int cpu);
165 extern int del_timer(struct timer_list * timer);
166 extern int mod_timer(struct timer_list *timer, unsigned long expires);
167 extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
168 extern int mod_timer_pinned(struct timer_list *timer, unsigned long expires);
170 extern void set_timer_slack(struct timer_list *time, int slack_hz);
172 extern bool check_pending_deferrable_timers(int cpu);
175 #define TIMER_NOT_PINNED 0
176 #define TIMER_PINNED 1
178 * The jiffies value which is added to now, when there is no timer
179 * in the timer wheel:
181 #define NEXT_TIMER_MAX_DELTA ((1UL << 30) - 1)
183 /* To be used from cpusets, only */
184 extern void timer_quiesce_cpu(void *cpup);
186 extern void add_timer(struct timer_list *timer);
188 extern int try_to_del_timer_sync(struct timer_list *timer);
191 extern int del_timer_sync(struct timer_list *timer);
193 # define del_timer_sync(t) del_timer(t)
196 #define del_singleshot_timer_sync(t) del_timer_sync(t)
198 extern void init_timers(void);
199 extern void run_local_timers(void);
201 extern enum hrtimer_restart it_real_fn(struct hrtimer *);
203 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
204 #include <linux/sysctl.h>
206 extern struct tvec_base tvec_base_deferrable;
208 extern unsigned int sysctl_timer_migration;
209 int timer_migration_handler(struct ctl_table *table, int write,
210 void __user *buffer, size_t *lenp,
214 unsigned long __round_jiffies(unsigned long j, int cpu);
215 unsigned long __round_jiffies_relative(unsigned long j, int cpu);
216 unsigned long round_jiffies(unsigned long j);
217 unsigned long round_jiffies_relative(unsigned long j);
219 unsigned long __round_jiffies_up(unsigned long j, int cpu);
220 unsigned long __round_jiffies_up_relative(unsigned long j, int cpu);
221 unsigned long round_jiffies_up(unsigned long j);
222 unsigned long round_jiffies_up_relative(unsigned long j);