Commit | Line | Data |
---|---|---|
c1797baf TG |
1 | /* |
2 | * Tick related global functions | |
906568c9 TG |
3 | */ |
4 | #ifndef _LINUX_TICK_H | |
5 | #define _LINUX_TICK_H | |
6 | ||
7 | #include <linux/clockchips.h> | |
2bbb6817 | 8 | #include <linux/irqflags.h> |
33a5f626 | 9 | #include <linux/percpu.h> |
460775df FW |
10 | #include <linux/context_tracking_state.h> |
11 | #include <linux/cpumask.h> | |
c0f489d2 | 12 | #include <linux/sched.h> |
906568c9 | 13 | |
c1797baf | 14 | /* ARM BL switcher abuse support */ |
906568c9 | 15 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
906568c9 TG |
16 | enum tick_device_mode { |
17 | TICKDEV_MODE_PERIODIC, | |
18 | TICKDEV_MODE_ONESHOT, | |
19 | }; | |
20 | ||
21 | struct tick_device { | |
22 | struct clock_event_device *evtdev; | |
23 | enum tick_device_mode mode; | |
24 | }; | |
289f480a | 25 | extern struct tick_device *tick_get_device(int cpu); |
c1797baf | 26 | #endif |
79bf2bb3 | 27 | |
c1797baf TG |
28 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
29 | extern void __init tick_init(void); | |
124cf911 RW |
30 | extern void tick_freeze(void); |
31 | extern void tick_unfreeze(void); | |
f46481d0 TG |
32 | /* Should be core only, but XEN resume magic requires this */ |
33 | extern void tick_resume_local(void); | |
c1797baf TG |
34 | #else /* CONFIG_GENERIC_CLOCKEVENTS */ |
35 | static inline void tick_init(void) { } | |
36 | static inline void tick_freeze(void) { } | |
37 | static inline void tick_unfreeze(void) { } | |
f46481d0 | 38 | static inline void tick_resume_local(void) { } |
c1797baf | 39 | #endif /* !CONFIG_GENERIC_CLOCKEVENTS */ |
124cf911 | 40 | |
c1797baf | 41 | #ifdef CONFIG_TICK_ONESHOT |
5acac1be | 42 | extern void tick_irq_enter(void); |
3c5d92a0 | 43 | # ifndef arch_needs_cpu |
fe0f4976 | 44 | # define arch_needs_cpu() (0) |
3c5d92a0 | 45 | # endif |
79bf2bb3 | 46 | # else |
5acac1be | 47 | static inline void tick_irq_enter(void) { } |
c1797baf | 48 | #endif |
33a5f626 | 49 | |
c1797baf TG |
50 | #ifdef CONFIG_NO_HZ_COMMON |
51 | extern int tick_nohz_tick_stopped(void); | |
1268fbc7 | 52 | extern void tick_nohz_idle_enter(void); |
280f0677 FW |
53 | extern void tick_nohz_idle_exit(void); |
54 | extern void tick_nohz_irq_exit(void); | |
4f86d3a8 | 55 | extern ktime_t tick_nohz_get_sleep_length(void); |
6378ddb5 | 56 | extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); |
0224cf4c | 57 | extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); |
c1797baf TG |
58 | #else /* !CONFIG_NO_HZ_COMMON */ |
59 | static inline int tick_nohz_tick_stopped(void) { return 0; } | |
2bbb6817 FW |
60 | static inline void tick_nohz_idle_enter(void) { } |
61 | static inline void tick_nohz_idle_exit(void) { } | |
280f0677 | 62 | |
4f86d3a8 LB |
63 | static inline ktime_t tick_nohz_get_sleep_length(void) |
64 | { | |
65 | ktime_t len = { .tv64 = NSEC_PER_SEC/HZ }; | |
66 | ||
67 | return len; | |
68 | } | |
8083e4ad | 69 | static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } |
0224cf4c | 70 | static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } |
c1797baf | 71 | #endif /* !CONFIG_NO_HZ_COMMON */ |
906568c9 | 72 | |
c5bfece2 | 73 | #ifdef CONFIG_NO_HZ_FULL |
460775df FW |
74 | extern bool tick_nohz_full_running; |
75 | extern cpumask_var_t tick_nohz_full_mask; | |
c0f489d2 | 76 | extern cpumask_var_t housekeeping_mask; |
460775df FW |
77 | |
78 | static inline bool tick_nohz_full_enabled(void) | |
79 | { | |
58135f57 | 80 | if (!context_tracking_is_enabled()) |
460775df FW |
81 | return false; |
82 | ||
83 | return tick_nohz_full_running; | |
84 | } | |
85 | ||
86 | static inline bool tick_nohz_full_cpu(int cpu) | |
87 | { | |
88 | if (!tick_nohz_full_enabled()) | |
89 | return false; | |
90 | ||
91 | return cpumask_test_cpu(cpu, tick_nohz_full_mask); | |
92 | } | |
93 | ||
d13508f9 | 94 | extern void __tick_nohz_full_check(void); |
40bea039 | 95 | extern void tick_nohz_full_kick(void); |
3d36aebc | 96 | extern void tick_nohz_full_kick_cpu(int cpu); |
76c24fb0 | 97 | extern void tick_nohz_full_kick_all(void); |
d13508f9 | 98 | extern void __tick_nohz_task_switch(struct task_struct *tsk); |
a831881b | 99 | #else |
460775df FW |
100 | static inline bool tick_nohz_full_enabled(void) { return false; } |
101 | static inline bool tick_nohz_full_cpu(int cpu) { return false; } | |
d13508f9 | 102 | static inline void __tick_nohz_full_check(void) { } |
3d36aebc | 103 | static inline void tick_nohz_full_kick_cpu(int cpu) { } |
76c24fb0 FW |
104 | static inline void tick_nohz_full_kick(void) { } |
105 | static inline void tick_nohz_full_kick_all(void) { } | |
d13508f9 | 106 | static inline void __tick_nohz_task_switch(struct task_struct *tsk) { } |
a831881b FW |
107 | #endif |
108 | ||
c0f489d2 PM |
109 | static inline bool is_housekeeping_cpu(int cpu) |
110 | { | |
111 | #ifdef CONFIG_NO_HZ_FULL | |
112 | if (tick_nohz_full_enabled()) | |
113 | return cpumask_test_cpu(cpu, housekeeping_mask); | |
114 | #endif | |
115 | return true; | |
116 | } | |
117 | ||
118 | static inline void housekeeping_affine(struct task_struct *t) | |
119 | { | |
120 | #ifdef CONFIG_NO_HZ_FULL | |
121 | if (tick_nohz_full_enabled()) | |
122 | set_cpus_allowed_ptr(t, housekeeping_mask); | |
123 | ||
124 | #endif | |
125 | } | |
126 | ||
d13508f9 FW |
127 | static inline void tick_nohz_full_check(void) |
128 | { | |
129 | if (tick_nohz_full_enabled()) | |
130 | __tick_nohz_full_check(); | |
131 | } | |
132 | ||
133 | static inline void tick_nohz_task_switch(struct task_struct *tsk) | |
134 | { | |
135 | if (tick_nohz_full_enabled()) | |
136 | __tick_nohz_task_switch(tsk); | |
137 | } | |
138 | ||
906568c9 | 139 | #endif |