linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Alexey Budankov <alexey.budankov@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 28/53] perf record: Bind the AIO user space buffers to nodes
Date: Wed,  6 Feb 2019 15:48:38 -0300	[thread overview]
Message-ID: <20190206184903.24054-29-acme@kernel.org> (raw)
In-Reply-To: <20190206184903.24054-1-acme@kernel.org>

From: Alexey Budankov <alexey.budankov@linux.intel.com>

Allocate and bind AIO user space buffers to the memory nodes that mmap
kernel buffers are bound to.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/5a5adebc-afe0-4806-81cd-180d49ec043f@linux.intel.com
[ Do not use 'index' as a variable name, it is a define in older glibcs ]
Link: http://lkml.kernel.org/r/20190205151526.GC10613@kernel.org
[ Add -lnuma to the python build when -DHAVE_LIBNUMA_SUPPORT is present, fixing 'perf test python' ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/mmap.c   | 77 +++++++++++++++++++++++++++++++++++++---
 tools/perf/util/setup.py |  5 +++
 2 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index e68ba754a8e2..d882f43148c3 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"
@@ -154,9 +157,72 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb
 }
 
 #ifdef HAVE_AIO_SUPPORT
+
+#ifdef HAVE_LIBNUMA_SUPPORT
+static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
+{
+	map->aio.data[idx] = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE,
+				  MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+	if (map->aio.data[idx] == MAP_FAILED) {
+		map->aio.data[idx] = NULL;
+		return -1;
+	}
+
+	return 0;
+}
+
+static void perf_mmap__aio_free(struct perf_mmap *map, int idx)
+{
+	if (map->aio.data[idx]) {
+		munmap(map->aio.data[idx], perf_mmap__mmap_len(map));
+		map->aio.data[idx] = NULL;
+	}
+}
+
+static int perf_mmap__aio_bind(struct perf_mmap *map, int idx, int cpu, int affinity)
+{
+	void *data;
+	size_t mmap_len;
+	unsigned long node_mask;
+
+	if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) {
+		data = map->aio.data[idx];
+		mmap_len = perf_mmap__mmap_len(map);
+		node_mask = 1UL << cpu__get_node(cpu);
+		if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) {
+			pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n",
+				data, data + mmap_len, cpu__get_node(cpu));
+			return -1;
+		}
+	}
+
+	return 0;
+}
+#else
+static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
+{
+	map->aio.data[idx] = malloc(perf_mmap__mmap_len(map));
+	if (map->aio.data[idx] == NULL)
+		return -1;
+
+	return 0;
+}
+
+static void perf_mmap__aio_free(struct perf_mmap *map, int idx)
+{
+	zfree(&(map->aio.data[idx]));
+}
+
+static int perf_mmap__aio_bind(struct perf_mmap *map __maybe_unused, int idx __maybe_unused,
+		int cpu __maybe_unused, int affinity __maybe_unused)
+{
+	return 0;
+}
+#endif
+
 static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
 {
-	int delta_max, i, prio;
+	int delta_max, i, prio, ret;
 
 	map->aio.nr_cblocks = mp->nr_cblocks;
 	if (map->aio.nr_cblocks) {
@@ -177,11 +243,14 @@ 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) {
-			map->aio.data[i] = malloc(perf_mmap__mmap_len(map));
-			if (!map->aio.data[i]) {
+			ret = perf_mmap__aio_alloc(map, i);
+			if (ret == -1) {
 				pr_debug2("failed to allocate data buffer area, error %m");
 				return -1;
 			}
+			ret = perf_mmap__aio_bind(map, i, map->cpu, mp->affinity);
+			if (ret == -1)
+				return -1;
 			/*
 			 * Use cblock.aio_fildes value different from -1
 			 * to denote started aio write operation on the
@@ -210,7 +279,7 @@ static void perf_mmap__aio_munmap(struct perf_mmap *map)
 	int i;
 
 	for (i = 0; i < map->aio.nr_cblocks; ++i)
-		zfree(&map->aio.data[i]);
+		perf_mmap__aio_free(map, i);
 	if (map->aio.data)
 		zfree(&map->aio.data);
 	zfree(&map->aio.cblocks);
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index d3ffc18424b5..5b5a167b43ce 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -53,9 +53,14 @@ ext_sources = [f.strip() for f in open('util/python-ext-sources')
 # use full paths with source files
 ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources))
 
+extra_libraries = []
+if '-DHAVE_LIBNUMA_SUPPORT' in cflags:
+    extra_libraries = [ 'numa' ]
+
 perf = Extension('perf',
 		  sources = ext_sources,
 		  include_dirs = ['util/include'],
+		  libraries = extra_libraries,
 		  extra_compile_args = cflags,
 		  extra_objects = [libtraceevent, libapikfs],
                  )
-- 
2.20.1

  parent reply	other threads:[~2019-02-06 18:48 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06 18:48 [GIT PULL 00/53] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 01/53] perf powerpc: Add missing headers to skip-callchain-idx.c Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 02/53] perf arm pmu: Add missing linux/string.h header Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 03/53] perf srccode: Move struct definition from map.h to srccode.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 04/53] perf callchain: Uninline callchain_cursor_reset() to remove map.h dependency Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 05/53] perf symbols: Introduce map_symbol.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 06/53] pref tools: Add missing map.h includes Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 07/53] perf map: Move structs and prototypes for map groups to a separate header Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 08/53] perf tests: Add missing headers so far obtained indirectly Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 09/53] perf hist: Remove symbol.h from hist.h, just fwd decls are needed Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 10/53] perf tools: Add missing include for symbols.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 11/53] perf evsel: No need to include symbol.h in evsel.h, symbol_conf.h is enough Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 12/53] perf thread: Don't include symbol.h, " Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 13/53] perf tools: Add missing include <callchain.h> in various places Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 14/53] perf hist: Remove the needless callchain.h include from hist.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 15/53] perf tests pmu: Add missing headers Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 16/53] perf pmu: Remove needless evsel.h include, only needs one fwd decl Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 17/53] perf kvm stat: Replace kvm-stat.h includes with forward declarations Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 18/53] perf powerpc kvm-stat: Add missing evlist.h header Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 19/53] perf bpf-loader: Remove unecessary includes from bpf-loader.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 20/53] perf/aux: Make perf_event accessible to setup_aux() Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 21/53] coresight: perf: Add "sinks" group to PMU directory Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 22/53] coresight: Use event attributes for sink selection Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 23/53] perf pmu: Move EVENT_SOURCE_DEVICE_PATH to PMU header file Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 24/53] perf arm cs-etm: Use event attributes to send sink information to kernel Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 25/53] perf coresight: Remove set_drv_config() API Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 26/53] perf pmu: Remove set_drv_config API Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 27/53] perf record: Allocate affinity masks Arnaldo Carvalho de Melo
2019-02-06 18:48 ` Arnaldo Carvalho de Melo [this message]
2019-02-06 18:48 ` [PATCH 29/53] perf tools: Add fallback versions for CPU_{OR,EQUAL}() Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 30/53] perf record: Apply affinity masks when reading mmap buffers Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 31/53] perf clang: Do not use 'return std::move(something)' Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 32/53] perf hists: Add argument to hists__resort_cb_t callback Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 33/53] perf evsel: Add output_resort_cb method Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 34/53] perf report: Move symbol annotation to the resort phase Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 35/53] perf tools: Add documentation for BPF event selection Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 36/53] perf cs-etm: Add last instruction information in packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 37/53] perf cs-etm: Set sample flags for instruction range packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 38/53] perf cs-etm: Set sample flags for trace discontinuity Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 39/53] perf cs-etm: Add exception number in exception packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 40/53] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 41/53] perf cs-etm: Add traceID in packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 42/53] perf cs-etm: Set sample flags for exception packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 43/53] perf cs-etm: Set sample flags for exception return packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 44/53] perf vendor events intel: Fix Load_Miss_Real_Latency on CLX Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 45/53] perf tools: Fix split_kallsyms_for_kcore() for trampoline symbols Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 46/53] perf thread-stack: Tidy thread_stack__push_cp() usage Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 47/53] perf thread-stack: Tidy thread_stack__no_call_return() by adding more local variables Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 48/53] perf thread-stack: Represent jmps to the start of a different symbol Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 49/53] perf auxtrace: Define auxtrace record alignment Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 50/53] perf intel-pt: Fix overlap calculation for padding Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 51/53] perf intel-pt: Fix CYC timestamp calculation after OVF Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 52/53] perf intel-pt: Packet splitting can happen only on 32-bit Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 53/53] perf auxtrace: Add timestamp to auxtrace errors Arnaldo Carvalho de Melo
2019-02-09 12:17 ` [GIT PULL 00/53] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190206184903.24054-29-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).