diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2015-05-26 18:50:35 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2015-06-19 09:18:28 -0400 |
commit | 683be13a284720205228e29207ef11a1c3c322b9 (patch) | |
tree | 02a925c3d34bd79de893c152d793aae46218a113 /kernel/time/timer.c | |
parent | bc7a34b8b9ebfb0f4b8a35a72a0b134fd6c5ef50 (diff) |
timer: Minimize nohz off overhead
If nohz is disabled on the kernel command line the [hr]timer code
still calls wake_up_nohz_cpu() and tick_nohz_full_cpu(), a pretty
pointless exercise. Cache nohz_active in [hr]timer per cpu bases and
avoid the overhead.
Before:
48.10% hog [.] main
15.25% [kernel] [k] _raw_spin_lock_irqsave
9.76% [kernel] [k] _raw_spin_unlock_irqrestore
6.50% [kernel] [k] mod_timer
6.44% [kernel] [k] lock_timer_base.isra.38
3.87% [kernel] [k] detach_if_pending
3.80% [kernel] [k] del_timer
2.67% [kernel] [k] internal_add_timer
1.33% [kernel] [k] __internal_add_timer
0.73% [kernel] [k] timerfn
0.54% [kernel] [k] wake_up_nohz_cpu
After:
48.73% hog [.] main
15.36% [kernel] [k] _raw_spin_lock_irqsave
9.77% [kernel] [k] _raw_spin_unlock_irqrestore
6.61% [kernel] [k] lock_timer_base.isra.38
6.42% [kernel] [k] mod_timer
3.90% [kernel] [k] detach_if_pending
3.76% [kernel] [k] del_timer
2.41% [kernel] [k] internal_add_timer
1.39% [kernel] [k] __internal_add_timer
0.76% [kernel] [k] timerfn
We probably should have a cached value for nohz full in the per cpu
bases as well to avoid the cpumask check. The base cache line is hot
already, the cpumask not necessarily.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Joonwoo Park <joonwoop@codeaurora.org>
Cc: Wenbo Wang <wenbo.wang@memblaze.com>
Link: http://lkml.kernel.org/r/20150526224512.207378134@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/time/timer.c')
-rw-r--r-- | kernel/time/timer.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 343142ed996a..520499dd85af 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c | |||
@@ -86,6 +86,7 @@ struct tvec_base { | |||
86 | unsigned long all_timers; | 86 | unsigned long all_timers; |
87 | int cpu; | 87 | int cpu; |
88 | bool migration_enabled; | 88 | bool migration_enabled; |
89 | bool nohz_active; | ||
89 | struct tvec_root tv1; | 90 | struct tvec_root tv1; |
90 | struct tvec tv2; | 91 | struct tvec tv2; |
91 | struct tvec tv3; | 92 | struct tvec tv3; |
@@ -99,7 +100,7 @@ static DEFINE_PER_CPU(struct tvec_base, tvec_bases); | |||
99 | #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) | 100 | #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) |
100 | unsigned int sysctl_timer_migration = 1; | 101 | unsigned int sysctl_timer_migration = 1; |
101 | 102 | ||
102 | void timers_update_migration(void) | 103 | void timers_update_migration(bool update_nohz) |
103 | { | 104 | { |
104 | bool on = sysctl_timer_migration && tick_nohz_active; | 105 | bool on = sysctl_timer_migration && tick_nohz_active; |
105 | unsigned int cpu; | 106 | unsigned int cpu; |
@@ -111,6 +112,10 @@ void timers_update_migration(void) | |||
111 | for_each_possible_cpu(cpu) { | 112 | for_each_possible_cpu(cpu) { |
112 | per_cpu(tvec_bases.migration_enabled, cpu) = on; | 113 | per_cpu(tvec_bases.migration_enabled, cpu) = on; |
113 | per_cpu(hrtimer_bases.migration_enabled, cpu) = on; | 114 | per_cpu(hrtimer_bases.migration_enabled, cpu) = on; |
115 | if (!update_nohz) | ||
116 | continue; | ||
117 | per_cpu(tvec_bases.nohz_active, cpu) = true; | ||
118 | per_cpu(hrtimer_bases.nohz_active, cpu) = true; | ||
114 | } | 119 | } |
115 | } | 120 | } |
116 | 121 | ||
@@ -124,7 +129,7 @@ int timer_migration_handler(struct ctl_table *table, int write, | |||
124 | mutex_lock(&mutex); | 129 | mutex_lock(&mutex); |
125 | ret = proc_dointvec(table, write, buffer, lenp, ppos); | 130 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
126 | if (!ret && write) | 131 | if (!ret && write) |
127 | timers_update_migration(); | 132 | timers_update_migration(false); |
128 | mutex_unlock(&mutex); | 133 | mutex_unlock(&mutex); |
129 | return ret; | 134 | return ret; |
130 | } | 135 | } |
@@ -436,8 +441,11 @@ static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) | |||
436 | * require special care against races with idle_cpu(), lets deal | 441 | * require special care against races with idle_cpu(), lets deal |
437 | * with that later. | 442 | * with that later. |
438 | */ | 443 | */ |
439 | if (!(timer->flags & TIMER_DEFERRABLE) || tick_nohz_full_cpu(base->cpu)) | 444 | if (base->nohz_active) { |
440 | wake_up_nohz_cpu(base->cpu); | 445 | if (!(timer->flags & TIMER_DEFERRABLE) || |
446 | tick_nohz_full_cpu(base->cpu)) | ||
447 | wake_up_nohz_cpu(base->cpu); | ||
448 | } | ||
441 | } | 449 | } |
442 | 450 | ||
443 | #ifdef CONFIG_TIMER_STATS | 451 | #ifdef CONFIG_TIMER_STATS |