[PATCH 2/5] selftests/powerpc/dscr: Add lockstep test cases to DSCR explicit tests

Michael Ellerman mpe at ellerman.id.au
Tue Mar 7 20:59:37 AEDT 2023


Benjamin Gray <bgray at linux.ibm.com> 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 <bgray at linux.ibm.com>
> ---
>  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(-)
...
> 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


More information about the Linuxppc-dev mailing list