Re: [RFC PATCH] sched: Add scx_cpuperf_target in sched_cpu_util()
From: Xuewen Yan
Date: Wed Mar 18 2026 - 22:39:17 EST
On Thu, Mar 19, 2026 at 10:24 AM Xuewen Yan <xuewen.yan94@xxxxxxxxx> wrote:
>
> On Thu, Mar 19, 2026 at 9:08 AM Tejun Heo <tj@xxxxxxxxxx> wrote:
> >
> > On Wed, Mar 18, 2026 at 01:47:18PM +0100, Peter Zijlstra wrote:
> > > On Wed, Mar 18, 2026 at 08:17:55PM +0800, Xuewen Yan wrote:
> > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > > > index bf948db905ed..20adb6fede2a 100644
> > > > --- a/kernel/sched/fair.c
> > > > +++ b/kernel/sched/fair.c
> > > > @@ -8198,7 +8198,12 @@ unsigned long effective_cpu_util(int cpu, unsigned long util_cfs,
> > > >
> > > > unsigned long sched_cpu_util(int cpu)
> > > > {
> > > > - return effective_cpu_util(cpu, cpu_util_cfs(cpu), NULL, NULL);
> > > > + unsigned long util = scx_cpuperf_target(cpu);
> > > > +
> > > > + if (!scx_switched_all())
> > > > + util += cpu_util_cfs(cpu);
> > > > +
> > > > + return effective_cpu_util(cpu, util, NULL, NULL);
> > > > }
> > >
> > > This puts the common case of no ext muck into the slow path of that
> > > static_branch.
> > >
> > > This wants to be something like:
> > >
> > > unsigned long sched_cpu_util(int cpu)
> > > {
> > > unsigned long util = cpu_util_cfs(cpu);
> > >
> > > if (scx_enabled()) {
> > > unsigned long scx_util = scx_cpuperf_target(cpu);
> > >
> > > if (!scx_switched_all())
> > > scx_util += util;
> > >
> > > util = scx_util;
> > > }
> > >
> > > return effective_cpu_util(cpu, util, NULL, NULL);
> > > }
> >
> > scx_switched_all() is an unlikely static branch just like scx_enabled() and
> > scx_cpuperf_target() has scx_enabled() in it too, so the difference for the
> > fair path between the two versions is two noop run-throughs vs. one. Either
> > way is fine but it is more code for likely no discernible gain.
>
> Agree, and for scx_switched_all(), there is no need to call cpu_util_cfs(),
> Maybe we could modify it as follows?
>
> --->
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index bf948db905ed..8f5d0c7e8ea2 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8198,7 +8198,18 @@ unsigned long effective_cpu_util(int cpu,
> unsigned long util_cfs,
>
> unsigned long sched_cpu_util(int cpu)
> {
> - return effective_cpu_util(cpu, cpu_util_cfs(cpu), NULL, NULL);
> + unsigned long util;
> +
> + if (scx_enabled()) {
> + unsigned long util = scx_cpuperf_target(cpu);
Sorry, that was a typo, this will be fixed in patch v2 if the proposed
fix is acceptable.
Thanks!
> +
> + if (!scx_switched_all())
> + util += cpu_util_cfs(cpu);
> + } else {
> + util = cpu_util_cfs(cpu);
> + }
> +
> + return effective_cpu_util(cpu, util, NULL, NULL);
> }
> ---
>
>
> Thanks!