aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/clockchips.h15
-rw-r--r--include/linux/tick.h134
-rw-r--r--kernel/time/clocksource.c2
-rw-r--r--kernel/time/hrtimer.c2
-rw-r--r--kernel/time/tick-internal.h15
-rw-r--r--kernel/time/tick-sched.c7
-rw-r--r--kernel/time/tick-sched.h64
-rw-r--r--kernel/time/timer_list.c2
8 files changed, 112 insertions, 129 deletions
diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h
index 57975131dac1..bc3af821350b 100644
--- a/include/linux/clockchips.h
+++ b/include/linux/clockchips.h
@@ -193,15 +193,6 @@ extern void clockevents_config_and_register(struct clock_event_device *dev,
193 193
194extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq); 194extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
195 195
196extern void clockevents_exchange_device(struct clock_event_device *old,
197 struct clock_event_device *new);
198extern void clockevents_set_state(struct clock_event_device *dev,
199 enum clock_event_state state);
200extern int clockevents_program_event(struct clock_event_device *dev,
201 ktime_t expires, bool force);
202
203extern void clockevents_handle_noop(struct clock_event_device *dev);
204
205static inline void 196static inline void
206clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec) 197clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
207{ 198{
@@ -209,6 +200,12 @@ clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
209 freq, minsec); 200 freq, minsec);
210} 201}
211 202
203/* Should be core only, but is abused by arm bl_switcher */
204extern void clockevents_set_state(struct clock_event_device *dev,
205 enum clock_event_state state);
206extern int clockevents_program_event(struct clock_event_device *dev,
207 ktime_t expires, bool force);
208
212extern void clockevents_suspend(void); 209extern void clockevents_suspend(void);
213extern void clockevents_resume(void); 210extern void clockevents_resume(void);
214 211
diff --git a/include/linux/tick.h b/include/linux/tick.h
index 9c085dc12ae9..f9a2d2687a46 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -1,7 +1,5 @@
1/* linux/include/linux/tick.h 1/*
2 * 2 * Tick related global functions
3 * This file contains the structure definitions for tick related functions
4 *
5 */ 3 */
6#ifndef _LINUX_TICK_H 4#ifndef _LINUX_TICK_H
7#define _LINUX_TICK_H 5#define _LINUX_TICK_H
@@ -9,13 +7,12 @@
9#include <linux/clockchips.h> 7#include <linux/clockchips.h>
10#include <linux/irqflags.h> 8#include <linux/irqflags.h>
11#include <linux/percpu.h> 9#include <linux/percpu.h>
12#include <linux/hrtimer.h>
13#include <linux/context_tracking_state.h> 10#include <linux/context_tracking_state.h>
14#include <linux/cpumask.h> 11#include <linux/cpumask.h>
15#include <linux/sched.h> 12#include <linux/sched.h>
16 13
14/* ARM BL switcher abuse support */
17#ifdef CONFIG_GENERIC_CLOCKEVENTS 15#ifdef CONFIG_GENERIC_CLOCKEVENTS
18
19enum tick_device_mode { 16enum tick_device_mode {
20 TICKDEV_MODE_PERIODIC, 17 TICKDEV_MODE_PERIODIC,
21 TICKDEV_MODE_ONESHOT, 18 TICKDEV_MODE_ONESHOT,
@@ -25,133 +22,38 @@ struct tick_device {
25 struct clock_event_device *evtdev; 22 struct clock_event_device *evtdev;
26 enum tick_device_mode mode; 23 enum tick_device_mode mode;
27}; 24};
28
29enum tick_nohz_mode {
30 NOHZ_MODE_INACTIVE,
31 NOHZ_MODE_LOWRES,
32 NOHZ_MODE_HIGHRES,
33};
34
35/**
36 * struct tick_sched - sched tick emulation and no idle tick control/stats
37 * @sched_timer: hrtimer to schedule the periodic tick in high
38 * resolution mode
39 * @last_tick: Store the last tick expiry time when the tick
40 * timer is modified for nohz sleeps. This is necessary
41 * to resume the tick timer operation in the timeline
42 * when the CPU returns from nohz sleep.
43 * @tick_stopped: Indicator that the idle tick has been stopped
44 * @idle_jiffies: jiffies at the entry to idle for idle time accounting
45 * @idle_calls: Total number of idle calls
46 * @idle_sleeps: Number of idle calls, where the sched tick was stopped
47 * @idle_entrytime: Time when the idle call was entered
48 * @idle_waketime: Time when the idle was interrupted
49 * @idle_exittime: Time when the idle state was left
50 * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
51 * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
52 * @sleep_length: Duration of the current idle sleep
53 * @do_timer_lst: CPU was the last one doing do_timer before going idle
54 */
55struct tick_sched {
56 struct hrtimer sched_timer;
57 unsigned long check_clocks;
58 enum tick_nohz_mode nohz_mode;
59 ktime_t last_tick;
60 int inidle;
61 int tick_stopped;
62 unsigned long idle_jiffies;
63 unsigned long idle_calls;
64 unsigned long idle_sleeps;
65 int idle_active;
66 ktime_t idle_entrytime;
67 ktime_t idle_waketime;
68 ktime_t idle_exittime;
69 ktime_t idle_sleeptime;
70 ktime_t iowait_sleeptime;
71 ktime_t sleep_length;
72 unsigned long last_jiffies;
73 unsigned long next_jiffies;
74 ktime_t idle_expires;
75 int do_timer_last;
76};
77
78extern void __init tick_init(void);
79extern int tick_is_oneshot_available(void);
80extern struct tick_device *tick_get_device(int cpu); 25extern struct tick_device *tick_get_device(int cpu);
26#endif
81 27
28#ifdef CONFIG_GENERIC_CLOCKEVENTS
29extern void __init tick_init(void);
82extern void tick_freeze(void); 30extern void tick_freeze(void);
83extern void tick_unfreeze(void); 31extern void tick_unfreeze(void);
32#else /* CONFIG_GENERIC_CLOCKEVENTS */
33static inline void tick_init(void) { }
34static inline void tick_freeze(void) { }
35static inline void tick_unfreeze(void) { }
36#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
84 37
85# ifdef CONFIG_HIGH_RES_TIMERS 38#ifdef CONFIG_TICK_ONESHOT
86extern int tick_init_highres(void);
87extern int tick_program_event(ktime_t expires, int force);
88extern void tick_setup_sched_timer(void);
89# endif
90
91# if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
92extern void tick_cancel_sched_timer(int cpu);
93# else
94static inline void tick_cancel_sched_timer(int cpu) { }
95# endif
96
97# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
98extern struct tick_device *tick_get_broadcast_device(void);
99extern struct cpumask *tick_get_broadcast_mask(void);
100
101# ifdef CONFIG_TICK_ONESHOT
102extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
103# endif
104
105# endif /* BROADCAST */
106
107# ifdef CONFIG_TICK_ONESHOT
108extern void tick_clock_notify(void);
109extern int tick_check_oneshot_change(int allow_nohz);
110extern struct tick_sched *tick_get_tick_sched(int cpu);
111extern void tick_irq_enter(void); 39extern void tick_irq_enter(void);
112extern int tick_oneshot_mode_active(void);
113# ifndef arch_needs_cpu 40# ifndef arch_needs_cpu
114# define arch_needs_cpu() (0) 41# define arch_needs_cpu() (0)
115# endif 42# endif
116# else 43# else
117static inline void tick_clock_notify(void) { }
118static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
119static inline void tick_irq_enter(void) { }
120static inline int tick_oneshot_mode_active(void) { return 0; }
121# endif
122
123#else /* CONFIG_GENERIC_CLOCKEVENTS */
124static inline void tick_init(void) { }
125static inline void tick_freeze(void) { }
126static inline void tick_unfreeze(void) { }
127static inline void tick_cancel_sched_timer(int cpu) { }
128static inline void tick_clock_notify(void) { }
129static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
130static inline void tick_irq_enter(void) { } 44static inline void tick_irq_enter(void) { }
131static inline int tick_oneshot_mode_active(void) { return 0; } 45#endif
132#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
133
134# ifdef CONFIG_NO_HZ_COMMON
135DECLARE_PER_CPU(struct tick_sched, tick_cpu_sched);
136
137static inline int tick_nohz_tick_stopped(void)
138{
139 return __this_cpu_read(tick_cpu_sched.tick_stopped);
140}
141 46
47#ifdef CONFIG_NO_HZ_COMMON
48extern int tick_nohz_tick_stopped(void);
142extern void tick_nohz_idle_enter(void); 49extern void tick_nohz_idle_enter(void);
143extern void tick_nohz_idle_exit(void); 50extern void tick_nohz_idle_exit(void);
144extern void tick_nohz_irq_exit(void); 51extern void tick_nohz_irq_exit(void);
145extern ktime_t tick_nohz_get_sleep_length(void); 52extern ktime_t tick_nohz_get_sleep_length(void);
146extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); 53extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
147extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); 54extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
148 55#else /* !CONFIG_NO_HZ_COMMON */
149# else /* !CONFIG_NO_HZ_COMMON */ 56static inline int tick_nohz_tick_stopped(void) { return 0; }
150static inline int tick_nohz_tick_stopped(void)
151{
152 return 0;
153}
154
155static inline void tick_nohz_idle_enter(void) { } 57static inline void tick_nohz_idle_enter(void) { }
156static inline void tick_nohz_idle_exit(void) { } 58static inline void tick_nohz_idle_exit(void) { }
157 59
@@ -163,7 +65,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
163} 65}
164static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } 66static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
165static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } 67static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
166# endif /* !CONFIG_NO_HZ_COMMON */ 68#endif /* !CONFIG_NO_HZ_COMMON */
167 69
168#ifdef CONFIG_NO_HZ_FULL 70#ifdef CONFIG_NO_HZ_FULL
169extern bool tick_nohz_full_running; 71extern bool tick_nohz_full_running;
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 8b4010f0b1b4..c3be3c71bbad 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -31,7 +31,7 @@
31#include <linux/tick.h> 31#include <linux/tick.h>
32#include <linux/kthread.h> 32#include <linux/kthread.h>
33 33
34#include "timekeeping.h" 34#include "tick-internal.h"
35#include "timekeeping_internal.h" 35#include "timekeeping_internal.h"
36 36
37/** 37/**
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index bee0c1f78091..721d29b99d10 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -54,7 +54,7 @@
54 54
55#include <trace/events/timer.h> 55#include <trace/events/timer.h>
56 56
57#include "timekeeping.h" 57#include "tick-internal.h"
58 58
59/* 59/*
60 * The timer bases: 60 * The timer bases:
diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h
index d86eb8d485e9..dd2c45d057b9 100644
--- a/kernel/time/tick-internal.h
+++ b/kernel/time/tick-internal.h
@@ -5,6 +5,7 @@
5#include <linux/tick.h> 5#include <linux/tick.h>
6 6
7#include "timekeeping.h" 7#include "timekeeping.h"
8#include "tick-sched.h"
8 9
9#ifdef CONFIG_GENERIC_CLOCKEVENTS 10#ifdef CONFIG_GENERIC_CLOCKEVENTS
10 11
@@ -26,6 +27,7 @@ extern void tick_resume(void);
26extern bool tick_check_replacement(struct clock_event_device *curdev, 27extern bool tick_check_replacement(struct clock_event_device *curdev,
27 struct clock_event_device *newdev); 28 struct clock_event_device *newdev);
28extern void tick_install_replacement(struct clock_event_device *dev); 29extern void tick_install_replacement(struct clock_event_device *dev);
30extern int tick_is_oneshot_available(void);
29 31
30extern int clockevents_tick_resume(struct clock_event_device *dev); 32extern int clockevents_tick_resume(struct clock_event_device *dev);
31/* Check, if the device is functional or a dummy for broadcast */ 33/* Check, if the device is functional or a dummy for broadcast */
@@ -35,6 +37,9 @@ static inline int tick_device_is_functional(struct clock_event_device *dev)
35} 37}
36 38
37extern void clockevents_shutdown(struct clock_event_device *dev); 39extern void clockevents_shutdown(struct clock_event_device *dev);
40extern void clockevents_exchange_device(struct clock_event_device *old,
41 struct clock_event_device *new);
42extern void clockevents_handle_noop(struct clock_event_device *dev);
38extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq); 43extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
39extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt); 44extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
40#endif /* GENERIC_CLOCKEVENTS */ 45#endif /* GENERIC_CLOCKEVENTS */
@@ -49,6 +54,10 @@ extern void tick_oneshot_notify(void);
49extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)); 54extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
50extern void tick_resume_oneshot(void); 55extern void tick_resume_oneshot(void);
51static inline bool tick_oneshot_possible(void) { return true; } 56static inline bool tick_oneshot_possible(void) { return true; }
57extern int tick_oneshot_mode_active(void);
58extern void tick_clock_notify(void);
59extern int tick_check_oneshot_change(int allow_nohz);
60extern int tick_init_highres(void);
52#else /* !ONESHOT */ 61#else /* !ONESHOT */
53static inline 62static inline
54void tick_setup_oneshot(struct clock_event_device *newdev, 63void tick_setup_oneshot(struct clock_event_device *newdev,
@@ -58,6 +67,9 @@ static inline void tick_resume_oneshot(void) { BUG(); }
58static inline int tick_program_event(ktime_t expires, int force) { return 0; } 67static inline int tick_program_event(ktime_t expires, int force) { return 0; }
59static inline void tick_oneshot_notify(void) { } 68static inline void tick_oneshot_notify(void) { }
60static inline bool tick_oneshot_possible(void) { return false; } 69static inline bool tick_oneshot_possible(void) { return false; }
70static inline int tick_oneshot_mode_active(void) { return 0; }
71static inline void tick_clock_notify(void) { }
72static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
61#endif /* !TICK_ONESHOT */ 73#endif /* !TICK_ONESHOT */
62 74
63/* Broadcasting support */ 75/* Broadcasting support */
@@ -72,6 +84,8 @@ extern int tick_resume_broadcast(void);
72extern void tick_broadcast_init(void); 84extern void tick_broadcast_init(void);
73extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast); 85extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
74extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq); 86extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
87extern struct tick_device *tick_get_broadcast_device(void);
88extern struct cpumask *tick_get_broadcast_mask(void);
75#else /* !BROADCAST */ 89#else /* !BROADCAST */
76static inline void tick_install_broadcast_device(struct clock_event_device *dev) { } 90static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
77static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; } 91static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
@@ -101,6 +115,7 @@ extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc);
101extern int tick_broadcast_oneshot_active(void); 115extern int tick_broadcast_oneshot_active(void);
102extern void tick_check_oneshot_broadcast_this_cpu(void); 116extern void tick_check_oneshot_broadcast_this_cpu(void);
103bool tick_broadcast_oneshot_available(void); 117bool tick_broadcast_oneshot_available(void);
118extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
104#else /* BROADCAST && ONESHOT */ 119#else /* BROADCAST && ONESHOT */
105static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); } 120static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
106static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; } 121static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; }
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index a4c4edac4528..914259128145 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -34,7 +34,7 @@
34/* 34/*
35 * Per cpu nohz control structure 35 * Per cpu nohz control structure
36 */ 36 */
37DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched); 37static DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
38 38
39/* 39/*
40 * The time, when the last jiffy update happened. Protected by jiffies_lock. 40 * The time, when the last jiffy update happened. Protected by jiffies_lock.
@@ -416,6 +416,11 @@ static int __init setup_tick_nohz(char *str)
416 416
417__setup("nohz=", setup_tick_nohz); 417__setup("nohz=", setup_tick_nohz);
418 418
419int tick_nohz_tick_stopped(void)
420{
421 return __this_cpu_read(tick_cpu_sched.tick_stopped);
422}
423
419/** 424/**
420 * tick_nohz_update_jiffies - update jiffies when idle was interrupted 425 * tick_nohz_update_jiffies - update jiffies when idle was interrupted
421 * 426 *
diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h
new file mode 100644
index 000000000000..930743249127
--- /dev/null
+++ b/kernel/time/tick-sched.h
@@ -0,0 +1,64 @@
1#ifndef _TICK_SCHED_H
2#define _TICK_SCHED_H
3
4#include <linux/hrtimer.h>
5
6enum tick_nohz_mode {
7 NOHZ_MODE_INACTIVE,
8 NOHZ_MODE_LOWRES,
9 NOHZ_MODE_HIGHRES,
10};
11
12/**
13 * struct tick_sched - sched tick emulation and no idle tick control/stats
14 * @sched_timer: hrtimer to schedule the periodic tick in high
15 * resolution mode
16 * @last_tick: Store the last tick expiry time when the tick
17 * timer is modified for nohz sleeps. This is necessary
18 * to resume the tick timer operation in the timeline
19 * when the CPU returns from nohz sleep.
20 * @tick_stopped: Indicator that the idle tick has been stopped
21 * @idle_jiffies: jiffies at the entry to idle for idle time accounting
22 * @idle_calls: Total number of idle calls
23 * @idle_sleeps: Number of idle calls, where the sched tick was stopped
24 * @idle_entrytime: Time when the idle call was entered
25 * @idle_waketime: Time when the idle was interrupted
26 * @idle_exittime: Time when the idle state was left
27 * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
28 * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
29 * @sleep_length: Duration of the current idle sleep
30 * @do_timer_lst: CPU was the last one doing do_timer before going idle
31 */
32struct tick_sched {
33 struct hrtimer sched_timer;
34 unsigned long check_clocks;
35 enum tick_nohz_mode nohz_mode;
36 ktime_t last_tick;
37 int inidle;
38 int tick_stopped;
39 unsigned long idle_jiffies;
40 unsigned long idle_calls;
41 unsigned long idle_sleeps;
42 int idle_active;
43 ktime_t idle_entrytime;
44 ktime_t idle_waketime;
45 ktime_t idle_exittime;
46 ktime_t idle_sleeptime;
47 ktime_t iowait_sleeptime;
48 ktime_t sleep_length;
49 unsigned long last_jiffies;
50 unsigned long next_jiffies;
51 ktime_t idle_expires;
52 int do_timer_last;
53};
54
55extern struct tick_sched *tick_get_tick_sched(int cpu);
56
57extern void tick_setup_sched_timer(void);
58#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
59extern void tick_cancel_sched_timer(int cpu);
60#else
61static inline void tick_cancel_sched_timer(int cpu) { }
62#endif
63
64#endif
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 05aa5590106a..e878c2e0ba45 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -16,10 +16,10 @@
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/seq_file.h> 17#include <linux/seq_file.h>
18#include <linux/kallsyms.h> 18#include <linux/kallsyms.h>
19#include <linux/tick.h>
20 19
21#include <asm/uaccess.h> 20#include <asm/uaccess.h>
22 21
22#include "tick-internal.h"
23 23
24struct timer_list_iter { 24struct timer_list_iter {
25 int cpu; 25 int cpu;