Re: [RFC PATCH v4 06/28] sched: Save the per LLC utilization for better cache aware scheduling

From: Peter Zijlstra

Date: Mon Sep 29 2025 - 10:09:52 EST


On Sat, Aug 09, 2025 at 01:02:54PM +0800, Chen Yu wrote:

> +#ifdef CONFIG_SCHED_CACHE
> +/*
> + * Save this sched group's statistic for later use:
> + * The task wakeup and load balance can make better
> + * decision based on these statistics.
> + */
> +static void update_sg_if_llc(struct lb_env *env, struct sg_lb_stats *sgs,
> + struct sched_group *group)
> +{
> + /* Find the sched domain that spans this group. */
> + struct sched_domain *sd = env->sd->child;
> + struct sched_domain_shared *sd_share;
> +
> + if (!sched_feat(SCHED_CACHE) || env->idle == CPU_NEWLY_IDLE)
> + return;
> +
> + /* only care the sched domain that spans 1 LLC */
> + if (!sd || !(sd->flags & SD_SHARE_LLC) ||
> + !sd->parent || (sd->parent->flags & SD_SHARE_LLC))
> + return;

Did you want to write:

if (sd != per_cpu(sd_llc))
return;

Or something?

> + sd_share = rcu_dereference(per_cpu(sd_llc_shared,
> + cpumask_first(sched_group_span(group))));
> + if (!sd_share)
> + return;
> +
> + if (likely(READ_ONCE(sd_share->util_avg) != sgs->group_util))
> + WRITE_ONCE(sd_share->util_avg, sgs->group_util);

If you expect it to be different, does that whole load and compare still
matter?

> +}