Re: [PATCH 1/7] sched/balancing: Switch the 'DEFINE_SPINLOCK(balancing)' spinlock into an 'atomic_t sched_balance_running' flag

From: Shrikanth Hegde
Date: Fri Mar 01 2024 - 10:36:04 EST




On 3/1/24 4:39 PM, Ingo Molnar wrote:
> The 'balancing' spinlock added in:

Hi Ingo.

>
> 08c183f31bdb ("[PATCH] sched: add option to serialize load balancing")
>


[...]

>
> need_serialize = sd->flags & SD_SERIALIZE;
> if (need_serialize) {
> - if (!spin_trylock(&balancing))
> + if (atomic_cmpxchg_acquire(&sched_balance_running, 0, 1))

Thinking from very little I know, I may be completely wrong.

Is it possible that arch_spin_trylock, which would be called from spin_trylock is
faster in some architectures? Maybe in contended case?

For example, in powerpc, queued_spin_trylock, uses more optimal ll/sc style access patterns
rather than cmpxchg.
https://lore.kernel.org/all/20221126095932.1234527-4-npiggin@xxxxxxxxx/

+nick


> goto out;
> }
>
> @@ -11729,7 +11742,7 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle)
> interval = get_sd_balance_interval(sd, busy);
> }
> if (need_serialize)
> - spin_unlock(&balancing);
> + atomic_set_release(&sched_balance_running, 0);
> out:
> if (time_after(next_balance, sd->last_balance + interval)) {
> next_balance = sd->last_balance + interval;