[PATCH v2] selftests: powerpc: Fix online CPU selection
Srikar Dronamraju
srikar at linux.vnet.ibm.com
Thu Jul 30 02:03:44 AEST 2020
* Sandipan Das <sandipan at linux.ibm.com> [2020-06-09 13:07:33]:
> The size of the CPU affinity mask must be large enough for
> systems with a very large number of CPUs. Otherwise, tests
> which try to determine the first online CPU by calling
> sched_getaffinity() will fail. This makes sure that the size
> of the allocated affinity mask is dependent on the number of
> CPUs as reported by get_nprocs().
>
> Fixes: 3752e453f6ba ("selftests/powerpc: Add tests of PMU EBBs")
> Reported-by: Shirisha Ganta <shiganta at in.ibm.com>
> Signed-off-by: Sandipan Das <sandipan at linux.ibm.com>
> Reviewed-by: Kamalesh Babulal <kamalesh at linux.vnet.ibm.com>
> ---
> Previous versions can be found at:
> v1: https://lore.kernel.org/linuxppc-dev/20200608144212.985144-1-sandipan@linux.ibm.com/
>
> @@ -88,28 +89,40 @@ void *get_auxv_entry(int type)
>
> int pick_online_cpu(void)
> {
> - cpu_set_t mask;
> - int cpu;
> + int ncpus, cpu = -1;
> + cpu_set_t *mask;
> + size_t size;
> +
> + ncpus = get_nprocs();
Please use get_nprocs_conf or sysconf(_SC_NPROCESSORS_CONF). The manpage
seems to suggest the latter. Not sure how accurate the manpage is.
get_nprocs is returning online cpus and when smt is off, the cpu numbers
would be sparse and hence the result from get_nprocs wouldn't be ideal for
allocating cpumask. However get_nprocs_conf would return the max configured
cpus and would be able to handle it.
I think this was the same situation hit by Michael Ellerman.
> + size = CPU_ALLOC_SIZE(ncpus);
> + mask = CPU_ALLOC(ncpus);
> + if (!mask) {
> + perror("malloc");
> + return -1;
> + }
>
--
Thanks and Regards
Srikar Dronamraju
More information about the Linuxppc-dev
mailing list