public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "peter at cordes dot ca" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/104688] gcc and libatomic can use SSE for 128-bit atomic loads on Intel and AMD CPUs with AVX
Date: Mon, 28 Nov 2022 18:35:22 +0000	[thread overview]
Message-ID: <bug-104688-4-ZGN5z5LBm3@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104688-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688

Peter Cordes <peter at cordes dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter at cordes dot ca

--- Comment #23 from Peter Cordes <peter at cordes dot ca> ---
(In reply to Xi Ruoyao from comment #20)
> "On Zhaoxin CPUs with AVX, the VMOVDQA instruction is atomic if the accessed
> memory is Write Back, but it's not guaranteed for other memory types."

VMOVDQA is still fine, I think WB is the only memory type that's relevant for
atomics, at least on the mainstream OSes we compile for.  It's not normally
possible for user-space to allocate memory of other types.  Kernels normally
use WB memory for their shared data, too.

You're correct that WT and WP are the other two cacheable memory types, and
Zhaoxin's statement doesn't explicitly guarantee atomicity for those, unlike
Intel and AMD.

But at least on Linux, I don't think there's a way for user-space to even ask
for a page of WT or WP memory (or UC or WC).  Only WB memory is easily
available without hacking the kernel.  As far as I know, this is true on other
existing OSes.

WT = write-through: read caching, no write-allocate.  Write hits update the
line and memory.
WP = write-protect: read caching, no write-allocate.  Writes go around the
cache, evicting even on hit.
(https://stackoverflow.com/questions/65953033/whats-the-usecase-of-write-protected-pat-memory-type
quotes the Intel definitions.)

Until recently, the main work on formalizing the x86 TSO memory model had only
looked at WB memory.
A 2022 paper looked at WT, UC, and WC memory types:
https://dl.acm.org/doi/pdf/10.1145/3498683 - Extending Intel-x86 Consistency
and Persistency
Formalising the Semantics of Intel-x86 Memory Types and Non-temporal Stores
(The intro part describing memory types is quite readable, in plain English not
full of formal symbols.  They only mention WP once, but tested some litmus
tests with readers and writers using any combination of the other memory
types.)


Some commenters on my answer on when WT is ever used or useful confirmed that
mainstream OSes don't give easy access to it.
https://stackoverflow.com/questions/61129142/when-use-write-through-cache-policy-for-pages/61130838#61130838
* Linux has never merged a patch to let user-space allocate WT pages.
* The Windows kernel reportedly doesn't have a mechanism to keep track of pages
that should be WT or WP, so you won't find any.

I don't know about *BSD making it plausible for user-space to point an _Atomic
int * at a page of WT or WP memory.  I'd guess not.

I don't know if there's anywhere we can document that _Atomic objects need to
be in memory that's allocated in a "normal" way.  Probably hard to word without
accidentally disallowing something that's fine.

  parent reply	other threads:[~2022-11-28 18:35 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25 14:22 [Bug target/104688] New: gcc and libatomic can use SSE for 128-bit atomic loads on Intel " xry111 at mengyan1223 dot wang
2022-02-25 14:30 ` [Bug target/104688] " jakub at gcc dot gnu.org
2022-02-25 14:33 ` xry111 at mengyan1223 dot wang
2022-02-25 14:34 ` fw at gcc dot gnu.org
2022-02-25 16:36 ` jakub at gcc dot gnu.org
2022-02-25 16:37 ` jakub at gcc dot gnu.org
2022-03-17 17:50 ` cvs-commit at gcc dot gnu.org
2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
2022-04-05 12:30 ` xry111 at mengyan1223 dot wang
2022-04-05 12:35 ` jakub at gcc dot gnu.org
2022-11-14  3:31 ` Ganesh.Gopalasubramanian at amd dot com
2022-11-14  4:58 ` sam at gentoo dot org
2022-11-14  5:10 ` [Bug target/104688] gcc and libatomic can use SSE for 128-bit atomic loads on Intel and AMD " xry111 at gcc dot gnu.org
2022-11-14  7:54 ` jakub at gcc dot gnu.org
2022-11-14  9:24 ` amonakov at gcc dot gnu.org
2022-11-14  9:29 ` jakub at gcc dot gnu.org
2022-11-14  9:52 ` amonakov at gcc dot gnu.org
2022-11-15  7:18 ` cvs-commit at gcc dot gnu.org
2022-11-15  7:20 ` jakub at gcc dot gnu.org
2022-11-20 23:11 ` cvs-commit at gcc dot gnu.org
2022-11-21  9:23 ` cvs-commit at gcc dot gnu.org
2022-11-23  9:18 ` xry111 at gcc dot gnu.org
2022-11-23  9:51 ` jakub at gcc dot gnu.org
2022-11-23 10:23 ` xry111 at gcc dot gnu.org
2022-11-28 18:35 ` peter at cordes dot ca [this message]
2022-11-28 18:46 ` amonakov at gcc dot gnu.org
2022-11-28 19:03 ` peter at cordes dot ca
2022-11-28 20:11 ` amonakov at gcc dot gnu.org
2022-11-28 20:47 ` peter at cordes dot ca
2022-11-29  8:11 ` fw at gcc dot gnu.org
2023-02-15 12:27 ` segher at gcc dot gnu.org
2023-02-15 12:46 ` fw at gcc dot gnu.org
2023-02-15 16:03 ` segher at gcc dot gnu.org
2023-02-15 16:07 ` pinskia at gcc dot gnu.org
2023-02-15 16:09 ` segher at gcc dot gnu.org

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=bug-104688-4-ZGN5z5LBm3@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).