Skip to contentSkip to conversation

sched/fair: factor out common sched_entity stats/task lookup

PATCH Shubhang Kaushik Prasanna Kumar 1 participant 1 message Dec 18, 2025

lore
Share & tools
lore
#0 lore raw

Hi Zhan,

The cleanup looks nice, but these helpers are sitting in some very critical hot paths. update_stats_wait_end_fair and update_stats_enqueue_sleeper_fair are hit on practically every task wakeup and context switch.

Even though it's not a functional refactoring, have you verified it with any benchmarks? I'm concerned that introducing the helper and passing around addresses of local variables (&stats, &p) might make it harder for the compiler to optimize compared to the original version.

I'm actually looking at a similar improvement in the PELT area, so I'd be curious to know if you've seen any measurable change in overhead.. To help the compiler, it might be better to have the helper return the stats pointer directly rather than passing &stats. This avoids the "double indirection" and makes it easier for the compiler to keep everything in registers. Also, for these hot paths, using __always_inline would be safer than just inline to avoid possible overhead.

Thanks,
Shubhang Kaushik