Re: Refactoring mutex spin on owner code

Peter Zijlstra
2015-01-30T07:51:45Z

On Thu, Jan 29, 2015 at 11:14:40PM -0800, Davidlohr Bueso wrote:
> > +bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
> > {
> > + bool ret;
> > +
> > rcu_read_lock();
> > - while (owner_running(lock, owner)) {
> > - if (need_resched())
> > + while (true) {
> > + /* Return success when the lock owner changed */
> > + if (lock->owner != owner) {
>
> Shouldn't this be a READ_ONCE(lock->owner)? We're in a loop and need to
> avoid gcc giving us stale data if the owner is updated after a few
> iterations, no?

There's a barrier() in that loop, and cpu_relax() also implies
barrier(). I'm pretty sure that's more than sufficient to make GCC emit
loads.