All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Artem Polyakov <artpol84@gmail.com>
Cc: perfbook@vger.kernel.org
Subject: Re: Memory barrier pairing question
Date: Sun, 22 Jul 2018 19:37:53 -0700	[thread overview]
Message-ID: <20180723023753.GJ12945@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAJ2Qj5qej+kBZxpy4cUbKVE3NJAnOSc9FZ5wur_rKVU_rnYhVw@mail.gmail.com>

On Sun, Jul 22, 2018 at 06:42:45PM -0700, Artem Polyakov wrote:
> Hello,
> I have a question about the following scenario (considering POWER arch):
> 
> initial { x = 0; y = 0; }
> 
> thread0 {
>     x = 1;
>     lwsync;
>     y = 1;
> }
> 
> thread1 {
>     a = y;
>     isync;
>     b = x;
> }
> 
> Because "isync" is not a memory barrier this example doesn't have
> read/write barrier pairing. However, if I understand correctly, lwsync will
> ensure that "x = 1" will become visible to thread1 before lwsync is done
> and before "y = 1" will become visible. So "isync" here can be sort of
> control dependency as it ensures that "a = y" will be performed before "b =
> x" and even will flush the pipeline according to POWER9 spec.
> 
> Can someone comment on this scenario and tell if I am right or where I am
> wrong.

I am not a Power hardware architect, but here is my understanding.

The isync waits until all the prior instructions "execute", but for
a limited definition of "execute".  One way to think of isync is as
an instruction that does not allow subsequent instructions to start
until it can be proven that execution really will reach the isync
instruction.

So given a load, how could it be that execution would be prevented
from reaching the isync instruction?  One possibility is a SEGV.
But once address translation completes successfully, SEGV cannot
happen.  So isync doesn't need to wait for the load to return an
actual value, but instead only for its execution to reach a point
where the hardware knows that a value will eventually be returned.

And that is why you need a compare and conditional branch before the
isync to ensure that the load has completed.  In that case, the
hardware cannot prove that execution will actually reach the isync
until the load completes, the compare sets the condition code,
and the branch condition is evaluated.  Therefore, anything after
the compare-branch-isync series cannot start executing until after
the load returns its value.

Make sense, or am I missing the point of your question?

							Thanx, Paul


  reply	other threads:[~2018-07-23  3:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23  1:42 Memory barrier pairing question Artem Polyakov
2018-07-23  2:37 ` Paul E. McKenney [this message]
2018-07-23  4:52   ` Artem Polyakov
2018-07-23 12:03     ` 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=20180723023753.GJ12945@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=artpol84@gmail.com \
    --cc=perfbook@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.