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>
This commit is contained in:
Jiri Olsa
2019-10-07 14:53:17 +02:00
committed by Arnaldo Carvalho de Melo
parent 1d40ae4e17
commit 7728fa0cfa
23 changed files with 87 additions and 54 deletions

View File

@@ -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);
}