blob: 589868b09affb53be3b366a04902c95064c0fe32 [file] [log] [blame]
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +01001/*
2 * Tick related global functions
Thomas Gleixner906568c2007-02-16 01:28:01 -08003 */
4#ifndef _LINUX_TICK_H
5#define _LINUX_TICK_H
6
7#include <linux/clockchips.h>
Frederic Weisbecker2bbb6812011-10-08 16:01:00 +02008#include <linux/irqflags.h>
Frederic Weisbecker33a5f622012-10-11 17:52:56 +02009#include <linux/percpu.h>
Frederic Weisbecker460775df2013-07-24 23:52:27 +020010#include <linux/context_tracking_state.h>
11#include <linux/cpumask.h>
Paul E. McKenneyc0f489d2014-06-04 13:46:03 -070012#include <linux/sched.h>
Thomas Gleixner906568c2007-02-16 01:28:01 -080013
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010014#ifdef CONFIG_GENERIC_CLOCKEVENTS
15extern void __init tick_init(void);
Rafael J. Wysocki124cf9112015-02-13 23:50:43 +010016extern void tick_freeze(void);
17extern void tick_unfreeze(void);
Thomas Gleixner7270d112015-03-25 13:11:52 +010018/* Should be core only, but ARM BL switcher requires it */
19extern void tick_suspend_local(void);
20/* Should be core only, but XEN resume magic and ARM BL switcher require it */
Thomas Gleixnerf46481d2015-03-25 13:11:04 +010021extern void tick_resume_local(void);
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080022#else /* CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -080023static inline void tick_init(void) { }
Rafael J. Wysocki124cf9112015-02-13 23:50:43 +010024static inline void tick_freeze(void) { }
25static inline void tick_unfreeze(void) { }
Thomas Gleixner7270d112015-03-25 13:11:52 +010026static inline void tick_suspend_local(void) { }
Thomas Gleixnerf46481d2015-03-25 13:11:04 +010027static inline void tick_resume_local(void) { }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080028#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -080029
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010030#ifdef CONFIG_TICK_ONESHOT
31extern void tick_irq_enter(void);
32# ifndef arch_needs_cpu
33# define arch_needs_cpu() (0)
34# endif
35# else
36static inline void tick_irq_enter(void) { }
37#endif
Frederic Weisbecker33a5f622012-10-11 17:52:56 +020038
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010039#ifdef CONFIG_NO_HZ_COMMON
40extern int tick_nohz_tick_stopped(void);
Frederic Weisbecker1268fbc2011-11-17 18:48:14 +010041extern void tick_nohz_idle_enter(void);
Frederic Weisbecker280f0672011-10-07 18:22:06 +020042extern void tick_nohz_idle_exit(void);
43extern void tick_nohz_irq_exit(void);
Len Brown4f86d3a2007-10-03 18:58:00 -040044extern ktime_t tick_nohz_get_sleep_length(void);
Venki Pallipadi6378ddb52008-01-30 13:30:04 +010045extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
Arjan van de Ven0224cf42010-05-09 08:25:23 -070046extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010047#else /* !CONFIG_NO_HZ_COMMON */
48static inline int tick_nohz_tick_stopped(void) { return 0; }
Frederic Weisbecker2bbb6812011-10-08 16:01:00 +020049static inline void tick_nohz_idle_enter(void) { }
50static inline void tick_nohz_idle_exit(void) { }
Frederic Weisbecker280f0672011-10-07 18:22:06 +020051
Len Brown4f86d3a2007-10-03 18:58:00 -040052static inline ktime_t tick_nohz_get_sleep_length(void)
53{
54 ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
55
56 return len;
57}
[email protected]8083e4a2008-08-04 11:59:11 -070058static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
Arjan van de Ven0224cf42010-05-09 08:25:23 -070059static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010060#endif /* !CONFIG_NO_HZ_COMMON */
Thomas Gleixner906568c2007-02-16 01:28:01 -080061
Frederic Weisbeckerc5bfece2013-04-12 16:45:34 +020062#ifdef CONFIG_NO_HZ_FULL
Frederic Weisbecker460775df2013-07-24 23:52:27 +020063extern bool tick_nohz_full_running;
64extern cpumask_var_t tick_nohz_full_mask;
Paul E. McKenneyc0f489d2014-06-04 13:46:03 -070065extern cpumask_var_t housekeeping_mask;
Frederic Weisbecker460775df2013-07-24 23:52:27 +020066
67static inline bool tick_nohz_full_enabled(void)
68{
Frederic Weisbecker58135f52013-11-06 14:45:57 +010069 if (!context_tracking_is_enabled())
Frederic Weisbecker460775df2013-07-24 23:52:27 +020070 return false;
71
72 return tick_nohz_full_running;
73}
74
75static inline bool tick_nohz_full_cpu(int cpu)
76{
77 if (!tick_nohz_full_enabled())
78 return false;
79
80 return cpumask_test_cpu(cpu, tick_nohz_full_mask);
81}
82
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020083extern void __tick_nohz_full_check(void);
Frederic Weisbecker40bea032014-08-13 18:50:16 +020084extern void tick_nohz_full_kick(void);
Frederic Weisbecker3d36aeb2014-06-04 16:17:33 +020085extern void tick_nohz_full_kick_cpu(int cpu);
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +020086extern void tick_nohz_full_kick_all(void);
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020087extern void __tick_nohz_task_switch(struct task_struct *tsk);
Frederic Weisbeckera8318812012-12-18 17:32:19 +010088#else
Frederic Weisbecker460775df2013-07-24 23:52:27 +020089static inline bool tick_nohz_full_enabled(void) { return false; }
90static inline bool tick_nohz_full_cpu(int cpu) { return false; }
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020091static inline void __tick_nohz_full_check(void) { }
Frederic Weisbecker3d36aeb2014-06-04 16:17:33 +020092static inline void tick_nohz_full_kick_cpu(int cpu) { }
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +020093static inline void tick_nohz_full_kick(void) { }
94static inline void tick_nohz_full_kick_all(void) { }
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020095static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
Frederic Weisbeckera8318812012-12-18 17:32:19 +010096#endif
97
Paul E. McKenneyc0f489d2014-06-04 13:46:03 -070098static inline bool is_housekeeping_cpu(int cpu)
99{
100#ifdef CONFIG_NO_HZ_FULL
101 if (tick_nohz_full_enabled())
102 return cpumask_test_cpu(cpu, housekeeping_mask);
103#endif
104 return true;
105}
106
107static inline void housekeeping_affine(struct task_struct *t)
108{
109#ifdef CONFIG_NO_HZ_FULL
110 if (tick_nohz_full_enabled())
111 set_cpus_allowed_ptr(t, housekeeping_mask);
112
113#endif
114}
115
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200116static inline void tick_nohz_full_check(void)
117{
118 if (tick_nohz_full_enabled())
119 __tick_nohz_full_check();
120}
121
122static inline void tick_nohz_task_switch(struct task_struct *tsk)
123{
124 if (tick_nohz_full_enabled())
125 __tick_nohz_task_switch(tsk);
126}
127
Thomas Gleixner906568c2007-02-16 01:28:01 -0800128#endif