From: Boqun Feng <boqun.feng@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Jules Maselbas" <jmaselbas@kalray.eu>,
"Will Deacon" <will@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Arnd Bergmann" <arnd@arndb.de>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
"Alan Stern" <stern@rowland.harvard.edu>,
"Andrea Parri" <parri.andrea@gmail.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"David Howells" <dhowells@redhat.com>,
"Jade Alglave" <j.alglave@ucl.ac.uk>,
"Luc Maranget" <luc.maranget@inria.fr>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Akira Yokosawa" <akiyks@gmail.com>,
"Daniel Lustig" <dlustig@nvidia.com>,
"Joel Fernandes" <joel@joelfernandes.org>,
"Jonas Oberhauser" <jonas.oberhauser@huaweicloud.com>,
"Hernan Ponce de Leon" <hernan.poncedeleon@huaweicloud.com>,
"Paul Heidekrüger" <paul.heidekrueger@in.tum.de>,
"Marco Elver" <elver@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>
Subject: Re: [PATCH] locking/atomic: atomic: Use arch_atomic_{read,set} in generic atomic ops
Date: Fri, 27 Jan 2023 14:09:41 -0800 [thread overview]
Message-ID: <Y9RLpYGmzW1KPksE@boqun-archlinux> (raw)
In-Reply-To: <Y9Pg+aNM9f48SY5Z@hirez.programming.kicks-ass.net>
On Fri, Jan 27, 2023 at 03:34:33PM +0100, Peter Zijlstra wrote:
> > I also noticed that GCC has some builtin/extension to do such things,
> > __atomic_OP_fetch and __atomic_fetch_OP, but I do not know if this
> > can be used in the kernel.
>
> On a per-architecture basis only, the C/C++ memory model does not match
> the Linux Kernel memory model so using the compiler to generate the
> atomic ops is somewhat tricky and needs architecture audits.
Hijack this thread a little bit, but while we are at it, do you think it
makes sense that we have a config option that allows archs to
implement LKMM atomics via C11 (volatile) atomics? I know there are gaps
between two memory models, but the option is only for fallback/generic
implementation so we can put extra barriers/orderings to make things
guaranteed to work.
It'll be a code version of this document:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0124r7.html
(although I realise there may be a few mistakes in that doc since I
wasn't familiar with C11 memory model when I wrote part of the doc, but
these can be fixed)
Another reason I ask is that since Rust is coming, we need to provide
our LKMM atomics in Rust so that C code and Rust code can talk via same
atomic variables, since both sides need to use the same memory model.
My choices are:
1. Using FFI to call Linux atomic APIs: not inline therefore not
efficient.
2. Implementing Rust LKMM atomics in asm: much more work although
I'm OK if we have to do it.
3. Implementing Rust LKMM atomics with standard atomics (i.e. C/C++
atomics):
* Requires Rust has "volatile" atomics, which is WIP but
looks promising
* Less efficient compared to choice #2 but more efficient
compared to choice #1
Ideally, choice #2 is the best option for all architectures, however, if
we have the generic implementation based on choice #3, for some archs it
may be good enough.
Thoughts?
[Cc LKMM and Rust people]
Regards,
Boqun
next prev parent reply other threads:[~2023-01-27 22:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 17:33 [PATCH] locking/atomic: atomic: Use arch_atomic_{read,set} in generic atomic ops Jules Maselbas
2023-01-27 11:18 ` Peter Zijlstra
2023-01-27 13:49 ` Jules Maselbas
2023-01-27 14:34 ` Peter Zijlstra
2023-01-27 22:09 ` Boqun Feng [this message]
2023-01-30 12:23 ` Jonas Oberhauser
2023-01-30 18:38 ` Boqun Feng
2023-01-31 15:08 ` Jonas Oberhauser
2023-01-31 22:03 ` Boqun Feng
2023-02-01 10:51 ` Jonas Oberhauser
2023-01-30 18:15 ` Jules Maselbas
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=Y9RLpYGmzW1KPksE@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=akiyks@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=arnd@arndb.de \
--cc=bjorn3_gh@protonmail.com \
--cc=dhowells@redhat.com \
--cc=dlustig@nvidia.com \
--cc=elver@google.com \
--cc=gary@garyguo.net \
--cc=hernan.poncedeleon@huaweicloud.com \
--cc=j.alglave@ucl.ac.uk \
--cc=jmaselbas@kalray.eu \
--cc=joel@joelfernandes.org \
--cc=jonas.oberhauser@huaweicloud.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luc.maranget@inria.fr \
--cc=mark.rutland@arm.com \
--cc=npiggin@gmail.com \
--cc=ojeda@kernel.org \
--cc=parri.andrea@gmail.com \
--cc=paul.heidekrueger@in.tum.de \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=stern@rowland.harvard.edu \
--cc=wedsonaf@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).