OSDN Git Service

mm/vmap: keep track of free blocks for vmap allocation
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / tick.h
1 /*
2  * Tick related global functions
3  */
4 #ifndef _LINUX_TICK_H
5 #define _LINUX_TICK_H
6
7 #include <linux/clockchips.h>
8 #include <linux/irqflags.h>
9 #include <linux/percpu.h>
10 #include <linux/context_tracking_state.h>
11 #include <linux/cpumask.h>
12 #include <linux/sched.h>
13
14 #ifdef CONFIG_GENERIC_CLOCKEVENTS
15 extern void __init tick_init(void);
16 /* Should be core only, but ARM BL switcher requires it */
17 extern void tick_suspend_local(void);
18 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
19 extern void tick_resume_local(void);
20 extern void tick_handover_do_timer(void);
21 extern void tick_cleanup_dead_cpu(int cpu);
22 #else /* CONFIG_GENERIC_CLOCKEVENTS */
23 static inline void tick_init(void) { }
24 static inline void tick_suspend_local(void) { }
25 static inline void tick_resume_local(void) { }
26 static inline void tick_handover_do_timer(void) { }
27 static inline void tick_cleanup_dead_cpu(int cpu) { }
28 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
29
30 extern u64 jiffy_to_ktime_ns(u64 *now, u64 *jiffy_ktime_ns);
31
32 #if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND)
33 extern void tick_freeze(void);
34 extern void tick_unfreeze(void);
35 #else
36 static inline void tick_freeze(void) { }
37 static inline void tick_unfreeze(void) { }
38 #endif
39
40 #ifdef CONFIG_TICK_ONESHOT
41 extern void tick_irq_enter(void);
42 #  ifndef arch_needs_cpu
43 #   define arch_needs_cpu() (0)
44 #  endif
45 # else
46 static inline void tick_irq_enter(void) { }
47 #endif
48
49 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
50 extern void hotplug_cpu__broadcast_tick_pull(int dead_cpu);
51 #else
52 static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
53 #endif
54
55 enum tick_broadcast_mode {
56         TICK_BROADCAST_OFF,
57         TICK_BROADCAST_ON,
58         TICK_BROADCAST_FORCE,
59 };
60
61 enum tick_broadcast_state {
62         TICK_BROADCAST_EXIT,
63         TICK_BROADCAST_ENTER,
64 };
65
66 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
67 extern void tick_broadcast_control(enum tick_broadcast_mode mode);
68 #else
69 static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
70 #endif /* BROADCAST */
71
72 #ifdef CONFIG_GENERIC_CLOCKEVENTS
73 extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
74 #else
75 static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
76 {
77         return 0;
78 }
79 #endif
80
81 static inline void tick_broadcast_enable(void)
82 {
83         tick_broadcast_control(TICK_BROADCAST_ON);
84 }
85 static inline void tick_broadcast_disable(void)
86 {
87         tick_broadcast_control(TICK_BROADCAST_OFF);
88 }
89 static inline void tick_broadcast_force(void)
90 {
91         tick_broadcast_control(TICK_BROADCAST_FORCE);
92 }
93 static inline int tick_broadcast_enter(void)
94 {
95         return tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER);
96 }
97 static inline void tick_broadcast_exit(void)
98 {
99         tick_broadcast_oneshot_control(TICK_BROADCAST_EXIT);
100 }
101
102 #ifdef CONFIG_NO_HZ_COMMON
103 extern int tick_nohz_tick_stopped(void);
104 extern void tick_nohz_idle_enter(void);
105 extern void tick_nohz_idle_exit(void);
106 extern void tick_nohz_irq_exit(void);
107 extern ktime_t tick_nohz_get_sleep_length(void);
108 extern unsigned long tick_nohz_get_idle_calls(void);
109 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
110 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
111 #else /* !CONFIG_NO_HZ_COMMON */
112 static inline int tick_nohz_tick_stopped(void) { return 0; }
113 static inline void tick_nohz_idle_enter(void) { }
114 static inline void tick_nohz_idle_exit(void) { }
115
116 static inline ktime_t tick_nohz_get_sleep_length(void)
117 {
118         ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
119
120         return len;
121 }
122 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
123 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
124 #endif /* !CONFIG_NO_HZ_COMMON */
125
126 #ifdef CONFIG_NO_HZ_FULL
127 extern bool tick_nohz_full_running;
128 extern cpumask_var_t tick_nohz_full_mask;
129 extern cpumask_var_t housekeeping_mask;
130
131 static inline bool tick_nohz_full_enabled(void)
132 {
133         if (!context_tracking_is_enabled())
134                 return false;
135
136         return tick_nohz_full_running;
137 }
138
139 static inline bool tick_nohz_full_cpu(int cpu)
140 {
141         if (!tick_nohz_full_enabled())
142                 return false;
143
144         return cpumask_test_cpu(cpu, tick_nohz_full_mask);
145 }
146
147 static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask)
148 {
149         if (tick_nohz_full_enabled())
150                 cpumask_or(mask, mask, tick_nohz_full_mask);
151 }
152
153 static inline int housekeeping_any_cpu(void)
154 {
155         return cpumask_any_and(housekeeping_mask, cpu_online_mask);
156 }
157
158 extern void tick_nohz_full_kick(void);
159 extern void tick_nohz_full_kick_cpu(int cpu);
160 extern void tick_nohz_full_kick_all(void);
161 extern void __tick_nohz_task_switch(void);
162 #else
163 static inline int housekeeping_any_cpu(void)
164 {
165         cpumask_t available;
166         int cpu;
167
168         cpumask_andnot(&available, cpu_online_mask, cpu_isolated_mask);
169         cpu = cpumask_any(&available);
170         if (cpu >= nr_cpu_ids)
171                 cpu = smp_processor_id();
172
173         return cpu;
174 }
175 static inline bool tick_nohz_full_enabled(void) { return false; }
176 static inline bool tick_nohz_full_cpu(int cpu) { return false; }
177 static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { }
178 static inline void tick_nohz_full_kick_cpu(int cpu) { }
179 static inline void tick_nohz_full_kick(void) { }
180 static inline void tick_nohz_full_kick_all(void) { }
181 static inline void __tick_nohz_task_switch(void) { }
182 #endif
183
184 static inline const struct cpumask *housekeeping_cpumask(void)
185 {
186 #ifdef CONFIG_NO_HZ_FULL
187         if (tick_nohz_full_enabled())
188                 return housekeeping_mask;
189 #endif
190         return cpu_possible_mask;
191 }
192
193 static inline bool is_housekeeping_cpu(int cpu)
194 {
195 #ifdef CONFIG_NO_HZ_FULL
196         if (tick_nohz_full_enabled())
197                 return cpumask_test_cpu(cpu, housekeeping_mask);
198 #endif
199         return !cpu_isolated(cpu);
200 }
201
202 static inline void housekeeping_affine(struct task_struct *t)
203 {
204 #ifdef CONFIG_NO_HZ_FULL
205         if (tick_nohz_full_enabled())
206                 set_cpus_allowed_ptr(t, housekeeping_mask);
207
208 #endif
209 }
210
211 static inline void tick_nohz_task_switch(void)
212 {
213         if (tick_nohz_full_enabled())
214                 __tick_nohz_task_switch();
215 }
216
217 ktime_t *get_next_event_cpu(unsigned int cpu);
218 #endif