blob: b84773cb9f4c1f3fc480a460ba3c37a2121e1557 [file] [log] [blame]
Thomas Gleixner906568c2007-02-16 01:28:01 -08001/* linux/include/linux/tick.h
2 *
3 * This file contains the structure definitions for tick related functions
4 *
5 */
6#ifndef _LINUX_TICK_H
7#define _LINUX_TICK_H
8
9#include <linux/clockchips.h>
Frederic Weisbecker2bbb6812011-10-08 16:01:00 +020010#include <linux/irqflags.h>
Frederic Weisbecker33a5f622012-10-11 17:52:56 +020011#include <linux/percpu.h>
12#include <linux/hrtimer.h>
Frederic Weisbecker460775d2013-07-24 23:52:27 +020013#include <linux/context_tracking_state.h>
14#include <linux/cpumask.h>
Thomas Gleixner906568c2007-02-16 01:28:01 -080015
16#ifdef CONFIG_GENERIC_CLOCKEVENTS
17
18enum tick_device_mode {
19 TICKDEV_MODE_PERIODIC,
20 TICKDEV_MODE_ONESHOT,
21};
22
23struct tick_device {
24 struct clock_event_device *evtdev;
25 enum tick_device_mode mode;
26};
27
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080028enum tick_nohz_mode {
29 NOHZ_MODE_INACTIVE,
30 NOHZ_MODE_LOWRES,
31 NOHZ_MODE_HIGHRES,
32};
33
34/**
35 * struct tick_sched - sched tick emulation and no idle tick control/stats
36 * @sched_timer: hrtimer to schedule the periodic tick in high
37 * resolution mode
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +020038 * @last_tick: Store the last tick expiry time when the tick
39 * timer is modified for nohz sleeps. This is necessary
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080040 * to resume the tick timer operation in the timeline
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +020041 * when the CPU returns from nohz sleep.
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080042 * @tick_stopped: Indicator that the idle tick has been stopped
43 * @idle_jiffies: jiffies at the entry to idle for idle time accounting
44 * @idle_calls: Total number of idle calls
45 * @idle_sleeps: Number of idle calls, where the sched tick was stopped
46 * @idle_entrytime: Time when the idle call was entered
Thomas Gleixner5df7fa12008-02-01 17:45:14 +010047 * @idle_waketime: Time when the idle was interrupted
48 * @idle_exittime: Time when the idle state was left
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080049 * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
Arjan van de Ven0224cf42010-05-09 08:25:23 -070050 * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
Len Brown4f86d3a2007-10-03 18:58:00 -040051 * @sleep_length: Duration of the current idle sleep
Thomas Gleixner27185012009-11-12 22:12:06 +010052 * @do_timer_lst: CPU was the last one doing do_timer before going idle
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080053 */
54struct tick_sched {
55 struct hrtimer sched_timer;
56 unsigned long check_clocks;
57 enum tick_nohz_mode nohz_mode;
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +020058 ktime_t last_tick;
Thomas Gleixnerb8f8c3c2008-07-18 17:27:28 +020059 int inidle;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080060 int tick_stopped;
61 unsigned long idle_jiffies;
62 unsigned long idle_calls;
63 unsigned long idle_sleeps;
Venki Pallipadi6378ddb2008-01-30 13:30:04 +010064 int idle_active;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080065 ktime_t idle_entrytime;
Thomas Gleixner5df7fa12008-02-01 17:45:14 +010066 ktime_t idle_waketime;
67 ktime_t idle_exittime;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080068 ktime_t idle_sleeptime;
Arjan van de Ven0224cf42010-05-09 08:25:23 -070069 ktime_t iowait_sleeptime;
Len Brown4f86d3a2007-10-03 18:58:00 -040070 ktime_t sleep_length;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080071 unsigned long last_jiffies;
72 unsigned long next_jiffies;
73 ktime_t idle_expires;
Thomas Gleixner27185012009-11-12 22:12:06 +010074 int do_timer_last;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080075};
76
Thomas Gleixner906568c2007-02-16 01:28:01 -080077extern void __init tick_init(void);
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080078extern int tick_is_oneshot_available(void);
Ingo Molnar289f4802007-02-16 01:28:15 -080079extern struct tick_device *tick_get_device(int cpu);
Thomas Gleixner906568c2007-02-16 01:28:01 -080080
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080081# ifdef CONFIG_HIGH_RES_TIMERS
82extern int tick_init_highres(void);
83extern int tick_program_event(ktime_t expires, int force);
84extern void tick_setup_sched_timer(void);
Miao Xie3c4fbe52008-08-20 16:37:38 -070085# endif
86
Frederic Weisbecker3451d022011-08-10 23:21:01 +020087# if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080088extern void tick_cancel_sched_timer(int cpu);
89# else
90static inline void tick_cancel_sched_timer(int cpu) { }
Miao Xie3c4fbe52008-08-20 16:37:38 -070091# endif
Thomas Gleixner906568c2007-02-16 01:28:01 -080092
Ingo Molnar289f4802007-02-16 01:28:15 -080093# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
94extern struct tick_device *tick_get_broadcast_device(void);
Rusty Russell6b954822009-01-01 10:12:25 +103095extern struct cpumask *tick_get_broadcast_mask(void);
Ingo Molnar289f4802007-02-16 01:28:15 -080096
97# ifdef CONFIG_TICK_ONESHOT
Rusty Russell6b954822009-01-01 10:12:25 +103098extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
Ingo Molnar289f4802007-02-16 01:28:15 -080099# endif
100
101# endif /* BROADCAST */
102
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800103# ifdef CONFIG_TICK_ONESHOT
104extern void tick_clock_notify(void);
105extern int tick_check_oneshot_change(int allow_nohz);
106extern struct tick_sched *tick_get_tick_sched(int cpu);
Frederic Weisbecker5acac1b2013-12-04 18:28:20 +0100107extern void tick_irq_enter(void);
Thomas Gleixnercd6d95d2009-06-12 11:29:27 +0200108extern int tick_oneshot_mode_active(void);
Martin Schwidefsky3c5d92a2009-09-29 14:25:16 +0200109# ifndef arch_needs_cpu
110# define arch_needs_cpu(cpu) (0)
111# endif
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800112# else
113static inline void tick_clock_notify(void) { }
114static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
Frederic Weisbecker5acac1b2013-12-04 18:28:20 +0100115static inline void tick_irq_enter(void) { }
Thomas Gleixnercd6d95d2009-06-12 11:29:27 +0200116static inline int tick_oneshot_mode_active(void) { return 0; }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800117# endif
118
119#else /* CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -0800120static inline void tick_init(void) { }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800121static inline void tick_cancel_sched_timer(int cpu) { }
122static inline void tick_clock_notify(void) { }
123static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
Frederic Weisbecker5acac1b2013-12-04 18:28:20 +0100124static inline void tick_irq_enter(void) { }
Thomas Gleixnercd6d95d2009-06-12 11:29:27 +0200125static inline int tick_oneshot_mode_active(void) { return 0; }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800126#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -0800127
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200128# ifdef CONFIG_NO_HZ_COMMON
Frederic Weisbecker33a5f622012-10-11 17:52:56 +0200129DECLARE_PER_CPU(struct tick_sched, tick_cpu_sched);
130
131static inline int tick_nohz_tick_stopped(void)
132{
133 return __this_cpu_read(tick_cpu_sched.tick_stopped);
134}
135
Frederic Weisbecker1268fbc2011-11-17 18:48:14 +0100136extern void tick_nohz_idle_enter(void);
Frederic Weisbecker280f0672011-10-07 18:22:06 +0200137extern void tick_nohz_idle_exit(void);
138extern void tick_nohz_irq_exit(void);
Len Brown4f86d3a2007-10-03 18:58:00 -0400139extern ktime_t tick_nohz_get_sleep_length(void);
Venki Pallipadi6378ddb2008-01-30 13:30:04 +0100140extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
Arjan van de Ven0224cf42010-05-09 08:25:23 -0700141extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
Frederic Weisbecker33a5f622012-10-11 17:52:56 +0200142
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200143# else /* !CONFIG_NO_HZ_COMMON */
Frederic Weisbecker33a5f622012-10-11 17:52:56 +0200144static inline int tick_nohz_tick_stopped(void)
145{
146 return 0;
147}
148
Frederic Weisbecker2bbb6812011-10-08 16:01:00 +0200149static inline void tick_nohz_idle_enter(void) { }
150static inline void tick_nohz_idle_exit(void) { }
Frederic Weisbecker280f0672011-10-07 18:22:06 +0200151
Len Brown4f86d3a2007-10-03 18:58:00 -0400152static inline ktime_t tick_nohz_get_sleep_length(void)
153{
154 ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
155
156 return len;
157}
venkatesh.pallipadi@intel.com8083e4a2008-08-04 11:59:11 -0700158static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
Arjan van de Ven0224cf42010-05-09 08:25:23 -0700159static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200160# endif /* !CONFIG_NO_HZ_COMMON */
Thomas Gleixner906568c2007-02-16 01:28:01 -0800161
Frederic Weisbeckerc5bfece2013-04-12 16:45:34 +0200162#ifdef CONFIG_NO_HZ_FULL
Frederic Weisbecker460775d2013-07-24 23:52:27 +0200163extern bool tick_nohz_full_running;
164extern cpumask_var_t tick_nohz_full_mask;
165
166static inline bool tick_nohz_full_enabled(void)
167{
Frederic Weisbecker58135f52013-11-06 14:45:57 +0100168 if (!context_tracking_is_enabled())
Frederic Weisbecker460775d2013-07-24 23:52:27 +0200169 return false;
170
171 return tick_nohz_full_running;
172}
173
174static inline bool tick_nohz_full_cpu(int cpu)
175{
176 if (!tick_nohz_full_enabled())
177 return false;
178
179 return cpumask_test_cpu(cpu, tick_nohz_full_mask);
180}
181
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +0100182extern void tick_nohz_init(void);
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200183extern void __tick_nohz_full_check(void);
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +0200184extern void tick_nohz_full_kick(void);
185extern void tick_nohz_full_kick_all(void);
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200186extern void __tick_nohz_task_switch(struct task_struct *tsk);
Frederic Weisbeckera8318812012-12-18 17:32:19 +0100187#else
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +0100188static inline void tick_nohz_init(void) { }
Frederic Weisbecker460775d2013-07-24 23:52:27 +0200189static inline bool tick_nohz_full_enabled(void) { return false; }
190static inline bool tick_nohz_full_cpu(int cpu) { return false; }
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200191static inline void __tick_nohz_full_check(void) { }
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +0200192static inline void tick_nohz_full_kick(void) { }
193static inline void tick_nohz_full_kick_all(void) { }
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200194static inline void __tick_nohz_task_switch(struct task_struct *tsk) { }
Frederic Weisbeckera8318812012-12-18 17:32:19 +0100195#endif
196
Frederic Weisbeckerd13508f2013-07-24 23:52:27 +0200197static inline void tick_nohz_full_check(void)
198{
199 if (tick_nohz_full_enabled())
200 __tick_nohz_full_check();
201}
202
203static inline void tick_nohz_task_switch(struct task_struct *tsk)
204{
205 if (tick_nohz_full_enabled())
206 __tick_nohz_task_switch(tsk);
207}
208
Frederic Weisbeckera8318812012-12-18 17:32:19 +0100209
Thomas Gleixner906568c2007-02-16 01:28:01 -0800210#endif