Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Andrea Parri
[...] > >>+ /* > >>+* wake_up_process() paired with set_current_state() inserts > >>+* sufficient barriers to make sure @owner either sees it's > >>+* wounded or has a wakeup pending to re-read the wounded > >>+* state. > >IIUC, "sufficient

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Andrea Parri
Hi Thomas, On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: > The current Wound-Wait mutex algorithm is actually not Wound-Wait but > Wait-Die. Implement also Wound-Wait as a per-ww-class choice. Wound-Wait > is, contrary to Wait-Die a preemptive algorithm and is known to generate

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Matthew Wilcox
On Thu, Jun 14, 2018 at 01:54:15PM +0200, Thomas Hellstrom wrote: > On 06/14/2018 01:36 PM, Peter Zijlstra wrote: > > Currently you don't allow mixing WD and WW contexts (which is not > > immediately obvious from the above code), and the above hard relies on > > that. Are there sensible use cases f

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Peter Zijlstra
On Thu, Jun 14, 2018 at 03:43:04PM +0200, Thomas Hellstrom wrote: > It's intended to be enforced by storing the algorithm choice in the > WW_MUTEX_CLASS which must be common for an acquire context and the > ww_mutexes it acquires. However, I don't think there is a check that that > holds. I guess w

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
On 06/14/2018 03:29 PM, Matthew Wilcox wrote: On Thu, Jun 14, 2018 at 01:54:15PM +0200, Thomas Hellstrom wrote: On 06/14/2018 01:36 PM, Peter Zijlstra wrote: Currently you don't allow mixing WD and WW contexts (which is not immediately obvious from the above code), and the above hard relies on

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
On 06/14/2018 02:48 PM, Thomas Hellstrom wrote: Hi, Peter, On 06/14/2018 02:41 PM, Peter Zijlstra wrote: On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: +static bool __ww_mutex_wound(struct mutex *lock, + struct ww_acquire_ctx *ww_ctx, + struct

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
Hi, Peter, On 06/14/2018 02:41 PM, Peter Zijlstra wrote: On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: +static bool __ww_mutex_wound(struct mutex *lock, +struct ww_acquire_ctx *ww_ctx, +struct ww_acquire_ctx *hold_ctx)

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Peter Zijlstra
On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: > +static bool __ww_mutex_wound(struct mutex *lock, > + struct ww_acquire_ctx *ww_ctx, > + struct ww_acquire_ctx *hold_ctx) > +{ > + struct task_struct *owner = __mutex_owner(lock

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
Resending hopefully better formatted.. On 06/14/2018 01:49 PM, Andrea Parri wrote: [...] + /* +* wake_up_process() paired with set_current_state() inserts +* sufficient barriers to make sure @owner either sees it's +* wounded or ha

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
On 06/14/2018 01:49 PM, Andrea Parri wrote: [...] + /* +* wake_up_process() paired with set_current_state() inserts +* sufficient barriers to make sure @owner either sees it's +* wounded or has a wakeup pending to re-read the wounded

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
On 06/14/2018 01:36 PM, Peter Zijlstra wrote: On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: __ww_mutex_wakeup_for_backoff(struct mutex *lock, struct ww_acquire_ctx *ww_ctx) { struct mutex_waiter *cur; + unsigned int is_wait_die = ww_ctx->ww_class->is_wait_

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Peter Zijlstra
On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: > __ww_mutex_wakeup_for_backoff(struct mutex *lock, struct ww_acquire_ctx > *ww_ctx) > { > struct mutex_waiter *cur; > + unsigned int is_wait_die = ww_ctx->ww_class->is_wait_die; > > lockdep_assert_held(&lock->w

Re: [PATCH v2 1/2] locking: Implement an algorithm choice for Wound-Wait mutexes

2018-06-14 Thread Thomas Hellstrom
On 06/14/2018 12:38 PM, Andrea Parri wrote: Hi Thomas, On Thu, Jun 14, 2018 at 09:29:21AM +0200, Thomas Hellstrom wrote: The current Wound-Wait mutex algorithm is actually not Wound-Wait but Wait-Die. Implement also Wound-Wait as a per-ww-class choice. Wound-Wait is, contrary to Wait-Die a pree