Re: [PATCH 3/3] rtmutex: Reduce top-waiter blocking on a lock

From: Peter Zijlstra
Date: Mon Mar 14 2016 - 09:24:10 EST


On Tue, Mar 08, 2016 at 10:20:23AM -0800, Davidlohr Bueso wrote:
> lock->owner = (void *) RT_MUTEX_HAS_WAITERS;

> static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
> {
> return (struct task_struct *)
> - ((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
> + ((unsigned long)READ_ONCE(lock->owner) & ~RT_MUTEX_OWNER_MASKALL);
> }

If you READ_ONCE(), you should also WRITE_ONCE(), because while the
write is under the proper locks, our friendly compiler might still
choose to emit the store in a random sequence of byte stores, rendering
our READ_ONCE() pointless.