mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kuba Piecuch <jpiecuch@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Kuba Piecuch <jpiecuch@google.com>,
	Ingo Molnar <mingo@redhat.com>,
	 Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	 Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	 linux-kernel@vger.kernel.org
Subject: [PATCH] sched/core: Skip empty source rqs in try_steal_cookie()
Date: Thu, 26 Nov 2026 18:24:26 +0000	[thread overview]
Message-ID: <20261126182255.4146389-1-jpiecuch@google.com> (raw)

sched_core_balance() walks each CPU of each sched domain of a forced-idle
CPU via steal_cookie_task() -> try_steal_cookie() until a matching-cookie
task is stolen or need_resched() is set.

try_steal_cookie() disables IRQs and acquires double_rq_lock(dst, src)
before inspecting @src, even when src->core_tree is empty and no task can
be stolen from @src. On large machines, a forced-idle balance pass incurs
many IRQ-off double_rq_lock() rounds and remote rq lock contention for
nothing.

Return early if src->core_tree is empty via a lockless data_race() peek
before disabling IRQs and locking both runqueues. Missing a task enqueued
just after the peek is equivalent to missing one enqueued right after
releasing the locks; all remaining checks stay under double_rq_lock().

Signed-off-by: Kuba Piecuch <jpiecuch@google.com>
---
This patch was written with the help of an AI coding assistant. I have
reviewed the patch and verified the tests run by the tool.

 kernel/sched/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ea89471d4743..dfff7756465f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6591,6 +6591,13 @@ static bool try_steal_cookie(int this, int that)
 	unsigned long cookie;
 	bool success = false;
 
+	/*
+	 * Lockless hint: a missed concurrent enqueue is like arriving after
+	 * unlock; a concurrent dequeue is caught under double_rq_lock().
+	 */
+	if (data_race(RB_EMPTY_ROOT(&src->core_tree)))
+		return false;
+
 	guard(irq)();
 	guard(double_rq_lock)(dst, src);
 

base-commit: c47af85667065c6dd5b79564203c2d29948ef60e
-- 
2.56.1.839.g22a8290db9-goog


                 reply	other threads:[~2026-11-26 18:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261126182255.4146389-1-jpiecuch@google.com \
    --to=jpiecuch@google.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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

all inboxes | Powered by JetHome®