From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
Andrew Morton <akpm@linux-foundation.org>,
Anton Blanchard <anton@au1.ibm.com>,
Tim Pepper <lnxninja@linux.vnet.ibm.com>
Subject: [RFC PATCH 04/15] nohz_task: Stop the tick when the nohz task runs alone
Date: Mon, 20 Dec 2010 16:24:11 +0100 [thread overview]
Message-ID: <1292858662-5650-5-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1292858662-5650-1-git-send-email-fweisbec@gmail.com>
Check from the timer interrupt that we are a nohz task running
alone in the CPU and stop the tick if this is the case.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Anton Blanchard <anton@au1.ibm.com>
Cc: Tim Pepper <lnxninja@linux.vnet.ibm.com>
---
include/linux/sched.h | 6 ++++++
include/linux/tick.h | 11 ++++++++++-
kernel/sched.c | 14 ++++++++++++++
kernel/softirq.c | 4 ++--
kernel/time/tick-sched.c | 30 ++++++++++++++++++++++++++++--
5 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 2c79e92..858a876 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2549,6 +2549,12 @@ static inline void inc_syscw(struct task_struct *tsk)
extern void task_oncpu_function_call(struct task_struct *p,
void (*func) (void *info), void *info);
+#ifdef CONFIG_NO_HZ_TASK
+extern int nohz_task_can_stop_tick(void);
+#else
+static inline int nohz_task_can_stop_tick(void) { return 0; }
+#endif
+
#ifdef CONFIG_MM_OWNER
extern void mm_update_next_owner(struct mm_struct *mm);
diff --git a/include/linux/tick.h b/include/linux/tick.h
index b232ccc..7465a47 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -7,6 +7,7 @@
#define _LINUX_TICK_H
#include <linux/clockchips.h>
+#include <linux/percpu-defs.h>
#ifdef CONFIG_GENERIC_CLOCKEVENTS
@@ -126,7 +127,15 @@ extern void tick_nohz_restart_sched_tick(void);
extern ktime_t tick_nohz_get_sleep_length(void);
extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
-# else
+
+#ifdef CONFIG_NO_HZ_TASK
+DECLARE_PER_CPU(int, task_nohz_mode);
+extern int tick_nohz_task_mode(void);
+#else
+static inline int tick_nohz_task_mode(void) { return 0; }
+#endif
+
+# else /* !NO_HZ */
static inline void tick_nohz_stop_sched_tick(int inidle) { }
static inline void tick_nohz_restart_sched_tick(void) { }
static inline ktime_t tick_nohz_get_sleep_length(void)
diff --git a/kernel/sched.c b/kernel/sched.c
index 2cd6823..e9cdd7a 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2443,6 +2443,20 @@ static void update_avg(u64 *avg, u64 sample)
}
#endif
+#ifdef CONFIG_NO_HZ_TASK
+DEFINE_PER_CPU(int, task_nohz_mode);
+
+int nohz_task_can_stop_tick(void)
+{
+ struct rq *rq = this_rq();
+
+ if (rq->nr_running > 1)
+ return 0;
+
+ return 1;
+}
+#endif
+
static inline void ttwu_activate(struct task_struct *p, struct rq *rq,
bool is_sync, bool is_migrate, bool is_local,
unsigned long en_flags)
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 18f4be0..e24c456a 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -297,7 +297,7 @@ void irq_enter(void)
int cpu = smp_processor_id();
rcu_irq_enter();
- if (idle_cpu(cpu) && !in_interrupt()) {
+ if ((idle_cpu(cpu) || tick_nohz_task_mode()) && !in_interrupt()) {
/*
* Prevent raise_softirq from needlessly waking up ksoftirqd
* here, as softirq will be serviced on return from interrupt.
@@ -330,7 +330,7 @@ void irq_exit(void)
rcu_irq_exit();
#ifdef CONFIG_NO_HZ
/* Make sure that timer wheel updates are propagated */
- if (idle_cpu(smp_processor_id()) && !in_interrupt() && !need_resched())
+ if ((idle_cpu(smp_processor_id()) || tick_nohz_task_mode()) && !in_interrupt() && !need_resched())
tick_nohz_stop_sched_tick(0);
#endif
preempt_enable_no_resched();
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index e706fa8..88011b9 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -274,7 +274,7 @@ void tick_nohz_stop_sched_tick(int inidle)
* updated. Thus, it must not be called in the event we are called from
* irq_exit() with the prior state different than idle.
*/
- if (!inidle && !ts->inidle)
+ if (!inidle && !ts->inidle && !tick_nohz_task_mode())
goto end;
/*
@@ -510,6 +510,11 @@ void tick_nohz_restart_sched_tick(void)
local_irq_save(flags);
+ if (tick_nohz_task_mode()) {
+ local_irq_restore(flags);
+ return;
+ }
+
if (ts->idle_active || (ts->inidle && ts->tick_stopped))
now = ktime_get();
@@ -714,10 +719,29 @@ void tick_check_idle(int cpu)
tick_check_nohz(cpu);
}
+#ifdef CONFIG_NO_HZ_TASK
+int tick_nohz_task_mode(void)
+{
+ return __get_cpu_var(task_nohz_mode);
+}
+
+static void tick_nohz_task_stop_tick(void)
+{
+ if (!test_thread_flag(TIF_NOHZ) || __get_cpu_var(task_nohz_mode))
+ return;
+
+ if (nohz_task_can_stop_tick())
+ __get_cpu_var(task_nohz_mode) = 1;
+}
+#else
+static void tick_nohz_task_stop_tick(void) { }
+#endif /* CONFIG_NO_HZ_TASK */
+
/*
* High resolution timer specific code
*/
#ifdef CONFIG_HIGH_RES_TIMERS
+
/*
* We rearm the timer until we get disabled by the idle code.
* Called with interrupts disabled and timer->base->cpu_base->lock held.
@@ -738,7 +762,7 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)
* this duty, then the jiffies update is still serialized by
* xtime_lock.
*/
- if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE))
+ if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE) && !test_thread_flag(TIF_NOHZ))
tick_do_timer_cpu = cpu;
#endif
@@ -767,6 +791,8 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)
profile_tick(CPU_PROFILING);
}
+ tick_nohz_task_stop_tick();
+
hrtimer_forward(timer, now, tick_period);
return HRTIMER_RESTART;
--
1.7.3.2
next prev parent reply other threads:[~2010-12-20 15:27 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-20 15:24 [RFC PATCH 00/15] Nohz task support Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 01/15] nohz_task: New mask for cpus having nohz task Frederic Weisbecker
2010-12-24 8:00 ` Lai Jiangshan
2010-12-24 8:19 ` Dario Faggioli
2010-12-24 12:29 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 02/15] nohz_task: Avoid nohz task cpu as non-idle timer target Frederic Weisbecker
2010-12-20 15:47 ` Peter Zijlstra
2010-12-20 16:06 ` Steven Rostedt
2010-12-20 16:12 ` Peter Zijlstra
2010-12-21 0:20 ` Frederic Weisbecker
2010-12-21 7:51 ` Peter Zijlstra
2010-12-21 13:58 ` Frederic Weisbecker
2010-12-21 0:13 ` Frederic Weisbecker
2010-12-21 7:50 ` Peter Zijlstra
2010-12-21 13:52 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 03/15] nohz_task: Make tick stop and restart callable outside idle Frederic Weisbecker
2010-12-20 15:48 ` Peter Zijlstra
2010-12-20 16:19 ` Steven Rostedt
2010-12-20 16:25 ` Peter Zijlstra
2010-12-21 1:34 ` Frederic Weisbecker
2010-12-20 15:24 ` Frederic Weisbecker [this message]
2010-12-20 15:51 ` [RFC PATCH 04/15] nohz_task: Stop the tick when the nohz task runs alone Peter Zijlstra
2010-12-20 23:37 ` Frederic Weisbecker
2010-12-21 7:35 ` Peter Zijlstra
2010-12-21 13:22 ` Frederic Weisbecker
2010-12-21 14:34 ` Steven Rostedt
2010-12-21 15:14 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 05/15] nohz_task: Restart the tick when another task compete on the cpu Frederic Weisbecker
2010-12-20 15:53 ` Peter Zijlstra
2010-12-20 23:39 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 06/15] nohz_task: Keep the tick if rcu needs it Frederic Weisbecker
2010-12-20 15:58 ` Peter Zijlstra
2010-12-20 23:49 ` Frederic Weisbecker
2010-12-21 0:12 ` Jonathan Corbet
2010-12-21 2:10 ` Frederic Weisbecker
2010-12-21 8:10 ` Paul E. McKenney
2010-12-20 15:24 ` [RFC PATCH 07/15] nohz_task: Restart tick when RCU forces nohz task cpu quiescent state Frederic Weisbecker
2010-12-20 16:02 ` Peter Zijlstra
2010-12-20 23:52 ` Frederic Weisbecker
2010-12-21 7:41 ` Peter Zijlstra
2010-12-21 13:28 ` Frederic Weisbecker
2010-12-21 15:35 ` Paul E. McKenney
2010-12-20 15:24 ` [RFC PATCH 08/15] smp: Don't warn if irq are disabled but we don't wait for the ipi Frederic Weisbecker
2010-12-20 16:03 ` Peter Zijlstra
2010-12-21 0:02 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 09/15] rcu: Make rcu_enter,exit_nohz() callable from irq Frederic Weisbecker
2010-12-21 19:26 ` Paul E. McKenney
2010-12-21 19:27 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 10/15] nohz_task: Enter in extended quiescent state when in userspace Frederic Weisbecker
2010-12-20 16:18 ` Peter Zijlstra
2010-12-21 1:27 ` Frederic Weisbecker
2010-12-21 8:04 ` Peter Zijlstra
2010-12-21 14:06 ` Frederic Weisbecker
2010-12-21 19:28 ` Paul E. McKenney
2010-12-21 21:49 ` Frederic Weisbecker
2010-12-22 2:20 ` Paul E. McKenney
2010-12-20 15:24 ` [RFC PATCH 11/15] x86: Nohz task support Frederic Weisbecker
2010-12-20 16:23 ` Peter Zijlstra
2010-12-21 1:30 ` Frederic Weisbecker
2010-12-21 8:05 ` Peter Zijlstra
2010-12-21 14:19 ` Frederic Weisbecker
2010-12-21 15:12 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 12/15] clocksource: Ignore nohz task cpu in clocksource watchdog Frederic Weisbecker
2010-12-20 16:27 ` Peter Zijlstra
2010-12-21 1:40 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 13/15] sched: Protect nohz task cpu affinity Frederic Weisbecker
2010-12-20 16:28 ` Peter Zijlstra
2010-12-20 17:05 ` Steven Rostedt
2010-12-21 1:55 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 14/15] nohz_task: Clear nohz task attribute on exit() Frederic Weisbecker
2010-12-20 16:30 ` Peter Zijlstra
2010-12-21 1:48 ` Frederic Weisbecker
2010-12-21 8:07 ` Peter Zijlstra
2010-12-21 14:22 ` Frederic Weisbecker
2010-12-20 15:24 ` [RFC PATCH 15/15] nohz_task: Procfs interface Frederic Weisbecker
2010-12-20 15:42 ` Peter Zijlstra
2010-12-20 15:57 ` Frederic Weisbecker
2010-12-20 16:16 ` Peter Zijlstra
2010-12-21 1:24 ` Frederic Weisbecker
2010-12-21 8:14 ` Peter Zijlstra
2010-12-21 14:00 ` Avi Kivity
2010-12-21 17:05 ` Frederic Weisbecker
2010-12-21 18:17 ` Avi Kivity
2010-12-21 21:08 ` Frederic Weisbecker
2010-12-22 9:22 ` Avi Kivity
2010-12-22 9:51 ` Peter Zijlstra
2010-12-22 20:41 ` Frederic Weisbecker
2010-12-21 14:26 ` Frederic Weisbecker
2010-12-20 15:44 ` [RFC PATCH 00/15] Nohz task support Steven Rostedt
2010-12-20 23:33 ` Frederic Weisbecker
2010-12-21 1:36 ` Steven Rostedt
2010-12-21 2:15 ` Frederic Weisbecker
2010-12-21 7:34 ` Peter Zijlstra
2010-12-21 13:13 ` Frederic Weisbecker
2010-12-21 13:56 ` Avi Kivity
2010-12-21 17:01 ` Frederic Weisbecker
2010-12-20 16:35 ` Peter Zijlstra
2010-12-21 1:53 ` Frederic Weisbecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292858662-5650-5-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=anton@au1.ibm.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lnxninja@linux.vnet.ibm.com \
--cc=mingo@elte.hu \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome