mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: mingo@kernel.org, peterz@infradead.org,
	vincent.guittot@linaro.org, tglx@kernel.org, frederic@kernel.org,
	anna-maria@linutronix.de, linux-kernel@vger.kernel.org
Cc: sshegde@linux.ibm.com, kprateek.nayak@amd.com,
	juri.lelli@redhat.com, vschneid@redhat.com, rostedt@goodmis.org,
	dietmar.eggemann@arm.com, mkchauras@gmail.com
Subject: [PATCH 2/4] sched/core: get this cpu once in ttwu_queue_cond
Date: Tue, 24 Mar 2026 01:06:28 +0530	[thread overview]
Message-ID: <20260323193630.640311-3-sshegde@linux.ibm.com> (raw)
In-Reply-To: <20260323193630.640311-1-sshegde@linux.ibm.com>

Calling smp_processor_id() on:
- In CONFIG_DEBUG_PREEMPT=y, if preemption/irq is disabled, then it does
not print any warning.
- In CONFIG_DEBUG_PREEMPT=n, it doesn't do anything apart from getting
__smp_processor_id

So with both CONFIG_DEBUG_PREEMPT=y/n, in preemption disabled section
it is better to cache the value. It could save a few cycles. Though
tiny, repeated could add up to a small value.

ttwu_queue_cond is called with interrupt disabled. So preemption is
disabled. Hence cache the value once instead.

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 kernel/sched/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 49af425f6a73..14996c7a0a31 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3900,6 +3900,8 @@ bool cpus_share_resources(int this_cpu, int that_cpu)
 
 static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)
 {
+	int this_cpu = smp_processor_id();
+
 	/* See SCX_OPS_ALLOW_QUEUED_WAKEUP. */
 	if (!scx_allow_ttwu_queue(p))
 		return false;
@@ -3924,10 +3926,10 @@ static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)
 	 * If the CPU does not share cache, then queue the task on the
 	 * remote rqs wakelist to avoid accessing remote data.
 	 */
-	if (!cpus_share_cache(smp_processor_id(), cpu))
+	if (!cpus_share_cache(this_cpu, cpu))
 		return true;
 
-	if (cpu == smp_processor_id())
+	if (cpu == this_cpu)
 		return false;
 
 	/*
-- 
2.47.3


  parent reply	other threads:[~2026-03-23 19:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 19:36 [PATCH 0/4] Micro optimise to get this_cpu once Shrikanth Hegde
2026-03-23 19:36 ` [PATCH 1/4] sched/fair: get this cpu once in find_new_ilb Shrikanth Hegde
2026-03-24  9:09   ` [tip: sched/core] sched/fair: Get this cpu once in find_new_ilb() tip-bot2 for Shrikanth Hegde
2026-03-23 19:36 ` Shrikanth Hegde [this message]
2026-03-24  5:58   ` [PATCH 2/4] sched/core: get this cpu once in ttwu_queue_cond Mukesh Kumar Chaurasiya
2026-03-24  9:09   ` [tip: sched/core] sched/core: Get this cpu once in ttwu_queue_cond() tip-bot2 for Shrikanth Hegde
2026-03-23 19:36 ` [PATCH 3/4] smp: get this_cpu once in smp_call_function Shrikanth Hegde
2026-03-24  6:02   ` Mukesh Kumar Chaurasiya
2026-03-26 12:59   ` [tip: smp/core] smp: Get " tip-bot2 for Shrikanth Hegde
2026-03-23 19:36 ` [PATCH 4/4] timers: Get this_cpu once while clearing idle timer Shrikanth Hegde
2026-03-24  6:04   ` Mukesh Kumar Chaurasiya
2026-03-24 22:27   ` [tip: timers/core] timers: Get this_cpu once while clearing the idle state tip-bot2 for Shrikanth Hegde
2026-03-24  6:06 ` [PATCH 0/4] Micro optimise to get this_cpu once Mukesh Kumar Chaurasiya

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=20260323193630.640311-3-sshegde@linux.ibm.com \
    --to=sshegde@linux.ibm.com \
    --cc=anna-maria@linutronix.de \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mkchauras@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.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

Powered by JetHome