Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Tick related global functions |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 3 | */ |
| 4 | #ifndef _LINUX_TICK_H |
| 5 | #define _LINUX_TICK_H |
| 6 | |
| 7 | #include <linux/clockchips.h> |
Frederic Weisbecker | 2bbb681 | 2011-10-08 16:01:00 +0200 | [diff] [blame] | 8 | #include <linux/irqflags.h> |
Frederic Weisbecker | 33a5f62 | 2012-10-11 17:52:56 +0200 | [diff] [blame] | 9 | #include <linux/percpu.h> |
Frederic Weisbecker | 460775df | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 10 | #include <linux/context_tracking_state.h> |
| 11 | #include <linux/cpumask.h> |
Paul E. McKenney | c0f489d | 2014-06-04 13:46:03 -0700 | [diff] [blame] | 12 | #include <linux/sched.h> |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 13 | |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 14 | /* ARM BL switcher abuse support */ |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 15 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 16 | enum tick_device_mode { |
| 17 | TICKDEV_MODE_PERIODIC, |
| 18 | TICKDEV_MODE_ONESHOT, |
| 19 | }; |
| 20 | |
| 21 | struct tick_device { |
| 22 | struct clock_event_device *evtdev; |
| 23 | enum tick_device_mode mode; |
| 24 | }; |
Ingo Molnar | 289f480 | 2007-02-16 01:28:15 -0800 | [diff] [blame] | 25 | extern struct tick_device *tick_get_device(int cpu); |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 26 | #endif |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 27 | |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 28 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
| 29 | extern void __init tick_init(void); |
Rafael J. Wysocki | 124cf911 | 2015-02-13 23:50:43 +0100 | [diff] [blame] | 30 | extern void tick_freeze(void); |
| 31 | extern void tick_unfreeze(void); |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 32 | #else /* CONFIG_GENERIC_CLOCKEVENTS */ |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 33 | static inline void tick_init(void) { } |
Rafael J. Wysocki | 124cf911 | 2015-02-13 23:50:43 +0100 | [diff] [blame] | 34 | static inline void tick_freeze(void) { } |
| 35 | static inline void tick_unfreeze(void) { } |
Thomas Gleixner | 79bf2bb | 2007-02-16 01:28:03 -0800 | [diff] [blame] | 36 | #endif /* !CONFIG_GENERIC_CLOCKEVENTS */ |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 37 | |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 38 | #ifdef CONFIG_TICK_ONESHOT |
| 39 | extern void tick_irq_enter(void); |
| 40 | # ifndef arch_needs_cpu |
| 41 | # define arch_needs_cpu() (0) |
| 42 | # endif |
| 43 | # else |
| 44 | static inline void tick_irq_enter(void) { } |
| 45 | #endif |
Frederic Weisbecker | 33a5f62 | 2012-10-11 17:52:56 +0200 | [diff] [blame] | 46 | |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 47 | #ifdef CONFIG_NO_HZ_COMMON |
| 48 | extern int tick_nohz_tick_stopped(void); |
Frederic Weisbecker | 1268fbc | 2011-11-17 18:48:14 +0100 | [diff] [blame] | 49 | extern void tick_nohz_idle_enter(void); |
Frederic Weisbecker | 280f067 | 2011-10-07 18:22:06 +0200 | [diff] [blame] | 50 | extern void tick_nohz_idle_exit(void); |
| 51 | extern void tick_nohz_irq_exit(void); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 52 | extern ktime_t tick_nohz_get_sleep_length(void); |
Venki Pallipadi | 6378ddb | 2008-01-30 13:30:04 +0100 | [diff] [blame] | 53 | extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); |
Arjan van de Ven | 0224cf4 | 2010-05-09 08:25:23 -0700 | [diff] [blame] | 54 | extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 55 | #else /* !CONFIG_NO_HZ_COMMON */ |
| 56 | static inline int tick_nohz_tick_stopped(void) { return 0; } |
Frederic Weisbecker | 2bbb681 | 2011-10-08 16:01:00 +0200 | [diff] [blame] | 57 | static inline void tick_nohz_idle_enter(void) { } |
| 58 | static inline void tick_nohz_idle_exit(void) { } |
Frederic Weisbecker | 280f067 | 2011-10-07 18:22:06 +0200 | [diff] [blame] | 59 | |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 60 | static 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.com | 8083e4a | 2008-08-04 11:59:11 -0700 | [diff] [blame] | 66 | static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } |
Arjan van de Ven | 0224cf4 | 2010-05-09 08:25:23 -0700 | [diff] [blame] | 67 | static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } |
Thomas Gleixner | c1797ba | 2015-03-25 13:07:37 +0100 | [diff] [blame^] | 68 | #endif /* !CONFIG_NO_HZ_COMMON */ |
Thomas Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 69 | |
Frederic Weisbecker | c5bfece | 2013-04-12 16:45:34 +0200 | [diff] [blame] | 70 | #ifdef CONFIG_NO_HZ_FULL |
Frederic Weisbecker | 460775df | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 71 | extern bool tick_nohz_full_running; |
| 72 | extern cpumask_var_t tick_nohz_full_mask; |
Paul E. McKenney | c0f489d | 2014-06-04 13:46:03 -0700 | [diff] [blame] | 73 | extern cpumask_var_t housekeeping_mask; |
Frederic Weisbecker | 460775df | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 74 | |
| 75 | static inline bool tick_nohz_full_enabled(void) |
| 76 | { |
Frederic Weisbecker | 58135f5 | 2013-11-06 14:45:57 +0100 | [diff] [blame] | 77 | if (!context_tracking_is_enabled()) |
Frederic Weisbecker | 460775df | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 78 | return false; |
| 79 | |
| 80 | return tick_nohz_full_running; |
| 81 | } |
| 82 | |
| 83 | static 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 Weisbecker | d13508f | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 91 | extern void __tick_nohz_full_check(void); |
Frederic Weisbecker | 40bea03 | 2014-08-13 18:50:16 +0200 | [diff] [blame] | 92 | extern void tick_nohz_full_kick(void); |
Frederic Weisbecker | 3d36aeb | 2014-06-04 16:17:33 +0200 | [diff] [blame] | 93 | extern void tick_nohz_full_kick_cpu(int cpu); |
Frederic Weisbecker | 76c24fb | 2013-04-18 00:15:40 +0200 | [diff] [blame] | 94 | extern void tick_nohz_full_kick_all(void); |
Frederic Weisbecker | d13508f | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 95 | extern void __tick_nohz_task_switch(struct task_struct *tsk); |
Frederic Weisbecker | a831881 | 2012-12-18 17:32:19 +0100 | [diff] [blame] | 96 | #else |
Frederic Weisbecker | 460775df | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 97 | static inline bool tick_nohz_full_enabled(void) { return false; } |
| 98 | static inline bool tick_nohz_full_cpu(int cpu) { return false; } |
Frederic Weisbecker | d13508f | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 99 | static inline void __tick_nohz_full_check(void) { } |
Frederic Weisbecker | 3d36aeb | 2014-06-04 16:17:33 +0200 | [diff] [blame] | 100 | static inline void tick_nohz_full_kick_cpu(int cpu) { } |
Frederic Weisbecker | 76c24fb | 2013-04-18 00:15:40 +0200 | [diff] [blame] | 101 | static inline void tick_nohz_full_kick(void) { } |
| 102 | static inline void tick_nohz_full_kick_all(void) { } |
Frederic Weisbecker | d13508f | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 103 | static inline void __tick_nohz_task_switch(struct task_struct *tsk) { } |
Frederic Weisbecker | a831881 | 2012-12-18 17:32:19 +0100 | [diff] [blame] | 104 | #endif |
| 105 | |
Paul E. McKenney | c0f489d | 2014-06-04 13:46:03 -0700 | [diff] [blame] | 106 | static 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 | |
| 115 | static 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 Weisbecker | d13508f | 2013-07-24 23:52:27 +0200 | [diff] [blame] | 124 | static inline void tick_nohz_full_check(void) |
| 125 | { |
| 126 | if (tick_nohz_full_enabled()) |
| 127 | __tick_nohz_full_check(); |
| 128 | } |
| 129 | |
| 130 | static 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 Gleixner | 906568c | 2007-02-16 01:28:01 -0800 | [diff] [blame] | 136 | #endif |