lkml.org 
[lkml]   [2015]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] locking/rwsem: Fix lock optimistic spinning when owner is not running
On Fri, Mar 06, 2015 at 11:45:31PM -0800, Jason Low wrote:
> static noinline
> bool rwsem_spin_on_owner(struct rw_semaphore *sem, struct task_struct *owner)
> {
> long count;
>
> rcu_read_lock();
> + while (sem->owner == owner) {
> + /*
> + * Ensure we emit the owner->on_cpu, dereference _after_
> + * checking sem->owner still matches owner, if that fails,
> + * owner might point to free()d memory, if it still matches,
> + * the rcu_read_lock() ensures the memory stays valid.
> + */
> + barrier();
> +
> + /* abort spinning when need_resched or owner is not running */
> + if (!owner->on_cpu || need_resched()) {
> rcu_read_unlock();
> return false;
> }


Thanks, looks good; do we want to change the mutex code (again) to more
closely resemble this too? It still has the while (true) instead of the
while(lock->owner != owner).




\
 
 \ /
  Last update: 2015-03-07 11:21    [W:0.133 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site