From: Michael Ellerman <patch-notifications@ellerman.id.au>
To: Nicholas Piggin <npiggin@gmail.com>, linuxppc-dev@lists.ozlabs.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: Re: [PATCH] powerpc/64: allow compiler to cache 'current'
Date: Thu, 22 Aug 2019 23:08:53 +1000 (AEST) [thread overview]
Message-ID: <46DlGY5J97z9sNy@ozlabs.org> (raw)
In-Reply-To: <20190612140317.24490-1-npiggin@gmail.com>
On Wed, 2019-06-12 at 14:03:17 UTC, Nicholas Piggin wrote:
> current may be cached by the compiler, so remove the volatile asm
> restriction. This results in better generated code, as well as being
> smaller and fewer dependent loads, it can avoid store-hit-load flushes
> like this one that shows up in irq_exit():
>
> preempt_count_sub(HARDIRQ_OFFSET);
> if (!in_interrupt() && ...)
>
> Which ends up as:
>
> ((struct thread_info *)current)->preempt_count -= HARDIRQ_OFFSET;
> if (((struct thread_info *)current)->preempt_count ...
>
> Evaluating current twice presently means it has to be loaded twice, and
> here gcc happens to pick a different register each time, then
> preempt_count is accessed via that base register:
>
> 1058: ld r10,2392(r13) <-- current
> 105c: lwz r9,0(r10) <-- preempt_count
> 1060: addis r9,r9,-1
> 1064: stw r9,0(r10) <-- preempt_count
> 1068: ld r9,2392(r13) <-- current
> 106c: lwz r9,0(r9) <-- preempt_count
> 1070: rlwinm. r9,r9,0,11,23
> 1074: bne 1090 <irq_exit+0x60>
>
> This can frustrate store-hit-load detection heuristics and cause
> flushes. Allowing the compiler to cache current in a reigster with this
> patch results in the same base register being used for all accesses,
> which is more likely to be detected as an alias:
>
> 1058: ld r31,2392(r13)
> ...
> 1070: lwz r9,0(r31)
> 1074: addis r9,r9,-1
> 1078: stw r9,0(r31)
> 107c: lwz r9,0(r31)
> 1080: rlwinm. r9,r9,0,11,23
> 1084: bne 10a0 <irq_exit+0x60>
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/e354d7dc81d0e81bea33165f381aff1eda45f5d9
cheers
prev parent reply other threads:[~2019-08-22 13:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-12 14:03 [PATCH] powerpc/64: allow compiler to cache 'current' Nicholas Piggin
2019-08-22 13:08 ` Michael Ellerman [this message]
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=46DlGY5J97z9sNy@ozlabs.org \
--to=patch-notifications@ellerman.id.au \
--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).