Re: [PATCH v1 3/3] perf record: adapt affinity to machines with #CPUs > 1K

From: Jiri Olsa
Date: Fri Nov 22 2019 - 08:22:37 EST


On Wed, Nov 20, 2019 at 12:38:57PM +0300, Alexey Budankov wrote:

SNIP

> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index 063d1b93c53d..070b1873cd45 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -23,6 +23,7 @@
> #include "mmap.h"
> #include "../perf.h"
> #include <internal/lib.h> /* page_size */
> +#include <linux/bitmap.h>
>
> size_t mmap__mmap_len(struct mmap *map)
> {
> @@ -215,7 +216,7 @@ void mmap__munmap(struct mmap *map)
> auxtrace_mmap__munmap(&map->auxtrace_mmap);
> }
>
> -static void build_node_mask(int node, cpu_set_t *mask)
> +static void build_node_mask(int node, struct mmap_cpu_mask *mask)
> {
> int c, cpu, nr_cpus;
> const struct perf_cpu_map *cpu_map = NULL;
> @@ -228,28 +229,43 @@ static void build_node_mask(int node, cpu_set_t *mask)
> for (c = 0; c < nr_cpus; c++) {
> cpu = cpu_map->map[c]; /* map c index to online cpu index */
> if (cpu__get_node(cpu) == node)
> - CPU_SET(cpu, mask);
> + set_bit(cpu, mask->bits);
> }
> }
>
> -static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp)
> +static int perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp)
> {
> - CPU_ZERO(&map->affinity_mask);
> + map->affinity_mask.nbits = cpu__max_cpu();
> + map->affinity_mask.bits = bitmap_alloc(map->affinity_mask.nbits);
> + if (!map->affinity_mask.bits)
> + return 1;

I guess this works, but please return < 0 on error

thanks,
jirka