Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 16.12.2016 21:00, Peter Zijlstra wrote: On Fri, Dec 16, 2016 at 07:11:41PM +0100, Nicolai Hähnle wrote: mutex_optimistic_spin() already calls __mutex_trylock, and for the no-spin case, __mutex_unlock_slowpath() only calls wake_up_q() after releasing the wait_lock. mutex_optimistic_spin()

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 16.12.2016 21:00, Peter Zijlstra wrote: On Fri, Dec 16, 2016 at 07:11:41PM +0100, Nicolai Hähnle wrote: mutex_optimistic_spin() already calls __mutex_trylock, and for the no-spin case, __mutex_unlock_slowpath() only calls wake_up_q() after releasing the wait_lock. mutex_optimistic_spin()

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 07:11:41PM +0100, Nicolai Hähnle wrote: > mutex_optimistic_spin() already calls __mutex_trylock, and for the no-spin > case, __mutex_unlock_slowpath() only calls wake_up_q() after releasing the > wait_lock. mutex_optimistic_spin() is a no-op when

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 07:11:41PM +0100, Nicolai Hähnle wrote: > mutex_optimistic_spin() already calls __mutex_trylock, and for the no-spin > case, __mutex_unlock_slowpath() only calls wake_up_q() after releasing the > wait_lock. mutex_optimistic_spin() is a no-op when

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 16.12.2016 18:20, Peter Zijlstra wrote: On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: @@ -716,7 +775,20 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, spin_unlock_mutex(>wait_lock, flags);

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 16.12.2016 18:20, Peter Zijlstra wrote: On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: @@ -716,7 +775,20 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, spin_unlock_mutex(>wait_lock, flags);

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 16.12.2016 18:15, Peter Zijlstra wrote: On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: The concern about picking up a handoff that we didn't request is real, though it cannot happen in the first iteration. Perhaps this __mutex_trylock can be moved to the end of the loop? See

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 16.12.2016 18:15, Peter Zijlstra wrote: On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: The concern about picking up a handoff that we didn't request is real, though it cannot happen in the first iteration. Perhaps this __mutex_trylock can be moved to the end of the loop? See

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: > >>@@ -716,7 +775,20 @@ __mutex_lock_common(struct mutex *lock, long state, > >>unsigned int subclass, > >>spin_unlock_mutex(>wait_lock, flags); > >>schedule_preempt_disabled(); > >> > >>- if

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: > >>@@ -716,7 +775,20 @@ __mutex_lock_common(struct mutex *lock, long state, > >>unsigned int subclass, > >>spin_unlock_mutex(>wait_lock, flags); > >>schedule_preempt_disabled(); > >> > >>- if

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: > The concern about picking up a handoff that we didn't request is real, > though it cannot happen in the first iteration. Perhaps this __mutex_trylock > can be moved to the end of the loop? See below... > >>@@ -728,7 +800,7 @@

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: > The concern about picking up a handoff that we didn't request is real, > though it cannot happen in the first iteration. Perhaps this __mutex_trylock > can be moved to the end of the loop? See below... > >>@@ -728,7 +800,7 @@

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: > Hi Peter and Chris, > > (trying to combine the handoff discussion here) > > On 06.12.2016 17:55, Peter Zijlstra wrote: > >On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > >>@@ -693,8 +748,12 @@

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Peter Zijlstra
On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai Hähnle wrote: > Hi Peter and Chris, > > (trying to combine the handoff discussion here) > > On 06.12.2016 17:55, Peter Zijlstra wrote: > >On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > >>@@ -693,8 +748,12 @@

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 01.12.2016 16:59, Chris Wilson wrote: On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: @@ -677,15 +722,25 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, debug_mutex_lock_common(lock, ); debug_mutex_add_waiter(lock, , task); -

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 01.12.2016 16:59, Chris Wilson wrote: On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: @@ -677,15 +722,25 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, debug_mutex_lock_common(lock, ); debug_mutex_add_waiter(lock, , task); -

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
Hi Peter and Chris, (trying to combine the handoff discussion here) On 06.12.2016 17:55, Peter Zijlstra wrote: On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: @@ -693,8 +748,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, *

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
Hi Peter and Chris, (trying to combine the handoff discussion here) On 06.12.2016 17:55, Peter Zijlstra wrote: On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: @@ -693,8 +748,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, *

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 06.12.2016 16:36, Peter Zijlstra wrote: On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: +static inline int __sched +__ww_mutex_add_waiter(struct mutex_waiter *waiter, + struct mutex *lock, + struct ww_acquire_ctx *ww_ctx) +{ +

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-16 Thread Nicolai Hähnle
On 06.12.2016 16:36, Peter Zijlstra wrote: On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: +static inline int __sched +__ww_mutex_add_waiter(struct mutex_waiter *waiter, + struct mutex *lock, + struct ww_acquire_ctx *ww_ctx) +{ +

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-06 Thread Peter Zijlstra
On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > @@ -693,8 +748,12 @@ __mutex_lock_common(struct mutex *lock, long state, > unsigned int subclass, >* mutex_unlock() handing the lock off to us, do a trylock >* before testing the error conditions to

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-06 Thread Peter Zijlstra
On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > @@ -693,8 +748,12 @@ __mutex_lock_common(struct mutex *lock, long state, > unsigned int subclass, >* mutex_unlock() handing the lock off to us, do a trylock >* before testing the error conditions to

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-06 Thread Peter Zijlstra
On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > +static inline int __sched > +__ww_mutex_add_waiter(struct mutex_waiter *waiter, > + struct mutex *lock, > + struct ww_acquire_ctx *ww_ctx) > +{ > + struct mutex_waiter *cur; > + > + if

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-06 Thread Peter Zijlstra
On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > +static inline int __sched > +__ww_mutex_add_waiter(struct mutex_waiter *waiter, > + struct mutex *lock, > + struct ww_acquire_ctx *ww_ctx) > +{ > + struct mutex_waiter *cur; > + > + if

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-01 Thread Chris Wilson
On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > @@ -677,15 +722,25 @@ __mutex_lock_common(struct mutex *lock, long state, > unsigned int subclass, > debug_mutex_lock_common(lock, ); > debug_mutex_add_waiter(lock, , task); > > - /* add waiting tasks to the end

Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-01 Thread Chris Wilson
On Thu, Dec 01, 2016 at 03:06:48PM +0100, Nicolai Hähnle wrote: > @@ -677,15 +722,25 @@ __mutex_lock_common(struct mutex *lock, long state, > unsigned int subclass, > debug_mutex_lock_common(lock, ); > debug_mutex_add_waiter(lock, , task); > > - /* add waiting tasks to the end

[PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-01 Thread Nicolai Hähnle
From: Nicolai Hähnle Add regular waiters in stamp order. Keep adding waiters that have no context in FIFO order and take care not to starve them. While adding our task as a waiter, back off if we detect that there is a waiter with a lower stamp in front of us. Make

[PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order

2016-12-01 Thread Nicolai Hähnle
From: Nicolai Hähnle Add regular waiters in stamp order. Keep adding waiters that have no context in FIFO order and take care not to starve them. While adding our task as a waiter, back off if we detect that there is a waiter with a lower stamp in front of us. Make sure to call lock_contended