Re: [PATCH 2/5] selftests/powerpc/dscr: Add lockstep test cases to DSCR explicit tests
From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2023-03-07 10:00:35
Benjamin Gray [off-list ref] writes:
Add 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. Signed-off-by: Benjamin Gray <redacted> --- tools/testing/selftests/powerpc/dscr/Makefile | 1 + tools/testing/selftests/powerpc/dscr/dscr.h | 23 +++++ .../powerpc/dscr/dscr_default_test.c | 87 ++++++++++++++++--- .../powerpc/dscr/dscr_explicit_test.c | 87 ++++++++++++++++++- 4 files changed, 183 insertions(+), 15 deletions(-)
...
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/powerpc/dscr/dscr.h b/tools/testing/selftests/powerpc/dscr/dscr.h index 2c54998d4715..903ee0c83fac 100644 --- a/tools/testing/selftests/powerpc/dscr/dscr.h +++ b/tools/testing/selftests/powerpc/dscr/dscr.h@@ -90,4 +92,25 @@ double uniform_deviate(int seed) { return seed * (1.0 / (RAND_MAX + 1.0)); } + +int restrict_to_one_cpu(void) +{ + cpu_set_t cpus; + int cpu; + + FAIL_IF(sched_getaffinity(0, sizeof(cpu_set_t), &cpus)); + + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) + if (CPU_ISSET(cpu, &cpus)) + break; + + FAIL_IF(cpu == CPU_SETSIZE); + + CPU_ZERO(&cpus); + CPU_SET(cpu, &cpus); + FAIL_IF(sched_setaffinity(0, sizeof(cpu_set_t), &cpus)); + + return 0; +}
We have pick_online_cpu() in utils.c, can you use that? You probably also need to move bind_to_cpu() from pmu/lib.c to utils.c so you can use it. cheers