[PATCH 46/73] libperf: Add perf_mmap__new function
From: Jiri Olsa
Date: Fri Sep 13 2019 - 09:26:00 EST
Adding perf_mmap__new function to create and
initialize new 'struct perf_mmap' object to
internal header internal/mmap.h
Link: http://lkml.kernel.org/n/tip-e0zucg7w3h6j1hrq0cq2v8kc@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/mmap.c | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index cc0a5995cd3c..31946e26368a 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -41,6 +41,8 @@ struct perf_mmap_param {
size_t perf_mmap__mmap_len(struct perf_mmap *map);
+struct perf_mmap *perf_mmap__new(bool overwrite,
+ libperf_unmap_cb_t unmap_cb);
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,
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index ea46f325fa98..720dda578ed9 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <sys/mman.h>
+#include <linux/zalloc.h>
#include <internal/mmap.h>
#include <internal/lib.h>
@@ -12,6 +13,16 @@ void perf_mmap__init(struct perf_mmap *map, bool overwrite,
refcount_set(&map->refcnt, 0);
}
+struct perf_mmap *perf_mmap__new(bool overwrite, libperf_unmap_cb_t unmap_cb)
+{
+ struct perf_mmap *map = zalloc(sizeof(*map));
+
+ if (map)
+ perf_mmap__init(map, overwrite, unmap_cb);
+
+ return map;
+}
+
size_t perf_mmap__mmap_len(struct perf_mmap *map)
{
return map->mask + 1 + page_size;
--
2.21.0