summaryrefslogtreecommitdiff
path: root/tools/perf/util/mmap.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2019-10-07 15:53:17 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-10-10 17:43:49 +0300
commit7728fa0cfaeb7d25b12c8865c733359cc8e5fb13 (patch)
tree38b413ae51030cdc8006b3f000db7776915ea678 /tools/perf/util/mmap.c
parent1d40ae4e1784bfa1646fd153ca022db21511284f (diff)
downloadlinux-7728fa0cfaeb7d25b12c8865c733359cc8e5fb13.tar.xz
libperf: Adopt perf_mmap__consume() function from tools/perf
Move perf_mmap__consume() vrom tools/perf to libperf and export it in the perf/mmap.h header. Move also the needed helpers perf_mmap__write_tail(), perf_mmap__read_head() and perf_mmap__empty(). 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-10-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/mmap.c')
-rw-r--r--tools/perf/util/mmap.c32
1 files changed, 7 insertions, 25 deletions
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index f246dd403507..abe7cbe6c95f 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // sysconf()
+#include <perf/mmap.h>
#ifdef HAVE_LIBNUMA_SUPPORT
#include <numaif.h>
#endif
@@ -95,7 +96,7 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
/* non-overwirte doesn't pause the ringbuffer */
if (!map->core.overwrite)
- map->core.end = perf_mmap__read_head(map);
+ map->core.end = perf_mmap__read_head(&map->core);
event = perf_mmap__read(map, &map->core.start, map->core.end);
@@ -105,25 +106,6 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
return event;
}
-static bool perf_mmap__empty(struct mmap *map)
-{
- struct perf_event_mmap_page *pc = map->core.base;
-
- return perf_mmap__read_head(map) == map->core.prev && !pc->aux_size;
-}
-
-void perf_mmap__consume(struct mmap *map)
-{
- if (!map->core.overwrite) {
- u64 old = map->core.prev;
-
- perf_mmap__write_tail(map, old);
- }
-
- if (refcount_read(&map->core.refcnt) == 1 && perf_mmap__empty(map))
- perf_mmap__put(&map->core);
-}
-
int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
struct auxtrace_mmap_params *mp __maybe_unused,
void *userpg __maybe_unused,
@@ -420,7 +402,7 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
*/
static int __perf_mmap__read_init(struct mmap *md)
{
- u64 head = perf_mmap__read_head(md);
+ u64 head = perf_mmap__read_head(&md->core);
u64 old = md->core.prev;
unsigned char *data = md->core.base + page_size;
unsigned long size;
@@ -437,7 +419,7 @@ static int __perf_mmap__read_init(struct mmap *md)
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
md->core.prev = head;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
return -EAGAIN;
}
@@ -466,7 +448,7 @@ int perf_mmap__read_init(struct mmap *map)
int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size))
{
- u64 head = perf_mmap__read_head(md);
+ u64 head = perf_mmap__read_head(&md->core);
unsigned char *data = md->core.base + page_size;
unsigned long size;
void *buf;
@@ -499,7 +481,7 @@ int perf_mmap__push(struct mmap *md, void *to,
}
md->core.prev = head;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
out:
return rc;
}
@@ -518,5 +500,5 @@ void perf_mmap__read_done(struct mmap *map)
if (!refcount_read(&map->core.refcnt))
return;
- map->core.prev = perf_mmap__read_head(map);
+ map->core.prev = perf_mmap__read_head(&map->core);
}