tick.h 3.7 KB
Newer Older
1 2
/*
 * Tick related global functions
3 4 5 6 7
 */
#ifndef _LINUX_TICK_H
#define _LINUX_TICK_H

#include <linux/clockchips.h>
8
#include <linux/irqflags.h>
9
#include <linux/percpu.h>
10 11
#include <linux/context_tracking_state.h>
#include <linux/cpumask.h>
12
#include <linux/sched.h>
13

14
/* ARM BL switcher abuse support */
15 16 17 18 19 20 21 22 23 24
#ifdef CONFIG_GENERIC_CLOCKEVENTS
enum tick_device_mode {
	TICKDEV_MODE_PERIODIC,
	TICKDEV_MODE_ONESHOT,
};

struct tick_device {
	struct clock_event_device *evtdev;
	enum tick_device_mode mode;
};
25
extern struct tick_device *tick_get_device(int cpu);
26
#endif
27

28 29
#ifdef CONFIG_GENERIC_CLOCKEVENTS
extern void __init tick_init(void);
30 31
extern void tick_freeze(void);
extern void tick_unfreeze(void);
32 33
/* Should be core only, but XEN resume magic requires this */
extern void tick_resume_local(void);
34 35 36 37
#else /* CONFIG_GENERIC_CLOCKEVENTS */
static inline void tick_init(void) { }
static inline void tick_freeze(void) { }
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 51
#ifdef CONFIG_NO_HZ_COMMON
extern int tick_nohz_tick_stopped(void);
52
extern void tick_nohz_idle_enter(void);
53 54
extern void tick_nohz_idle_exit(void);
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 59
#else /* !CONFIG_NO_HZ_COMMON */
static inline int tick_nohz_tick_stopped(void) { return 0; }
60 61
static inline void tick_nohz_idle_enter(void) { }
static inline void tick_nohz_idle_exit(void) { }
62

63 64 65 66 67 68
static inline ktime_t tick_nohz_get_sleep_length(void)
{
	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };

	return len;
}
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 75
extern bool tick_nohz_full_running;
extern cpumask_var_t tick_nohz_full_mask;
76
extern cpumask_var_t housekeeping_mask;
77 78 79

static inline bool tick_nohz_full_enabled(void)
{
80
	if (!context_tracking_is_enabled())
81 82 83 84 85 86 87 88 89 90 91 92 93
		return false;

	return tick_nohz_full_running;
}

static inline bool tick_nohz_full_cpu(int cpu)
{
	if (!tick_nohz_full_enabled())
		return false;

	return cpumask_test_cpu(cpu, tick_nohz_full_mask);
}

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 101
static inline bool tick_nohz_full_enabled(void) { return false; }
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 105
static inline void tick_nohz_full_kick(void) { }
static inline void tick_nohz_full_kick_all(void) { }
106
static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
107 108
#endif

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
static inline bool is_housekeeping_cpu(int cpu)
{
#ifdef CONFIG_NO_HZ_FULL
	if (tick_nohz_full_enabled())
		return cpumask_test_cpu(cpu, housekeeping_mask);
#endif
	return true;
}

static inline void housekeeping_affine(struct task_struct *t)
{
#ifdef CONFIG_NO_HZ_FULL
	if (tick_nohz_full_enabled())
		set_cpus_allowed_ptr(t, housekeeping_mask);

#endif
}

127 128 129 130 131 132 133 134 135 136 137 138
static inline void tick_nohz_full_check(void)
{
	if (tick_nohz_full_enabled())
		__tick_nohz_full_check();
}

static inline void tick_nohz_task_switch(struct task_struct *tsk)
{
	if (tick_nohz_full_enabled())
		__tick_nohz_task_switch(tsk);
}

139
#endif