Re: [PATCH v1 2/3] perf record: apply affinity masks when reading mmap buffers

Alexey Budankov
2018-12-13T06:26:38Z

Hi,
On 12.12.2018 15:14, Jiri Olsa wrote:
> On Wed, Dec 12, 2018 at 10:40:22AM +0300, Alexey Budankov wrote:
>
> SNIP
>
>> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
>> index e68ba754a8e2..0d017ea85dcb 100644
>> --- a/tools/perf/util/mmap.c
>> +++ b/tools/perf/util/mmap.c
>> @@ -10,6 +10,9 @@
>> #include <sys/mman.h>
>> #include <inttypes.h>
>> #include <asm/bug.h>
>> +#ifdef HAVE_LIBNUMA_SUPPORT
>> +#include <numaif.h>
>> +#endif
>> #include "debug.h"
>> #include "event.h"
>> #include "mmap.h"
>> @@ -177,11 +180,27 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
>> }
>> delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX);
>> for (i = 0; i < map->aio.nr_cblocks; ++i) {
>> +#ifndef HAVE_LIBNUMA_SUPPORT
>> map->aio.data[i] = malloc(perf_mmap__mmap_len(map));
>> +#else
>> + size_t mmap_len = perf_mmap__mmap_len(map);
>> + map->aio.data[i] = mmap(NULL, mmap_len,
>> + PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
>> +#endif
>> if (!map->aio.data[i]) {
>> pr_debug2("failed to allocate data buffer area, error %m");
>> return -1;
>> }
>> +#ifdef HAVE_LIBNUMA_SUPPORT
>> + if (mp->affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) {
>> + unsigned long node_mask = 1UL << cpu__get_node(map->cpu);
>> + if (mbind(map->aio.data[i], mmap_len, MPOL_BIND, &node_mask, 1, 0)) {
>> + pr_debug2("failed to bind [%p-%p] to node %d\n",
>> + map->aio.data[i], map->aio.data[i] + mmap_len,
>> + cpu__get_node(map->cpu));
>> + }
>> + }
>> +#endif
>
> could you please do the same thing as we did for aio functions
> (like record__aio_mmap_read_sync) and provide functions for both
> #fidef cases?

Implemented perf_mmap__aio_alloc(),
perf_mmap__aio_free(),
perf_mmap__aio_bind() in v2.

Thanks,
Alexey

>
> thanks,
> jirka
>