All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Jiri Olsa" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Jiri Olsa <jolsa@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org
Subject: [tip: perf/core] libperf: Adopt perf_mmap__put() function from tools/perf
Date: Tue, 15 Oct 2019 05:31:40 -0000	[thread overview]
Message-ID: <157111750050.12254.2005571943584191914.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20191007125344.14268-8-jolsa@kernel.org>

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     80e53d1148231d7d4fdc4cd89e5393616b33bf82
Gitweb:        https://git.kernel.org/tip/80e53d1148231d7d4fdc4cd89e5393616b33bf82
Author:        Jiri Olsa <jolsa@kernel.org>
AuthorDate:    Mon, 07 Oct 2019 14:53:15 +02:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 10 Oct 2019 10:09:25 -03:00

libperf: Adopt perf_mmap__put() function from tools/perf

Move perf_mmap__put() from tools/perf to libperf.

Once perf_mmap__put() is moved, we need a way to call application
related unmap code (AIO and aux related code for eprf), when the map
goes away.

Add the perf_mmap::unmap callback to do that.

The unmap path from perf is:

  perf_mmap__put                           (libperf)
    perf_mmap__munmap                      (libperf)
      map->unmap_cb -> perf_mmap__unmap_cb (perf)
        mmap__munmap                       (perf)

Committer notes:

Add missing linux/kernel.h to tools/perf/lib/mmap.c to get the BUG_ON
definition.

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-8-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c            |  4 +--
 tools/perf/lib/include/internal/mmap.h | 31 +++++++++++++++----------
 tools/perf/lib/mmap.c                  | 15 +++++++++++-
 tools/perf/util/evlist.c               | 17 +++++++++-----
 tools/perf/util/mmap.c                 | 11 +---------
 tools/perf/util/mmap.h                 |  2 +--
 6 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 025a12b..2fb83aa 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -197,7 +197,7 @@ static int record__aio_complete(struct mmap *md, struct aiocb *cblock)
 		 * every aio write request started in record__aio_push() so
 		 * decrement it because the request is now complete.
 		 */
-		perf_mmap__put(md);
+		perf_mmap__put(&md->core);
 		rc = 1;
 	} else {
 		/*
@@ -332,7 +332,7 @@ static int record__aio_push(struct record *rec, struct mmap *map, off_t *off)
 		 * map->refcount is decremented in record__aio_complete() after
 		 * aio write operation finishes successfully.
 		 */
-		perf_mmap__put(map);
+		perf_mmap__put(&map->core);
 	}
 
 	return ret;
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 5c2ca9a..bf9cc7d 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -10,23 +10,28 @@
 /* perf sample has 16 bits size limit */
 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
 
+struct perf_mmap;
+
+typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
+
 /**
  * struct perf_mmap - perf's ring buffer mmap details
  *
  * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
  */
 struct perf_mmap {
-	void		*base;
-	int		 mask;
-	int		 fd;
-	int		 cpu;
-	refcount_t	 refcnt;
-	u64		 prev;
-	u64		 start;
-	u64		 end;
-	bool		 overwrite;
-	u64		 flush;
-	char		 event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
+	void			*base;
+	int			 mask;
+	int			 fd;
+	int			 cpu;
+	refcount_t		 refcnt;
+	u64			 prev;
+	u64			 start;
+	u64			 end;
+	bool			 overwrite;
+	u64			 flush;
+	libperf_unmap_cb_t	 unmap_cb;
+	char			 event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
 };
 
 struct perf_mmap_param {
@@ -36,10 +41,12 @@ struct perf_mmap_param {
 
 size_t perf_mmap__mmap_len(struct perf_mmap *map);
 
-void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+void perf_mmap__init(struct perf_mmap *map, bool overwrite,
+		     libperf_unmap_cb_t unmap_cb);
 int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
 		    int fd, int cpu);
 void perf_mmap__munmap(struct perf_mmap *map);
 void perf_mmap__get(struct perf_mmap *map);
+void perf_mmap__put(struct perf_mmap *map);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 6eb228d..89c1e0e 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -2,11 +2,14 @@
 #include <sys/mman.h>
 #include <internal/mmap.h>
 #include <internal/lib.h>
+#include <linux/kernel.h>
 
-void perf_mmap__init(struct perf_mmap *map, bool overwrite)
+void perf_mmap__init(struct perf_mmap *map, bool overwrite,
+		     libperf_unmap_cb_t unmap_cb)
 {
 	map->fd = -1;
 	map->overwrite = overwrite;
+	map->unmap_cb  = unmap_cb;
 	refcount_set(&map->refcnt, 0);
 }
 
@@ -40,9 +43,19 @@ void perf_mmap__munmap(struct perf_mmap *map)
 		map->fd = -1;
 		refcount_set(&map->refcnt, 0);
 	}
+	if (map && map->unmap_cb)
+		map->unmap_cb(map);
 }
 
 void perf_mmap__get(struct perf_mmap *map)
 {
 	refcount_inc(&map->refcnt);
 }
+
+void perf_mmap__put(struct perf_mmap *map)
+{
+	BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
+
+	if (refcount_dec_and_test(&map->refcnt))
+		perf_mmap__munmap(map);
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0b877d3..4394a5a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -433,7 +433,7 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
 	struct mmap *map = fda->priv[fd].ptr;
 
 	if (map)
-		perf_mmap__put(map);
+		perf_mmap__put(&map->core);
 }
 
 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
@@ -601,11 +601,11 @@ static void evlist__munmap_nofree(struct evlist *evlist)
 
 	if (evlist->mmap)
 		for (i = 0; i < evlist->core.nr_mmaps; i++)
-			mmap__munmap(&evlist->mmap[i]);
+			perf_mmap__munmap(&evlist->mmap[i].core);
 
 	if (evlist->overwrite_mmap)
 		for (i = 0; i < evlist->core.nr_mmaps; i++)
-			mmap__munmap(&evlist->overwrite_mmap[i]);
+			perf_mmap__munmap(&evlist->overwrite_mmap[i].core);
 }
 
 void evlist__munmap(struct evlist *evlist)
@@ -615,6 +615,13 @@ void evlist__munmap(struct evlist *evlist)
 	zfree(&evlist->overwrite_mmap);
 }
 
+static void perf_mmap__unmap_cb(struct perf_mmap *map)
+{
+	struct mmap *m = container_of(map, struct mmap, core);
+
+	mmap__munmap(m);
+}
+
 static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
 				       bool overwrite)
 {
@@ -638,7 +645,7 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
 		 * Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
 		 * thus does perf_mmap__get() on it.
 		 */
-		perf_mmap__init(&map[i].core, overwrite);
+		perf_mmap__init(&map[i].core, overwrite, perf_mmap__unmap_cb);
 	}
 
 	return map;
@@ -715,7 +722,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
 		 */
 		if (!evsel->core.system_wide &&
 		     perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) {
-			perf_mmap__put(&maps[idx]);
+			perf_mmap__put(&maps[idx].core);
 			return -1;
 		}
 
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 2c73b5b..9f150d5 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -110,14 +110,6 @@ static bool perf_mmap__empty(struct mmap *map)
 	return perf_mmap__read_head(map) == map->core.prev && !map->auxtrace_mmap.base;
 }
 
-void perf_mmap__put(struct mmap *map)
-{
-	BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0);
-
-	if (refcount_dec_and_test(&map->core.refcnt))
-		mmap__munmap(map);
-}
-
 void perf_mmap__consume(struct mmap *map)
 {
 	if (!map->core.overwrite) {
@@ -127,7 +119,7 @@ void perf_mmap__consume(struct mmap *map)
 	}
 
 	if (refcount_read(&map->core.refcnt) == 1 && perf_mmap__empty(map))
-		perf_mmap__put(map);
+		perf_mmap__put(&map->core);
 }
 
 int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
@@ -308,7 +300,6 @@ static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused)
 
 void mmap__munmap(struct mmap *map)
 {
-	perf_mmap__munmap(&map->core);
 	perf_mmap__aio_munmap(map);
 	if (map->data != NULL) {
 		munmap(map->data, mmap__mmap_len(map));
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 6a18b29..78e3c44 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -45,8 +45,6 @@ struct mmap_params {
 int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
 void mmap__munmap(struct mmap *map);
 
-void perf_mmap__put(struct mmap *map);
-
 void perf_mmap__consume(struct mmap *map);
 
 static inline u64 perf_mmap__read_head(struct mmap *mm)

  parent reply	other threads:[~2019-10-15  5:32 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-bot2 for Jiri Olsa [this message]
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 ` [PATCH 21/36] perf tools: Switch to libperf mmap interface Jiri Olsa
2019-10-15  5:31   ` [tip: perf/core] perf evlist: Switch to libperf's " 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=157111750050.12254.2005571943584191914.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.