Re: [PATCH 2/2] rwsem: do optimistic spinning for writer lockacquisition

From: Peter Zijlstra
Date: Tue Jun 25 2013 - 03:38:24 EST


On Mon, Jun 24, 2013 at 01:17:45PM -0700, Tim Chen wrote:
> On second thought, I agree with you. I should change this to
> something like
>
> int retval = true;
> task_struct *sem_owner;
>
> /* Spin only if active writer running */
> if (!sem->owner)
> return false;
>
> rcu_read_lock();
> sem_owner = sem->owner;

That should be: sem_owner = ACCESS_ONCE(sem->owner); to make sure the
compiler doesn't try and be clever and rereads.

> if (sem_owner)
> retval = sem_owner->on_cpu;
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/