Skip to content

Commit 34b133f

Browse files
gerald-schaeferMartin Schwidefsky
authored andcommitted
[S390] mutex: Introduce arch_mutex_cpu_relax()
The spinning mutex implementation uses cpu_relax() in busy loops as a compiler barrier. Depending on the architecture, cpu_relax() may do more than needed in this specific mutex spin loops. On System z we also give up the time slice of the virtual cpu in cpu_relax(), which prevents effective spinning on the mutex. This patch replaces cpu_relax() in the spinning mutex code with arch_mutex_cpu_relax(), which can be defined by each architecture that selects HAVE_ARCH_MUTEX_CPU_RELAX. The default is still cpu_relax(), so this patch should not affect other architectures than System z for now. Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <1290437256.7455.4.camel@thinkpad> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent c030175 commit 34b133f

6 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎arch/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,7 @@ config HAVE_PERF_EVENTS_NMI
175175
config HAVE_ARCH_JUMP_LABEL
176176
bool
177177

178+
config HAVE_ARCH_MUTEX_CPU_RELAX
179+
bool
180+
178181
source "kernel/gcov/Kconfig"

‎arch/s390/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ config S390
8787
select HAVE_KERNEL_LZMA
8888
select HAVE_KERNEL_LZO
8989
select HAVE_GET_USER_PAGES_FAST
90+
select HAVE_ARCH_MUTEX_CPU_RELAX
9091
select ARCH_INLINE_SPIN_TRYLOCK
9192
select ARCH_INLINE_SPIN_TRYLOCK_BH
9293
select ARCH_INLINE_SPIN_LOCK

‎arch/s390/include/asm/mutex.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
*/
88

99
#include <asm-generic/mutex-dec.h>
10+
11+
#define arch_mutex_cpu_relax() barrier()

‎include/linux/mutex.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,8 @@ extern int mutex_trylock(struct mutex *lock);
160160
extern void mutex_unlock(struct mutex *lock);
161161
extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
162162

163+
#ifndef CONFIG_HAVE_ARCH_MUTEX_CPU_RELAX
164+
#define arch_mutex_cpu_relax() cpu_relax()
165+
#endif
166+
163167
#endif

‎kernel/mutex.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
199199
* memory barriers as we'll eventually observe the right
200200
* values at the cost of a few extra spins.
201201
*/
202-
cpu_relax();
202+
arch_mutex_cpu_relax();
203203
}
204204
#endif
205205
spin_lock_mutex(&lock->wait_lock, flags);

‎kernel/sched.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
#include <asm/tlb.h>
7777
#include <asm/irq_regs.h>
78+
#include <asm/mutex.h>
7879

7980
#include "sched_cpupri.h"
8081
#include "workqueue_sched.h"
@@ -4214,7 +4215,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
42144215
if (task_thread_info(rq->curr) != owner || need_resched())
42154216
return 0;
42164217

4217-
cpu_relax();
4218+
arch_mutex_cpu_relax();
42184219
}
42194220

42204221
return 1;

0 commit comments

Comments
 (0)