Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-09 Thread Benjamin Herrenschmidt
On Fri, 2014-02-07 at 09:51 -0600, Kumar Gala wrote: > On Feb 7, 2014, at 3:02 AM, Torsten Duwe wrote: > > > On Thu, Feb 06, 2014 at 02:19:52PM -0600, Scott Wood wrote: > >> On Thu, 2014-02-06 at 18:37 +0100, Torsten Duwe wrote: > >>> On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-09 Thread Benjamin Herrenschmidt
On Fri, 2014-02-07 at 10:02 +0100, Torsten Duwe wrote: > > > > Can you pair lwarx with sthcx ? I couldn't immediately find the answer > > > > in the PowerISA doc. If so I think you can do better by being able to > > > > atomically load both tickets but only storing the head without affecting > > >

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-09 Thread Benjamin Herrenschmidt
On Thu, 2014-02-06 at 13:28 -0600, Tom Musta wrote: > My read is consistent with Torsten's ... this looks like a bad idea. > > Look at the RTL for sthcx. on page 692 (Power ISA V2.06) and you will > see this: > > if RESERVE then > if RESERVE_LENGTH = 2 then > ... > else > undefined_

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 06:08:45PM +0100, Torsten Duwe wrote: > > static inline unsigned int xadd(unsigned int *v, unsigned int i) > > { > > int t, ret; > > > > __asm__ __volatile__ ( > > "1: lwarx %0, 0, %4\n" > > " mr %1, %0\n" > > " add %0, %3, %0\n" > > " stwcx. %

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Torsten Duwe
On Fri, Feb 07, 2014 at 04:18:47PM +0100, Peter Zijlstra wrote: > On Fri, Feb 07, 2014 at 01:28:37PM +0100, Peter Zijlstra wrote: > > Anyway, you can do a version with lwarx/stwcx if you're looking get rid > > of lharx. > > the below seems to compile into relatively ok asm. It can be done better >

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 09:51:16AM -0600, Kumar Gala wrote: > > On Feb 7, 2014, at 3:02 AM, Torsten Duwe wrote: > > > On Thu, Feb 06, 2014 at 02:19:52PM -0600, Scott Wood wrote: > >> On Thu, 2014-02-06 at 18:37 +0100, Torsten Duwe wrote: > >>> On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijl

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Kumar Gala
On Feb 7, 2014, at 3:02 AM, Torsten Duwe wrote: > On Thu, Feb 06, 2014 at 02:19:52PM -0600, Scott Wood wrote: >> On Thu, 2014-02-06 at 18:37 +0100, Torsten Duwe wrote: >>> On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote: >> Can you pair lwarx with sthcx ? I couldn't immediat

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 04:18:47PM +0100, Peter Zijlstra wrote: > void ticket_lock(tickets_t *lock) > { > tickets_t t; > > /* >* Because @head is MSB, the direct increment wrap doesn't disturb >* @tail. >*/ > t.pair = xadd(&lock->pair, 1<<16); > > i

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 01:28:37PM +0100, Peter Zijlstra wrote: > Anyway, you can do a version with lwarx/stwcx if you're looking get rid > of lharx. the below seems to compile into relatively ok asm. It can be done better if you write the entire thing by hand though. --- typedef unsigned short

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 12:49:49PM +0100, Torsten Duwe wrote: > On Fri, Feb 07, 2014 at 11:45:30AM +0100, Peter Zijlstra wrote: > > > > That might need to be lhz too, I'm confused on all the load variants. > > ;-) > > > > unlock: > > > lhz %0, 0, &tail > > > addic %0, %0, 1 > > No car

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Torsten Duwe
On Fri, Feb 07, 2014 at 11:45:30AM +0100, Peter Zijlstra wrote: > > That might need to be lhz too, I'm confused on all the load variants. ;-) > > unlock: > > lhz %0, 0, &tail > > addic %0, %0, 1 No carry with this one, I'd say. Besides, unlock increments the head. > > lwsync

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 11:31:39AM +0100, Peter Zijlstra wrote: > Anyway, what might work is something like (please forgive my ppc asm, I > can barely read the thing, I've never before attempted writing it): > > lock: > 1:lharx %0, 0, &head > mov %1, %0 > addic %0, %0, 1 >

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
> So if you have ll/sc on the whole word concurrent with the half-word > store, you can loose the half-word store like: > > lwarx &tickets > ... sth &tail > stwcd &tickets > > > The stwcd will over-write the tail store. Oh wait, that's stupid, it will invalidate the lock a

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Peter Zijlstra
On Fri, Feb 07, 2014 at 10:02:48AM +0100, Torsten Duwe wrote: > On Thu, Feb 06, 2014 at 02:19:52PM -0600, Scott Wood wrote: > > On Thu, 2014-02-06 at 18:37 +0100, Torsten Duwe wrote: > > > On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote: > > > > > > Can you pair lwarx with sthcx ? I

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Torsten Duwe
On Thu, Feb 06, 2014 at 02:19:52PM -0600, Scott Wood wrote: > On Thu, 2014-02-06 at 18:37 +0100, Torsten Duwe wrote: > > On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote: > > > > Can you pair lwarx with sthcx ? I couldn't immediately find the answer > > > in the PowerISA doc. If so I

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-07 Thread Torsten Duwe
On Thu, Feb 06, 2014 at 07:08:26PM +0100, Peter Zijlstra wrote: > On Thu, Feb 06, 2014 at 06:37:27PM +0100, Torsten Duwe wrote: > > I must admit that I haven't tested the patch on non-pseries ppc64 nor on > > ppc32. Only ppc64 has the ldarx and I tried to atomically replace the > > holder along wi

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-06 Thread Scott Wood
On Thu, 2014-02-06 at 18:37 +0100, Torsten Duwe wrote: > On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote: > > On Thu, Feb 06, 2014 at 11:37:37AM +0100, Torsten Duwe wrote: > > > x86 has them, MIPS has them, ARM has them, even ia64 has them: > > > ticket locks. They reduce memory bus

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-06 Thread Tom Musta
On 2/6/2014 12:08 PM, Peter Zijlstra wrote: >>> Can you pair lwarx with sthcx ? I couldn't immediately find the answer >>> > > in the PowerISA doc. If so I think you can do better by being able to >>> > > atomically load both tickets but only storing the head without affecting >>> > > the tail. >>

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-06 Thread Peter Zijlstra
On Thu, Feb 06, 2014 at 06:37:27PM +0100, Torsten Duwe wrote: > On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote: > > On Thu, Feb 06, 2014 at 11:37:37AM +0100, Torsten Duwe wrote: > > > x86 has them, MIPS has them, ARM has them, even ia64 has them: > > > ticket locks. They reduce memo

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-06 Thread Torsten Duwe
On Thu, Feb 06, 2014 at 05:38:37PM +0100, Peter Zijlstra wrote: > On Thu, Feb 06, 2014 at 11:37:37AM +0100, Torsten Duwe wrote: > > x86 has them, MIPS has them, ARM has them, even ia64 has them: > > ticket locks. They reduce memory bus and cache pressure especially > > for contended spinlocks, incr

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-06 Thread Peter Zijlstra
On Thu, Feb 06, 2014 at 11:37:37AM +0100, Torsten Duwe wrote: > x86 has them, MIPS has them, ARM has them, even ia64 has them: > ticket locks. They reduce memory bus and cache pressure especially > for contended spinlocks, increasing performance. > > This patch is a port of the x86 spin locks, mos

Re: [PATCH] Convert powerpc simple spinlocks into ticket locks

2014-02-06 Thread Benjamin Herrenschmidt
On Thu, 2014-02-06 at 11:37 +0100, Torsten Duwe wrote: > x86 has them, MIPS has them, ARM has them, even ia64 has them: > ticket locks. They reduce memory bus and cache pressure especially > for contended spinlocks, increasing performance. > > This patch is a port of the x86 spin locks, mostly wri