Skip to contentSkip to conversation

powerpc/tm: Abort syscalls in active transactions

PATCH Superseded Sam Bobroff 4 participants 13 messages Mar 19, 2015 – Mar 30, 2015

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover powerpc/tm: Abort syscalls in active transactions

See the first patch for a description of the reasoning behind this change.

This set includes the change, a kernel selftest for it and some slight refactoring of the selftest code.

Sam Bobroff (3):
powerpc/tm: Abort syscalls in active transactions selftests/powerpc: Move get_auxv_entry() to harness.c selftests/powerpc: Add transactional syscall test

 Documentation/powerpc/transactional_memory.txt  |   33 +++----
 arch/powerpc/include/uapi/asm/tm.h              |    2 +-
 arch/powerpc/kernel/entry_64.S                  |   19 ++++
 tools/testing/selftests/powerpc/harness.c       |   47 ++++++++++
 tools/testing/selftests/powerpc/pmu/lib.c       |   47 ----------
 tools/testing/selftests/powerpc/pmu/lib.h       |    1 -
 tools/testing/selftests/powerpc/tm/Makefile     |    3 +-
 tools/testing/selftests/powerpc/tm/tm-syscall.c |  113 +++++++++++++++++++++++
 tools/testing/selftests/powerpc/utils.h         |    2 +-
 9 files changed, 200 insertions(+), 67 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-syscall.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 powerpc/tm: Abort syscalls in active transactions

This patch changes the syscall handler to doom (tabort) active transactions when a syscall is made and return immediately without performing the syscall.

Currently, the system call instruction automatically suspends an active transaction which causes side effects to persist when an active transaction fails.

This does change the kernel's behaviour, but in a way that was documented as unsupported. It doesn't reduce functionality because syscalls will still be performed after tsuspend. It also provides a consistent interface and makes the behaviour of user code substantially the same across powerpc and platforms that do not support suspended transactions (e.g. x86 and s390).

Performance measurements using
http://ozlabs.org/~anton/junkcode/null_syscall.c
indicate the cost of a system call increases by about 0.5%.

---
 Documentation/powerpc/transactional_memory.txt |   33 ++++++++++++------------
 arch/powerpc/include/uapi/asm/tm.h             |    2 +-
 arch/powerpc/kernel/entry_64.S                 |   19 ++++++++++++++
 3 files changed, 37 insertions(+), 17 deletions(-)
Documentation/powerpc/transactional_memory.txt +17 -16
index 9791e98..4167bc2 100644
@@ -74,22 +74,23 @@ Causes of transaction aborts
 Syscalls
 ========
 
-Performing syscalls from within transaction is not recommended, and can lead
-to unpredictable results.
-
-Syscalls do not by design abort transactions, but beware: The kernel code will
-not be running in transactional state.  The effect of syscalls will always
-remain visible, but depending on the call they may abort your transaction as a
-side-effect, read soon-to-be-aborted transactional data that should not remain
-invisible, etc.  If you constantly retry a transaction that constantly aborts
-itself by calling a syscall, you'll have a livelock & make no progress.
-
-Simple syscalls (e.g. sigprocmask()) "could" be OK.  Even things like write()
-from, say, printf() should be OK as long as the kernel does not access any
-memory that was accessed transactionally.
-
-Consider any syscalls that happen to work as debug-only -- not recommended for
-production use.  Best to queue them up till after the transaction is over.
+Syscalls made from within an active transaction will not be performed and the
+transaction will be doomed by the kernel with the failure code TM_CAUSE_SYSCALL
+| TM_CAUSE_PERSISTENT.
+
+Syscalls made from within a suspended transaction are performed as normal and
+the transaction is not explicitly doomed by the kernel.  However, what the
+kernel does to perform the syscall may result in the transaction being doomed
+by the hardware.  The syscall is performed in suspended mode so any side
+effects will be persistent, independent of transaction success or failure.  No
+guarantees are provided by the kernel about which syscalls will affect
+transaction success.
+
+Care must be taken when relying on syscalls to abort during active transactions
+if the calls are made via a library.  Libraries may cache values (which may
+give the appearence of success) or perform operations that cause transaction
+failure before entering the kernel (which may produce different failure codes).
+Examples are glibc's getpid() and lazy symbol resolution.
 
 
 Signals
arch/powerpc/include/uapi/asm/tm.h +1 -1
index 5d836b7..5047659 100644
@@ -11,7 +11,7 @@
 #define TM_CAUSE_RESCHED	0xde
 #define TM_CAUSE_TLBI		0xdc
 #define TM_CAUSE_FAC_UNAV	0xda
-#define TM_CAUSE_SYSCALL	0xd8  /* future use */
+#define TM_CAUSE_SYSCALL	0xd8
 #define TM_CAUSE_MISC		0xd6  /* future use */
 #define TM_CAUSE_SIGNAL		0xd4
 #define TM_CAUSE_ALIGNMENT	0xd2
arch/powerpc/kernel/entry_64.S +19 -0
index d180caf2..85bf81d 100644
@@ -34,6 +34,7 @@
 #include <asm/ftrace.h>
 #include <asm/hw_irq.h>
 #include <asm/context_tracking.h>
+#include <asm/tm.h>
 
 /*
  * System calls.
@@ -145,6 +146,24 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
 	andi.	r11,r10,_TIF_SYSCALL_DOTRACE
 	bne	syscall_dotrace
 .Lsyscall_dotrace_cont:
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+BEGIN_FTR_SECTION
+	b	1f
+END_FTR_SECTION_IFCLR(CPU_FTR_TM)
+	extrdi.	r11, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */
+	beq+	1f
+
+	/* Doom the transaction and don't perform the syscall: */
+	mfmsr	r11
+	li	r12, 1
+	rldimi	r11, r12, MSR_TM_LG, 63-MSR_TM_LG
+	mtmsrd	r11, 0
+	li	r11, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
+	tabort. r11
+
+	b	.Lsyscall_exit
+1:
+#endif
 	cmpldi	0,r0,NR_syscalls
 	bge-	syscall_enosys
 
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 2/3 selftests/powerpc: Move get_auxv_entry() to harness.c

In reply to Sam Bobroff

Move get_auxv_entry() from pmu/lib.c up to harness.c in order to make it available to other tests.

---
 tools/testing/selftests/powerpc/harness.c |   47 +++++++++++++++++++++++++++++
 tools/testing/selftests/powerpc/pmu/lib.c |   47 -----------------------------
 tools/testing/selftests/powerpc/pmu/lib.h |    1 -
 tools/testing/selftests/powerpc/utils.h   |    2 +-
 4 files changed, 48 insertions(+), 49 deletions(-)
tools/testing/selftests/powerpc/harness.c +47 -0
index 8ebc58a..f7997af 100644
@@ -11,6 +11,10 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <elf.h>
+#include <fcntl.h>
+#include <link.h>
+#include <sys/stat.h>
 
 #include "subunit.h"
 #include "utils.h"
@@ -112,3 +116,46 @@ int test_harness(int (test_function)(void), char *name)
 
 	return rc;
 }
+
+static char auxv[4096];
+
+void *get_auxv_entry(int type)
+{
+	ElfW(auxv_t) *p;
+	void *result;
+	ssize_t num;
+	int fd;
+
+	fd = open("/proc/self/auxv", O_RDONLY);
+	if (fd == -1) {
+		perror("open");
+		return NULL;
+	}
+
+	result = NULL;
+
+	num = read(fd, auxv, sizeof(auxv));
+	if (num < 0) {
+		perror("read");
+		goto out;
+	}
+
+	if (num > sizeof(auxv)) {
+		printf("Overflowed auxv buffer\n");
+		goto out;
+	}
+
+	p = (ElfW(auxv_t) *)auxv;
+
+	while (p->a_type != AT_NULL) {
+		if (p->a_type == type) {
+			result = (void *)p->a_un.a_val;
+			break;
+		}
+
+		p++;
+	}
+out:
+	close(fd);
+	return result;
+}
tools/testing/selftests/powerpc/pmu/lib.c +0 -47

60 lines not on this page · raw message

tools/testing/selftests/powerpc/pmu/lib.h +0 -1
index 0f0339c..ca5d72a 100644
@@ -29,7 +29,6 @@ extern int notify_parent(union pipe write_pipe);
 extern int notify_parent_of_error(union pipe write_pipe);
 extern pid_t eat_cpu(int (test_function)(void));
 extern bool require_paranoia_below(int level);
-extern void *get_auxv_entry(int type);
 
 struct addr_range {
 	uint64_t first, last;
tools/testing/selftests/powerpc/utils.h +1 -1
index a93777a..64f53cd 100644
@@ -19,7 +19,7 @@ typedef uint8_t u8;
 
 
 int test_harness(int (test_function)(void), char *name);
-
+extern void *get_auxv_entry(int type);
 
 /* Yes, this is evil */
 #define FAIL_IF(x)						\
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 3/3 selftests/powerpc: Add transactional syscall test

In reply to Sam Bobroff

Check that a syscall made during an active transaction will fail with the correct failure code and that one made during a suspended transaction will succeed.

---
 tools/testing/selftests/powerpc/tm/Makefile     |    3 +-
 tools/testing/selftests/powerpc/tm/tm-syscall.c |  113 +++++++++++++++++++++++
 2 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-syscall.c
tools/testing/selftests/powerpc/tm/Makefile +2 -1
index 2cede23..d8dab0d 100644
@@ -1,4 +1,5 @@
-PROGS := tm-resched-dscr
+PROGS := tm-resched-dscr tm-syscall
+CFLAGS:=$(CFLAGS) -mhtm -Wl,-z,now
 
 all: $(PROGS)
 
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
1.7.10.4
Acked-by on v1 1/3
#2 lore raw
In reply to Sam Bobroff
Quoted 19 lines · Sam Bobroff

This patch changes the syscall handler to doom (tabort) active transactions when a syscall is made and return immediately without performing the syscall.
=20
Currently, the system call instruction automatically suspends an active transaction which causes side effects to persist when an active transaction fails.
=20
This does change the kernel's behaviour, but in a way that was documented as unsupported. It doesn't reduce functionality because syscalls will still be performed after tsuspend. It also provides a consistent interface and makes the behaviour of user code substantially the same across powerpc and platforms that do not support suspended transactions (e.g. x86 and s390).
=20
Performance measurements using
http://ozlabs.org/~anton/junkcode/null_syscall.c
indicate the cost of a system call increases by about 0.5%. =20

Quoted 1 line

Thanks Sam!

Quoted 2 lines

---
Documentation/powerpc/transactional_memory.txt | 33 ++++++++++++------=

------

Documentati=

Quoted 5 lines
 arch/powerpc/include/uapi/asm/tm.h             |    2 +-
 arch/powerpc/kernel/entry_64.S                 |   19 ++++++++++++++
 3 files changed, 37 insertions(+), 17 deletions(-)

=20

Documentati= renamed from Documentation/powerpc/transactional_memory.txt +0 -0

on/powerpc/transactional_memory.txt

Quoted 8 lines

index 9791e98..4167bc2 100644

Documentation/powerpc/transactional_memory.txt +0 -0
@@ -74,22 +74,23 @@ Causes of transaction aborts
 Syscalls
 =3D=3D=3D=3D=3D=3D=3D=3D

=20
-Performing syscalls from within transaction is not recommended, and can =

lead

Documentation/powerpc/transactional_memory.txt Causes of transaction aborts

Quoted 3 lines
Documentation/powerpc/transactional_memory.txt +0 -3
-to unpredictable results.
-
-Syscalls do not by design abort transactions, but beware: The kernel cod=

e will

Quoted 1 line

-not be running in transactional state. The effect of syscalls will alwa=

ys

Quoted 1 line

-remain visible, but depending on the call they may abort your transactio=

n as a

Quoted 1 line

-side-effect, read soon-to-be-aborted transactional data that should not =

remain

Quoted 1 line

-invisible, etc. If you constantly retry a transaction that constantly a=

borts

Documentation/powerpc/transactional_memory.txt Causes of transaction aborts

Quoted 3 lines
Documentation/powerpc/transactional_memory.txt +0 -3
-itself by calling a syscall, you'll have a livelock & make no progress.
-
-Simple syscalls (e.g. sigprocmask()) "could" be OK.  Even things like wr=

ite()

Quoted 1 line

-from, say, printf() should be OK as long as the kernel does not access a=

ny

Documentation/powerpc/transactional_memory.txt Causes of transaction aborts

Quoted 3 lines
Documentation/powerpc/transactional_memory.txt +0 -3
-memory that was accessed transactionally.
-
-Consider any syscalls that happen to work as debug-only -- not recommend=

ed for

Quoted 1 line

-production use. Best to queue them up till after the transaction is ove=

r.

Quoted 1 line

+Syscalls made from within an active transaction will not be performed an=

d the

Quoted 1 line

+transaction will be doomed by the kernel with the failure code TM_CAUSE_=

SYSCALL

Documentation/powerpc/transactional_memory.txt

Quoted 3 lines

+| TM_CAUSE_PERSISTENT.

Documentation/powerpc/transactional_memory.txt +2 -0
+
+Syscalls made from within a suspended transaction are performed as norma=

l and

Quoted 1 line

+the transaction is not explicitly doomed by the kernel. However, what t=

he

Quoted 1 line

+kernel does to perform the syscall may result in the transaction being d=

oomed

Documentation/powerpc/transactional_memory.txt

Quoted 2 lines
Documentation/powerpc/transactional_memory.txt +2 -0
+by the hardware.  The syscall is performed in suspended mode so any side
+effects will be persistent, independent of transaction success or failur=

e. No

Documentation/powerpc/transactional_memory.txt Causes of transaction aborts

Quoted 4 lines
Documentation/powerpc/transactional_memory.txt +4 -0
+guarantees are provided by the kernel about which syscalls will affect
+transaction success.
+
+Care must be taken when relying on syscalls to abort during active trans=

actions

Quoted 1 line

+if the calls are made via a library. Libraries may cache values (which =

may

Quoted 1 line

+give the appearence of success) or perform operations that cause transac=

tion

Quoted 1 line

+failure before entering the kernel (which may produce different failure =

codes).

arch/powerpc/include/ua=

Quoted 5 lines

+Examples are glibc's getpid() and lazy symbol resolution. =20
=20
Signals

arch/powerpc/include/ua= renamed from arch/powerpc/include/uapi/asm/tm.h +0 -0

pi/asm/tm.h

arch/powerpc/kernel/entry_6=

Quoted 13 lines

index 5d836b7..5047659 100644

arch/powerpc/include/uapi/asm/tm.h +1 -1
@@ -11,7 +11,7 @@
 #define TM_CAUSE_RESCHED	0xde
 #define TM_CAUSE_TLBI		0xdc
 #define TM_CAUSE_FAC_UNAV	0xda
-#define TM_CAUSE_SYSCALL	0xd8  /* future use */
+#define TM_CAUSE_SYSCALL	0xd8
 #define TM_CAUSE_MISC		0xd6  /* future use */
 #define TM_CAUSE_SIGNAL		0xd4
 #define TM_CAUSE_ALIGNMENT	0xd2
arch/powerpc/kernel/entry_6= renamed from arch/powerpc/kernel/entry_64.S +0 -0

4.S

Quoted 36 lines

index d180caf2..85bf81d 100644

arch/powerpc/kernel/entry_64.S +1 -0
@@ -34,6 +34,7 @@
 #include <asm/ftrace.h>
 #include <asm/hw_irq.h>
 #include <asm/context_tracking.h>
+#include <asm/tm.h>

=20
/*
* System calls.

arch/powerpc/kernel/entry_64.S +18 -0
@@ -145,6 +146,24 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
 	andi.	r11,r10,_TIF_SYSCALL_DOTRACE
 	bne	syscall_dotrace
 .Lsyscall_dotrace_cont:
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+BEGIN_FTR_SECTION
+	b	1f
+END_FTR_SECTION_IFCLR(CPU_FTR_TM)
+	extrdi.	r11, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */
+	beq+	1f
+
+	/* Doom the transaction and don't perform the syscall: */
+	mfmsr	r11
+	li	r12, 1
+	rldimi	r11, r12, MSR_TM_LG, 63-MSR_TM_LG
+	mtmsrd	r11, 0
+	li	r11, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
+	tabort. r11
+
+	b	.Lsyscall_exit
+1:
+#endif
 	cmpldi	0,r0,NR_syscalls
 	bge-	syscall_enosys

=20

Tested-by on v1 1/3
#3 lore raw
In reply to Sam Bobroff
Quoted 15 lines · Sam Bobroff

This patch changes the syscall handler to doom (tabort) active transactions when a syscall is made and return immediately without performing the syscall.

Currently, the system call instruction automatically suspends an active transaction which causes side effects to persist when an active transaction fails.

This does change the kernel's behaviour, but in a way that was documented as unsupported. It doesn't reduce functionality because syscalls will still be performed after tsuspend. It also provides a consistent interface and makes the behaviour of user code substantially the same across powerpc and platforms that do not support suspended transactions (e.g. x86 and s390).

Quoted 3 lines

Performance measurements using
http://ozlabs.org/~anton/junkcode/null_syscall.c
indicate the cost of a system call increases by about 0.5%.

Performance test results verified which shows an improvement of around ~0.52% with the patch compared to without it.

[With patch] null_syscall: 757.59 cycles 100.00%
[Without patch]] null_syscall: 753.66 cycles 100.00%

Quoted 2 lines
#9 lore raw

Re: [PATCH 3/3] selftests/powerpc: Add transactional syscall test

In reply to Sam Bobroff
Quoted 5 lines · Sam Bobroff

Check that a syscall made during an active transaction will fail with the correct failure code and that one made during a suspended transaction will succeed.

The test works.

Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +7 -0
+
+int tm_syscall(void)
+{
+	SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM));
+	setbuf(stdout, 0);
+	FAIL_IF(!t_active_getppid_test());
+	printf("%d active transactions correctly aborted.\n", TM_TEST_RUNS);

tools/testing/selftests/powerpc/tm/tm-syscall.c line 113

Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +10 -0
+	FAIL_IF(!t_suspended_getppid_test());
+	printf("%d suspended transactions succeeded.\n", TM_TEST_RUNS);
+	return 0;
+}
+
+int main(void)
+{
+	return test_harness(tm_syscall, "tm_syscall");
+}
+

There is an extra blank line at the end of this file. Interchanging return codes of 0 and 1 for various functions make it very confusing along with negative FAIL_IF checks in the primary test function. Control flow structures like these can use some in-code documentation for readability.

+ for (i = 0; i < TM_RETRIES; i++) {
+ if (__builtin_tbegin(0)) {
+ getppid();
+ __builtin_tend(0);
+ return 1;
+ }
+ if (t_failure_persistent())
+ return 0;

or

+ if (__builtin_tbegin(0)) {
+ __builtin_tsuspend();
+ getppid();
+ __builtin_tresume();
+ __builtin_tend(0);
+ return 1;
+ }
+ if (t_failure_persistent())
+ return 0;

#10 lore raw

Re: [PATCH 3/3] selftests/powerpc: Add transactional syscall test

Quoted 8 lines · Anshuman Khandual
Quoted 5 lines · Sam Bobroff

Check that a syscall made during an active transaction will fail with the correct failure code and that one made during a suspended transaction will succeed.

The test works.

Great :-)

Quoted 35 lines
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +7 -0
+
+int tm_syscall(void)
+{
+	SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM));
+	setbuf(stdout, 0);
+	FAIL_IF(!t_active_getppid_test());
+	printf("%d active transactions correctly aborted.\n", TM_TEST_RUNS);

tools/testing/selftests/powerpc/tm/tm-syscall.c line 113

Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +10 -0
+	FAIL_IF(!t_suspended_getppid_test());
+	printf("%d suspended transactions succeeded.\n", TM_TEST_RUNS);
+	return 0;
+}
+
+int main(void)
+{
+	return test_harness(tm_syscall, "tm_syscall");
+}
+

There is an extra blank line at the end of this file. Interchanging return codes of 0 and 1 for various functions make it very confusing along with negative FAIL_IF checks in the primary test function. Control flow structures like these can use some in-code documentation for readability.

tools/testing/selftests/powerpc/tm/tm-syscall.c new file +8 -0
+	for (i = 0; i < TM_RETRIES; i++) {
+		if (__builtin_tbegin(0)) {
+			getppid();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;

or

tools/testing/selftests/powerpc/tm/tm-syscall.c line 82

Quoted 9 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +9 -0
+		if (__builtin_tbegin(0)) {
+			__builtin_tsuspend();
+			getppid();
+			__builtin_tresume();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;

Good points. I'll remove the blank line and comment the code.

I'm not sure I can do any better with the FAIL_IF() macro: I wanted it to read "fail if the test failed", but I can see what you mean about a double negative. Maybe it would be better to introduce a different macro, more like a standard assert: TEST(XXX) which fails if XXX is false. However, I think "TEST" would be too generic a name and I'm not should what would be better. Any comments/suggestions?

Thanks for the review!

Cheers,
Sam.

#11 lore raw

Re: [PATCH 3/3] selftests/powerpc: Add transactional syscall test

Quoted 59 lines · Sam Bobroff
Quoted 8 lines · Anshuman Khandual
Quoted 5 lines · Sam Bobroff

Check that a syscall made during an active transaction will fail with the correct failure code and that one made during a suspended transaction will succeed.

The test works.

Great :-)

Quoted 35 lines
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +7 -0
+
+int tm_syscall(void)
+{
+	SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM));
+	setbuf(stdout, 0);
+	FAIL_IF(!t_active_getppid_test());
+	printf("%d active transactions correctly aborted.\n", TM_TEST_RUNS);

tools/testing/selftests/powerpc/tm/tm-syscall.c line 113

Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +10 -0
+	FAIL_IF(!t_suspended_getppid_test());
+	printf("%d suspended transactions succeeded.\n", TM_TEST_RUNS);
+	return 0;
+}
+
+int main(void)
+{
+	return test_harness(tm_syscall, "tm_syscall");
+}
+

There is an extra blank line at the end of this file. Interchanging return codes of 0 and 1 for various functions make it very confusing along with negative FAIL_IF checks in the primary test function. Control flow structures like these can use some in-code documentation for readability.

tools/testing/selftests/powerpc/tm/tm-syscall.c new file +8 -0
+	for (i = 0; i < TM_RETRIES; i++) {
+		if (__builtin_tbegin(0)) {
+			getppid();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;

or

tools/testing/selftests/powerpc/tm/tm-syscall.c line 82

Quoted 9 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +9 -0
+		if (__builtin_tbegin(0)) {
+			__builtin_tsuspend();
+			getppid();
+			__builtin_tresume();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;

Good points. I'll remove the blank line and comment the code.

Quoted 6 lines

I'm not sure I can do any better with the FAIL_IF() macro: I wanted it to read "fail if the test failed", but I can see what you mean about a double negative. Maybe it would be better to introduce a different macro, more like a standard assert: TEST(XXX) which fails if XXX is false. However, I think "TEST" would be too generic a name and I'm not should what would be better. Any comments/suggestions?

FAIL_IF() is designed for things that return 0 for OK and !0 for failure. Like most things in C.

So I think it would be improved if you inverted your return codes in your test routines.

Even better to return ESOMETHING in the error cases, and zero otherwise.

cheers

#4 lore raw
In reply to Anshuman Khandual
Quoted 20 lines · Anshuman Khandual
Quoted 15 lines · Sam Bobroff

This patch changes the syscall handler to doom (tabort) active transactions when a syscall is made and return immediately without performing the syscall.

Currently, the system call instruction automatically suspends an active transaction which causes side effects to persist when an active transaction fails.

This does change the kernel's behaviour, but in a way that was documented as unsupported. It doesn't reduce functionality because syscalls will still be performed after tsuspend. It also provides a consistent interface and makes the behaviour of user code substantially the same across powerpc and platforms that do not support suspended transactions (e.g. x86 and s390).

Quoted 3 lines

Performance measurements using
http://ozlabs.org/~anton/junkcode/null_syscall.c
indicate the cost of a system call increases by about 0.5%.

Quoted 5 lines

Performance test results verified which shows an improvement of around ~0.52% with the patch compared to without it.

[With patch] null_syscall: 757.59 cycles 100.00%
[Without patch]] null_syscall: 753.66 cycles 100.00%

No that's a performance *decrease* with the patch applied. ?

cheers

#5 lore raw
Quoted 21 lines · Michael Ellerman
Quoted 20 lines · Anshuman Khandual
Quoted 18 lines · Sam Bobroff

This patch changes the syscall handler to doom (tabort) active transactions when a syscall is made and return immediately without performing the syscall.

Currently, the system call instruction automatically suspends an active transaction which causes side effects to persist when an active transaction fails.

This does change the kernel's behaviour, but in a way that was documented as unsupported. It doesn't reduce functionality because syscalls will still be performed after tsuspend. It also provides a consistent interface and makes the behaviour of user code substantially the same across powerpc and platforms that do not support suspended transactions (e.g. x86 and s390).

Performance measurements using
http://ozlabs.org/~anton/junkcode/null_syscall.c
indicate the cost of a system call increases by about 0.5%.

Quoted 7 lines
Quoted 5 lines

Performance test results verified which shows an improvement of around ~0.52% with the patch compared to without it.

[With patch] null_syscall: 757.59 cycles 100.00%
[Without patch]] null_syscall: 753.66 cycles 100.00%

No that's a performance *decrease* with the patch applied. ?

Micheal, thats true. The cycle counts are more with patch being applied. Here are some more results on mainline.

Without the patch:

        null_syscall:     754.14 cycles     100.00%
        null_syscall:     754.50 cycles     100.00%
        null_syscall:     754.17 cycles     100.00%
        null_syscall:     754.43 cycles     100.00%
        null_syscall:     754.17 cycles     100.00%
        null_syscall:     754.20 cycles     100.00%
        null_syscall:     754.47 cycles     100.00%
        null_syscall:     754.70 cycles     100.00%
        null_syscall:     754.43 cycles     100.00%
        null_syscall:     753.72 cycles     100.00%

With the patch:

        null_syscall:     756.76 cycles     100.00%
        null_syscall:     756.40 cycles     100.00%
        null_syscall:     756.46 cycles     100.00%
        null_syscall:     756.86 cycles     100.00%
        null_syscall:     756.56 cycles     100.00%
        null_syscall:     756.66 cycles     100.00%
        null_syscall:     756.86 cycles     100.00%
        null_syscall:     756.86 cycles     100.00%
        null_syscall:     757.02 cycles     100.00%
        null_syscall:     756.93 cycles     100.00%
#6 lore raw
Quoted 25 lines · Anshuman Khandual
Quoted 24 lines · Michael Ellerman
Quoted 23 lines · Anshuman Khandual
Quoted 15 lines · Sam Bobroff

This patch changes the syscall handler to doom (tabort) active transactions when a syscall is made and return immediately without performing the syscall.

Currently, the system call instruction automatically suspends an active transaction which causes side effects to persist when an active transaction fails.

This does change the kernel's behaviour, but in a way that was documented as unsupported. It doesn't reduce functionality because syscalls will still be performed after tsuspend. It also provides a consistent interface and makes the behaviour of user code substantially the same across powerpc and platforms that do not support suspended transactions (e.g. x86 and s390).

Quoted 3 lines

Performance measurements using
http://ozlabs.org/~anton/junkcode/null_syscall.c
indicate the cost of a system call increases by about 0.5%.

Performance test results verified which shows an improvement of around ~0.52% with the patch compared to without it.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

[With patch] null_syscall: 757.59 cycles 100.00%
[Without patch]] null_syscall: 753.66 cycles 100.00%

No that's a performance *decrease* with the patch applied. ?

Micheal, thats true. The cycle counts are more with patch being applied. Here are some more results on mainline.

Right, more cycles == worse :)

But it's not much more so we'll merge it.

cheers

#12 lore raw

Re: [PATCH 3/3] selftests/powerpc: Add transactional syscall test

In reply to Michael Ellerman
Quoted 70 lines · Michael Ellerman
Quoted 59 lines · Sam Bobroff
Quoted 8 lines · Anshuman Khandual
Quoted 5 lines · Sam Bobroff

Check that a syscall made during an active transaction will fail with the correct failure code and that one made during a suspended transaction will succeed.

The test works.

Great :-)

Quoted 35 lines
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +7 -0
+
+int tm_syscall(void)
+{
+	SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM));
+	setbuf(stdout, 0);
+	FAIL_IF(!t_active_getppid_test());
+	printf("%d active transactions correctly aborted.\n", TM_TEST_RUNS);

tools/testing/selftests/powerpc/tm/tm-syscall.c line 113

Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +10 -0
+	FAIL_IF(!t_suspended_getppid_test());
+	printf("%d suspended transactions succeeded.\n", TM_TEST_RUNS);
+	return 0;
+}
+
+int main(void)
+{
+	return test_harness(tm_syscall, "tm_syscall");
+}
+

There is an extra blank line at the end of this file. Interchanging return codes of 0 and 1 for various functions make it very confusing along with negative FAIL_IF checks in the primary test function. Control flow structures like these can use some in-code documentation for readability.

tools/testing/selftests/powerpc/tm/tm-syscall.c new file +8 -0
+	for (i = 0; i < TM_RETRIES; i++) {
+		if (__builtin_tbegin(0)) {
+			getppid();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;

or

tools/testing/selftests/powerpc/tm/tm-syscall.c line 82

Quoted 9 lines
tools/testing/selftests/powerpc/tm/tm-syscall.c new file +9 -0
+		if (__builtin_tbegin(0)) {
+			__builtin_tsuspend();
+			getppid();
+			__builtin_tresume();
+			__builtin_tend(0);
+			return 1;
+		}
+		if (t_failure_persistent())
+			return 0;

Good points. I'll remove the blank line and comment the code.

Quoted 6 lines

I'm not sure I can do any better with the FAIL_IF() macro: I wanted it to read "fail if the test failed", but I can see what you mean about a double negative. Maybe it would be better to introduce a different macro, more like a standard assert: TEST(XXX) which fails if XXX is false. However, I think "TEST" would be too generic a name and I'm not should what would be better. Any comments/suggestions?

FAIL_IF() is designed for things that return 0 for OK and !0 for failure. Like most things in C.

Quoted 6 lines

So I think it would be improved if you inverted your return codes in your test routines.

Even better to return ESOMETHING in the error cases, and zero otherwise.

cheers

Fair enough. I think the *_test() functions I added for "clarity" were just making it more confusing, so I've dropped them.

Moving the code around, even a little, has also exposed the fact that transactions are very sensitive to how the code is compiled so I'm going to move the transaction blocks out into a separate assembly file where I can control exactly what instructions get used. This will also mean that it's no longer dependent on using linker magic (or some other trick) to avoid lazy symbol loading.

I'll repost the series.

Thanks for the review!

Cheers,
Sam.