Re: [PATCH] sched/fair: factor out common sched_entity stats/task lookup
From: Shubhang Kaushik Prasanna Kumar
Date: Wed Dec 17 2025 - 14:23:02 EST
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, given how hot these paths are, using `__always_inline` would be safer than just `inline` to reduce function call overhead.
Thanks,
Shubhang Kaushik