Re: [RFC][PATCH 06/13] percpu-rwsem: Provide percpu_down_read_trylock()

From: Oleg Nesterov
Date: Mon Jun 22 2015 - 19:10:38 EST


On 06/22, Peter Zijlstra wrote:
>
> +static inline bool percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
> +{
> + bool ret = true;
> +
> + preempt_disable();
> + __this_cpu_inc(*sem->refcount);
> + if (unlikely(!rcu_sync_is_idle(&sem->rss)))
> + ret = __percpu_down_read_trylock(sem);
> + preempt_enable();
> +
> + if (ret)
> + rwsem_acquire_read(&sem->rw_sem.dep_map, 0, 1, _RET_IP_);
> +
> + return ret;
> +}
...
> +bool __percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
> +{
> + smp_mb(); /* A matches D */
> +
> + if (likely(smp_load_acquire(&sem->state) != readers_block))
> + return true;
> +
> + __percpu_up_read(sem);
> +
> + return false;
> +}

Looks like we can slightly refactor this code to avoid the code
duplication. But this is minor too and we can do this later.

Reviewed-by: Oleg Nesterov <oleg@xxxxxxxxxx>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at http://www.tux.org/lkml/