Update DSCR tests
PATCH v2 4/7 selftests/powerpc/dscr: Add lockstep test cases to DSCR explicit tests
In reply to Benjamin GrayAdd new cases to the relevant tests that use explicitly synchronized threads to test the behaviour across context switches with less randomness. By locking the participants to the same CPU we guarantee a context switch occurs each time they make progress, which is a likely failure point if the kernel is not tracking the thread local DSCR correctly.
The random case is left in to keep exercising potential edge cases.
---
v2: * Use the bind_to_cpu() added in the previous 2 new patches
instead of reimplementing it
--- tools/testing/selftests/powerpc/dscr/Makefile | 1 + .../powerpc/dscr/dscr_default_test.c | 87 ++++++++++++++++--- .../powerpc/dscr/dscr_explicit_test.c | 85 +++++++++++++++++- 3 files changed, 159 insertions(+), 14 deletions(-)
tools/testing/selftests/powerpc/dscr/Makefile +1 -0
@@ -9,5 +9,6 @@ top_srcdir = ../../../../.. include ../../lib.mk $(OUTPUT)/dscr_default_test: LDLIBS += -lpthread +$(OUTPUT)/dscr_explicit_test: LDLIBS += -lpthread $(TEST_GEN_PROGS): ../harness.c ../utils.c
tools/testing/selftests/powerpc/dscr/dscr_default_test.c +75 -12
129 lines not on this page · raw message
tools/testing/selftests/powerpc/dscr/dscr_explicit_test.c +83 -2
97 lines not on this page · raw message
Signature · 1 line
2.39.2
v2 cover Update DSCR tests
The randomness based DSCR tests currently have a low probability of doing any writes to the DSCR, making them inefficient in uncovering bugs.
This series adds lockstep variants to these RNG tests, to ensure the happy path is always tested, and improves the randomness and size of the RNG tests.
It also removes many iterations of the sysfs DSCR test, allowing the default timeout to be re-enabled.
v2: * Pull bind_to_cpu() out to utils.c and allow an automatically
determined CPU selection.
Previous versions:
v1: https://lore.kernel.org/all/[email protected]/
Benjamin Gray (7):
selftests/powerpc/dscr: Correct typos
selftests/powerpc: Move bind_to_cpu() to utils.h selftests/powerpc: Allow bind_to_cpu() to automatically pick CPU selftests/powerpc/dscr: Add lockstep test cases to DSCR explicit tests selftests/powerpc/dscr: Improve DSCR explicit random test case selftests/powerpc/dscr: Speed up DSCR sysfs tests selftests/powerpc/dscr: Restore timeout to DSCR selftests
tools/testing/selftests/powerpc/dscr/Makefile | 3 +- tools/testing/selftests/powerpc/dscr/dscr.h | 4 - .../powerpc/dscr/dscr_default_test.c | 207 +++++++++++------- .../powerpc/dscr/dscr_explicit_test.c | 169 +++++++++++--- .../powerpc/dscr/dscr_inherit_test.c | 4 +- .../selftests/powerpc/dscr/dscr_sysfs_test.c | 11 +- .../selftests/powerpc/dscr/dscr_user_test.c | 4 +- tools/testing/selftests/powerpc/dscr/settings | 1 - .../testing/selftests/powerpc/include/utils.h | 3 + .../pmu/ebb/cpu_event_pinned_vs_ebb_test.c | 3 +- .../powerpc/pmu/ebb/cpu_event_vs_ebb_test.c | 3 +- .../powerpc/pmu/ebb/ebb_vs_cpu_event_test.c | 3 +- .../powerpc/pmu/ebb/multi_ebb_procs_test.c | 6 +- tools/testing/selftests/powerpc/pmu/lib.c | 19 +- tools/testing/selftests/powerpc/pmu/lib.h | 1 - tools/testing/selftests/powerpc/utils.c | 23 ++ 16 files changed, 303 insertions(+), 161 deletions(-) delete mode 100644 tools/testing/selftests/powerpc/dscr/settings
--
2.39.2
PATCH v2 2/7 selftests/powerpc: Move bind_to_cpu() to utils.h
This function will be useful in the DSCR test patches later in this series, so promote it to be shared by all powerpc selftests.
---
v2: * New in v2
--- tools/testing/selftests/powerpc/include/utils.h | 1 + tools/testing/selftests/powerpc/pmu/lib.c | 13 ------------- tools/testing/selftests/powerpc/pmu/lib.h | 1 - tools/testing/selftests/powerpc/utils.c | 12 ++++++++++++ 4 files changed, 13 insertions(+), 14 deletions(-)
tools/testing/selftests/powerpc/include/utils.h +1 -0
@@ -32,6 +32,7 @@ void *find_auxv_entry(int type, char *auxv);void *get_auxv_entry (int type);int pick_online_cpu (void ); +int bind_to_cpu (int cpu);int parse_intmax (const char *buffer,size_t count,intmax_t *result,int base);int parse_uintmax (const char *buffer,size_t count,uintmax_t *result,int base);
tools/testing/selftests/powerpc/pmu/lib.c +0 -13
@@ -14,19 +14,6 @@#include "utils.h" #include "lib.h" - -int bind_to_cpu (int cpu) -{ -cpu_set_t mask; - -printf ("Binding to cpu %d\n" , cpu); - -CPU_ZERO (&mask); -CPU_SET (cpu, &mask); - -return sched_setaffinity (0 ,sizeof (mask), &mask); -} -#define PARENT_TOKEN 0xAA#define CHILD_TOKEN 0x55
tools/testing/selftests/powerpc/pmu/lib.h +0 -1
@@ -20,7 +20,6 @@ union pipe {int fds[2 ]; }; -extern int bind_to_cpu (int cpu);extern int kill_child_and_wait (pid_t child_pid);extern int wait_for_child (pid_t child_pid);extern int sync_with_child (union pipe read_pipe,union pipe write_pipe);
tools/testing/selftests/powerpc/utils.c +12 -0
@@ -452,6 +452,18 @@ int pick_online_cpu(void)return cpu; } +int bind_to_cpu (int cpu) +{ +cpu_set_t mask; + +printf ("Binding to cpu %d\n" , cpu); + +CPU_ZERO (&mask); +CPU_SET (cpu, &mask); + +return sched_setaffinity (0 ,sizeof (mask), &mask); +} +bool is_ppc64le (void ) {struct utsname uts;
Signature · 1 line
2.39.2
PATCH v2 1/7 selftests/powerpc/dscr: Correct typos
In reply to Benjamin GrayCorrect a couple of typos while working on other improvements to the DSCR tests.
--- tools/testing/selftests/powerpc/dscr/dscr_explicit_test.c | 4 ++-- tools/testing/selftests/powerpc/dscr/dscr_inherit_test.c | 4 ++-- tools/testing/selftests/powerpc/dscr/dscr_user_test.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/powerpc/dscr/dscr_explicit_test.c +2 -2
@@ -7,8 +7,8 @@* privilege state SPR and the problem state SPR for this purpose. * * When using the privilege state SPR, the instructions such as -* mfspr or mtspr are priviledged and the kernel emulates them -* for us. Instructions using problem state SPR can be exuecuted +* mfspr or mtspr are privileged and the kernel emulates them +* for us. Instructions using problem state SPR can be executed * directly without any emulation if the HW supports them. Else * they also get emulated by the kernel. *
tools/testing/selftests/powerpc/dscr/dscr_inherit_test.c +2 -2
@@ -7,8 +7,8 @@* value using mfspr. * * When using the privilege state SPR, the instructions such as -* mfspr or mtspr are priviledged and the kernel emulates them -* for us. Instructions using problem state SPR can be exuecuted +* mfspr or mtspr are privileged and the kernel emulates them +* for us. Instructions using problem state SPR can be executed * directly without any emulation if the HW supports them. Else * they also get emulated by the kernel. *
tools/testing/selftests/powerpc/dscr/dscr_user_test.c +2 -2
@@ -8,8 +8,8 @@* numbers. * * When using the privilege state SPR, the instructions such as -* mfspr or mtspr are priviledged and the kernel emulates them -* for us. Instructions using problem state SPR can be exuecuted +* mfspr or mtspr are privileged and the kernel emulates them +* for us. Instructions using problem state SPR can be executed * directly without any emulation if the HW supports them. Else * they also get emulated by the kernel. *
Signature · 1 line
2.39.2
PATCH v2 3/7 selftests/powerpc: Allow bind_to_cpu() to automatically pick CPU
In reply to Benjamin GrayAll current users of bind_to_cpu() don't care _which_ CPU they get, just that they are bound to a single free one. So alter the interface to
1. Accept a BIND_CPU_ANY value that tells it to automatically pick a CPU
2. Return the picked CPU
And convert all these users to bind_to_cpu(BIND_CPU_ANY).
---
v2: * New in v2
--- tools/testing/selftests/powerpc/include/utils.h | 2 ++ .../powerpc/pmu/ebb/cpu_event_pinned_vs_ebb_test.c | 3 +-- .../powerpc/pmu/ebb/cpu_event_vs_ebb_test.c | 3 +-- .../powerpc/pmu/ebb/ebb_vs_cpu_event_test.c | 3 +-- .../powerpc/pmu/ebb/multi_ebb_procs_test.c | 6 ++---- tools/testing/selftests/powerpc/pmu/lib.c | 6 ++---- tools/testing/selftests/powerpc/utils.c | 13 ++++++++++++- 7 files changed, 21 insertions(+), 15 deletions(-)
tools/testing/selftests/powerpc/include/utils.h +2 -0
@@ -31,6 +31,8 @@ int read_auxv(char *buf, ssize_t buf_size);void *find_auxv_entry (int type,char *auxv);void *get_auxv_entry (int type); +#define BIND_CPU_ANY (-1) +int pick_online_cpu (void );int bind_to_cpu (int cpu);
tools/testing/selftests/powerpc/pmu/ebb/cpu_event_pinned_vs_ebb_test.c +1 -2
@@ -45,9 +45,8 @@ int cpu_event_pinned_vs_ebb(void)SKIP_IF (!ebb_is_supported ()); - cpu =pick_online_cpu (); + cpu =bind_to_cpu (BIND_CPU_ANY );FAIL_IF (cpu <0 ); -FAIL_IF (bind_to_cpu (cpu));FAIL_IF (pipe (read_pipe.fds) ==-1 );FAIL_IF (pipe (write_pipe.fds) ==-1 );
tools/testing/selftests/powerpc/pmu/ebb/cpu_event_vs_ebb_test.c +1 -2
@@ -43,9 +43,8 @@ int cpu_event_vs_ebb(void)SKIP_IF (!ebb_is_supported ()); - cpu =pick_online_cpu (); + cpu =bind_to_cpu (BIND_CPU_ANY );FAIL_IF (cpu <0 ); -FAIL_IF (bind_to_cpu (cpu));FAIL_IF (pipe (read_pipe.fds) ==-1 );FAIL_IF (pipe (write_pipe.fds) ==-1 );
tools/testing/selftests/powerpc/pmu/ebb/ebb_vs_cpu_event_test.c +1 -2
@@ -43,9 +43,8 @@ int ebb_vs_cpu_event(void)SKIP_IF (!ebb_is_supported ()); - cpu =pick_online_cpu (); + cpu =bind_to_cpu (BIND_CPU_ANY );FAIL_IF (cpu <0 ); -FAIL_IF (bind_to_cpu (cpu));FAIL_IF (pipe (read_pipe.fds) ==-1 );FAIL_IF (pipe (write_pipe.fds) ==-1 );
tools/testing/selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c +2 -4
@@ -75,13 +75,11 @@ static int cycles_child(void)int multi_ebb_procs (void ) {pid_t pids[NR_CHILDREN ]; -int cpu, rc, i; +int rc, i;SKIP_IF (!ebb_is_supported ()); - cpu =pick_online_cpu (); -FAIL_IF (cpu <0 ); -FAIL_IF (bind_to_cpu (cpu)); +FAIL_IF (bind_to_cpu (BIND_CPU_ANY ) <0 );for (i =0 ; i <NR_CHILDREN ; i++) { pids[i] =fork ();
tools/testing/selftests/powerpc/pmu/lib.c +2 -4
@@ -103,12 +103,10 @@ static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe)pid_t eat_cpu (int (test_function )(void )) {union pipe read_pipe, write_pipe; -int cpu, rc; +int rc;pid_t pid; - cpu =pick_online_cpu (); -FAIL_IF (cpu <0 ); -FAIL_IF (bind_to_cpu (cpu)); +FAIL_IF (bind_to_cpu (BIND_CPU_ANY ) <0 );if (pipe (read_pipe.fds) ==-1 )return -1 ;
tools/testing/selftests/powerpc/utils.c +12 -1
@@ -455,13 +455,24 @@ int pick_online_cpu(void)int bind_to_cpu (int cpu) {cpu_set_t mask; +int err; + +if (cpu ==BIND_CPU_ANY ) { + cpu =pick_online_cpu (); +if (cpu <0 ) +return cpu; + }printf ("Binding to cpu %d\n" , cpu);CPU_ZERO (&mask);CPU_SET (cpu, &mask); -return sched_setaffinity (0 ,sizeof (mask), &mask); + err =sched_setaffinity (0 ,sizeof (mask), &mask); +if (err) +return err; + +return cpu; }bool is_ppc64le (void )
Signature · 1 line
2.39.2
PATCH v2 6/7 selftests/powerpc/dscr: Speed up DSCR sysfs tests
In reply to Benjamin GrayThis test case is extremely slow, taking around a minute compared to most of the other DSCR tests taking a second at most. Perf shows most time is spent by the kernel switching to each CPU it reads in /sys/devices/system/cpu. This switching is an unavoidable consequnce of reading all the .../cpuN/dscr values.
Remove the outer iteration loop from this test case, reducing the reads from 1600 to 16. This still updates the DSCR 16 times and verifies on every CPU each time, so I do not expect the lower coverage to be meaningful. The speedup is significant: back down to ~1 second like the other tests.
--- .../testing/selftests/powerpc/dscr/dscr_sysfs_test.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c +4 -7
@@ -67,17 +67,14 @@ static int check_all_cpu_dscr_defaults(unsigned long val)int dscr_sysfs (void ) {unsigned long orig_dscr_default; -int i, j;SKIP_IF (!have_hwcap2 (PPC_FEATURE2_DSCR )); orig_dscr_default =get_default_dscr (); -for (i =0 ; i <COUNT ; i++) { -for (j =0 ; j <DSCR_MAX ; j++) { -set_default_dscr (j); -if (check_all_cpu_dscr_defaults (j)) - goto fail; - } +for (int i =0 ; i <DSCR_MAX ; i++) { +set_default_dscr (i); +if (check_all_cpu_dscr_defaults (i)) + goto fail; }set_default_dscr (orig_dscr_default);return 0 ;
Signature · 1 line
2.39.2
PATCH v2 5/7 selftests/powerpc/dscr: Improve DSCR explicit random test case
In reply to Benjamin GrayThe tests currently have a single writer thread updating the system DSCR with a 1/1000 chance looped only 100 times. So only around one in 10 runs actually do anything.
* Add multiple threads to the dscr_explicit_random_test case.
* Use a barrier to make all the threads start work as simultaneously as possible.
* Use a rwlock and make all threads have a reasonable chance to write to the DSCR on each iteration. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is used to prevent writers from starving while all the other threads keep reading. Logging the reads/writes shows a decent mix across the whole test.
* Allow all threads a chance to write.
* Make the chance of writing more likely.
--- tools/testing/selftests/powerpc/dscr/dscr.h | 4 - .../powerpc/dscr/dscr_default_test.c | 140 ++++++++---------- .../powerpc/dscr/dscr_explicit_test.c | 84 +++++++---- 3 files changed, 113 insertions(+), 115 deletions(-)
tools/testing/selftests/powerpc/dscr/dscr.h +0 -4
@@ -86,8 +86,4 @@ void set_default_dscr(unsigned long val) } } -double uniform_deviate (int seed) -{ -return seed * (1.0 / (RAND_MAX +1.0 )); -}#endif /* _SELFTESTS_POWERPC_DSCR_DSCR_H */
tools/testing/selftests/powerpc/dscr/dscr_default_test.c +60 -80
165 lines not on this page · raw message
tools/testing/selftests/powerpc/dscr/dscr_explicit_test.c +53 -31
103 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v2 7/7 selftests/powerpc/dscr: Restore timeout to DSCR selftests
In reply to Benjamin GrayReducing the time taken by dscr_sysfs_test.c allows restoring the default timeout, which was removed in
commit 850507f30c38 ("selftests/powerpc: Turn off timeout setting for benchmarks, dscr, signal, tm") because that test took too long.
--- tools/testing/selftests/powerpc/dscr/Makefile | 2 -- tools/testing/selftests/powerpc/dscr/settings | 1 - 2 files changed, 3 deletions(-) delete mode 100644 tools/testing/selftests/powerpc/dscr/settings
tools/testing/selftests/powerpc/dscr/Makefile +0 -2
@@ -3,8 +3,6 @@ TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test \ dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test \ dscr_sysfs_thread_test -TEST_FILES := settings - top_srcdir = ../../../../.. include ../../lib.mk
tools/testing/selftests/powerpc/dscr/settings deleted +0 -1
@@ -1 +0,0 @@ -timeout=0
Signature · 1 line
2.39.2
Michael Ellerman
AppliedQuoted 8 lines · Benjamin Gray
The randomness based DSCR tests currently have a low probability of doing any writes to the DSCR, making them inefficient in uncovering bugs.
This series adds lockstep variants to these RNG tests, to ensure the happy path is always tested, and improves the randomness and size of the RNG tests.
[...]
Applied to powerpc/next.
[1/7] selftests/powerpc/dscr: Correct typos
https://git.kernel.org/powerpc/c/15f0c2601e141e3c01c8dc3368b81181bc1c9228 [2/7] selftests/powerpc: Move bind_to_cpu() to utils.h https://git.kernel.org/powerpc/c/c97b2fc6627e1c26a3a84633e135322918a1e592 [3/7] selftests/powerpc: Allow bind_to_cpu() to automatically pick CPU https://git.kernel.org/powerpc/c/6ff4dc25483f3f49d1db48af28d4c485fc77bd21 [4/7] selftests/powerpc/dscr: Add lockstep test cases to DSCR explicit tests https://git.kernel.org/powerpc/c/fda8158870063b99b88a0904bbb95188973b4297 [5/7] selftests/powerpc/dscr: Improve DSCR explicit random test case https://git.kernel.org/powerpc/c/3067b89ab62305c54ec15b00a2c4dbaf64809c59 [6/7] selftests/powerpc/dscr: Speed up DSCR sysfs tests https://git.kernel.org/powerpc/c/c14a9d0a79d4fb83c4e9e8cadc5cb094f41d01d0 [7/7] selftests/powerpc/dscr: Restore timeout to DSCR selftests https://git.kernel.org/powerpc/c/ae7312c09014fceb782a92cfb934e973f08b338f
cheers