|
|
077c9d |
commit f0458cf4f9ff3d870c43b624e6dccaaf657d5e83
|
|
|
077c9d |
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
077c9d |
Date: Mon Aug 27 09:42:50 2018 -0300
|
|
|
077c9d |
|
|
|
077c9d |
powerpc: Only enable TLE with PPC_FEATURE2_HTM_NOSC
|
|
|
077c9d |
|
|
|
077c9d |
Linux from 3.9 through 4.2 does not abort HTM transaction on syscalls,
|
|
|
077c9d |
instead it suspend and resume it when leaving the kernel. The
|
|
|
077c9d |
side-effects of the syscall will always remain visible, even if the
|
|
|
077c9d |
transaction is aborted. This is an issue when transaction is used along
|
|
|
077c9d |
with futex syscall, on pthread_cond_wait for instance, where the futex
|
|
|
077c9d |
call might succeed but the transaction is rolled back leading the
|
|
|
077c9d |
pthread_cond object in an inconsistent state.
|
|
|
077c9d |
|
|
|
077c9d |
Glibc used to prevent it by always aborting a transaction before issuing
|
|
|
077c9d |
a syscall. Linux 4.2 also decided to abort active transaction in
|
|
|
077c9d |
syscalls which makes the glibc workaround superfluous. Worse, glibc
|
|
|
077c9d |
transaction abortion leads to a performance issue on recent kernels
|
|
|
077c9d |
where the HTM state is saved/restore lazily (v4.9). By aborting a
|
|
|
077c9d |
transaction on every syscalls, regardless whether a transaction has being
|
|
|
077c9d |
initiated before, GLIBS makes the kernel always save/restore HTM state
|
|
|
077c9d |
(it can not even lazily disable it after a certain number of syscall
|
|
|
077c9d |
iterations).
|
|
|
077c9d |
|
|
|
077c9d |
Because of this shortcoming, Transactional Lock Elision is just enabled
|
|
|
077c9d |
when it has been explicitly set (either by tunables of by a configure
|
|
|
077c9d |
switch) and if kernel aborts HTM transactions on syscalls
|
|
|
077c9d |
(PPC_FEATURE2_HTM_NOSC). It is reported that using simple benchmark [1],
|
|
|
077c9d |
the context-switch is about 5% faster by not issuing a tabort in every
|
|
|
077c9d |
syscall in newer kernels.
|
|
|
077c9d |
|
|
|
077c9d |
Checked on powerpc64le-linux-gnu with 4.4.0 kernel (Ubuntu 16.04).
|
|
|
077c9d |
|
|
|
077c9d |
* NEWS: Add note about new TLE support on powerpc64le.
|
|
|
077c9d |
* sysdeps/powerpc/nptl/tcb-offsets.sym (TM_CAPABLE): Remove.
|
|
|
077c9d |
* sysdeps/powerpc/nptl/tls.h (tcbhead_t): Rename tm_capable to
|
|
|
077c9d |
__ununsed1.
|
|
|
077c9d |
(TLS_INIT_TP, TLS_DEFINE_INIT_TP): Remove tm_capable setup.
|
|
|
077c9d |
(THREAD_GET_TM_CAPABLE, THREAD_SET_TM_CAPABLE): Remove macros.
|
|
|
077c9d |
* sysdeps/powerpc/powerpc32/sysdep.h,
|
|
|
077c9d |
sysdeps/powerpc/powerpc64/sysdep.h (ABORT_TRANSACTION_IMPL,
|
|
|
077c9d |
ABORT_TRANSACTION): Remove macros.
|
|
|
077c9d |
* sysdeps/powerpc/sysdep.h (ABORT_TRANSACTION): Likewise.
|
|
|
077c9d |
* sysdeps/unix/sysv/linux/powerpc/elision-conf.c (elision_init): Set
|
|
|
077c9d |
__pthread_force_elision iff PPC_FEATURE2_HTM_NOSC is set.
|
|
|
077c9d |
* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h,
|
|
|
077c9d |
sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
sysdeps/unix/sysv/linux/powerpc/syscall.S (ABORT_TRANSACTION): Remove
|
|
|
077c9d |
usage.
|
|
|
077c9d |
* sysdeps/unix/sysv/linux/powerpc/not-errno.h: Remove file.
|
|
|
077c9d |
|
|
|
077c9d |
Reported-by: Breno Leitão <leitao@debian.org>
|
|
|
077c9d |
|
|
|
077c9d |
diff --git a/sysdeps/powerpc/nptl/tcb-offsets.sym b/sysdeps/powerpc/nptl/tcb-offsets.sym
|
|
|
077c9d |
index e5bb2b3..4c01615 100644
|
|
|
077c9d |
--- a/sysdeps/powerpc/nptl/tcb-offsets.sym
|
|
|
077c9d |
+++ b/sysdeps/powerpc/nptl/tcb-offsets.sym
|
|
|
077c9d |
@@ -21,7 +21,6 @@ DSO_SLOT2 (offsetof (tcbhead_t, dso_slot2) - TLS_TCB_OFFSET - sizeof (tcbhead_
|
|
|
077c9d |
#ifdef __powerpc64__
|
|
|
077c9d |
TCB_AT_PLATFORM (offsetof (tcbhead_t, at_platform) - TLS_TCB_OFFSET - sizeof(tcbhead_t))
|
|
|
077c9d |
#endif
|
|
|
077c9d |
-TM_CAPABLE (offsetof (tcbhead_t, tm_capable) - TLS_TCB_OFFSET - sizeof (tcbhead_t))
|
|
|
077c9d |
#ifndef __powerpc64__
|
|
|
077c9d |
TCB_AT_PLATFORM (offsetof (tcbhead_t, at_platform) - TLS_TCB_OFFSET - sizeof(tcbhead_t))
|
|
|
077c9d |
PADDING (offsetof (tcbhead_t, padding) - TLS_TCB_OFFSET - sizeof(tcbhead_t))
|
|
|
077c9d |
diff --git a/sysdeps/powerpc/nptl/tls.h b/sysdeps/powerpc/nptl/tls.h
|
|
|
077c9d |
index f88fed5..8317ca7 100644
|
|
|
077c9d |
--- a/sysdeps/powerpc/nptl/tls.h
|
|
|
077c9d |
+++ b/sysdeps/powerpc/nptl/tls.h
|
|
|
077c9d |
@@ -67,8 +67,7 @@ typedef struct
|
|
|
077c9d |
uint32_t padding;
|
|
|
077c9d |
uint32_t at_platform;
|
|
|
077c9d |
#endif
|
|
|
077c9d |
- /* Indicate if HTM capable (ISA 2.07). */
|
|
|
077c9d |
- uint32_t tm_capable;
|
|
|
077c9d |
+ uint32_t __unused;
|
|
|
077c9d |
/* Reservation for AT_PLATFORM data - powerpc64. */
|
|
|
077c9d |
#ifdef __powerpc64__
|
|
|
077c9d |
uint32_t at_platform;
|
|
|
077c9d |
@@ -142,7 +141,6 @@ register void *__thread_register __asm__ ("r13");
|
|
|
077c9d |
# define TLS_INIT_TP(tcbp) \
|
|
|
077c9d |
({ \
|
|
|
077c9d |
__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET; \
|
|
|
077c9d |
- THREAD_SET_TM_CAPABLE (__tcb_hwcap & PPC_FEATURE2_HAS_HTM ? 1 : 0); \
|
|
|
077c9d |
THREAD_SET_HWCAP (__tcb_hwcap); \
|
|
|
077c9d |
THREAD_SET_AT_PLATFORM (__tcb_platform); \
|
|
|
077c9d |
NULL; \
|
|
|
077c9d |
@@ -151,8 +149,6 @@ register void *__thread_register __asm__ ("r13");
|
|
|
077c9d |
/* Value passed to 'clone' for initialization of the thread register. */
|
|
|
077c9d |
# define TLS_DEFINE_INIT_TP(tp, pd) \
|
|
|
077c9d |
void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE; \
|
|
|
077c9d |
- (((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].tm_capable) = \
|
|
|
077c9d |
- THREAD_GET_TM_CAPABLE (); \
|
|
|
077c9d |
(((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].hwcap) = \
|
|
|
077c9d |
THREAD_GET_HWCAP (); \
|
|
|
077c9d |
(((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].at_platform) = \
|
|
|
077c9d |
@@ -210,13 +206,6 @@ register void *__thread_register __asm__ ("r13");
|
|
|
077c9d |
+ TLS_PRE_TCB_SIZE))[-1].pointer_guard \
|
|
|
077c9d |
= THREAD_GET_POINTER_GUARD())
|
|
|
077c9d |
|
|
|
077c9d |
-/* tm_capable field in TCB head. */
|
|
|
077c9d |
-# define THREAD_GET_TM_CAPABLE() \
|
|
|
077c9d |
- (((tcbhead_t *) ((char *) __thread_register \
|
|
|
077c9d |
- - TLS_TCB_OFFSET))[-1].tm_capable)
|
|
|
077c9d |
-# define THREAD_SET_TM_CAPABLE(value) \
|
|
|
077c9d |
- (THREAD_GET_TM_CAPABLE () = (value))
|
|
|
077c9d |
-
|
|
|
077c9d |
/* hwcap field in TCB head. */
|
|
|
077c9d |
# define THREAD_GET_HWCAP() \
|
|
|
077c9d |
(((tcbhead_t *) ((char *) __thread_register \
|
|
|
077c9d |
diff --git a/sysdeps/powerpc/powerpc32/sysdep.h b/sysdeps/powerpc/powerpc32/sysdep.h
|
|
|
077c9d |
index 5f1294e..93097c5 100644
|
|
|
077c9d |
--- a/sysdeps/powerpc/powerpc32/sysdep.h
|
|
|
077c9d |
+++ b/sysdeps/powerpc/powerpc32/sysdep.h
|
|
|
077c9d |
@@ -90,24 +90,7 @@ GOT_LABEL: ; \
|
|
|
077c9d |
cfi_endproc; \
|
|
|
077c9d |
ASM_SIZE_DIRECTIVE(name)
|
|
|
077c9d |
|
|
|
077c9d |
-#if !IS_IN(rtld) && !defined(__SPE__)
|
|
|
077c9d |
-# define ABORT_TRANSACTION_IMPL \
|
|
|
077c9d |
- cmpwi 2,0; \
|
|
|
077c9d |
- beq 1f; \
|
|
|
077c9d |
- lwz 0,TM_CAPABLE(2); \
|
|
|
077c9d |
- cmpwi 0,0; \
|
|
|
077c9d |
- beq 1f; \
|
|
|
077c9d |
- li 11,_ABORT_SYSCALL; \
|
|
|
077c9d |
- tabort. 11; \
|
|
|
077c9d |
- .align 4; \
|
|
|
077c9d |
-1:
|
|
|
077c9d |
-#else
|
|
|
077c9d |
-# define ABORT_TRANSACTION_IMPL
|
|
|
077c9d |
-#endif
|
|
|
077c9d |
-#define ABORT_TRANSACTION ABORT_TRANSACTION_IMPL
|
|
|
077c9d |
-
|
|
|
077c9d |
#define DO_CALL(syscall) \
|
|
|
077c9d |
- ABORT_TRANSACTION \
|
|
|
077c9d |
li 0,syscall; \
|
|
|
077c9d |
sc
|
|
|
077c9d |
|
|
|
077c9d |
diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
index 2df1d9b..50e64f9 100644
|
|
|
077c9d |
--- a/sysdeps/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
+++ b/sysdeps/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
@@ -263,24 +263,7 @@ LT_LABELSUFFIX(name,_name_end): ; \
|
|
|
077c9d |
TRACEBACK_MASK(name,mask); \
|
|
|
077c9d |
END_2(name)
|
|
|
077c9d |
|
|
|
077c9d |
-#if !IS_IN(rtld)
|
|
|
077c9d |
-# define ABORT_TRANSACTION_IMPL \
|
|
|
077c9d |
- cmpdi 13,0; \
|
|
|
077c9d |
- beq 1f; \
|
|
|
077c9d |
- lwz 0,TM_CAPABLE(13); \
|
|
|
077c9d |
- cmpwi 0,0; \
|
|
|
077c9d |
- beq 1f; \
|
|
|
077c9d |
- li 11,_ABORT_SYSCALL; \
|
|
|
077c9d |
- tabort. 11; \
|
|
|
077c9d |
- .p2align 4; \
|
|
|
077c9d |
-1:
|
|
|
077c9d |
-#else
|
|
|
077c9d |
-# define ABORT_TRANSACTION_IMPL
|
|
|
077c9d |
-#endif
|
|
|
077c9d |
-#define ABORT_TRANSACTION ABORT_TRANSACTION_IMPL
|
|
|
077c9d |
-
|
|
|
077c9d |
#define DO_CALL(syscall) \
|
|
|
077c9d |
- ABORT_TRANSACTION \
|
|
|
077c9d |
li 0,syscall; \
|
|
|
077c9d |
sc
|
|
|
077c9d |
|
|
|
077c9d |
diff --git a/sysdeps/powerpc/sysdep.h b/sysdeps/powerpc/sysdep.h
|
|
|
077c9d |
index 8a6d236..c8bf25e 100644
|
|
|
077c9d |
--- a/sysdeps/powerpc/sysdep.h
|
|
|
077c9d |
+++ b/sysdeps/powerpc/sysdep.h
|
|
|
077c9d |
@@ -21,8 +21,6 @@
|
|
|
077c9d |
*/
|
|
|
077c9d |
#define _SYSDEPS_SYSDEP_H 1
|
|
|
077c9d |
#include <bits/hwcap.h>
|
|
|
077c9d |
-#include <tls.h>
|
|
|
077c9d |
-#include <htm.h>
|
|
|
077c9d |
|
|
|
077c9d |
#define PPC_FEATURE_970 (PPC_FEATURE_POWER4 + PPC_FEATURE_HAS_ALTIVEC)
|
|
|
077c9d |
|
|
|
077c9d |
@@ -166,22 +164,4 @@
|
|
|
077c9d |
#define ALIGNARG(log2) log2
|
|
|
077c9d |
#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
|
|
|
077c9d |
|
|
|
077c9d |
-#else
|
|
|
077c9d |
-
|
|
|
077c9d |
-/* Linux kernel powerpc documentation [1] states issuing a syscall inside a
|
|
|
077c9d |
- transaction is not recommended and may lead to undefined behavior. It
|
|
|
077c9d |
- also states syscalls do not abort transactions. To avoid such traps,
|
|
|
077c9d |
- we abort transaction just before syscalls.
|
|
|
077c9d |
-
|
|
|
077c9d |
- [1] Documentation/powerpc/transactional_memory.txt [Syscalls] */
|
|
|
077c9d |
-#if !IS_IN(rtld) && !defined(__SPE__)
|
|
|
077c9d |
-# define ABORT_TRANSACTION \
|
|
|
077c9d |
- ({ \
|
|
|
077c9d |
- if (THREAD_GET_TM_CAPABLE ()) \
|
|
|
077c9d |
- __libc_tabort (_ABORT_SYSCALL); \
|
|
|
077c9d |
- })
|
|
|
077c9d |
-#else
|
|
|
077c9d |
-# define ABORT_TRANSACTION
|
|
|
077c9d |
-#endif
|
|
|
077c9d |
-
|
|
|
077c9d |
#endif /* __ASSEMBLER__ */
|
|
|
077c9d |
diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-conf.c b/sysdeps/unix/sysv/linux/powerpc/elision-conf.c
|
|
|
077c9d |
index 906882a..fc82bd1 100644
|
|
|
077c9d |
--- a/sysdeps/unix/sysv/linux/powerpc/elision-conf.c
|
|
|
077c9d |
+++ b/sysdeps/unix/sysv/linux/powerpc/elision-conf.c
|
|
|
077c9d |
@@ -127,6 +127,26 @@ elision_init (int argc __attribute__ ((unused)),
|
|
|
077c9d |
TUNABLE_CALLBACK (set_elision_skip_trylock_internal_abort));
|
|
|
077c9d |
#endif
|
|
|
077c9d |
|
|
|
077c9d |
+ /* Linux from 3.9 through 4.2 do not abort HTM transaction on syscalls,
|
|
|
077c9d |
+ instead it suspends the transaction and resumes it when returning to
|
|
|
077c9d |
+ usercode. The side-effects of the syscall will always remain visible,
|
|
|
077c9d |
+ even if the transaction is aborted. This is an issue when a transaction
|
|
|
077c9d |
+ is used along with futex syscall, on pthread_cond_wait for instance,
|
|
|
077c9d |
+ where futex might succeed but the transaction is rolled back leading
|
|
|
077c9d |
+ the condition variable object in an inconsistent state.
|
|
|
077c9d |
+
|
|
|
077c9d |
+ Glibc used to prevent it by always aborting a transaction before issuing
|
|
|
077c9d |
+ a syscall. Linux 4.2 also decided to abort active transaction in
|
|
|
077c9d |
+ syscalls which makes the glibc workaround superflours. Worse, glibc
|
|
|
077c9d |
+ transaction abortions leads to a performance issues on recent kernels.
|
|
|
077c9d |
+
|
|
|
077c9d |
+ So Lock Elision is just enabled when it has been explict set (either
|
|
|
077c9d |
+ by tunables of by a configure switch) and if kernel aborts HTM
|
|
|
077c9d |
+ transactions on syscalls (PPC_FEATURE2_HTM_NOSC) */
|
|
|
077c9d |
+
|
|
|
077c9d |
+ __pthread_force_elision = (__pthread_force_elision
|
|
|
077c9d |
+ && GLRO (dl_hwcap2) & PPC_FEATURE2_HTM_NOSC);
|
|
|
077c9d |
+
|
|
|
077c9d |
if (!__pthread_force_elision)
|
|
|
077c9d |
__elision_aconf.try_tbegin = 0; /* Disable elision on rwlocks. */
|
|
|
077c9d |
}
|
|
|
077c9d |
diff --git a/sysdeps/unix/sysv/linux/powerpc/not-errno.h b/sysdeps/unix/sysv/linux/powerpc/not-errno.h
|
|
|
077c9d |
deleted file mode 100644
|
|
|
077c9d |
index 27da21b..0000000
|
|
|
077c9d |
--- a/sysdeps/unix/sysv/linux/powerpc/not-errno.h
|
|
|
077c9d |
+++ /dev/null
|
|
|
077c9d |
@@ -1,30 +0,0 @@
|
|
|
077c9d |
-/* Syscall wrapper that do not set errno. Linux powerpc version.
|
|
|
077c9d |
- Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
077c9d |
- This file is part of the GNU C Library.
|
|
|
077c9d |
-
|
|
|
077c9d |
- The GNU C Library is free software; you can redistribute it and/or
|
|
|
077c9d |
- modify it under the terms of the GNU Lesser General Public
|
|
|
077c9d |
- License as published by the Free Software Foundation; either
|
|
|
077c9d |
- version 2.1 of the License, or (at your option) any later version.
|
|
|
077c9d |
-
|
|
|
077c9d |
- The GNU C Library is distributed in the hope that it will be useful,
|
|
|
077c9d |
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
077c9d |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
077c9d |
- Lesser General Public License for more details.
|
|
|
077c9d |
-
|
|
|
077c9d |
- You should have received a copy of the GNU Lesser General Public
|
|
|
077c9d |
- License along with the GNU C Library; if not, see
|
|
|
077c9d |
- <http://www.gnu.org/licenses/>. */
|
|
|
077c9d |
-
|
|
|
077c9d |
-/* __access_noerrno is used during process initialization in elf/dl-tunables.c
|
|
|
077c9d |
- before the TCB is initialized, prohibiting the usage of
|
|
|
077c9d |
- ABORT_TRANSACTION. */
|
|
|
077c9d |
-#undef ABORT_TRANSACTION
|
|
|
077c9d |
-#define ABORT_TRANSACTION
|
|
|
077c9d |
-
|
|
|
077c9d |
-#include "sysdeps/unix/sysv/linux/not-errno.h"
|
|
|
077c9d |
-
|
|
|
077c9d |
-/* Recover ABORT_TRANSACTION's previous value, in order to not affect
|
|
|
077c9d |
- other syscalls. */
|
|
|
077c9d |
-#undef ABORT_TRANSACTION
|
|
|
077c9d |
-#define ABORT_TRANSACTION ABORT_TRANSACTION_IMPL
|
|
|
077c9d |
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
|
|
|
077c9d |
index f7277d5..ec5c525 100644
|
|
|
077c9d |
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
|
|
|
077c9d |
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
|
|
|
077c9d |
@@ -109,7 +109,6 @@
|
|
|
077c9d |
register long int r11 __asm__ ("r11"); \
|
|
|
077c9d |
register long int r12 __asm__ ("r12"); \
|
|
|
077c9d |
LOADARGS_##nr(name, args); \
|
|
|
077c9d |
- ABORT_TRANSACTION; \
|
|
|
077c9d |
__asm__ __volatile__ \
|
|
|
077c9d |
("sc \n\t" \
|
|
|
077c9d |
"mfcr %0" \
|
|
|
077c9d |
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
index 0956cf0..1f17f7b 100644
|
|
|
077c9d |
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
|
|
|
077c9d |
@@ -131,7 +131,6 @@
|
|
|
077c9d |
register long int r7 __asm__ ("r7"); \
|
|
|
077c9d |
register long int r8 __asm__ ("r8"); \
|
|
|
077c9d |
LOADARGS_##nr (name, ##args); \
|
|
|
077c9d |
- ABORT_TRANSACTION; \
|
|
|
077c9d |
__asm__ __volatile__ \
|
|
|
077c9d |
("sc\n\t" \
|
|
|
077c9d |
"mfcr %0\n\t" \
|
|
|
077c9d |
diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall.S b/sysdeps/unix/sysv/linux/powerpc/syscall.S
|
|
|
077c9d |
index 2da9172..bbab613 100644
|
|
|
077c9d |
--- a/sysdeps/unix/sysv/linux/powerpc/syscall.S
|
|
|
077c9d |
+++ b/sysdeps/unix/sysv/linux/powerpc/syscall.S
|
|
|
077c9d |
@@ -18,7 +18,6 @@
|
|
|
077c9d |
#include <sysdep.h>
|
|
|
077c9d |
|
|
|
077c9d |
ENTRY (syscall)
|
|
|
077c9d |
- ABORT_TRANSACTION
|
|
|
077c9d |
mr r0,r3
|
|
|
077c9d |
mr r3,r4
|
|
|
077c9d |
mr r4,r5
|