libperf: Add perf_mmap__init() function
authorJiri Olsa <jolsa@kernel.org>
Mon, 7 Oct 2019 12:53:09 +0000 (14:53 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 10 Oct 2019 12:37:25 +0000 (09:37 -0300)
Add perf_mmap__init() function to initialize 'struct perf_mmap' objects.

Add it to a new mmap.c source file, that will carry all the mmap related
functions.

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-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/lib/Build
tools/perf/lib/include/internal/mmap.h
tools/perf/lib/mmap.c [new file with mode: 0644]
tools/perf/util/evlist.c

index c31f1c1..2ef9a4e 100644 (file)
@@ -3,6 +3,7 @@ libperf-y += cpumap.o
 libperf-y += threadmap.o
 libperf-y += evsel.o
 libperf-y += evlist.o
+libperf-y += mmap.o
 libperf-y += zalloc.o
 libperf-y += xyarray.o
 libperf-y += lib.o
index ba1e519..e25890d 100644 (file)
@@ -29,4 +29,6 @@ struct perf_mmap {
        char             event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
 };
 
+void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
new file mode 100644 (file)
index 0000000..3da6177
--- /dev/null
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <internal/mmap.h>
+
+void perf_mmap__init(struct perf_mmap *map, bool overwrite)
+{
+       map->fd = -1;
+       map->overwrite = overwrite;
+       refcount_set(&map->refcnt, 0);
+}
index e33b46a..6c8de08 100644 (file)
@@ -629,8 +629,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
                return NULL;
 
        for (i = 0; i < evlist->core.nr_mmaps; i++) {
-               map[i].core.fd = -1;
-               map[i].core.overwrite = overwrite;
                /*
                 * When the perf_mmap() call is made we grab one refcount, plus
                 * one extra to let perf_mmap__consume() get the last
@@ -640,8 +638,9 @@ 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.
                 */
-               refcount_set(&map[i].core.refcnt, 0);
+               perf_mmap__init(&map[i].core, overwrite);
        }
+
        return map;
 }