From: "Paul E. McKenney" <paulmck@kernel.org>
To: szyhb810501.student@sina.com
Cc: stern <stern@rowland.harvard.edu>,
"parri.andrea" <parri.andrea@gmail.com>, will <will@kernel.org>,
peterz <peterz@infradead.org>,
"boqun.feng" <boqun.feng@gmail.com>, npiggin <npiggin@gmail.com>,
dhowells <dhowells@redhat.com>, "j.alglave" <j.alglave@ucl.ac.uk>,
"luc.maranget" <luc.maranget@inria.fr>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Documentation/memory-barriers.txt: Is "stores are not speculated" correct?
Date: Sun, 25 Apr 2021 20:50:43 -0700 [thread overview]
Message-ID: <20210426035043.GW975577@paulmck-ThinkPad-P17-Gen-1> (raw)
In-Reply-To: <20210426022309.2333D4640475@webmail.sinamail.sina.com.cn>
On Mon, Apr 26, 2021 at 10:23:09AM +0800, szyhb810501.student@sina.com wrote:
>
> Hello everyone, I have a question."Documentation/memory-barriers.txt"
> says:However, stores are not speculated. This means that ordering -is-
> providedfor load-store control dependencies, as in the following example:
q = READ_ONCE(a);
if (q) {
WRITE_ONCE(b, 1);
}
> Is "stores are not speculated" correct? I
> think store instructions can be executed speculatively.
> "https://stackoverflow.com/questions/64141366/can-a-speculatively-executed-cpu-branch-contain-opcodes-that-access-ram"
> says:Store instructions can also be executed speculatively thanks to the
> store buffer. The actual execution of a store just writes the address and
> data into the store buffer.Commit to L1d cache happens some time after
> the store instruction retires from the ROB, i.e. when the store is known
> to be non-speculative, the associated store-buffer entry "graduates"
> and becomes eligible to commit to cache and become globally visible.
From the viewpoint of other CPUs, the store hasn't really happened
until it finds its way into a cacheline. As you yourself note above,
if the store is still in the store buffer, it might be squashed when
speculation fails.
So Documentation/memory-barriers.txt and that stackoverflow entry are
not really in conflict, but are instead using words a bit differently
from each other. The stackoverflow entry is considering a store to have
in some sense happened during a time when it might later be squashed.
In contrast, the Documentation/memory-barriers.txt document only considers
a store to have completed once it is visible outside of the CPU executing
that store.
So from a stackoverflow viewpoint, stores can be speculated, but until
they are finalized, they must be hidden from other CPUs.
From a Documentation/memory-barriers.txt viewpoint, stores don't complete
until they update their cachelines, and stores may not be speculated.
Some of the actions that lead up to the completion of a store may be
speculated, but not the completion of the store itself.
Different words, but same effect. Welcome to our world! ;-)
Thanx, Paul
next parent reply other threads:[~2021-04-26 4:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210426022309.2333D4640475@webmail.sinamail.sina.com.cn>
2021-04-26 3:50 ` Paul E. McKenney [this message]
2021-04-26 9:30 ` Documentation/memory-barriers.txt: Is "stores are not speculated" correct? Luc Maranget
2021-04-26 15:13 ` Randy Dunlap
2021-04-26 15:16 ` maranget
2021-04-26 15:34 ` Paul E. McKenney
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=20210426035043.GW975577@paulmck-ThinkPad-P17-Gen-1 \
--to=paulmck@kernel.org \
--cc=boqun.feng@gmail.com \
--cc=dhowells@redhat.com \
--cc=j.alglave@ucl.ac.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=luc.maranget@inria.fr \
--cc=npiggin@gmail.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=stern@rowland.harvard.edu \
--cc=szyhb810501.student@sina.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).