Re: [PATCH] locking/percpu_rwsem: Rewrite to not use rwsem

From: Peter Zijlstra
Date: Wed Oct 30 2019 - 15:31:36 EST


On Wed, Oct 30, 2019 at 06:52:31PM +0100, Peter Zijlstra wrote:
> @@ -58,16 +72,17 @@ static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
> preempt_enable();
> }
>
> -static inline int percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
> +static inline bool percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
> {
> - int ret = 1;
> + bool ret = true;
>
> preempt_disable();
> /*
> * Same as in percpu_down_read().
> */
> - __this_cpu_inc(*sem->read_count);
> - if (unlikely(!rcu_sync_is_idle(&sem->rss)))
> + if (likely(!rcu_sync_is_idle(&sem->rss)))

That should obviously also loose the !

> + __this_cpu_inc(*sem->read_count);
> + else
> ret = __percpu_down_read(sem, true); /* Unconditional memory barrier */
> preempt_enable();
> /*