Re: [PATCH v8 15/19] locking/rwsem: Adaptive disabling of reader optimistic spinning
From: Peter Zijlstra
Date: Tue Jun 04 2019 - 07:03:01 EST
On Mon, May 20, 2019 at 04:59:14PM -0400, Waiman Long wrote:
> +static inline bool rwsem_reader_phase_trylock(struct rw_semaphore *sem,
> + long last_rowner)
> +{
> + long owner = atomic_long_read(&sem->owner);
> +
> + if (!(owner & RWSEM_READER_OWNED))
> + return false;
> +
> + owner &= ~RWSEM_OWNER_FLAGS_MASK;
> + last_rowner &= ~RWSEM_OWNER_FLAGS_MASK;
> + if ((owner != last_rowner) && rwsem_try_read_lock_unqueued(sem)) {
just because I'm struggling with sleep deprivation and the big picture
isn't making sense,.. you can write that like:
((owner ^ last_rowner) & ~RWSEM_OWNER_FLAGS_MASK)
> + lockevent_inc(rwsem_opt_rlock2);
> + lockevent_add(rwsem_opt_fail, -1);
> + return true;
> + }
> + return false;
> +}