From: Balbir Singh <bsingharora@gmail.com>
To: Nicholas Piggin <npiggin@gmail.com>, linux-arch@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH][RFC] Implement arch primitives for busywait loops
Date: Mon, 19 Sep 2016 17:45:52 +1000 [thread overview]
Message-ID: <77737e9a-e8d7-0f2d-2303-8fdbaf45b8bb@gmail.com> (raw)
In-Reply-To: <20160916085736.7857-1-npiggin@gmail.com>
On 16/09/16 18:57, Nicholas Piggin wrote:
> 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).
>
IIUC, what you are proposing is that cpu_relax() be split such
that on entry we do HMT_low() and on exit do HMT_medium(). I think
that makes a lot of sense, in that it allows the required transition
time from low to medium
> 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 would not propose to switch all callers immediately, just some
> core synchronisation primitives.
>
> ---
> arch/powerpc/include/asm/processor.h | 22 ++++++++++++++++++++++
> include/asm-generic/barrier.h | 7 ++-----
> include/linux/bit_spinlock.h | 5 ++---
> include/linux/cgroup.h | 7 ++-----
> include/linux/seqlock.h | 10 ++++------
> 5 files changed, 32 insertions(+), 19 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
> index 68e3bf5..e10aee2 100644
> --- a/arch/powerpc/include/asm/processor.h
> +++ b/arch/powerpc/include/asm/processor.h
> @@ -402,6 +402,28 @@ static inline unsigned long __pack_fe01(unsigned int fpmode)
>
> #ifdef CONFIG_PPC64
> #define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
> +
> +#define spin_do \
How about cpu_relax_begin()?
> +do { \
> + HMT_low(); \
> + __asm__ __volatile__ ( "1010:");
> +
> +#define spin_while(cond) \
cpu_relax_while()
> + barrier(); \
> + __asm__ __volatile__ ( "cmpdi %0,0 \n\t" \
> + "beq- 1010b \n\t" \
> + : : "r" (cond)); \
> + HMT_medium(); \
> +} while (0)
> +
> +#define spin_until(cond) \
This is just spin_while(!cond) from an implementation perspective right?
cpu_relax_until()
> + barrier(); \
> + __asm__ __volatile__ ( "cmpdi %0,0 \n\t" \
> + "bne- 1010b \n\t" \
> + : : "r" (cond)); \
> + HMT_medium(); \
> +} while (0)
> +
Then add cpu_relax_end() that does HMT_medium()
Balbir Singh.
next prev parent reply other threads:[~2016-09-19 7:45 UTC|newest]
Thread overview: 16+ 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 11:57 ` David Laight
2016-09-16 12:06 ` Nicholas Piggin
2016-09-16 12:59 ` Nicholas Piggin
2016-09-19 5:05 ` Aneesh Kumar K.V
2016-09-19 5:05 ` Aneesh Kumar K.V
2016-09-19 7:45 ` Balbir Singh [this message]
2016-09-19 8:48 ` Nicholas Piggin
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=77737e9a-e8d7-0f2d-2303-8fdbaf45b8bb@gmail.com \
--to=bsingharora@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.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).