linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Michael Petlan <mpetlan@redhat.com>
Subject: [PATCH 21/36] perf tools: Switch to libperf mmap interface
Date: Mon,  7 Oct 2019 14:53:29 +0200	[thread overview]
Message-ID: <20191007125344.14268-22-jolsa@kernel.org> (raw)
In-Reply-To: <20191007125344.14268-1-jolsa@kernel.org>

Switching to libperf mmap interface by calling directly
perf_evlist__mmap_ops and removing perf's evlist__mmap_per_*
functions.

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

Link: http://lkml.kernel.org/n/tip-de3008b8kzdup7qn5jxol0ie@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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 e7216139f37a..bbefb81a6364 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -407,10 +407,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)
@@ -424,22 +424,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;
@@ -628,93 +612,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,
@@ -759,61 +656,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;
@@ -941,9 +783,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.
@@ -955,7 +794,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,
@@ -976,17 +815,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-07 12:54 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07 12:53 [PATCHv2 00/36] libperf: Add sampling interface Jiri Olsa
2019-10-07 12:53 ` [PATCH 01/36] libperf: Add perf_mmap__init() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 02/36] libperf: Add 'struct perf_mmap_param' Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 03/36] libperf: Add perf_mmap__mmap_len() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__mmap_len() function from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 04/36] libperf: Add perf_mmap__mmap() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__mmap() function from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 05/36] libperf: Add perf_mmap__get() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__get() function from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 06/36] libperf: Add perf_mmap__unmap() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__unmap() function from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 07/36] libperf: Add perf_mmap__put() function Jiri Olsa
2019-10-10 13:11   ` Arnaldo Carvalho de Melo
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__put() function from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 08/36] perf tools: Use perf_mmap way to detect aux mmap Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 09/36] libperf: Add perf_mmap__consume() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__consume() function from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 10/36] libperf: Add perf_mmap__read_init() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__read_init() from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 11/36] libperf: Add perf_mmap__read_done() function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__read_done() from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 12/36] libperf: Add perf_mmap__read_event() function Jiri Olsa
2019-10-10 14:47   ` Arnaldo Carvalho de Melo
2019-10-10 15:32     ` Jiri Olsa
2019-10-10 16:07       ` Arnaldo Carvalho de Melo
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_mmap__read_event() from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 13/36] libperf: Add perf_evlist__mmap()/munmap() functions Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_evlist__mmap()/munmap() from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 14/36] libperf: Add perf_evlist__mmap_ops function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Introduce perf_evlist__mmap_ops() tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 15/36] libperf: Add perf_evlist_mmap_ops::idx callback Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Introduce " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 16/36] libperf: Add perf_evlist_mmap_ops::get callback Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 17/36] libperf: Add perf_evlist_mmap_ops::mmap callback Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Introduce " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 18/36] perf tools: Add perf_evlist__mmap_cb_idx function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] perf tools: Introduce perf_evlist__mmap_cb_idx() tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 19/36] perf tools: Add perf_evlist__mmap_cb_get function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] perf evlist: Introduce perf_evlist__mmap_cb_get() tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 20/36] perf tools: Add perf_evlist__mmap_cb_mmap function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] perf evlist: Introduce perf_evlist__mmap_cb_mmap() tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` Jiri Olsa [this message]
2019-10-15  5:31   ` [tip: perf/core] perf evlist: Switch to libperf's mmap interface tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 22/36] libperf: Centralize map refcnt setting Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 23/36] libperf: Move pollfd allocation to libperf Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Move the pollfd allocation from tools/perf " tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 24/36] libperf: Add perf_evlist__exit function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Introduce perf_evlist__exit() tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 25/36] libperf: Add perf_evlist__purge function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Introduce perf_evlist__purge() tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 26/36] libperf: Add perf_evlist__filter_pollfd function Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] libperf: Adopt perf_evlist__filter_pollfd() from tools/perf tip-bot2 for Jiri Olsa
2019-10-07 12:53 ` [PATCH 27/36] libperf: Add perf_evlist__for_each_mmap function Jiri Olsa
2019-10-10 16:06   ` Arnaldo Carvalho de Melo
2019-10-10 16:20     ` Jiri Olsa
2019-10-07 12:53 ` [PATCH 28/36] libperf: Move mmap allocation to perf_evlist__mmap_ops::get Jiri Olsa
2019-10-07 12:53 ` [PATCH 29/36] libperf: Move mask setup to perf_evlist__mmap_ops function Jiri Olsa
2019-10-07 12:53 ` [PATCH 30/36] libperf: Link static tests with libapi.a Jiri Olsa
2019-10-07 12:53 ` [PATCH 31/36] libperf: Add _GNU_SOURCE define to compilation Jiri Olsa
2019-10-07 12:53 ` [PATCH 32/36] libperf: Add tests_mmap_thread test Jiri Olsa
2019-10-07 12:53 ` [PATCH 33/36] libperf: Add tests_mmap_cpus test Jiri Olsa
2019-10-07 12:53 ` [PATCH 34/36] libperf: Keep count of failed tests Jiri Olsa
2019-10-07 12:53 ` [PATCH 35/36] libperf: Do not export perf_evsel__init/perf_evlist__init Jiri Olsa
2019-10-07 12:53 ` [PATCH 36/36] libperf: Add pr_err macro Jiri Olsa

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=20191007125344.14268-22-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    /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).