From: Peter Zijlstra <peterz@infradead.org>
To: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Fernand Sieber <sieberf@amazon.com>,
mingo@redhat.com, linux-kernel@vger.kernel.org,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, bristot@redhat.com,
vschneid@redhat.com, dwmw@amazon.co.uk, jschoenh@amazon.de,
liuyuxua@amazon.com
Subject: Re: [PATCH] sched: Optimize core cookie matching check
Date: Thu, 6 Nov 2025 12:09:43 +0100 [thread overview]
Message-ID: <20251106110943.GP3245006@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <f7169de1-76f4-4bde-8d9a-cc62b7e3157a@amd.com>
On Wed, Nov 05, 2025 at 10:04:01PM +0530, K Prateek Nayak wrote:
> Hello Fernand,
>
> On 11/5/2025 8:55 PM, Fernand Sieber wrote:
> > Early return true if the core cookie matches. This avoids the SMT mask
> > loop to check for an idle core, which might be more expensive on wide
> > platforms.
> >
> > Signed-off-by: Fernand Sieber <sieberf@amazon.com>
> > ---
> > kernel/sched/sched.h | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> > index adfb6e3409d7..381cd561e99b 100644
> > --- a/kernel/sched/sched.h
> > +++ b/kernel/sched/sched.h
> > @@ -1432,6 +1432,9 @@ static inline bool sched_core_cookie_match(struct rq *rq, struct task_struct *p)
> > if (!sched_core_enabled(rq))
> > return true;
> >
> > + if (rq->core->core_cookie == p->core_cookie)
> > + return true;
>
> nit. We can use sched_cpu_cookie_match(rq, p) to check for the
> above two conditions. but even this is good.
>
> Apart from that, I think this optimization makes sense.
>
> > +
> > for_each_cpu(cpu, cpu_smt_mask(cpu_of(rq))) {
> > if (!available_idle_cpu(cpu)) {
> > idle_core = false;
> > @@ -1443,7 +1446,7 @@ static inline bool sched_core_cookie_match(struct rq *rq, struct task_struct *p)
> > * A CPU in an idle core is always the best choice for tasks with
> > * cookies.
> > */
> > - return idle_core || rq->core->core_cookie == p->core_cookie;
> > + return idle_core;
>
> Peter, do we care about checking the core_cookie again before
> returning just in case the task cookie was selected between the
> check above an here?
I don't think it really matters, but someone what runs this stuff would
probably know better than me ;-)
> If not, then this looks good to me. Feel free to include:
>
> Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Thanks all!
next prev parent reply other threads:[~2025-11-06 11:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 15:25 [PATCH] sched: Optimize core cookie matching check Fernand Sieber
2025-11-05 16:34 ` K Prateek Nayak
2025-11-06 11:09 ` Peter Zijlstra [this message]
2025-11-06 10:27 ` Madadi Vineeth Reddy
2025-11-11 11:37 ` [tip: sched/core] sched/core: " tip-bot2 for Fernand Sieber
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=20251106110943.GP3245006@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=dwmw@amazon.co.uk \
--cc=jschoenh@amazon.de \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyuxua@amazon.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=sieberf@amazon.com \
--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