lkml.org 
[lkml]   [2019]   [Sep]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 56/73] libperf: Add perf_evlist_mmap_ops::mmap callback
Date
Adding perf_evlist_mmap_ops::mmap callback to be called
in mmap_per_evsel to actually mmap the map.

Adding libperf's perf_evlist__mmap_cb_mmap function as
libperf's mmap callback.

Link: http://lkml.kernel.org/n/tip-9cksnv3xbb1eset7ge67at4a@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/lib/evlist.c | 15 ++++++++++++---
tools/perf/lib/include/internal/evlist.h | 3 +++
2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 8caced7d489a..ec83022cd62f 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -341,6 +341,14 @@ perf_evlist__mmap_cb_new(struct perf_evlist *evlist, bool overwrite, int idx)
return map;
}

+static int
+perf_evlist__mmap_cb_mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+ int output, int cpu)
+{
+ refcount_set(&map->refcnt, 2);
+ return perf_mmap__mmap(map, mp, output, cpu);
+}
+
static int
mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
int idx, struct perf_mmap_param *mp, int cpu_idx,
@@ -379,7 +387,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
if (*output == -1) {
*output = fd;

- if (perf_mmap__mmap(map, mp, *output, evlist_cpu) < 0)
+ if (ops->mmap(map, mp, *output, evlist_cpu) < 0)
return -1;
} else {
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
@@ -471,7 +479,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;

- if (!ops || !ops->new)
+ if (!ops || !ops->new || !ops->mmap)
return -EINVAL;

perf_evlist__for_each_entry(evlist, evsel) {
@@ -491,7 +499,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
{
struct perf_mmap_param mp;
struct perf_evlist_mmap_ops ops = {
- .new = perf_evlist__mmap_cb_new,
+ .new = perf_evlist__mmap_cb_new,
+ .mmap = perf_evlist__mmap_cb_mmap,
};

if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 3cb836912ee6..851837ce4ff8 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -31,10 +31,13 @@ typedef void
(*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool);
typedef struct perf_mmap*
(*perf_evlist_mmap__cb_new_t)(struct perf_evlist*, bool, int);
+typedef int
+(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, int);

struct perf_evlist_mmap_ops {
perf_evlist_mmap__cb_idx_t idx;
perf_evlist_mmap__cb_new_t new;
+ perf_evlist_mmap__cb_mmap_t mmap;
};

int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
--
2.21.0
\
 
 \ /
  Last update: 2019-09-13 15:28    [W:0.218 / U:6.928 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site