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/fair: Get this cpu once in find_new_ilb()

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 in loop could add up to a small value.

find_new_ilb is called in interrupt context. So preemption is disabled.
So Hoist the this_cpu out of loop

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>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://patch.msgid.link/20260323193630.640311-2-sshegde@linux.ibm.com

authored by

Shrikanth Hegde and committed by
Peter Zijlstra
76504bce e379dce8

+2 -2
+2 -2
kernel/sched/fair.c
··· 12614 12614 */ 12615 12615 static inline int find_new_ilb(void) 12616 12616 { 12617 + int this_cpu = smp_processor_id(); 12617 12618 const struct cpumask *hk_mask; 12618 12619 int ilb_cpu; 12619 12620 12620 12621 hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE); 12621 12622 12622 12623 for_each_cpu_and(ilb_cpu, nohz.idle_cpus_mask, hk_mask) { 12623 - 12624 - if (ilb_cpu == smp_processor_id()) 12624 + if (ilb_cpu == this_cpu) 12625 12625 continue; 12626 12626 12627 12627 if (idle_cpu(ilb_cpu))