linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
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,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 62/69] perf evlist: Switch to libperf's mmap interface
Date: Fri, 11 Oct 2019 17:05:52 -0300	[thread overview]
Message-ID: <20191011200559.7156-63-acme@kernel.org> (raw)
In-Reply-To: <20191011200559.7156-1-acme@kernel.org>

From: Jiri Olsa <jolsa@kernel.org>

Switch to the libperf mmap interface by calling directly
perf_evlist__mmap_ops() and removing perf's evlist__mmap_per_*
functions.

By switching to libperf perf_evlist__mmap() we need to operate over
'struct perf_mmap' in evlist__add_pollfd, so make the related changes
there.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20191007125344.14268-22-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evlist.c | 179 +--------------------------------------
 1 file changed, 4 insertions(+), 175 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d57b684b4b7b..3f4f11f27b94 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -431,10 +431,10 @@ int evlist__add_pollfd(struct evlist *evlist, int fd)
 static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
 					 void *arg __maybe_unused)
 {
-	struct mmap *map = fda->priv[fd].ptr;
+	struct perf_mmap *map = fda->priv[fd].ptr;
 
 	if (map)
-		perf_mmap__put(&map->core);
+		perf_mmap__put(map);
 }
 
 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
@@ -448,22 +448,6 @@ int evlist__poll(struct evlist *evlist, int timeout)
 	return perf_evlist__poll(&evlist->core, timeout);
 }
 
-static void perf_evlist__set_sid_idx(struct evlist *evlist,
-				     struct evsel *evsel, int idx, int cpu,
-				     int thread)
-{
-	struct perf_sample_id *sid = SID(evsel, cpu, thread);
-	sid->idx = idx;
-	if (evlist->core.cpus && cpu >= 0)
-		sid->cpu = evlist->core.cpus->map[cpu];
-	else
-		sid->cpu = -1;
-	if (!evsel->core.system_wide && evlist->core.threads && thread >= 0)
-		sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
-	else
-		sid->tid = -1;
-}
-
 struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id)
 {
 	struct hlist_head *head;
@@ -652,93 +636,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
 	return map;
 }
 
-static bool
-perf_evlist__should_poll(struct evlist *evlist __maybe_unused,
-			 struct evsel *evsel)
-{
-	if (evsel->core.attr.write_backward)
-		return false;
-	return true;
-}
-
-static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
-				       struct mmap_params *mp, int cpu_idx,
-				       int thread, int *_output, int *_output_overwrite)
-{
-	struct evsel *evsel;
-	int revent;
-	int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
-
-	evlist__for_each_entry(evlist, evsel) {
-		struct mmap *maps = evlist->mmap;
-		int *output = _output;
-		int fd;
-		int cpu;
-
-		mp->core.prot = PROT_READ | PROT_WRITE;
-		if (evsel->core.attr.write_backward) {
-			output = _output_overwrite;
-			maps = evlist->overwrite_mmap;
-
-			if (!maps) {
-				maps = evlist__alloc_mmap(evlist, true);
-				if (!maps)
-					return -1;
-				evlist->overwrite_mmap = maps;
-				if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
-					perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
-			}
-			mp->core.prot &= ~PROT_WRITE;
-		}
-
-		if (evsel->core.system_wide && thread)
-			continue;
-
-		cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
-		if (cpu == -1)
-			continue;
-
-		fd = FD(evsel, cpu, thread);
-
-		if (*output == -1) {
-			*output = fd;
-
-			if (mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0)
-				return -1;
-		} else {
-			if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
-				return -1;
-
-			perf_mmap__get(&maps[idx].core);
-		}
-
-		revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
-
-		/*
-		 * The system_wide flag causes a selected event to be opened
-		 * always without a pid.  Consequently it will never get a
-		 * POLLHUP, but it is used for tracking in combination with
-		 * other events, so it should not need to be polled anyway.
-		 * Therefore don't add it for polling.
-		 */
-		if (!evsel->core.system_wide &&
-		     perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) {
-			perf_mmap__put(&maps[idx].core);
-			return -1;
-		}
-
-		if (evsel->core.attr.read_format & PERF_FORMAT_ID) {
-			if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, cpu, thread,
-						   fd) < 0)
-				return -1;
-			perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
-						 thread);
-		}
-	}
-
-	return 0;
-}
-
 static void
 perf_evlist__mmap_cb_idx(struct perf_evlist *_evlist,
 			 struct perf_mmap_param *_mp,
@@ -783,61 +680,6 @@ perf_evlist__mmap_cb_mmap(struct perf_mmap *_map, struct perf_mmap_param *_mp,
 	return mmap__mmap(map, mp, output, cpu);
 }
 
-static int evlist__mmap_per_cpu(struct evlist *evlist,
-				     struct mmap_params *mp)
-{
-	int cpu, thread;
-	int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
-	int nr_threads = perf_thread_map__nr(evlist->core.threads);
-
-	pr_debug2("perf event ring buffer mmapped per cpu\n");
-	for (cpu = 0; cpu < nr_cpus; cpu++) {
-		int output = -1;
-		int output_overwrite = -1;
-
-		auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, cpu,
-					      true);
-
-		for (thread = 0; thread < nr_threads; thread++) {
-			if (evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
-							thread, &output, &output_overwrite))
-				goto out_unmap;
-		}
-	}
-
-	return 0;
-
-out_unmap:
-	evlist__munmap_nofree(evlist);
-	return -1;
-}
-
-static int evlist__mmap_per_thread(struct evlist *evlist,
-					struct mmap_params *mp)
-{
-	int thread;
-	int nr_threads = perf_thread_map__nr(evlist->core.threads);
-
-	pr_debug2("perf event ring buffer mmapped per thread\n");
-	for (thread = 0; thread < nr_threads; thread++) {
-		int output = -1;
-		int output_overwrite = -1;
-
-		auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
-					      false);
-
-		if (evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
-						&output, &output_overwrite))
-			goto out_unmap;
-	}
-
-	return 0;
-
-out_unmap:
-	evlist__munmap_nofree(evlist);
-	return -1;
-}
-
 unsigned long perf_event_mlock_kb_in_pages(void)
 {
 	unsigned long pages;
@@ -965,9 +807,6 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
 			 bool auxtrace_overwrite, int nr_cblocks, int affinity, int flush,
 			 int comp_level)
 {
-	struct evsel *evsel;
-	const struct perf_cpu_map *cpus = evlist->core.cpus;
-	const struct perf_thread_map *threads = evlist->core.threads;
 	/*
 	 * Delay setting mp.prot: set it before calling perf_mmap__mmap.
 	 * Its value is decided by evsel's write_backward.
@@ -979,7 +818,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
 		.flush		= flush,
 		.comp_level	= comp_level
 	};
-	struct perf_evlist_mmap_ops ops __maybe_unused = {
+	struct perf_evlist_mmap_ops ops = {
 		.idx  = perf_evlist__mmap_cb_idx,
 		.get  = perf_evlist__mmap_cb_get,
 		.mmap = perf_evlist__mmap_cb_mmap,
@@ -1000,17 +839,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
 	auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->core.mmap_len,
 				   auxtrace_pages, auxtrace_overwrite);
 
-	evlist__for_each_entry(evlist, evsel) {
-		if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
-		    evsel->core.sample_id == NULL &&
-		    perf_evsel__alloc_id(&evsel->core, perf_cpu_map__nr(cpus), threads->nr) < 0)
-			return -ENOMEM;
-	}
-
-	if (perf_cpu_map__empty(cpus))
-		return evlist__mmap_per_thread(evlist, &mp);
-
-	return evlist__mmap_per_cpu(evlist, &mp);
+	return perf_evlist__mmap_ops(&evlist->core, &ops, &mp.core);
 }
 
 int evlist__mmap(struct evlist *evlist, unsigned int pages)
-- 
2.21.0


  parent reply	other threads:[~2019-10-11 20:12 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 20:04 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 01/69] perf env: Add routine to read the env->cpuid from the running machine Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 02/69] perf top: Initialize perf_env->cpuid, needed by the per arch annotation init routine Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 03/69] perf evlist: Adopt __set_tracepoint_handlers method from perf_session Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 04/69] perf trace: Make evlist__set_evsel_handler() affect just entries without a handler Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 05/69] perf trace: Separate 'struct syscall_fmt' definition from syscall_fmts variable Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 06/69] perf trace: Generalize the syscall_fmt find routines Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 07/69] perf trace: Postpone parsing .perfconfig trace.add_events to after --verbose is processed Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 08/69] perf trace augmented_syscalls: Do not show syscalls when none was asked for Arnaldo Carvalho de Melo
2019-10-11 20:04 ` [PATCH 09/69] perf scripts python: exported-sql-viewer.py: Add LookupModel() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 10/69] perf scripts python: exported-sql-viewer.py: Add HBoxLayout and VBoxLayout Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 11/69] perf scripts python: exported-sql-viewer.py: Add global time range calculations Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 12/69] perf scripts python: exported-sql-viewer.py: Tidy up Call tree call_time Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 13/69] perf scripts python: exported-sql-viewer.py: Add ability for Call tree to open at a specified task and time Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 14/69] perf scripts python: exported-sql-viewer.py: Add Time chart by CPU Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 15/69] perf tools: Make usage of test_attr__* optional for perf-sys.h Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 16/69] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 17/69] perf script: Allow --time with --reltime Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 18/69] perf trace: Factor out the initialization of syscal_arg_fmt->scnprintf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 19/69] perf trace: Allocate an array of beautifiers for tracepoint args Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 20/69] perf trace: Move some scnprintf methods from syscall to syscall_arg_fmt Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 21/69] perf trace: Add the syscall_arg_fmt pointer to syscall_arg Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 22/69] perf trace: Add array of chars scnprintf beautifier Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 23/69] perf trace: Enclose all events argument lists with () Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 24/69] perf trace: Allow choosing how to augment the tracepoint arguments Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 25/69] tools arch x86: Grab a copy of the file containing the MSR numbers Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 26/69] perf beauty: Make strarray's offset be u64 Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 27/69] perf trace beauty: Add a x86 MSR cmd id->str table generator Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 28/69] perf beauty: Hook up the x86 MSR " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 29/69] perf trace: Allow associating scnprintf routines with well known arg names Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 30/69] perf trace beauty: Add the glue for the autogenerated MSR arrays Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 31/69] perf trace: Associate the "msr" tracepoint arg name with x86_MSR__scnprintf() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 32/69] perf evlist: Factor out asprintf routine to build a tracepoint pid filter Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 33/69] perf evlist: Introduce append_tp_filter() method Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 34/69] perf evlist: Introduce append_tp_filter_pid() and append_tp_filter_pids() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 35/69] perf trace: Introduce --filter for tracepoint events Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 36/69] perf trace: Add a strtoul() method to 'struct syscall_arg_fmt' Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 37/69] perf trace: Introduce a strtoul() method for 'struct strarrays' Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 38/69] perf trace: Expand strings in filters to integers Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 39/69] perf beauty: Introduce strtoul() for x86 MSRs Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 40/69] perf tools: Avoid 'sample_reg_masks' being const + weak Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 41/69] MAINTAINERS: Add entry for perf tool arm64 pmu-events files Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 42/69] libperf: Add perf_mmap__init() function Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 43/69] libperf: Add 'struct perf_mmap_param' Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 44/69] libperf: Adopt perf_mmap__mmap_len() function from tools/perf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 45/69] libperf: Adopt perf_mmap__mmap() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 46/69] libperf: Adopt perf_mmap__get() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 47/69] libperf: Adopt perf_mmap__unmap() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 48/69] libperf: Adopt perf_mmap__put() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 49/69] perf tools: Use perf_mmap way to detect aux mmap Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 50/69] libperf: Adopt perf_mmap__consume() function from tools/perf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 51/69] libperf: Adopt perf_mmap__read_init() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 52/69] libperf: Adopt perf_mmap__read_done() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 53/69] libperf: Adopt perf_mmap__read_event() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 54/69] libperf: Adopt perf_evlist__mmap()/munmap() " Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 55/69] libperf: Introduce perf_evlist__mmap_ops() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 56/69] libperf: Introduce perf_evlist_mmap_ops::idx callback Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 57/69] libperf: Add perf_evlist_mmap_ops::get callback Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 58/69] libperf: Introduce perf_evlist_mmap_ops::mmap callback Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 59/69] perf tools: Introduce perf_evlist__mmap_cb_idx() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 60/69] perf evlist: Introduce perf_evlist__mmap_cb_get() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 61/69] perf evlist: Introduce perf_evlist__mmap_cb_mmap() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` Arnaldo Carvalho de Melo [this message]
2019-10-11 20:05 ` [PATCH 63/69] libperf: Centralize map refcnt setting Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 64/69] libperf: Move the pollfd allocation from tools/perf to libperf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 65/69] libperf: Introduce perf_evlist__exit() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 66/69] libperf: Introduce perf_evlist__purge() Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 67/69] libperf: Adopt perf_evlist__filter_pollfd() from tools/perf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 68/69] perf tools: Propagate CFLAGS to libperf Arnaldo Carvalho de Melo
2019-10-11 20:05 ` [PATCH 69/69] perf diff: Report noisy for cycles diff Arnaldo Carvalho de Melo
2019-10-15  5:25 ` [GIT PULL] 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=20191011200559.7156-63-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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).