OSDN Git Service

a3d4d2840e7fa9160b739f10dede9fcd981ff777
[uclinux-h8/linux.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 /* ARM BL switcher abuse support */
15 #ifdef CONFIG_GENERIC_CLOCKEVENTS
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 };
25 extern struct tick_device *tick_get_device(int cpu);
26 #endif
27
28 #ifdef CONFIG_GENERIC_CLOCKEVENTS
29 extern void __init tick_init(void);
30 extern void tick_freeze(void);
31 extern void tick_unfreeze(void);
32 /* Should be core only, but XEN resume magic requires this */
33 extern void tick_resume_local(void);
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) { }
38 static inline void tick_resume_local(void) { }
39 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
40
41 #ifdef CONFIG_TICK_ONESHOT
42 extern void tick_irq_enter(void);
43 #  ifndef arch_needs_cpu
44 #   define arch_needs_cpu() (0)
45 #  endif
46 # else
47 static inline void tick_irq_enter(void) { }
48 #endif
49
50 #ifdef CONFIG_NO_HZ_COMMON
51 extern int tick_nohz_tick_stopped(void);
52 extern void tick_nohz_idle_enter(void);
53 extern void tick_nohz_idle_exit(void);
54 extern void tick_nohz_irq_exit(void);
55 extern ktime_t tick_nohz_get_sleep_length(void);
56 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
57 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
58 #else /* !CONFIG_NO_HZ_COMMON */
59 static inline int tick_nohz_tick_stopped(void) { return 0; }
60 static inline void tick_nohz_idle_enter(void) { }
61 static inline void tick_nohz_idle_exit(void) { }
62
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 }
69 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
70 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
71 #endif /* !CONFIG_NO_HZ_COMMON */
72
73 #ifdef CONFIG_NO_HZ_FULL
74 extern bool tick_nohz_full_running;
75 extern cpumask_var_t tick_nohz_full_mask;
76 extern cpumask_var_t housekeeping_mask;
77
78 static inline bool tick_nohz_full_enabled(void)
79 {
80         if (!context_tracking_is_enabled())
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
94 extern void __tick_nohz_full_check(void);
95 extern void tick_nohz_full_kick(void);
96 extern void tick_nohz_full_kick_cpu(int cpu);
97 extern void tick_nohz_full_kick_all(void);
98 extern void __tick_nohz_task_switch(struct task_struct *tsk);
99 #else
100 static inline bool tick_nohz_full_enabled(void) { return false; }
101 static inline bool tick_nohz_full_cpu(int cpu) { return false; }
102 static inline void __tick_nohz_full_check(void) { }
103 static inline void tick_nohz_full_kick_cpu(int cpu) { }
104 static inline void tick_nohz_full_kick(void) { }
105 static inline void tick_nohz_full_kick_all(void) { }
106 static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
107 #endif
108
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
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
139 #endif