OSDN Git Service

Merge 72078891843ce0d5b8e95040d09ba92913916af9 on remote branch
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / timer.h
1 #ifndef _LINUX_TIMER_H
2 #define _LINUX_TIMER_H
3
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>
9
10 struct tvec_base;
11
12 struct timer_list {
13         /*
14          * All fields that change during normal runtime grouped to the
15          * same cacheline
16          */
17         struct hlist_node       entry;
18         unsigned long           expires;
19         void                    (*function)(unsigned long);
20         unsigned long           data;
21         u32                     flags;
22         int                     slack;
23
24 #ifdef CONFIG_LOCKDEP
25         struct lockdep_map      lockdep_map;
26 #endif
27 };
28
29 #ifdef CONFIG_LOCKDEP
30 /*
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.
35  */
36 #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn)                            \
37         .lockdep_map = STATIC_LOCKDEP_MAP_INIT(_kn, &_kn),
38 #else
39 #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn)
40 #endif
41
42 /*
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.
47  *
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().
51  *
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!
55  */
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
62
63 #define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \
64                 .entry = { .next = TIMER_ENTRY_STATIC },        \
65                 .function = (_function),                        \
66                 .expires = (_expires),                          \
67                 .data = (_data),                                \
68                 .flags = (_flags),                              \
69                 .slack = -1,                                    \
70                 __TIMER_LOCKDEP_MAP_INITIALIZER(                \
71                         __FILE__ ":" __stringify(__LINE__))     \
72         }
73
74 #define TIMER_INITIALIZER(_function, _expires, _data)           \
75         __TIMER_INITIALIZER((_function), (_expires), (_data), 0)
76
77 #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data)  \
78         __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE)
79
80 #define DEFINE_TIMER(_name, _function, _expires, _data)         \
81         struct timer_list _name =                               \
82                 TIMER_INITIALIZER(_function, _expires, _data)
83
84 void init_timer_key(struct timer_list *timer, unsigned int flags,
85                     const char *name, struct lock_class_key *key);
86
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);
92 #else
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)
97 {
98         init_timer_key(timer, flags, name, key);
99 }
100 #endif
101
102 #ifdef CONFIG_LOCKDEP
103 #define __init_timer(_timer, _flags)                                    \
104         do {                                                            \
105                 static struct lock_class_key __key;                     \
106                 init_timer_key((_timer), (_flags), #_timer, &__key);    \
107         } while (0)
108
109 #define __init_timer_on_stack(_timer, _flags)                           \
110         do {                                                            \
111                 static struct lock_class_key __key;                     \
112                 init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \
113         } while (0)
114 #else
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)
119 #endif
120
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)
127
128 #define __setup_timer(_timer, _fn, _data, _flags)                       \
129         do {                                                            \
130                 __init_timer((_timer), (_flags));                       \
131                 (_timer)->function = (_fn);                             \
132                 (_timer)->data = (_data);                               \
133         } while (0)
134
135 #define __setup_timer_on_stack(_timer, _fn, _data, _flags)              \
136         do {                                                            \
137                 __init_timer_on_stack((_timer), (_flags));              \
138                 (_timer)->function = (_fn);                             \
139                 (_timer)->data = (_data);                               \
140         } while (0)
141
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)
148
149 /**
150  * timer_pending - is a timer pending?
151  * @timer: the timer in question
152  *
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.
156  *
157  * return value: 1 if the timer is pending, 0 if not.
158  */
159 static inline int timer_pending(const struct timer_list * timer)
160 {
161         return timer->entry.pprev != NULL;
162 }
163
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);
169
170 extern void set_timer_slack(struct timer_list *time, int slack_hz);
171 #ifdef CONFIG_SMP
172 extern bool check_pending_deferrable_timers(int cpu);
173 #endif
174
175 #define TIMER_NOT_PINNED        0
176 #define TIMER_PINNED            1
177 /*
178  * The jiffies value which is added to now, when there is no timer
179  * in the timer wheel:
180  */
181 #define NEXT_TIMER_MAX_DELTA    ((1UL << 30) - 1)
182
183 /* To be used from cpusets, only */
184 extern void timer_quiesce_cpu(void *cpup);
185
186 extern void add_timer(struct timer_list *timer);
187
188 extern int try_to_del_timer_sync(struct timer_list *timer);
189
190 #ifdef CONFIG_SMP
191   extern int del_timer_sync(struct timer_list *timer);
192 #else
193 # define del_timer_sync(t)              del_timer(t)
194 #endif
195
196 #define del_singleshot_timer_sync(t) del_timer_sync(t)
197
198 extern void init_timers(void);
199 extern void run_local_timers(void);
200 struct hrtimer;
201 extern enum hrtimer_restart it_real_fn(struct hrtimer *);
202
203 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
204 #include <linux/sysctl.h>
205
206 extern struct tvec_base tvec_base_deferrable;
207
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,
211                             loff_t *ppos);
212 #endif
213
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);
218
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);
223
224 #endif