lkml.org 
[lkml]   [2011]   [Jun]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH] sched: remove unreliable pointer in mutex_spin_on_owner()
From
The dereference of unreliable owner pointer is unnecessary in owner_running(),
though under RCU protection, because the true result is only determined by
checking the validity of lock owner, as the comment says, due to likely heavy
lock contention, which has little to do with whether owner->on_cpu is false.

If owner->on_cpu is really false, only the owner_running loop is shortened,
but also returns incorrect result, since the lock owner is not changed, though
maybe changed soon.

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---
kernel/sched.c | 36 +-----------------------------------
1 files changed, 1 insertions(+), 35 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index fd18f39..2c32616 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4293,52 +4293,18 @@ EXPORT_SYMBOL(schedule);

#ifdef CONFIG_MUTEX_SPIN_ON_OWNER

-static inline bool owner_running(struct mutex *lock, struct task_struct *owner)
-{
- bool ret = false;
-
- rcu_read_lock();
- if (lock->owner != owner)
- goto fail;
-
- /*
- * Ensure we emit the owner->on_cpu, dereference _after_ checking
- * lock->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();
-
- ret = owner->on_cpu;
-fail:
- rcu_read_unlock();
-
- return ret;
-}
-
-/*
- * Look out! "owner" is an entirely speculative pointer
- * access and not reliable.
- */
int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
{
if (!sched_feat(OWNER_SPIN))
return 0;

- while (owner_running(lock, owner)) {
+ while (lock->owner != NULL) {
if (need_resched())
return 0;

arch_mutex_cpu_relax();
}

- /*
- * If the owner changed to another task there is likely
- * heavy contention, stop spinning.
- */
- if (lock->owner)
- return 0;
-
return 1;
}
#endif

\
 
 \ /
  Last update: 2011-06-08 14:53    [W:0.047 / U:0.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site