Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-19 Thread Waiman Long
On 02/19/2014 03:55 AM, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 07:58:49PM -0500, Waiman Long wrote: On 02/18/2014 04:37 PM, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: + /* +* At the head of the wait queue now +*/ + whil

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-19 Thread Waiman Long
On 02/19/2014 03:52 AM, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 07:50:13PM -0500, Waiman Long wrote: On 02/18/2014 04:34 PM, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: The #ifdef is harder to take away here. The point is that doing a 32-bit exchang

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-19 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 07:58:49PM -0500, Waiman Long wrote: > On 02/18/2014 04:37 PM, Peter Zijlstra wrote: > >On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: > + /* > + * At the head of the wait queue now > + */ > + while (true) { > + u32 qcode; > +

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-19 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 07:50:13PM -0500, Waiman Long wrote: > On 02/18/2014 04:34 PM, Peter Zijlstra wrote: > >On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: > >>The #ifdef is harder to take away here. The point is that doing a 32-bit > >>exchange may accidentally steal the lock with

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Waiman Long
On 02/18/2014 04:37 PM, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: + /* +* At the head of the wait queue now +*/ + while (true) { + u32 qcode; + int retval; + + retval = queue_get_lock_q

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Waiman Long
On 02/18/2014 04:34 PM, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: The #ifdef is harder to take away here. The point is that doing a 32-bit exchange may accidentally steal the lock with the additional code to handle that. Doing a 16-bit exchange, on the ot

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: > >>+ /* > >>+* At the head of the wait queue now > >>+*/ > >>+ while (true) { > >>+ u32 qcode; > >>+ int retval; > >>+ > >>+ retval = queue_get_lock_qcode(lock,&qcode, my_qcode); > >>+

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 02:39:31PM -0500, Waiman Long wrote: > The #ifdef is harder to take away here. The point is that doing a 32-bit > exchange may accidentally steal the lock with the additional code to handle > that. Doing a 16-bit exchange, on the other hand, will never steal the lock > and s

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Waiman Long
On 02/18/2014 02:39 AM, Peter Zijlstra wrote: On Mon, Feb 17, 2014 at 03:41:22PM -0500, Waiman Long wrote: +void queue_spin_lock_slowpath(struct qspinlock *lock, int qsval) +{ + unsigned int cpu_nr, qn_idx; + struct qnode *node, *next; + u32 prev_qcode, my_qcode; + +#ifdef queu

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Waiman Long
On 02/18/2014 02:33 AM, Peter Zijlstra wrote: On Mon, Feb 17, 2014 at 03:41:22PM -0500, Waiman Long wrote: +#define_QCODE(lock)(atomic_read(&(lock)->qlcode)>> _QCODE_OFFSET) +#define_QLOCK(lock)(atomic_read(&(lock)->qlcode)& _QSPINLOCK_LOCKED) +#define GET_QN_IDX(code)

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-18 Thread Waiman Long
On 02/18/2014 02:30 AM, Peter Zijlstra wrote: On Mon, Feb 17, 2014 at 03:41:22PM -0500, Waiman Long wrote: +/* + * The queue node structure + * + * This structure is essentially the same as the mcs_spinlock structure + * in mcs_spinlock.h file. This structure is retained for future extension + *

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-17 Thread Peter Zijlstra
On Mon, Feb 17, 2014 at 03:41:22PM -0500, Waiman Long wrote: > +void queue_spin_lock_slowpath(struct qspinlock *lock, int qsval) > +{ > + unsigned int cpu_nr, qn_idx; > + struct qnode *node, *next; > + u32 prev_qcode, my_qcode; > + > +#ifdef queue_spin_trylock_quick > + /* > +

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-17 Thread Peter Zijlstra
On Mon, Feb 17, 2014 at 03:41:22PM -0500, Waiman Long wrote: > +#define _QCODE(lock)(atomic_read(&(lock)->qlcode) >> _QCODE_OFFSET) > +#define _QLOCK(lock)(atomic_read(&(lock)->qlcode) & > _QSPINLOCK_LOCKED) > +#define GET_QN_IDX(code) (((code) >> _QCODE_VAL_OFFSET) & 3) > +

Re: [PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-17 Thread Peter Zijlstra
On Mon, Feb 17, 2014 at 03:41:22PM -0500, Waiman Long wrote: > +/* > + * The queue node structure > + * > + * This structure is essentially the same as the mcs_spinlock structure > + * in mcs_spinlock.h file. This structure is retained for future extension > + * where new fields may be added. > + *

[PATCH v4 1/3] qspinlock: Introducing a 4-byte queue spinlock implementation

2014-02-17 Thread Waiman Long
This patch introduces a new queue spinlock implementation that can serve as an alternative to the default ticket spinlock. Compared with the ticket spinlock, this queue spinlock should be almost as fair as the ticket spinlock. It has about the same speed in single-thread and it can be much faster i