Skip to content

Commit 41fcb9f

Browse files
longman88ingomolnar
authored andcommitted
mutex: Move mutex spinning code from sched/core.c back to mutex.c
As mentioned by Ingo, the SCHED_FEAT_OWNER_SPIN scheduler feature bit was really just an early hack to make with/without mutex-spinning testable. So it is no longer necessary. This patch removes the SCHED_FEAT_OWNER_SPIN feature bit and move the mutex spinning code from kernel/sched/core.c back to kernel/mutex.c which is where they should belong. Signed-off-by: Waiman Long <Waiman.Long@hp.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Chandramouleeswaran Aswin <aswin@hp.com> Cc: Davidlohr Bueso <davidlohr.bueso@hp.com> Cc: Norton Scott J <scott.norton@hp.com> Cc: Rik van Riel <riel@redhat.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: David Howells <dhowells@redhat.com> Cc: Dave Jones <davej@redhat.com> Cc: Clark Williams <williams@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1366226594-5506-2-git-send-email-Waiman.Long@hp.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 8184004 commit 41fcb9f

4 files changed

Lines changed: 46 additions & 53 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ extern signed long schedule_timeout_killable(signed long timeout);
320320
extern signed long schedule_timeout_uninterruptible(signed long timeout);
321321
asmlinkage void schedule(void);
322322
extern void schedule_preempt_disabled(void);
323-
extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
324323

325324
struct nsproxy;
326325
struct user_namespace;

‎kernel/mutex.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,52 @@ void __sched mutex_lock(struct mutex *lock)
9595
EXPORT_SYMBOL(mutex_lock);
9696
#endif
9797

98+
#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
99+
/*
100+
* Mutex spinning code migrated from kernel/sched/core.c
101+
*/
102+
103+
static inline bool owner_running(struct mutex *lock, struct task_struct *owner)
104+
{
105+
if (lock->owner != owner)
106+
return false;
107+
108+
/*
109+
* Ensure we emit the owner->on_cpu, dereference _after_ checking
110+
* lock->owner still matches owner, if that fails, owner might
111+
* point to free()d memory, if it still matches, the rcu_read_lock()
112+
* ensures the memory stays valid.
113+
*/
114+
barrier();
115+
116+
return owner->on_cpu;
117+
}
118+
119+
/*
120+
* Look out! "owner" is an entirely speculative pointer
121+
* access and not reliable.
122+
*/
123+
static noinline
124+
int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
125+
{
126+
rcu_read_lock();
127+
while (owner_running(lock, owner)) {
128+
if (need_resched())
129+
break;
130+
131+
arch_mutex_cpu_relax();
132+
}
133+
rcu_read_unlock();
134+
135+
/*
136+
* We break out the loop above on need_resched() and when the
137+
* owner changed, which is a sign for heavy contention. Return
138+
* success only when lock->owner is NULL.
139+
*/
140+
return lock->owner == NULL;
141+
}
142+
#endif
143+
98144
static __used noinline void __sched __mutex_unlock_slowpath(atomic_t *lock_count);
99145

100146
/**

‎kernel/sched/core.c‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,51 +2997,6 @@ void __sched schedule_preempt_disabled(void)
29972997
preempt_disable();
29982998
}
29992999

3000-
#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
3001-
3002-
static inline bool owner_running(struct mutex *lock, struct task_struct *owner)
3003-
{
3004-
if (lock->owner != owner)
3005-
return false;
3006-
3007-
/*
3008-
* Ensure we emit the owner->on_cpu, dereference _after_ checking
3009-
* lock->owner still matches owner, if that fails, owner might
3010-
* point to free()d memory, if it still matches, the rcu_read_lock()
3011-
* ensures the memory stays valid.
3012-
*/
3013-
barrier();
3014-
3015-
return owner->on_cpu;
3016-
}
3017-
3018-
/*
3019-
* Look out! "owner" is an entirely speculative pointer
3020-
* access and not reliable.
3021-
*/
3022-
int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
3023-
{
3024-
if (!sched_feat(OWNER_SPIN))
3025-
return 0;
3026-
3027-
rcu_read_lock();
3028-
while (owner_running(lock, owner)) {
3029-
if (need_resched())
3030-
break;
3031-
3032-
arch_mutex_cpu_relax();
3033-
}
3034-
rcu_read_unlock();
3035-
3036-
/*
3037-
* We break out the loop above on need_resched() and when the
3038-
* owner changed, which is a sign for heavy contention. Return
3039-
* success only when lock->owner is NULL.
3040-
*/
3041-
return lock->owner == NULL;
3042-
}
3043-
#endif
3044-
30453000
#ifdef CONFIG_PREEMPT
30463001
/*
30473002
* this is the entry point to schedule() from in-kernel preemption

‎kernel/sched/features.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ SCHED_FEAT(HRTICK, false)
4545
SCHED_FEAT(DOUBLE_TICK, false)
4646
SCHED_FEAT(LB_BIAS, true)
4747

48-
/*
49-
* Spin-wait on mutex acquisition when the mutex owner is running on
50-
* another cpu -- assumes that when the owner is running, it will soon
51-
* release the lock. Decreases scheduling overhead.
52-
*/
53-
SCHED_FEAT(OWNER_SPIN, true)
54-
5548
/*
5649
* Decrement CPU power based on time not spent running tasks
5750
*/

0 commit comments

Comments
 (0)