The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Uros Bizjak <ubizjak@gmail.com>,
	kernel test robot <lkp@intel.com>,
	oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>
Subject: Re: arch/x86/include/asm/cmpxchg_32.h:149:9: error: inline assembly requires more registers than available
Date: Wed, 26 Jun 2024 11:28:41 +0200	[thread overview]
Message-ID: <20240626092841.GC31592@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAHk-=wiWEgSo2Tb_bih7mnS27zAPL+RGg_7yX4qK1f710-j-Ng@mail.gmail.com>

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.

  parent reply	other threads:[~2024-06-26  9:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-23  2:01 arch/x86/include/asm/cmpxchg_32.h:149:9: error: inline assembly requires more registers than available kernel test robot
2024-06-23 10:14 ` Uros Bizjak
2024-06-23 15:42   ` Linus Torvalds
2024-06-23 17:42     ` Linus Torvalds
2024-06-23 17:43     ` Uros Bizjak
2024-06-23 17:48       ` Linus Torvalds
2024-06-23 18:07         ` Linus Torvalds
2024-06-24  7:36           ` Uros Bizjak
2024-06-24 13:59             ` Linus Torvalds
2024-06-24 14:17               ` Linus Torvalds
2024-06-24 15:42                 ` Uros Bizjak
2024-06-25 18:31                   ` Linus Torvalds
2024-06-26  1:09                     ` [PATCH] x86-32: fix cmpxchg8b_emu build error with clang Linus Torvalds
2024-06-26  7:39                       ` Uros Bizjak
2024-06-26  9:07                         ` Uros Bizjak
2024-06-26 15:11                         ` Linus Torvalds
2024-06-26  7:54                     ` arch/x86/include/asm/cmpxchg_32.h:149:9: error: inline assembly requires more registers than available Uros Bizjak
2024-06-26  9:28                     ` Peter Zijlstra [this message]
2024-06-26  9:33                       ` Uros Bizjak
2024-06-26  9:42                         ` Peter Zijlstra
2024-06-26 15:11                     ` [PATCH v2] x86-32: fix cmpxchg8b_emu build error with clang Linus Torvalds
2024-06-26 18:59                       ` Uros Bizjak
2024-06-30 23:12                         ` Linus Torvalds
2024-06-23 18:14         ` arch/x86/include/asm/cmpxchg_32.h:149:9: error: inline assembly requires more registers than available Uros Bizjak
2024-06-23 18:25           ` Linus Torvalds
2024-06-23 18:41             ` Uros Bizjak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240626092841.GC31592@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=mingo@kernel.org \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=torvalds@linux-foundation.org \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox