Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched/core: Get this cpu once in ttwu_queue_cond()

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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
Link: https://patch.msgid.link/20260323193630.640311-3-sshegde@linux.ibm.com

authored by

Shrikanth Hegde and committed by
Peter Zijlstra
0e81fe79 76504bce

+4 -2
+4 -2
kernel/sched/core.c
··· 3842 3842 3843 3843 static inline bool ttwu_queue_cond(struct task_struct *p, int cpu) 3844 3844 { 3845 + int this_cpu = smp_processor_id(); 3846 + 3845 3847 /* See SCX_OPS_ALLOW_QUEUED_WAKEUP. */ 3846 3848 if (!scx_allow_ttwu_queue(p)) 3847 3849 return false; ··· 3868 3866 * If the CPU does not share cache, then queue the task on the 3869 3867 * remote rqs wakelist to avoid accessing remote data. 3870 3868 */ 3871 - if (!cpus_share_cache(smp_processor_id(), cpu)) 3869 + if (!cpus_share_cache(this_cpu, cpu)) 3872 3870 return true; 3873 3871 3874 - if (cpu == smp_processor_id()) 3872 + if (cpu == this_cpu) 3875 3873 return false; 3876 3874 3877 3875 /*