blob: f9a2d2687a4620d99ed5c15b742535dc71708036 [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/* ARM BL switcher abuse support */
Thomas Gleixner906568c2007-02-16 01:28:01 -080015#ifdef CONFIG_GENERIC_CLOCKEVENTS
Thomas Gleixner906568c2007-02-16 01:28:01 -080016enum tick_device_mode {
17 TICKDEV_MODE_PERIODIC,
18 TICKDEV_MODE_ONESHOT,
19};
20
21struct tick_device {
22 struct clock_event_device *evtdev;
23 enum tick_device_mode mode;
24};
Ingo Molnar289f4802007-02-16 01:28:15 -080025extern struct tick_device *tick_get_device(int cpu);
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010026#endif
Thomas Gleixner906568c2007-02-16 01:28:01 -080027
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010028#ifdef CONFIG_GENERIC_CLOCKEVENTS
29extern void __init tick_init(void);
Rafael J. Wysocki124cf9112015-02-13 23:50:43 +010030extern void tick_freeze(void);
31extern void tick_unfreeze(void);
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080032#else /* CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -080033static inline void tick_init(void) { }
Rafael J. Wysocki124cf9112015-02-13 23:50:43 +010034static inline void tick_freeze(void) { }
35static inline void tick_unfreeze(void) { }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080036#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -080037
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010038#ifdef CONFIG_TICK_ONESHOT
39extern void tick_irq_enter(void);
40# ifndef arch_needs_cpu
41# define arch_needs_cpu() (0)
42# endif
43# else
44static inline void tick_irq_enter(void) { }
45#endif
Frederic Weisbecker33a5f622012-10-11 17:52:56 +020046
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010047#ifdef CONFIG_NO_HZ_COMMON
48extern int tick_nohz_tick_stopped(void);
Frederic Weisbecker1268fbc2011-11-17 18:48:14 +010049extern void tick_nohz_idle_enter(void);
Frederic Weisbecker280f0672011-10-07 18:22:06 +020050extern void tick_nohz_idle_exit(void);
51extern void tick_nohz_irq_exit(void);
Len Brown4f86d3a2007-10-03 18:58:00 -040052extern ktime_t tick_nohz_get_sleep_length(void);
Venki Pallipadi6378ddb2008-01-30 13:30:04 +010053extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
Arjan van de Ven0224cf42010-05-09 08:25:23 -070054extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010055#else /* !CONFIG_NO_HZ_COMMON */
56static inline int tick_nohz_tick_stopped(void) { return 0; }
Frederic Weisbecker2bbb6812011-10-08 16:01:00 +020057static inline void tick_nohz_idle_enter(void) { }
58static inline void tick_nohz_idle_exit(void) { }
Frederic Weisbecker280f0672011-10-07 18:22:06 +020059
Len Brown4f86d3a2007-10-03 18:58:00 -040060static inline ktime_t tick_nohz_get_sleep_length(void)
61{
62 ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
63
64 return len;
65}
venkatesh.pallipadi@intel.com8083e4a2008-08-04 11:59:11 -070066static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
Arjan van de Ven0224cf42010-05-09 08:25:23 -070067static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010068#endif /* !CONFIG_NO_HZ_COMMON */
Thomas Gleixner906568c2007-02-16 01:28:01 -080069
Frederic Weisbeckerc5bfece2013-04-12 16:45:34 +020070#ifdef CONFIG_NO_HZ_FULL
Frederic Weisbecker460775df2013-07-24 23:52:27 +020071extern bool tick_nohz_full_running;
72extern cpumask_var_t tick_nohz_full_mask;
Paul E. McKenneyc0f489d2014-06-04 13:46:03 -070073extern cpumask_var_t housekeeping_mask;
Frederic Weisbecker460775df2013-07-24 23:52:27 +020074
75static inline bool tick_nohz_full_enabled(void)
76{
Frederic Weisbecker58135f52013-11-06 14:45:57 +010077 if (!context_tracking_is_enabled())
Frederic Weisbecker460775df2013-07-24 23:52:27 +020078 return false;
79
80 return tick_nohz_full_running;
81}
82
83static inline bool tick_nohz_full_cpu(int cpu)
84{
85 if (!tick_nohz_full_enabled())
86 return false;
87
88 return cpumask_test_cpu(cpu, tick_nohz_full_mask);
89}
90
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020091extern void __tick_nohz_full_check(void);
Frederic Weisbecker40bea032014-08-13 18:50:16 +020092extern void tick_nohz_full_kick(void);
Frederic Weisbecker3d36aeb2014-06-04 16:17:33 +020093extern void tick_nohz_full_kick_cpu(int cpu);
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +020094extern void tick_nohz_full_kick_all(void);
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020095extern void __tick_nohz_task_switch(struct task_struct *tsk);
Frederic Weisbeckera8318812012-12-18 17:32:19 +010096#else
Frederic Weisbecker460775df2013-07-24 23:52:27 +020097static inline bool tick_nohz_full_enabled(void) { return false; }
98static inline bool tick_nohz_full_cpu(int cpu) { return false; }
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +020099static inline void __tick_nohz_full_check(void) { }
Frederic Weisbecker3d36aeb2014-06-04 16:17:33 +0200100static inline void tick_nohz_full_kick_cpu(int cpu) { }
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +0200101static inline void tick_nohz_full_kick(void) { }
102static inline void tick_nohz_full_kick_all(void) { }
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200103static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
Frederic Weisbeckera8318812012-12-18 17:32:19 +0100104#endif
105
Paul E. McKenneyc0f489d2014-06-04 13:46:03 -0700106static inline bool is_housekeeping_cpu(int cpu)
107{
108#ifdef CONFIG_NO_HZ_FULL
109 if (tick_nohz_full_enabled())
110 return cpumask_test_cpu(cpu, housekeeping_mask);
111#endif
112 return true;
113}
114
115static inline void housekeeping_affine(struct task_struct *t)
116{
117#ifdef CONFIG_NO_HZ_FULL
118 if (tick_nohz_full_enabled())
119 set_cpus_allowed_ptr(t, housekeeping_mask);
120
121#endif
122}
123
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200124static inline void tick_nohz_full_check(void)
125{
126 if (tick_nohz_full_enabled())
127 __tick_nohz_full_check();
128}
129
130static inline void tick_nohz_task_switch(struct task_struct *tsk)
131{
132 if (tick_nohz_full_enabled())
133 __tick_nohz_task_switch(tsk);
134}
135
Thomas Gleixner906568c2007-02-16 01:28:01 -0800136#endif