From: Peter Zijlstra <peterz@infradead.org>
To: Daniel Hodges <hodgesd@meta.com>
Cc: 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>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched: Skip schedule() in sched_yield() when CPU has no other work
Date: Mon, 2 Feb 2026 16:14:02 +0100 [thread overview]
Message-ID: <20260202151402.GE1282955@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260202140039.1970735-1-hodgesd@meta.com>
On Mon, Feb 02, 2026 at 06:00:38AM -0800, Daniel Hodges wrote:
> When a task calls sched_yield() but is the only runnable task on its
> CPU with no pending wakeups, there's nothing to yield to. In this case,
> skip the schedule() overhead entirely and return immediately.
>
> The yield_task() callback is still invoked to preserve per-class
> semantics (e.g., SCHED_DEADLINE's dl_yielded flag for bandwidth
> reclamation). The early exit only occurs after yield_task() completes
> and only if nr_running == 1 and ttwu_pending is false.
>
> Testing performed in a 32-CPU VM using virtme-ng:
>
> stress-ng --yield 8, unpinned workers, 10s each, 30 runs:
> Baseline: 10.18M yields/sec
> Optimized: 11.58M yields/sec
>
> The optimization benefits lightly-loaded systems and CPU-pinned
> workloads where tasks are often alone on their CPUs. On loaded systems
> where CPUs have multiple runnable tasks, the check fails and we fall
> through to the normal schedule() path with no regression.
What is calling sched_yield() enough for this to matter? Calling
sched_yield() outside of FIFO/DL is basically UB.
next parent reply other threads:[~2026-02-02 15:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260202140039.1970735-1-hodgesd@meta.com>
2026-02-02 15:14 ` Peter Zijlstra [this message]
2026-02-02 15:28 ` Daniel Hodges
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=20260202151402.GE1282955@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hodgesd@meta.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--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®