Skip to content

Commit cee41ea

Browse files
heicarstJiri Slaby
authored andcommitted
futex: Allow architectures to skip futex_atomic_cmpxchg_inatomic() test
commit 03b8c7b upstream. If an architecture has futex_atomic_cmpxchg_inatomic() implemented and there is no runtime check necessary, allow to skip the test within futex_init(). This allows to get rid of some code which would always give the same result, and also allows the compiler to optimize a couple of if statements away. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Finn Thain <fthain@telegraphics.com.au> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Link: http://lkml.kernel.org/r/20140302120947.GA3641@osiris Signed-off-by: Thomas Gleixner <tglx@linutronix.de> [geert: Backported to v3.10..v3.13] Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent 4a1bdd9 commit cee41ea

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎arch/s390/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ config S390
116116
select HAVE_FUNCTION_GRAPH_TRACER
117117
select HAVE_FUNCTION_TRACER
118118
select HAVE_FUNCTION_TRACE_MCOUNT_TEST
119+
select HAVE_FUTEX_CMPXCHG if FUTEX
119120
select HAVE_KERNEL_BZIP2
120121
select HAVE_KERNEL_GZIP
121122
select HAVE_KERNEL_LZ4

‎include/linux/futex.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ union futex_key {
5555
#ifdef CONFIG_FUTEX
5656
extern void exit_robust_list(struct task_struct *curr);
5757
extern void exit_pi_state_list(struct task_struct *curr);
58+
#ifdef CONFIG_HAVE_FUTEX_CMPXCHG
59+
#define futex_cmpxchg_enabled 1
60+
#else
5861
extern int futex_cmpxchg_enabled;
62+
#endif
5963
#else
6064
static inline void exit_robust_list(struct task_struct *curr)
6165
{

‎init/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,13 @@ config FUTEX
14061406
support for "fast userspace mutexes". The resulting kernel may not
14071407
run glibc-based applications correctly.
14081408

1409+
config HAVE_FUTEX_CMPXCHG
1410+
bool
1411+
help
1412+
Architectures should select this if futex_atomic_cmpxchg_inatomic()
1413+
is implemented and always working. This removes a couple of runtime
1414+
checks.
1415+
14091416
config EPOLL
14101417
bool "Enable eventpoll support" if EXPERT
14111418
default y

‎kernel/futex.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868

6969
#include "rtmutex_common.h"
7070

71+
#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
7172
int __read_mostly futex_cmpxchg_enabled;
73+
#endif
7274

7375
#define FUTEX_HASHBITS (CONFIG_BASE_SMALL ? 4 : 8)
7476

@@ -2731,10 +2733,10 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
27312733
return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
27322734
}
27332735

2734-
static int __init futex_init(void)
2736+
static void __init futex_detect_cmpxchg(void)
27352737
{
2738+
#ifndef CONFIG_HAVE_FUTEX_CMPXCHG
27362739
u32 curval;
2737-
int i;
27382740

27392741
/*
27402742
* This will fail and we want it. Some arch implementations do
@@ -2748,6 +2750,14 @@ static int __init futex_init(void)
27482750
*/
27492751
if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
27502752
futex_cmpxchg_enabled = 1;
2753+
#endif
2754+
}
2755+
2756+
static int __init futex_init(void)
2757+
{
2758+
int i;
2759+
2760+
futex_detect_cmpxchg();
27512761

27522762
for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
27532763
plist_head_init(&futex_queues[i].chain);

0 commit comments

Comments
 (0)