linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH][RFC] Implement arch primitives for busywait loops
Date: Fri, 16 Sep 2016 22:06:35 +1000	[thread overview]
Message-ID: <20160916220635.7e6fdbb7@roar.ozlabs.ibm.com> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DB00FF831@AcuExch.aculab.com>

On Fri, 16 Sep 2016 11:57:37 +0000
David Laight <David.Laight@ACULAB.COM> wrote:

> From: Nicholas Piggin
> > Sent: 16 September 2016 12:52
> > On Fri, 16 Sep 2016 11:30:58 +0000
> > David Laight <David.Laight@ACULAB.COM> wrote:
> >   
> > > From: Nicholas Piggin  
> > > > Sent: 16 September 2016 09:58
> > > > Implementing busy wait loops with cpu_relax() in callers poses
> > > > some difficulties for powerpc.
> > > >
> > > > First, we want to put our SMT thread into a low priority mode for the
> > > > duration of the loop, but then return to normal priority after exiting
> > > > the loop.  Dependong on the CPU design, 'HMT_low() ; HMT_medium();' as
> > > > cpu_relax() does may have HMT_medium take effect before HMT_low made
> > > > any (or much) difference.
> > > >
> > > > Second, it can be beneficial for some implementations to spin on the
> > > > exit condition with a statically predicted-not-taken branch (i.e.,
> > > > always predict the loop will exit).
> > > >
> > > > This is a quick RFC with a couple of users converted to see what
> > > > people think. I don't use a C branch with hints, because we don't want
> > > > the compiler moving the loop body out of line, which makes it a bit
> > > > messy unfortunately. If there's a better way to do it, I'm all ears.  
> > >
> > > I think it will still all go wrong if the conditional isn't trivial.
> > > In particular if the condition contains || or && it is likely to
> > > have a branch - which could invert the loop.  
> > 
> > I don't know that it will.
> > 
> > Yes, if we have exit condition that requires more branches in order to
> > be computed then we lose our nice property of never taking a branch
> > miss on loop exit. But we still avoid *this* branch miss, and still
> > prevent multiple iterations of the wait loop being speculatively
> > executed concurrently when there's no work to be done.
> > 
> > And C doesn't know about the loop, so it can't do any transformation
> > except to compute the final condition.
> > 
> > Or have I missed something?  
> 
> Try putting the code inside a conditional or at the bottom of a loop.
> gcc can replicate code to remove a branch.
> 
> So:
> 	for (;;) {
> 		a;
> 		if (b)
> 			c;
> 		d;
> 	}

That's not what this patch does though. The loop is purely asm. gcc has
no idea about it. Only thing gcc knows is to evaluate the condition and
put it in a register.

Thanks,
Nick

  reply	other threads:[~2016-09-16 12:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-16  8:57 [PATCH][RFC] Implement arch primitives for busywait loops Nicholas Piggin
2016-09-16 11:30 ` David Laight
2016-09-16 11:52   ` Nicholas Piggin
2016-09-16 11:57     ` David Laight
2016-09-16 12:06       ` Nicholas Piggin [this message]
2016-09-16 12:59         ` Nicholas Piggin
2016-09-19  5:05 ` Aneesh Kumar K.V
2016-09-19  7:45 ` Balbir Singh
2016-09-19  8:48   ` Nicholas Piggin
2016-09-20 11:19 ` Christian Borntraeger
2016-09-20 12:27   ` Nicholas Piggin
2016-09-20 12:35     ` Christian Borntraeger
2016-09-20 12:46       ` Nicholas Piggin

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=20160916220635.7e6fdbb7@roar.ozlabs.ibm.com \
    --to=npiggin@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=linux-arch@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.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).