Re: [RFC PATCH 3/6] sched/fair: SMT sibling exclusion after successful push

From: Peter Zijlstra

Date: Wed Oct 21 2026 - 08:55:45 EST


On Tue, Oct 20, 2026 at 04:37:43PM +0800, Li kunyu wrote:

> @@ -13377,7 +13379,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,
> struct sched_domain __maybe_unused *sd_tmp;
> unsigned int busiest_nr = 0;
> int __maybe_unused dst_llc;
> - int i;
> + int i, smt_cpu, dst_cpu = env->dst_cpu;
> +
> + if (sched_feat(SMT_BUDDY_ASSIST) && env->is_smt_move_task) {
> + /*
> + * Remove the SMT sibling CPU from the mask to avoid the
> + * extremely rare case of pulling tasks from it.

Your comment seems to think the SMT mask is only ever 2 cpus, we have a
ton of architectures where this is not true.

> + */
> + for_each_cpu(smt_cpu, cpu_smt_mask(dst_cpu)) {
> + if (smt_cpu == dst_cpu)
> + continue;
> +
> + cpumask_clear_cpu(smt_cpu, env->cpus);
> + }

This is terrifyingly horrible. You're using a loop and atomic bit clear
to clear bits in a local cpumask.

cpumask_andnot(env->cpus, env->cpus, cpu_smt_mask(dst_cpu));
__cpumask_set_cpu(dst_cpu, env->cpus);