Re: [RFC][PATCH tip/sched/core] sched/rt: Simplify the IPI rt balancing logic

From: Peter Zijlstra
Date: Mon Apr 24 2017 - 09:51:07 EST


On Mon, Apr 24, 2017 at 09:28:36AM -0400, Steven Rostedt wrote:

> > static inline bool rto_start_trylock(atomic_t *v)
> > {
> > int zero = 0;
> > return atomic_try_cmpxchg(v, &zero, 1);
>
> To keep the same semantics of spin_trylock(), should we:

try_cmpxchg returns the success of the "cmp" part. So if the above
returns true, the "cmp" part was a success and we did the "xchg" part,
so we now own the lock.

That's right, no?

> return !atomic_cmpxchg(v, &zero, 1);
>
> as the old value of zero means we got it.

The same, but results in an extra compare instruction to compare the
result, instead of using the one cmpxchg already did.

> BTW, I don't see any atomic_try_cmpxchg().

a9ebf306f52c ("locking/atomic: Introduce atomic_try_cmpxchg()")

Should be in tip someplace.