Skip to contentSkip to conversation

selftests/powerpc: Transactional Memory

PATCH In review Rashmica Gupta 5 participants 11 messages Dec 1, 2015 – Dec 2, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover selftests/powerpc: Transactional Memory

This is reliant on the following patch series:
- selftests/powerpc by Michael Ellerman
- selftests/powerpc by Michael Neuling
- powerpc/tm by Michael Neuling

Rashmica Gupta (3):
selftests/powerpc: Standardise TM calls selftests/powerpc: Add test for forking inside transaction selftests/powerpc: Add in check for TM

 tools/testing/selftests/powerpc/tm/.gitignore      |  1 +
 tools/testing/selftests/powerpc/tm/Makefile        |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c       | 41 ++++++++++++++++++++++
 .../testing/selftests/powerpc/tm/tm-resched-dscr.c | 18 +++++-----
 .../testing/selftests/powerpc/tm/tm-signal-stack.c |  4 +--
 5 files changed, 53 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/3 selftests/powerpc: Standardise TM calls

Currently tbegin, tend etc are written as opcodes or asm instructions. So standardise these to asm instructions.

---
 tools/testing/selftests/powerpc/tm/tm-resched-dscr.c | 16 ++++++----------
 tools/testing/selftests/powerpc/tm/tm-signal-stack.c |  4 ++--
 2 files changed, 8 insertions(+), 12 deletions(-)
tools/testing/selftests/powerpc/tm/tm-resched-dscr.c +6 -10
index 42d4c8caad81..88c46481e59b 100644
@@ -29,12 +29,8 @@
 #include <asm/tm.h>
 
 #include "utils.h"
+#include "tm.h"
 
-#define TBEGIN          ".long 0x7C00051D ;"
-#define TEND            ".long 0x7C00055D ;"
-#define TCHECK          ".long 0x7C00059C ;"
-#define TSUSPEND        ".long 0x7C0005DD ;"
-#define TRESUME         ".long 0x7C2005DD ;"
 #define SPRN_TEXASR     0x82
 #define SPRN_DSCR       0x03
 
@@ -52,13 +48,13 @@ int test_body(void)
 			"mtspr   %[sprn_dscr], 3;"
 
 			/* start and suspend a transaction */
-			TBEGIN
+			"tbegin.;"
 			"beq     1f;"
-			TSUSPEND
+			"tsuspend.;"
 
 			/* hard loop until the transaction becomes doomed */
 			"2: ;"
-			TCHECK
+			"tcheck 0;"
 			"bc      4, 0, 2b;"
 
 			/* record DSCR and TEXASR */
@@ -67,8 +63,8 @@ int test_body(void)
 			"mfspr   3, %[sprn_texasr];"
 			"std     3, %[texasr];"
 
-			TRESUME
-			TEND
+			"tresume.;"
+			"tend.;"
 			"li      %[rv], 0;"
 			"1: ;"
 			: [rv]"=r"(rv), [dscr2]"=m"(dscr2), [texasr]"=m"(texasr)
tools/testing/selftests/powerpc/tm/tm-signal-stack.c +2 -2
index 82c29cb222dc..8ffd5cee7271 100644
@@ -60,9 +60,9 @@ int tm_signal_stack()
 		exit(1);
 	asm volatile("li 1, 0 ;"		/* stack ptr == NULL */
 		     "1:"
-		     ".long 0x7C00051D ;"	/* tbegin */
+		     "tbegin.;"
 		     "beq 1b ;"			/* retry forever */
-		     ".long 0x7C0005DD ; ;"	/* tsuspend */
+		     "tsuspend.;"	
 		     "ld 2, 0(1) ;"		/* trigger segv" */
 		     : : : "memory");
 
Signature · 1 line
2.5.0
#2 lore raw

Re: [PATCH 1/3] selftests/powerpc: Standardise TM calls

Quoted 2 lines · Rashmica Gupta

Currently tbegin, tend etc are written as opcodes or asm instructions. So standardise these to asm instructions.

I think the asm instructions can be used with only newer versions of GCC. But not sure, does it work with the older gcc as well ?

#3 lore raw

Re: [PATCH 1/3] selftests/powerpc: Standardise TM calls

Quoted 6 lines · Anshuman Khandual
Quoted 2 lines · Rashmica Gupta

Currently tbegin, tend etc are written as opcodes or asm instructions. So standardise these to asm instructions.

I think the asm instructions can be used with only newer versions of GCC. But not sure, does it work with the older gcc as well ?

No they don't work with all versions of GCC.

The HTM instructions were added in 4.9 AFAICS, but also backported to 4.8. That seems old enough to me.

Also we have another test (tm-syscall) which is already using the tbegin instruction, and no one has complained, so I don't think anyone is trying to build the selftests with really old compilers.

cheers

#4 lore raw

Re: [PATCH 1/3] selftests/powerpc: Standardise TM calls

Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Anshuman Khandual
Quoted 6 lines · Rashmica Gupta
Quoted 2 lines
Quoted 2 lines

Currently tbegin, tend etc are written as opcodes or asm instructions. So standardise these to asm instructions.

I think the asm instructions can be used with only newer versions of GCC. But not sure, does it work with the older gcc as well ?

Quoted 8 lines

No they don't work with all versions of GCC.

The HTM instructions were added in 4.9 AFAICS, but also backported to 4.8. That seems old enough to me.

Also we have another test (tm-syscall) which is already using the tbegin instruction, and no one has complained, so I don't think anyone is trying to build the selftests with really old compilers.

Its only a concern if you try to build these self tests on some older distro. But then some other self tests dont build there because of lack of newer compiler options. Its generic problem not something specific to this test.

#5 lore raw

PATCH 2/3 selftests/powerpc: Add test for forking inside transaction

In reply to Rashmica Gupta

This test does a fork syscall inside a transaction. Basic sniff test to see if we can enter the kernel during a transaction.

---
 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c  | 41 +++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c
tools/testing/selftests/powerpc/tm/.gitignore +1 -0
index e6668217ccd0..d0c7c97e9b13 100644
@@ -2,3 +2,4 @@ tm-resched-dscr
 tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
+tm-fork
tools/testing/selftests/powerpc/tm/Makefile +1 -1
index 578572a3700a..f7d4727662aa 100644
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-fork
 
 all: $(TEST_PROGS)
 
tools/testing/selftests/powerpc/tm/tm-fork.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.5.0
#6 lore raw

Re: [PATCH 2/3] selftests/powerpc: Add test for forking inside transaction

Quoted 4 lines · Rashmica Gupta
tools/testing/selftests/powerpc/tm/tm-fork.c new file +4 -0
+int test_fork(void)
+{
+	SKIP_IF(!have_htm());
+

tools/testing/selftests/powerpc/tm/tm-fork.c line 33

Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-fork.c new file +10 -0
+	asm __volatile__(
+		"tbegin.;"
+		"blt    1f; "
+		"li     0, 2;"  /* fork syscall */
+		"sc  ;"
+		"tend.;"
+		"1: ;"
+		: : : "memory", "r0");
+	/* If we reach here, we've passed.  Otherwise we've probably crashed
+	 * the kernel */

The transaction inside the parent process will abort. What is expected inside the child process ? Why should the kernel crash ?

author
#7 lore raw

Re: [PATCH 2/3] selftests/powerpc: Add test for forking inside transaction

As far as I'm aware, the kernel used to crash when forking inside a transaction (see powerpc/tm: Fix crash when forking inside a transaction). So this is to check that the transaction aborts rather than your whole kernel crashing.

Quoted 19 lines · Anshuman Khandual
Quoted 4 lines · Rashmica Gupta
tools/testing/selftests/powerpc/tm/tm-fork.c new file +4 -0
+int test_fork(void)
+{
+	SKIP_IF(!have_htm());
+

tools/testing/selftests/powerpc/tm/tm-fork.c line 33

Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-fork.c new file +10 -0
+	asm __volatile__(
+		"tbegin.;"
+		"blt    1f; "
+		"li     0, 2;"  /* fork syscall */
+		"sc  ;"
+		"tend.;"
+		"1: ;"
+		: : : "memory", "r0");
+	/* If we reach here, we've passed.  Otherwise we've probably crashed
+	 * the kernel */

The transaction inside the parent process will abort. What is expected inside the child process ? Why should the kernel crash ?

#8 lore raw

Re: [PATCH 2/3] selftests/powerpc: Add test for forking inside transaction

In reply to Rashmica Gupta
Quoted 3 lines · Rashmica Gupta

This test does a fork syscall inside a transaction. Basic sniff test to see
if we can enter the kernel during a transaction.

Can you add this description to the top of the test case as well?

Mikey

Quoted 82 lines

=20

---
 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c  | 41
+++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c

=20

tools/testing/selftests/powerpc/tm/.gitignore +1 -0
index e6668217ccd0..d0c7c97e9b13 100644
@@ -2,3 +2,4 @@ tm-resched-dscr
 tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
+tm-fork
tools/testing/selftests/powerpc/tm/Makefile +1 -3
index 578572a3700a..f7d4727662aa 100644
@@ -1,4 +1,4 @@
-TEST_PROGS :=3D tm-resched-dscr tm-syscall tm-signal-msr-resv tm
-signal-stack
+TEST_PROGS :=3D tm-resched-dscr tm-syscall tm-signal-msr-resv tm
-signal-stack tm-fork

=20
all: $(TEST_PROGS)
=20

tools/testing/selftests/powerpc/tm/tm-fork.c new file +32 -0
new file mode 100644
index 000000000000..f571a48a59a0
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Edited: Rashmica Gupta, Nov 2015
+ *
+ * Fork inside a transaction
+ */
+
+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "utils.h"
+#include "tm.h"
+
+int test_fork(void)
+{
+	SKIP_IF(!have_htm());
+
+	asm __volatile__(
+		"tbegin.;"
+		"blt    1f; "
+		"li     0, 2;"  /* fork syscall */
+		"sc  ;"
+		"tend.;"
+		"1: ;"
+		: : : "memory", "r0");
+	/* If we reach here, we've passed.  Otherwise we've probably

crashed

tools/testing/selftests/powerpc/tm/tm-fork.c new file +9 -0
+	 * the kernel */
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	return test_harness(test_fork, "tm_fork");
+}
#9 lore raw

PATCH 3/3 selftests/powerpc: Add in check for TM

In reply to Rashmica Gupta

The resched-dscr test does not currently check for TM, so add in check.

---
 tools/testing/selftests/powerpc/tm/tm-resched-dscr.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/powerpc/tm/tm-resched-dscr.c +2 -0
index 88c46481e59b..8243558aac6c 100644
@@ -38,6 +38,8 @@ int test_body(void)
 {
 	uint64_t rv, dscr1 = 1, dscr2, texasr;
 
+	SKIP_IF(!have_htm());
+
 	printf("Check DSCR TM context switch: ");
 	fflush(stdout);
 	for (;;) {
Signature · 1 line
2.5.0
#10 lore raw
In reply to Rashmica Gupta
Quoted 4 lines · Rashmica Gupta

This is reliant on the following patch series:
- selftests/powerpc by Michael Ellerman
- selftests/powerpc by Michael Neuling
- powerpc/tm by Michael Neuling

Could you provide the full titles of the patch series? (Links to patchwork.ozlabs.org are good too.)

Andrew

Signature · 3 lines
Andrew Donnellan              Software Engineer, OzLabs
[email protected]  Australia Development Lab, Canberra
+61 2 6201 8874 (work)        IBM Australia Limited