blob: 9180f4b85e6deedd827fa071add91940c3ac48e5 [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>
Thomas Gleixner906568c2007-02-16 01:28:01 -080013
14#ifdef CONFIG_GENERIC_CLOCKEVENTS
15
16enum 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};
25
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080026enum tick_nohz_mode {
27 NOHZ_MODE_INACTIVE,
28 NOHZ_MODE_LOWRES,
29 NOHZ_MODE_HIGHRES,
30};
31
32/**
33 * struct tick_sched - sched tick emulation and no idle tick control/stats
34 * @sched_timer: hrtimer to schedule the periodic tick in high
35 * resolution mode
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +020036 * @last_tick: Store the last tick expiry time when the tick
37 * timer is modified for nohz sleeps. This is necessary
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080038 * to resume the tick timer operation in the timeline
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +020039 * when the CPU returns from nohz sleep.
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080040 * @tick_stopped: Indicator that the idle tick has been stopped
41 * @idle_jiffies: jiffies at the entry to idle for idle time accounting
42 * @idle_calls: Total number of idle calls
43 * @idle_sleeps: Number of idle calls, where the sched tick was stopped
44 * @idle_entrytime: Time when the idle call was entered
Thomas Gleixner5df7fa12008-02-01 17:45:14 +010045 * @idle_waketime: Time when the idle was interrupted
46 * @idle_exittime: Time when the idle state was left
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080047 * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
Arjan van de Ven0224cf42010-05-09 08:25:23 -070048 * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
Len Brown4f86d3a2007-10-03 18:58:00 -040049 * @sleep_length: Duration of the current idle sleep
Thomas Gleixner27185012009-11-12 22:12:06 +010050 * @do_timer_lst: CPU was the last one doing do_timer before going idle
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080051 */
52struct tick_sched {
53 struct hrtimer sched_timer;
54 unsigned long check_clocks;
55 enum tick_nohz_mode nohz_mode;
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +020056 ktime_t last_tick;
Thomas Gleixnerb8f8c3c2008-07-18 17:27:28 +020057 int inidle;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080058 int tick_stopped;
59 unsigned long idle_jiffies;
60 unsigned long idle_calls;
61 unsigned long idle_sleeps;
Venki Pallipadi6378ddb2008-01-30 13:30:04 +010062 int idle_active;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080063 ktime_t idle_entrytime;
Thomas Gleixner5df7fa12008-02-01 17:45:14 +010064 ktime_t idle_waketime;
65 ktime_t idle_exittime;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080066 ktime_t idle_sleeptime;
Arjan van de Ven0224cf42010-05-09 08:25:23 -070067 ktime_t iowait_sleeptime;
Len Brown4f86d3a2007-10-03 18:58:00 -040068 ktime_t sleep_length;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080069 unsigned long last_jiffies;
70 unsigned long next_jiffies;
71 ktime_t idle_expires;
Thomas Gleixner27185012009-11-12 22:12:06 +010072 int do_timer_last;
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080073};
74
Thomas Gleixner906568c2007-02-16 01:28:01 -080075extern void __init tick_init(void);
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080076extern int tick_is_oneshot_available(void);
Ingo Molnar289f4802007-02-16 01:28:15 -080077extern struct tick_device *tick_get_device(int cpu);
Thomas Gleixner906568c2007-02-16 01:28:01 -080078
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080079# ifdef CONFIG_HIGH_RES_TIMERS
80extern int tick_init_highres(void);
81extern int tick_program_event(ktime_t expires, int force);
82extern void tick_setup_sched_timer(void);
Miao Xie3c4fbe52008-08-20 16:37:38 -070083# endif
84
Frederic Weisbecker3451d022011-08-10 23:21:01 +020085# if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -080086extern void tick_cancel_sched_timer(int cpu);
87# else
88static inline void tick_cancel_sched_timer(int cpu) { }
Miao Xie3c4fbe52008-08-20 16:37:38 -070089# endif
Thomas Gleixner906568c2007-02-16 01:28:01 -080090
Ingo Molnar289f4802007-02-16 01:28:15 -080091# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
92extern struct tick_device *tick_get_broadcast_device(void);
Rusty Russell6b954822009-01-01 10:12:25 +103093extern struct cpumask *tick_get_broadcast_mask(void);
Ingo Molnar289f4802007-02-16 01:28:15 -080094
95# ifdef CONFIG_TICK_ONESHOT
Rusty Russell6b954822009-01-01 10:12:25 +103096extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
Ingo Molnar289f4802007-02-16 01:28:15 -080097# endif
98
99# endif /* BROADCAST */
100
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800101# ifdef CONFIG_TICK_ONESHOT
102extern void tick_clock_notify(void);
103extern int tick_check_oneshot_change(int allow_nohz);
104extern struct tick_sched *tick_get_tick_sched(int cpu);
Thomas Gleixner719254f2008-10-17 09:59:47 +0200105extern void tick_check_idle(int cpu);
Thomas Gleixnercd6d95d2009-06-12 11:29:27 +0200106extern int tick_oneshot_mode_active(void);
Martin Schwidefsky3c5d92a2009-09-29 14:25:16 +0200107# ifndef arch_needs_cpu
108# define arch_needs_cpu(cpu) (0)
109# endif
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800110# else
111static inline void tick_clock_notify(void) { }
112static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
Thomas Gleixner719254f2008-10-17 09:59:47 +0200113static inline void tick_check_idle(int cpu) { }
Thomas Gleixnercd6d95d2009-06-12 11:29:27 +0200114static inline int tick_oneshot_mode_active(void) { return 0; }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800115# endif
116
117#else /* CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -0800118static inline void tick_init(void) { }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800119static inline void tick_cancel_sched_timer(int cpu) { }
120static inline void tick_clock_notify(void) { }
121static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
Thomas Gleixner719254f2008-10-17 09:59:47 +0200122static inline void tick_check_idle(int cpu) { }
Thomas Gleixnercd6d95d2009-06-12 11:29:27 +0200123static inline int tick_oneshot_mode_active(void) { return 0; }
Thomas Gleixner79bf2bb2007-02-16 01:28:03 -0800124#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
Thomas Gleixner906568c2007-02-16 01:28:01 -0800125
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200126# ifdef CONFIG_NO_HZ_COMMON
Frederic Weisbecker33a5f622012-10-11 17:52:56 +0200127DECLARE_PER_CPU(struct tick_sched, tick_cpu_sched);
128
129static inline int tick_nohz_tick_stopped(void)
130{
131 return __this_cpu_read(tick_cpu_sched.tick_stopped);
132}
133
Frederic Weisbecker1268fbc2011-11-17 18:48:14 +0100134extern void tick_nohz_idle_enter(void);
Frederic Weisbecker280f0672011-10-07 18:22:06 +0200135extern void tick_nohz_idle_exit(void);
136extern void tick_nohz_irq_exit(void);
Len Brown4f86d3a2007-10-03 18:58:00 -0400137extern ktime_t tick_nohz_get_sleep_length(void);
Venki Pallipadi6378ddb2008-01-30 13:30:04 +0100138extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
Arjan van de Ven0224cf42010-05-09 08:25:23 -0700139extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
Frederic Weisbecker33a5f622012-10-11 17:52:56 +0200140
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200141# else /* !CONFIG_NO_HZ_COMMON */
Frederic Weisbecker33a5f622012-10-11 17:52:56 +0200142static inline int tick_nohz_tick_stopped(void)
143{
144 return 0;
145}
146
Frederic Weisbecker2bbb6812011-10-08 16:01:00 +0200147static inline void tick_nohz_idle_enter(void) { }
148static inline void tick_nohz_idle_exit(void) { }
Frederic Weisbecker280f0672011-10-07 18:22:06 +0200149
Len Brown4f86d3a2007-10-03 18:58:00 -0400150static inline ktime_t tick_nohz_get_sleep_length(void)
151{
152 ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
153
154 return len;
155}
venkatesh.pallipadi@intel.com8083e4a2008-08-04 11:59:11 -0700156static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
Arjan van de Ven0224cf42010-05-09 08:25:23 -0700157static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200158# endif /* !CONFIG_NO_HZ_COMMON */
Thomas Gleixner906568c2007-02-16 01:28:01 -0800159
Frederic Weisbeckerc5bfece2013-04-12 16:45:34 +0200160#ifdef CONFIG_NO_HZ_FULL
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +0100161extern void tick_nohz_init(void);
Frederic Weisbeckerc5bfece2013-04-12 16:45:34 +0200162extern int tick_nohz_full_cpu(int cpu);
Frederic Weisbeckerff442c52013-04-20 15:27:08 +0200163extern void tick_nohz_full_check(void);
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +0200164extern void tick_nohz_full_kick(void);
165extern void tick_nohz_full_kick_all(void);
Frederic Weisbecker99e5ada2013-04-20 17:11:50 +0200166extern void tick_nohz_task_switch(struct task_struct *tsk);
Frederic Weisbeckera8318812012-12-18 17:32:19 +0100167#else
Frederic Weisbeckerd1e43fa2013-03-26 23:47:24 +0100168static inline void tick_nohz_init(void) { }
Frederic Weisbeckerc5bfece2013-04-12 16:45:34 +0200169static inline int tick_nohz_full_cpu(int cpu) { return 0; }
Frederic Weisbeckerff442c52013-04-20 15:27:08 +0200170static inline void tick_nohz_full_check(void) { }
Frederic Weisbecker76c24fb2013-04-18 00:15:40 +0200171static inline void tick_nohz_full_kick(void) { }
172static inline void tick_nohz_full_kick_all(void) { }
Frederic Weisbecker99e5ada2013-04-20 17:11:50 +0200173static inline void tick_nohz_task_switch(struct task_struct *tsk) { }
Frederic Weisbeckera8318812012-12-18 17:32:19 +0100174#endif
175
176
Youquan Song69a37be2012-10-26 12:26:41 +0200177# ifdef CONFIG_CPU_IDLE_GOV_MENU
178extern void menu_hrtimer_cancel(void);
179# else
180static inline void menu_hrtimer_cancel(void) {}
181# endif /* CONFIG_CPU_IDLE_GOV_MENU */
182
Thomas Gleixner906568c2007-02-16 01:28:01 -0800183#endif