linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Guittot <vincent.guittot@linaro.org>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, bristot@redhat.com,
	linux-kernel@vger.kernel.org, joel@joelfernandes.org,
	valentin.schneider@arm.com
Cc: fweisbec@gmail.com, tglx@linutronix.de, qais.yousef@arm.com,
	Vincent Guittot <vincent.guittot@linaro.org>
Subject: [PATCH 6/7 v4] sched/fair: trigger the update of blocked load on newly idle cpu
Date: Wed, 24 Feb 2021 14:30:06 +0100	[thread overview]
Message-ID: <20210224133007.28644-7-vincent.guittot@linaro.org> (raw)
In-Reply-To: <20210224133007.28644-1-vincent.guittot@linaro.org>

Instead of waking up a random and already idle CPU, we can take advantage
of this_cpu being about to enter idle to run the ILB and update the
blocked load.

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
 kernel/sched/core.c  |  2 +-
 kernel/sched/fair.c  | 24 +++++++++++++++++++++---
 kernel/sched/idle.c  |  6 ++++++
 kernel/sched/sched.h |  7 +++++++
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 88a2e2bdbabe..61ec83e52a08 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -737,7 +737,7 @@ static void nohz_csd_func(void *info)
 	/*
 	 * Release the rq::nohz_csd.
 	 */
-	flags = atomic_fetch_andnot(NOHZ_KICK_MASK, nohz_flags(cpu));
+	flags = atomic_fetch_andnot(NOHZ_KICK_MASK | NOHZ_NEWILB_KICK, nohz_flags(cpu));
 	WARN_ON(!(flags & NOHZ_KICK_MASK));
 
 	rq->idle_balance = idle_cpu(cpu);
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 586f6ce0d302..46c220a4f7ed 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10453,6 +10453,24 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	return true;
 }
 
+/*
+ * Check if we need to run the ILB for updating blocked load before entering
+ * idle state.
+ */
+void nohz_run_idle_balance(int cpu)
+{
+	unsigned int flags;
+
+	flags = atomic_fetch_andnot(NOHZ_NEWILB_KICK, nohz_flags(cpu));
+
+	/*
+	 * Update the blocked load only if no SCHED_SOFTIRQ is about to happen
+	 * (ie NOHZ_STATS_KICK set) and will do the same.
+	 */
+	if ((flags == NOHZ_NEWILB_KICK) && !need_resched())
+		_nohz_idle_balance(cpu_rq(cpu), NOHZ_STATS_KICK, CPU_IDLE);
+}
+
 static void nohz_newidle_balance(struct rq *this_rq)
 {
 	int this_cpu = this_rq->cpu;
@@ -10474,10 +10492,10 @@ static void nohz_newidle_balance(struct rq *this_rq)
 		return;
 
 	/*
-	 * Blocked load of idle CPUs need to be updated.
-	 * Kick an ILB to update statistics.
+	 * Set the need to trigger ILB in order to update blocked load
+	 * before entering idle state.
 	 */
-	kick_ilb(NOHZ_STATS_KICK);
+	atomic_or(NOHZ_NEWILB_KICK, nohz_flags(this_cpu));
 }
 
 #else /* !CONFIG_NO_HZ_COMMON */
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 7199e6f23789..7a92d6054aba 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -261,6 +261,12 @@ static void cpuidle_idle_call(void)
 static void do_idle(void)
 {
 	int cpu = smp_processor_id();
+
+	/*
+	 * Check if we need to update blocked load
+	 */
+	nohz_run_idle_balance(cpu);
+
 	/*
 	 * If the arch has a polling bit, we maintain an invariant:
 	 *
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 10a1522b1e30..0ddc9a6ff03a 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2385,9 +2385,11 @@ extern void cfs_bandwidth_usage_dec(void);
 #ifdef CONFIG_NO_HZ_COMMON
 #define NOHZ_BALANCE_KICK_BIT	0
 #define NOHZ_STATS_KICK_BIT	1
+#define NOHZ_NEWILB_KICK_BIT	2
 
 #define NOHZ_BALANCE_KICK	BIT(NOHZ_BALANCE_KICK_BIT)
 #define NOHZ_STATS_KICK		BIT(NOHZ_STATS_KICK_BIT)
+#define NOHZ_NEWILB_KICK	BIT(NOHZ_NEWILB_KICK_BIT)
 
 #define NOHZ_KICK_MASK	(NOHZ_BALANCE_KICK | NOHZ_STATS_KICK)
 
@@ -2398,6 +2400,11 @@ extern void nohz_balance_exit_idle(struct rq *rq);
 static inline void nohz_balance_exit_idle(struct rq *rq) { }
 #endif
 
+#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
+extern void nohz_run_idle_balance(int cpu);
+#else
+static inline void nohz_run_idle_balance(int cpu) { }
+#endif
 
 #ifdef CONFIG_SMP
 static inline
-- 
2.17.1


  parent reply	other threads:[~2021-02-24 14:51 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 13:30 [PATCH 0/7 v4] move update blocked load outside newidle_balance Vincent Guittot
2021-02-24 13:30 ` [PATCH 1/7 v4] sched/fair: remove update of blocked load from newidle_balance Vincent Guittot
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Remove " tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-06 11:42   ` tip-bot2 for Vincent Guittot
2021-02-24 13:30 ` [PATCH 2/7 v4] sched/fair: remove unused return of _nohz_idle_balance Vincent Guittot
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Remove " tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-06 11:42   ` tip-bot2 for Vincent Guittot
2021-02-24 13:30 ` [PATCH 3/7 v4] sched/fair: remove unused parameter of update_nohz_stats Vincent Guittot
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Remove " tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-05 13:55   ` [PATCH 3/7 v4] sched/fair: remove " Qais Yousef
2021-03-06 11:42   ` [tip: sched/core] sched/fair: Remove " tip-bot2 for Vincent Guittot
2021-02-24 13:30 ` [PATCH 4/7 v4] sched/fair: merge for each idle cpu loop of ILB Vincent Guittot
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Merge " tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-06 11:42   ` tip-bot2 for Vincent Guittot
2021-02-24 13:30 ` [PATCH 5/7 v4] sched/fair: reorder newidle_balance pulled_task tests Vincent Guittot
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Reorder " tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-06 11:42   ` tip-bot2 for Vincent Guittot
2021-02-24 13:30 ` Vincent Guittot [this message]
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Trigger the update of blocked load on newly idle cpu tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-05 13:52   ` [PATCH 6/7 v4] sched/fair: trigger " Qais Yousef
2021-03-06 11:42   ` [tip: sched/core] sched/fair: Trigger " tip-bot2 for Vincent Guittot
2021-02-24 13:30 ` [PATCH 7/7 v4] sched/fair: reduce the window for duplicated update Vincent Guittot
2021-03-02  9:01   ` [tip: sched/core] sched/fair: Reduce " tip-bot2 for Vincent Guittot
2021-03-03  9:49   ` tip-bot2 for Vincent Guittot
2021-03-06 11:42   ` tip-bot2 for Vincent Guittot
2021-02-24 15:53 ` [PATCH 0/7 v4] move update blocked load outside newidle_balance Peter Zijlstra
2021-02-24 15:57   ` Vincent Guittot
2021-02-24 17:41     ` Peter Zijlstra
2021-02-24 17:51       ` Vincent Guittot
2021-02-24 18:17         ` Peter Zijlstra
2021-02-24 18:46 ` Valentin Schneider
2021-02-25  8:05   ` Vincent Guittot
2021-02-25 12:14     ` Valentin Schneider

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=20210224133007.28644-7-vincent.guittot@linaro.org \
    --to=vincent.guittot@linaro.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=fweisbec@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=qais.yousef@arm.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=valentin.schneider@arm.com \
    /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;
as well as URLs for NNTP newsgroup(s).