public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman•id.au>
To: Cyril Bur <cyrilbur@gmail•com>
Cc: mikey@neuling•org, anton@samba•org, linuxppc-dev@ozlabs•org
Subject: Re: [PATCH 5/8] powerpc: Restore FPU/VEC/VSX if previously used
Date: Mon, 23 Nov 2015 10:07:13 +1100	[thread overview]
Message-ID: <1448233633.15853.1.camel@ellerman.id.au> (raw)
In-Reply-To: <20151123091818.576d92af@camb691>

On Mon, 2015-11-23 at 09:18 +1100, Cyril Bur wrote:
> On Fri, 20 Nov 2015 22:01:04 +1100
> Michael Ellerman <mpe@ellerman•id.au> wrote:
> > On Wed, 2015-11-18 at 14:26 +1100, Cyril Bur wrote:
> > > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> > > index c8b4225..46e9869 100644
> > > --- a/arch/powerpc/kernel/entry_64.S
> > > +++ b/arch/powerpc/kernel/entry_64.S
> > > @@ -210,7 +210,54 @@ system_call:			/* label this so stack traces look sane */
> > >  	li	r11,-MAX_ERRNO
> > >  	andi.	r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
> > >  	bne-	syscall_exit_work
> > > -	cmpld	r3,r11
> > > +
> > > +	/*
> > > +	 * This is an assembly version of checks performed in restore_math()
> > > +	 * to avoid calling C unless absolutely necessary.
> > > +	 * Note: In order to simplify the assembly, if the FP or VEC registers
> > > +	 * are hot (and therefore restore_math() isn't called) the
> > > +	 * LOAD_{FP,VEC} thread counter doesn't get incremented.
> > > +	 * This is likely the best thing to do anyway because hot regs indicate
> > > +	 * that the workload is doing a lot of syscalls that can be handled
> > > +	 * quickly and without the need to touch FP or VEC regs (by the kernel).
> > > +	 * a) If this workload is long running then this is exactly what the
> > > +	 * kernel should be doing.
> > > +	 * b) If this workload isn't long running then we'll soon fall back to
> > > +	 * calling into C and the counter will be incremented regularly again
> > > +	 * anyway.
> > > +	 */
> > > +	ld	r9,PACACURRENT(r13)
> > > +	andi.	r0,r8,MSR_FP
> > > +	addi	r9,r9,THREAD
> > > +	lbz	r5,THREAD_LOAD_FP(r9)
> > > +	/*
> > > +	 * Goto 2 if !r0 && r5
> > > +	 * The cmpb works because r5 can only have bits set in the lowest byte
> > > +	 * and r0 may or may not have bit 13 set (different byte) but will have
> > > +	 * a zero low byte therefore the low bytes must differ if r5 == true
> > > +	 * and the bit 13 byte must be the same if !r0
> > > +	 */
> > > +	cmpb	r7,r0,r5  
> > 
> > cmpb is new since Power6, which means it doesn't exist on Cell -> Program Check :)
> > 
> Oops, sorry.

That's fine, there's almost no way for you to know that from reading the
documentation.

> > I'm testing a patch using crandc, but I don't like it.
> > 
> > I'm not a big fan of the logic here, it's unpleasantly complicated. Did you
> > benchmark going to C to do the checks? Or I wonder if we could just check
> > THREAD_LOAD_FP || THREAD_LOAD_VEC and if either is set we go to restore_math().
> > 
> 
> I didn't benchmark going to C mostly because you wanted to avoid calling C
> unless necessary in that path. Based off the results I got benchmarking the
> this series I expect calling C will also be in the noise of removing the
> exception.

Yeah I figured it was probably me that said "avoid C at all costs". But I've
changed my mind ;)

> > Or on the other hand we check !MSR_FP && !MSR_VEC and if so we go to
> > restore_math()?
> 
> That seems like the best check to leave in the assembly if you want to avoid
> complicated assembly in there.

Cool. If you can benchmark that that'd be great, mmkay.

cheers

  reply	other threads:[~2015-11-22 23:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18  3:26 [PATCH 0/8] FP/VEC/VSX switching optimisations Cyril Bur
2015-11-18  3:26 ` [PATCH 1/8] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall Cyril Bur
2015-11-23  0:23   ` Michael Neuling
2015-11-23  0:58     ` Cyril Bur
2015-11-23  1:06       ` Michael Neuling
2015-11-18  3:26 ` [PATCH 2/8] selftests/powerpc: Test preservation of FPU and VMX regs across preemption Cyril Bur
2015-11-23  0:34   ` Michael Neuling
2015-11-18  3:26 ` [PATCH 3/8] selftests/powerpc: Test FPU and VMX regs in signal ucontext Cyril Bur
2015-11-19 11:36   ` [3/8] " Michael Ellerman
2015-11-23  1:04   ` [PATCH 3/8] " Michael Neuling
2015-11-18  3:26 ` [PATCH 4/8] powerpc: Explicitly disable math features when copying thread Cyril Bur
2015-11-23  1:08   ` Michael Neuling
2015-11-23  3:20     ` Cyril Bur
2015-11-18  3:26 ` [PATCH 5/8] powerpc: Restore FPU/VEC/VSX if previously used Cyril Bur
2015-11-20 11:01   ` Michael Ellerman
2015-11-22 22:18     ` Cyril Bur
2015-11-22 23:07       ` Michael Ellerman [this message]
2015-11-23  1:29   ` Michael Neuling
2015-11-18  3:26 ` [PATCH 6/8] powerpc: Add the ability to save FPU without giving it up Cyril Bur
2015-11-18  3:26 ` [PATCH 7/8] powerpc: Add the ability to save Altivec " Cyril Bur
2015-11-18  3:26 ` [PATCH 8/8] powerpc: Add the ability to save VSX " Cyril Bur
2015-11-18 14:51 ` [PATCH 0/8] FP/VEC/VSX switching optimisations David Laight
2015-11-18 23:01   ` Cyril Bur

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=1448233633.15853.1.camel@ellerman.id.au \
    --to=mpe@ellerman$(echo .)id.au \
    --cc=anton@samba$(echo .)org \
    --cc=cyrilbur@gmail$(echo .)com \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    --cc=mikey@neuling$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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