On 05/12/2016 05:27 PM, Peter Hurley wrote:
Arguably, this check should be bumped out to the optimistic spin and
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.
That will make the main optimistic spinning loop more complex.
??

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);
}


I have been thinking about something like that, but my inclination is to make as few changes as possible to the existing patch. I did add a new patch to streamline the code as suggested.

Cheers,
Longman

Reply via email to