From: Linus Torvalds <torvalds@osdl.org>
To: David Howells <dhowells@redhat.com>
Cc: akpm@osdl.org, linux-arch@vger.kernel.org,
linux-kernel@vger.kernel.org, paulmck@us.ibm.com,
davem@redhat.com, linuxppc64-dev@ozlabs.org
Subject: Re: [PATCH] Document Linux's memory barriers [try #5]
Date: Thu, 23 Mar 2006 11:28:04 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0603231121110.26286@g5.osdl.org> (raw)
In-Reply-To: <895.1143138867@warthog.cambridge.redhat.com>
On Thu, 23 Mar 2006, David Howells wrote:
>
> > Some architectures have more expansive definition of data dependency,
> > including then- and else-clauses being data-dependent on the if-condition,
> > but this is probably too much detail.
>
> Linus calls that a "control dependency" and doesn't seem to think that's a
> problem as it's sorted out by branch prediction. What you said makes me
> wonder about conditional instructions (such as conditional move).
I'd put it the other way: a control dependency is not "sorted out" by
branch prediction, it is effectively _nullified_ by branch prediction.
Basically, control dependencies aren't dependencies at all. There is
absolutely _zero_ dependency between the following two loads:
if (load a)
load b;
because the "load b" can happen before the "load a" because of control
prediction.
So if you need a read barrier where there is a _control_ dependency in
between loading a and loading b, you need to make it a full "smp_rmb()".
It is _not_ sufficient to make this a "read_barrier_depends", because the
load of b really doesn't depend on the load of a at all.
So data dependencies that result in control dependencies aren't
dependencies at all. Not even if the address depends on the control
dependency.
So
int *address_of_b;
address_of_b = load(&a);
smp_read_barrier_depends();
b = load(address_of_b);
is correct, but
int *address_of_b = default_address_of_b;
if (load(&a))
address_of_b = another_address_of_b;
smp_read_barrier_depends();
b = load(address_of_b);
is NOT correct, because there is no data dependency on the load of b, just
a control dependency that the CPU may short-circuit with prediction, and
that second case thus needs a real smp_rmb().
And yes, if we ever hit a CPU that does actual data prediction, not just
control prediction, that will force smp_read_barrier_depends() to be the
same as smp_rmb() on such an architecture.
Linus
next prev parent reply other threads:[~2006-03-23 19:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060316231723.GB1323@us.ibm.com>
[not found] ` <16835.1141936162@warthog.cambridge.redhat.com>
[not found] ` <18351.1142432599@warthog.cambridge.redhat.com>
2006-03-23 18:34 ` [PATCH] Document Linux's memory barriers [try #5] David Howells
2006-03-23 19:28 ` Linus Torvalds [this message]
2006-03-23 22:26 ` 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=Pine.LNX.4.64.0603231121110.26286@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=akpm@osdl.org \
--cc=davem@redhat.com \
--cc=dhowells@redhat.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc64-dev@ozlabs.org \
--cc=paulmck@us.ibm.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;
as well as URLs for NNTP newsgroup(s).