Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-02-05 Thread Waiman Long
On 02/02/2014 04:03 AM, Ingo Molnar wrote: * Waiman Long wrote: How about making the selection of MCS or ticket queuing either user configurable or depending on the setting of NR_CPUS, NUMA, etc? No! There are lots of disadvantages to adding such CONFIG_NUMA Kconfig variants for locking prim

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-02-03 Thread Peter Zijlstra
On Sun, Feb 02, 2014 at 10:03:57AM +0100, Ingo Molnar wrote: > > * Waiman Long wrote: > > > How about making the selection of MCS or ticket queuing either user > > configurable or depending on the setting of NR_CPUS, NUMA, etc? > > No! > > There are lots of disadvantages to adding such CONFIG

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-02-02 Thread Ingo Molnar
* Waiman Long wrote: > How about making the selection of MCS or ticket queuing either user > configurable or depending on the setting of NR_CPUS, NUMA, etc? No! There are lots of disadvantages to adding such CONFIG_NUMA Kconfig variants for locking primitives: - an doubling of the test mat

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-02-01 Thread Paul E. McKenney
On Fri, Jan 31, 2014 at 11:17:29AM +0100, Peter Zijlstra wrote: > On Fri, Jan 31, 2014 at 05:03:48AM -0500, George Spelvin wrote: > > How about getting rid of that TICKET_MSB mess and doing something like: > > > > #define TICKET_MASK 0x > > > > static inline void ticket_spin_unlock(atomic_t *

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-02-01 Thread George Spelvin
Peter Zijlstra wrote: > On Fri, Jan 31, 2014 at 01:59:02PM -0500, Waiman Long wrote: >> Using a ticket lock instead will have the same scalability problem as the >> ticket spinlock as all the waiting threads will spin on the lock cacheline >> causing a lot of cache bouncing traffic. That is the rea

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Davidlohr Bueso
On Fri, 2014-01-31 at 16:09 -0500, Waiman Long wrote: > On 01/31/2014 03:14 PM, Peter Zijlstra wrote: > > On Fri, Jan 31, 2014 at 01:59:02PM -0500, Waiman Long wrote: > >> On 01/31/2014 04:26 AM, Peter Zijlstra wrote: > >>> On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: > The

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Waiman Long
On 01/31/2014 03:14 PM, Peter Zijlstra wrote: On Fri, Jan 31, 2014 at 01:59:02PM -0500, Waiman Long wrote: On 01/31/2014 04:26 AM, Peter Zijlstra wrote: On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: The below is still small and actually works. OK, so having actually worked t

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Peter Zijlstra
On Fri, Jan 31, 2014 at 01:59:02PM -0500, Waiman Long wrote: > On 01/31/2014 04:26 AM, Peter Zijlstra wrote: > >On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: > >>The below is still small and actually works. > >OK, so having actually worked through the thing; I realized we can > >a

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Peter Zijlstra
On Fri, Jan 31, 2014 at 01:59:02PM -0500, Waiman Long wrote: > On 01/31/2014 04:26 AM, Peter Zijlstra wrote: > >On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: > >>The below is still small and actually works. > >OK, so having actually worked through the thing; I realized we can > >a

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Waiman Long
On 01/31/2014 04:26 AM, Peter Zijlstra wrote: On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: The below is still small and actually works. OK, so having actually worked through the thing; I realized we can actually do a version without MCS lock and instead use a ticket lock for

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Peter Zijlstra
On Fri, Jan 31, 2014 at 11:17:29AM +0100, Peter Zijlstra wrote: > My main point was that we should seriously look at a ticket lock instead > of the MCS one, because while the MCS has better contention behaviour, > we shouldn't optimize locks for the worst contention. In fact, I should have just us

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Peter Zijlstra
On Fri, Jan 31, 2014 at 05:03:48AM -0500, George Spelvin wrote: > How about getting rid of that TICKET_MSB mess and doing something like: > > #define TICKET_MASK 0x > > static inline void ticket_spin_unlock(atomic_t *tickets) > { > u32 t = *tickets; > > smp_mb__before_atomic_in

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread George Spelvin
How about getting rid of that TICKET_MSB mess and doing something like: #define TICKET_MASK 0x static inline void ticket_spin_unlock(atomic_t *tickets) { u32 t = *tickets; smp_mb__before_atomic_inc(); /* Increment the low 16 bits without affecting the upper. */

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-31 Thread Peter Zijlstra
On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: > The below is still small and actually works. OK, so having actually worked through the thing; I realized we can actually do a version without MCS lock and instead use a ticket lock for the waitqueue. This is both smaller (back to 8

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Peter Zijlstra
On Thu, Jan 30, 2014 at 06:11:36PM +, Will Deacon wrote: > On Thu, Jan 30, 2014 at 06:05:33PM +, Peter Zijlstra wrote: > > On Thu, Jan 30, 2014 at 05:52:12PM +, Will Deacon wrote: > > > It would be nice if these were default implementations of the unlock, then > > > architectures just i

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Will Deacon
On Thu, Jan 30, 2014 at 06:05:33PM +, Peter Zijlstra wrote: > On Thu, Jan 30, 2014 at 05:52:12PM +, Will Deacon wrote: > > It would be nice if these were default implementations of the unlock, then > > architectures just implement atomic_sub_release how they like. > > Yes, I suppose that m

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Peter Zijlstra
On Thu, Jan 30, 2014 at 05:52:12PM +, Will Deacon wrote: > It would be nice if these were default implementations of the unlock, then > architectures just implement atomic_sub_release how they like. Yes, I suppose that makes sense. Last time I proposed the primitive nobody yelled at me, so I s

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Will Deacon
Hi Peter, On Thu, Jan 30, 2014 at 03:44:00PM +, Peter Zijlstra wrote: > Something like this would work for ARM and PPC, although I didn't do the > PPC variant of atomic_sub_release(). > > > --- a/arch/arm64/include/asm/atomic.h > +++ b/arch/arm64/include/asm/atomic.h > @@ -90,6 +90,21 @@ sta

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Peter Zijlstra
On Thu, Jan 30, 2014 at 10:50:41AM -0500, Waiman Long wrote: > One more thing, I often see line like > > #define queue_write_unlock queue_write_unlock > > So exactly what effect does this macro have? Makes sure the below doesn't emit another version. #ifndef queue_write_unlock /** * queue_writ

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Waiman Long
On 01/30/2014 10:43 AM, Waiman Long wrote: On 01/30/2014 10:17 AM, Peter Zijlstra wrote: On Thu, Jan 30, 2014 at 02:04:53PM +0100, Peter Zijlstra wrote: So I took out that ugly union and rewrote the code to be mostly atomic_*(), gcc generates acceptable code and its smaller too. 824

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Peter Zijlstra
On Thu, Jan 30, 2014 at 04:17:15PM +0100, Peter Zijlstra wrote: > --- /dev/null > +++ b/arch/x86/include/asm/qrwlock.h > @@ -0,0 +1,18 @@ > +#ifndef _ASM_X86_QRWLOCK_H > +#define _ASM_X86_QRWLOCK_H > + > +#include > + > +#if !defined(CONFIG_X86_OOSTORE) && !defined(CONFIG_X86_PPRO_FENCE) > +#defin

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Waiman Long
On 01/30/2014 10:17 AM, Peter Zijlstra wrote: On Thu, Jan 30, 2014 at 02:04:53PM +0100, Peter Zijlstra wrote: So I took out that ugly union and rewrote the code to be mostly atomic_*(), gcc generates acceptable code and its smaller too. 824 0 0 824 338 defconfig-build/

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Peter Zijlstra
On Thu, Jan 30, 2014 at 02:04:53PM +0100, Peter Zijlstra wrote: > > So I took out that ugly union and rewrote the code to be mostly > atomic_*(), gcc generates acceptable code and its smaller too. > > 824 0 0 824 338 > defconfig-build/kernel/locking/qrwlock.o > 776

Re: [PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-30 Thread Peter Zijlstra
So I took out that ugly union and rewrote the code to be mostly atomic_*(), gcc generates acceptable code and its smaller too. 824 0 0 824 338 defconfig-build/kernel/locking/qrwlock.o 776 0 0 776 308 defconfig-build/kernel/locking/qrwlock.o I don't

[PATCH v11 0/4] Introducing a queue read/write lock implementation

2014-01-23 Thread Waiman Long
v10->v11: - Insert appropriate smp_mb__{before,after}_atomic_* calls to make sure that the lock and unlock functions provide the proper memory barrier. v9->v10: - Eliminate the temporary smp_load_acquire()/smp_store_release() macros by merging v9 patch 4 into patch 1. - Include & remove