Re: [PATCH v4 08/16] locking/rwsem: Make rwsem_spin_on_owner() return owner state
From: Peter Zijlstra
Date:  Wed Apr 17 2019 - 05:00:14 EST
On Sat, Apr 13, 2019 at 01:22:51PM -0400, Waiman Long wrote:
> This patch modifies rwsem_spin_on_owner() to return four possible
> values to better reflect the state of lock holder which enables us to
> make a better decision of what to do next.
> 
> In the special case that there is no active lock and the handoff bit
> is set, optimistic spinning has to be stopped.
> 
> Signed-off-by: Waiman Long <longman@xxxxxxxxxx>
> ---
>  kernel/locking/rwsem.c | 45 +++++++++++++++++++++++++++++++++++-------
>  1 file changed, 38 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index aaab546a890d..2d6850c3e77b 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -156,6 +156,11 @@ static inline bool is_rwsem_owner_spinnable(struct task_struct *owner)
>  	return !((unsigned long)owner & RWSEM_ANONYMOUSLY_OWNED);
>  }
>  
> +static inline bool is_rwsem_owner_reader(struct task_struct *owner)
> +{
> +	return (unsigned long)owner & RWSEM_READER_OWNED;
> +}
Move this and the surrounding helpers into the RWSEM_SPIN_ON_OWNER
block, it is only used there and that way all the code is together.