mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/core: Skip empty source rqs in try_steal_cookie()
@ 2026-11-26 18:24 Kuba Piecuch
  0 siblings, 0 replies; only message in thread
From: Kuba Piecuch @ 2026-11-26 18:24 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Kuba Piecuch, Ingo Molnar, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, linux-kernel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26 18:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 18:24 [PATCH] sched/core: Skip empty source rqs in try_steal_cookie() Kuba Piecuch

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®