selftests/powerpc: Add test to check if TAR is corrupted
PATCH 1/1 selftests/powerpc: Add test to check if TAR is corrupted
If the transaction is aborted, the TAR should be rolled back to the checkpointed value before the transaction began.
---
To check this yourself, undo the changes from the patch "powerpc/tm: Fix context switching TAR, PPR and DSCR SPRs".
tools/testing/selftests/powerpc/tm/.gitignore | 1 + tools/testing/selftests/powerpc/tm/Makefile | 2 +- tools/testing/selftests/powerpc/tm/tm-tar.c | 90 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c
tools/testing/selftests/powerpc/tm/.gitignore +1 -0
@@ -4,3 +4,4 @@ tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr +tm-tar
tools/testing/selftests/powerpc/tm/Makefile +1 -1
@@ -1,4 +1,4 @@ -TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr +TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr tm-tar all: $(TEST_PROGS)
tools/testing/selftests/powerpc/tm/tm-tar.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
2.5.0
Quoted 2 lines · Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the checkpointed value before the transaction began.
And if it does not abort, it should continue to hold the changed (inside the transaction) TAR value after the transaction finishes. The test here does check for both these cases and hence the commit message should reflect that as well. This test can also accommodate checks for PPR and DSCR register in one go.
In the TM ptrace patch series (https://lkml.org/lkml/2015/10/8/522)
which is still under review, there are couple of tests related to (TAR, PPR, DSCR) registers with (TM running & TM suspended) and without TM. There, the values are being checked using ptrace interface instead. Can you please check them and just make sure that we are not duplicating anything here.
Quoted 37 lines
Signed-off-by Rashmica Gupta <[email protected]>---
To check this yourself, undo the changes from the patch "powerpc/tm: Fix context switching TAR, PPR and DSCR SPRs".tools/testing/selftests/powerpc/tm/.gitignore | 1 + tools/testing/selftests/powerpc/tm/Makefile | 2 +- tools/testing/selftests/powerpc/tm/tm-tar.c | 90 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.ctools/testing/selftests/powerpc/tm/.gitignore +1
-0@@ -4,3 +4,4 @@ tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr +tm-tartools/testing/selftests/powerpc/tm/Makefile +1
-1@@ -1,4 +1,4 @@ -TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr +TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr tm-tar all: $(TEST_PROGS)tools/testing/selftests/powerpc/tm/tm-tar.c new file +0
-0
tools/testing/selftests/powerpc/tm/tm-tar.c line 7
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +7
-0@@ -0,0 +1,90 @@ +/* +* Copyright 2015, Michael Neuling, IBM Corp. +* Licensed under GPLv2. +* Original: Michael Neuling 19/7/2013 +* Edited: Rashmica Gupta 01/12/2015 +* +* Do some transactions, see if the tar is corrupted.
It can use a better explanation here.
Quoted 17 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +17
-0+* +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include "tm.h" +#include "utils.h" + +#define SPRN_TAR 0x32f + +int num_loops =10000 ; + +int test_tar (void ) +{
tools/testing/selftests/powerpc/tm/tm-tar.c line 34
Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +10
-0+int i; + +SKIP_IF (!have_htm ()); + +for (i =0 ; i < num_loops; i++) + { +uint64_t result =0 ; + asm __volatile__( +"li 7, 1;" + "mtspr %[tar], 7;" // tar = 1
Please use /* */ kind of comment sections not //.
tools/testing/selftests/powerpc/tm/tm-tar.c line 38
Quoted 4 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +4
-0+"tbegin.;" +"beq 3f;" +"li 4, 0x7000;" // Loop lots, to use time +"2:;" // Start loop
Here as well.
Quoted 18 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +18
-0+"li 7, 2;" +"mtspr %[tar], 7;" // tar = 2 +"tsuspend.;" +"li 7, 3;" +"mtspr %[tar], 7;" // tar = 3 +"tresume.;" +"subi 4, 4, 1;" +"cmpdi 4, 0;" +"bne 2b;" +"tend.;" + +// Transaction sucess! TAR should be 3. +"mfspr 7, %[tar];" +"ori %[res], 7, 4;" // res = 3|4 = 7 +"b 4f;" + +// Abort handler. TAR should be rolled back to 1. +"3:;"
tools/testing/selftests/powerpc/tm/tm-tar.c line 66
Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +10
-0+"mfspr 7, %[tar];" +"ori %[res], 7, 8;" // res = 1|8 = 9 +"4:;" + + : [res]"=r"(result) + : [tar]"i"(SPRN_TAR) + : "memory", "r0", "r4", "r7"); + +// If result is anything else other than 7 or 9, the tar +// value must have been corrupted.
Here as well.
tools/testing/selftests/powerpc/tm/tm-tar.c line 76
Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +10
-0+if ((result !=7 ) && (result !=9 )) +return 1 ; + + } +return 0 ; +} + +int main (int argc,char *argv[]) + +// A low number of iterations (eg 100) can cause a false pass.
Here as well.
Quoted 15 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +14
-0+if (argc >1 ) { +if (strcmp (argv[1 ],"-h" ) ==0 ) { +printf ("Syntax:\n\t%s [<num loops>]\n" , + argv[0 ]); +return 0 ; + }else { + num_loops =atoi (argv[1 ]); + } + } + +printf ("Starting, %d loops\n" , num_loops); + +test_harness (test_tar,"tm_tar" ); +}
Quoted 1 line
Re: [PATCH] selftests/powerpc: Add test to check if TAR is corrupted
The patch description should mention TM too.
Quoted 9 lines · Anshuman Khandual
Quoted 2 lines · Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the checkpointed value before the transaction began.
=20
And if it does not abort, it should continue to hold the changed (inside the transaction) TAR value after the transaction finishes. The test here does check for both these cases and hence the commit message should reflect that as well. This test can also accommodate checks for PPR and DSCR register in one go.
Good point. =20
Quoted 7 lines
In the TM ptrace patch series (https://lkml.org/lkml/2015/10/8/522)
which is still under review, there are couple of tests related to (TAR, PPR, DSCR) registers with (TM running & TM suspended) and without TM. There, the values are being checked using ptrace interface
instead. Can you please check them and just make sure that we are not duplicating anything here.
Even if it is duplicated, I'd prefer to have this separate test as well. This is much simpler than that ptrace test.
Thanks for the review.
Mikey
Quoted 161 lines
=20
Quoted 44 lines
=20
Signed-off-by Rashmica Gupta <[email protected]>---
To check this yourself, undo the changes from the patch "powerpc/tm: Fix
context switching TAR, PPR and DSCR SPRs".
=20tools/testing/selftests/powerpc/tm/.gitignore | 1 + tools/testing/selftests/powerpc/tm/Makefile | 2 +- tools/testing/selftests/powerpc/tm/tm-tar.c | 90 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c=20
tools/testing/selftests/powerpc/tm/.gitignore +1
-0@@ -4,3 +4,4 @@ tm-signal-msr-resv tm-signal-stack tm-fork tm-dscr +tm-tartools/testing/selftests/powerpc/tm/Makefile +1
-3@@ -1,4 +1,4 @@ -TEST_PROGS :=3D tm-resched-dscr tm-syscall tm-signal-msr-resv tm -signal-stack tm-fork tm-dscr +TEST_PROGS :=3D tm-resched-dscr tm-syscall tm-signal-msr-resv tm -signal-stack tm-fork tm-dscr tm-tar=20
all: $(TEST_PROGS)
=20tools/testing/selftests/powerpc/tm/tm-tar.c new file +0
-0tools/testing/selftests/powerpc/tm/tm-tar.c line 7
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +7
-0@@ -0,0 +1,90 @@ +/*=20 +* Copyright 2015, Michael Neuling, IBM Corp.=20 +* Licensed under GPLv2. +* Original: Michael Neuling 19/7/2013 +* Edited: Rashmica Gupta 01/12/2015 +* +* Do some transactions, see if the tar is corrupted. =20
It can use a better explanation here.
=20Quoted 27 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +27
-0+* +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include "tm.h" +#include "utils.h" + +#define SPRN_TAR 0x32f + +int num_loops =3D 10000; + +int test_tar (void ) +{ +int i; + +SKIP_IF (!have_htm ()); + + for (i =3D 0; i < num_loops; i++) + { + uint64_t result =3D 0; + asm __volatile__( +"li 7, 1;" + "mtspr %[tar], 7;" // tar =3DQuoted 1 line
1
=20
Please use /* */ kind of comment sections not //.
=20tools/testing/selftests/powerpc/tm/tm-tar.c line 38
Quoted 5 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +3
-0+ "tbegin.;"=09 +"beq 3f;" +"li 4, 0x7000;" // Loop lots, to use time
tools/testing/selftests/powerpc/tm/tm-tar.c new file +1
-0+"2:;" // Start loop =20
Here as well.
=20Quoted 33 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +2
-0+"li 7, 2;" +"mtspr %[tar], 7;" // tar =3D 2
tools/testing/selftests/powerpc/tm/tm-tar.c new file +3
-0+"tsuspend.;" +"li 7, 3;" +"mtspr %[tar], 7;" // tar =3D 3
tools/testing/selftests/powerpc/tm/tm-tar.c new file +9
-0+"tresume.;" +"subi 4, 4, 1;" +"cmpdi 4, 0;" +"bne 2b;" +"tend.;" + +// Transaction sucess! TAR should be 3. +"mfspr 7, %[tar];" +"ori %[res], 7, 4;" // res =3D 3|4 =3D 7
tools/testing/selftests/powerpc/tm/tm-tar.c new file +3
-0+"b 4f;" + +// Abort handler. TAR should be rolled back to 1.
tools/testing/selftests/powerpc/tm/tm-tar.c new file +3
-0+"3:;" +"mfspr 7, %[tar];" +"ori %[res], 7, 8;" // res =3D 1|8 =3D 9
tools/testing/selftests/powerpc/tm/tm-tar.c new file +7
-0+"4:;" + + : [res]"=3Dr"(result) + : [tar]"i"(SPRN_TAR) + : "memory", "r0", "r4", "r7"); + +// If result is anything else other than 7 or 9, the tar
tools/testing/selftests/powerpc/tm/tm-tar.c line 66
Quoted 1 line
tools/testing/selftests/powerpc/tm/tm-tar.c new file +1
-0+// value must have been corrupted. =20
Here as well.
=20Quoted 11 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +10
-0+ if ((result !=3D 7) && (result !=3D 9))=20 +return 1 ; + =09 + } +return 0 ; +} + +int main (int argc,char *argv[]) + +// A low number of iterations (eg 100) can cause a false pass.
=20
Here as well.
=20Quoted 14 lines
tools/testing/selftests/powerpc/tm/tm-tar.c new file +14
-0+if (argc >1 ) { + if (strcmp(argv[1], "-h") =3D=3D 0) { +printf ("Syntax:\n\t%s [<num loops>]\n" , + argv[0 ]); +return 0 ; + }else { + num_loops =3D atoi(argv[1]); + } + } + +printf ("Starting, %d loops\n" , num_loops); + +test_harness (test_tar,"tm_tar" ); +}Quoted 1 line
=20
=20