??Arguably, this check should be bumped out to the optimistic spin andThat will make the main optimistic spinning loop more complex.
reload/check the owner there?
Or better yet; don't pass the owner in as a parameter at all, but
instead snapshot the owner and check its ownership on entry.
Simpler.
while (rwsem_spin_on_owner(sem)) {
if (rwsem_try_write_lock_unqueued(sem)) {
taken = true;
break;
}
if (!sem->owner&& (need_resched() || rt_task(current)))
break;
cpu_relax_lowlatency();
}
bool rwsem_spin_on_owner(struct rw_semaphore *sem)
{
struct task_struct *owner = READ_ONCE(sem->owner);
if (!rwsem_is_writer_owned(owner))
return false;
rcu_read_lock();
while (sem->owner == owner) {
....
}
rcu_read_unlock();
return !rwsem_is_reader_owned(sem->owner);
}