[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240626092841.GC31592@noisy.programming.kicks-ass.net>
Date: Wed, 26 Jun 2024 11:28:41 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Uros Bizjak <ubizjak@...il.com>, kernel test robot <lkp@...el.com>,
oe-kbuild-all@...ts.linux.dev, linux-kernel@...r.kernel.org,
Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>
Subject: Re: arch/x86/include/asm/cmpxchg_32.h:149:9: error: inline assembly
requires more registers than available
On Tue, Jun 25, 2024 at 11:31:05AM -0700, Linus Torvalds wrote:
> The thing is, when cmpxchg doesn't fail, then oldp should already be "old", no?
Correct.
> I mean, by the very definition, atomic_try_cmpxchg() can *not* be
> successful if the new value didn't match the old one.
>
> I mean, just look at the very doc you point to - the "definition" is
>
> bool atomic_try_cmpxchg(atomic_t *ptr, int *oldp, int new)
> {
> int ret, old = *oldp;
> ret = atomic_cmpxchg(ptr, old, new);
> if (ret != old)
> *oldp = ret;
> return ret == old;
> }
>
> iow, it only returns success of "ret == old", and "old" by definition
> is "the contents of oldp".
>
> (Here "oldp" is a local variable, not something that can be changing).
>
> So I *think* the whole
>
> if (ret != old)
> *oldp = ret;
>
> is actually counter-productive, and could/should be just that simpler
> unconditional *oldp = ret,
IIRC the reason I added that conditional is because at the time the GCC
compiler I tried it on generated slightly better code like this.
ISTR it emitting some superfluous assignments with the unconditional
store variant. Typically what seemed to happen is that since the
cmpxchg() user would have a loop termination on ret == old, it was able
to recognise it only needed that assignment in the failure case. Without
the condition on it would also do that assignment in the success case.
But yeah, otherwise it doesn't matter.
Powered by blists - more mailing lists