From: Peter Zijlstra <peterz@infradead.org>
To: hev <r@hev.cc>
Cc: Will Deacon <will@kernel.org>, Boqun Feng <boqun.feng@gmail.com>,
linux-kernel@vger.kernel.org, stern@rowland.harvard.edu,
parri.andrea@gmail.com, npiggin@gmail.com, dhowells@redhat.com,
j.alglave@ucl.ac.uk, luc.maranget@inria.fr, paulmck@kernel.org,
akiyks@gmail.com, dlustig@nvidia.com, joel@joelfernandes.org,
huacai chen <chenhuacai@gmail.com>, Guo Ren <guoren@kernel.org>,
geert@linux-m68k.org, Huacai Chen <chenhuacai@loongson.cn>,
Ingo Molnar <mingo@redhat.com>, Arnd Bergmann <arnd@arndb.de>,
wangrui <wangrui@loongson.cn>, lixuefeng <lixuefeng@loongson.cn>,
Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: Re: [PATCH] Documentation/atomic_t: Document forward progress expectations
Date: Thu, 29 Jul 2021 22:03:29 +0200 [thread overview]
Message-ID: <20210729200329.GC82583@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <CAHirt9hsN9cy16TKSn7Bb+HG5M52FR1Ct8=7xDiM14+5K_S8eg@mail.gmail.com>
On Fri, Jul 30, 2021 at 12:24:14AM +0800, hev wrote:
> We may need new APIs to help LL/SC to implement atomic operations, but
> this is obviously incompatible with native CAS. and many and many
> common functions are CAS friendly. Let's more functions that implement
> atomic semantics can be overridden by architecture may be a way. ;-)
>
> In the above example, the correct implementation on LL/SC may be like:
>
> do {
> old = LL(&v);
> new = func(old, &skip);
> if (skip) {
> break;
> }
> } while (!SC(&v, new);
>
> However, the success of SC may be affected by the inconstant
> complexity of func. :-(
Right, so you can't really do that because the architecture constraints
on what is allowed between LL and SC vary. Also, you couldn't compile
that code on a CAS architecture because you simply cannot implement the
LL/SC semantics using CAS.
One thing that can be done is having the compiler transform a CAS loop
into a LL/SC loop, and clang actually tries that, but GCC is absolutely
failing there:
https://godbolt.org/z/1MK6ceq46
(note; clang only does this for arm64, and the code it does generate is
pretty horrific)
And this is another thing where C11 is utter crap; because as far as
it's concerned this is equivalent, while obviously it is not, per the
parent argument.
Also, ideally there would be a variant where you'd mandate the
forward progress or a compiler error when not possible.
next prev parent reply other threads:[~2021-07-29 20:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-29 14:40 [PATCH] Documentation/atomic_t: Document forward progress expectations Peter Zijlstra
2021-07-29 16:24 ` hev
2021-07-29 20:03 ` Peter Zijlstra [this message]
2021-08-05 9:40 ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
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=20210729200329.GC82583@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akiyks@gmail.com \
--cc=arnd@arndb.de \
--cc=boqun.feng@gmail.com \
--cc=chenhuacai@gmail.com \
--cc=chenhuacai@loongson.cn \
--cc=dhowells@redhat.com \
--cc=dlustig@nvidia.com \
--cc=geert@linux-m68k.org \
--cc=guoren@kernel.org \
--cc=j.alglave@ucl.ac.uk \
--cc=jiaxun.yang@flygoat.com \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=luc.maranget@inria.fr \
--cc=mingo@redhat.com \
--cc=npiggin@gmail.com \
--cc=parri.andrea@gmail.com \
--cc=paulmck@kernel.org \
--cc=r@hev.cc \
--cc=stern@rowland.harvard.edu \
--cc=wangrui@loongson.cn \
--cc=will@kernel.org \
/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