libperf: Adopt simplified perf_evsel__close() function from tools/perf
authorJiri Olsa <jolsa@kernel.org>
Sun, 21 Jul 2019 11:24:50 +0000 (13:24 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 29 Jul 2019 21:34:46 +0000 (18:34 -0300)
Add perf_evsel__close() function to libperf while keeping a tools/perf
specific evsel__close() to free ids.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190721112506.12306-64-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c
tools/perf/lib/evsel.c
tools/perf/lib/include/internal/evsel.h
tools/perf/lib/include/perf/evsel.h
tools/perf/lib/libperf.map
tools/perf/tests/openat-syscall-all-cpus.c
tools/perf/tests/openat-syscall.c
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 35f3684f53279279627accbeb73533a46be737fe..75eb3811e94204cd5dcd7bc9cc211a5d26234c74 100644 (file)
@@ -2401,7 +2401,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,
 
                        if (evsel->max_events != ULONG_MAX && ++evsel->nr_events_printed == evsel->max_events) {
                                evsel__disable(evsel);
-                               perf_evsel__close(evsel);
+                               evsel__close(evsel);
                        }
                }
        }
index 7027dacb50f644077f1a1c19154435668a942dd3..50f09e939229963e618382d375c261b7639513d8 100644 (file)
@@ -111,3 +111,29 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
 
        return err;
 }
+
+void perf_evsel__close_fd(struct perf_evsel *evsel)
+{
+       int cpu, thread;
+
+       for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++)
+               for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
+                       close(FD(evsel, cpu, thread));
+                       FD(evsel, cpu, thread) = -1;
+               }
+}
+
+void perf_evsel__free_fd(struct perf_evsel *evsel)
+{
+       xyarray__delete(evsel->fd);
+       evsel->fd = NULL;
+}
+
+void perf_evsel__close(struct perf_evsel *evsel)
+{
+       if (evsel->fd == NULL)
+               return;
+
+       perf_evsel__close_fd(evsel);
+       perf_evsel__free_fd(evsel);
+}
index 3cb9a0f5f32e0e1bd9764998d29d52ed49b2e911..878e2cf41ffc23f3135ca788d75a563fffeb24fe 100644 (file)
@@ -21,5 +21,7 @@ struct perf_evsel {
 };
 
 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
+void perf_evsel__close_fd(struct perf_evsel *evsel);
+void perf_evsel__free_fd(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
index e9fbaa8fb51a02644a430c3f254267abf3111912..aa5c48f822d262fc2f371156e61d075fbded8cce 100644 (file)
@@ -15,5 +15,6 @@ LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
 LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
                                 struct perf_thread_map *threads);
+LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVSEL_H */
index 7594d3d89c5fa22d5ff6a5da7d2b7056395278fa..0b90999dcdcb006ec5006353f5a1ae232ab29a58 100644 (file)
@@ -15,6 +15,7 @@ LIBPERF_0.0.1 {
                perf_evsel__delete;
                perf_evsel__init;
                perf_evsel__open;
+               perf_evsel__close;
                perf_evlist__new;
                perf_evlist__delete;
                perf_evlist__init;
index d161b1a78703a4946135d475eac7673593da525e..8322b6aa4047db028a5f5a37419484e799e49d5c 100644 (file)
@@ -116,7 +116,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int
 
        perf_evsel__free_counts(evsel);
 out_close_fd:
-       perf_evsel__close_fd(evsel);
+       perf_evsel__close_fd(&evsel->core);
 out_evsel_delete:
        evsel__delete(evsel);
 out_cpu_map_delete:
index 87c21254576737950716a8926612e17579880d72..f217972977e017e8161e260ca753b5cd1334a66a 100644 (file)
@@ -57,7 +57,7 @@ int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __m
 
        err = 0;
 out_close_fd:
-       perf_evsel__close_fd(evsel);
+       perf_evsel__close_fd(&evsel->core);
 out_evsel_delete:
        evsel__delete(evsel);
 out_thread_map_delete:
index eac4d634b9c7ccc6a50720b6809b0d0ff830a814..c6b4883b2d49a552e7dc3a095ae2f8154abb5592 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/err.h>
 #include <linux/zalloc.h>
 #include <perf/evlist.h>
+#include <perf/evsel.h>
 #include <perf/cpumap.h>
 
 #ifdef LACKS_SIGQUEUE_PROTOTYPE
@@ -1303,7 +1304,7 @@ void evlist__close(struct evlist *evlist)
        struct evsel *evsel;
 
        evlist__for_each_entry_reverse(evlist, evsel)
-               perf_evsel__close(evsel);
+               evsel__close(evsel);
 }
 
 static int perf_evlist__create_syswide_maps(struct evlist *evlist)
@@ -1772,7 +1773,7 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,
                        is_open = false;
                if (c2->leader == leader) {
                        if (is_open)
-                               perf_evsel__close(c2);
+                               evsel__close(c2);
                        c2->leader = c2;
                        c2->core.nr_members = 0;
                }
index d3c8488f7069ac93bbfbac9dd4d3789b2ebb4d88..8d8ed36377f5f021e44543e61071a8cf46eb7ab1 100644 (file)
@@ -1265,12 +1265,6 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
        return 0;
 }
 
-static void perf_evsel__free_fd(struct evsel *evsel)
-{
-       xyarray__delete(evsel->core.fd);
-       evsel->core.fd = NULL;
-}
-
 static void perf_evsel__free_id(struct evsel *evsel)
 {
        xyarray__delete(evsel->sample_id);
@@ -1289,23 +1283,12 @@ static void perf_evsel__free_config_terms(struct evsel *evsel)
        }
 }
 
-void perf_evsel__close_fd(struct evsel *evsel)
-{
-       int cpu, thread;
-
-       for (cpu = 0; cpu < xyarray__max_x(evsel->core.fd); cpu++)
-               for (thread = 0; thread < xyarray__max_y(evsel->core.fd); ++thread) {
-                       close(FD(evsel, cpu, thread));
-                       FD(evsel, cpu, thread) = -1;
-               }
-}
-
 void perf_evsel__exit(struct evsel *evsel)
 {
        assert(list_empty(&evsel->core.node));
        assert(evsel->evlist == NULL);
        perf_evsel__free_counts(evsel);
-       perf_evsel__free_fd(evsel);
+       perf_evsel__free_fd(&evsel->core);
        perf_evsel__free_id(evsel);
        perf_evsel__free_config_terms(evsel);
        cgroup__put(evsel->cgrp);
@@ -2057,13 +2040,9 @@ out_close:
        return err;
 }
 
-void perf_evsel__close(struct evsel *evsel)
+void evsel__close(struct evsel *evsel)
 {
-       if (evsel->core.fd == NULL)
-               return;
-
-       perf_evsel__close_fd(evsel);
-       perf_evsel__free_fd(evsel);
+       perf_evsel__close(&evsel->core);
        perf_evsel__free_id(evsel);
 }
 
index afd3a5b7bcc31aa58c878ab597419a46b5e90fd4..03fc8edad49278d9c25e000559755154bfbbe1f3 100644 (file)
@@ -268,7 +268,6 @@ const char *perf_evsel__group_name(struct evsel *evsel);
 int perf_evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
 
 int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads);
-void perf_evsel__close_fd(struct evsel *evsel);
 
 void __perf_evsel__set_sample_bit(struct evsel *evsel,
                                  enum perf_event_sample_format bit);
@@ -298,7 +297,7 @@ int perf_evsel__open_per_thread(struct evsel *evsel,
                                struct perf_thread_map *threads);
 int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
                struct perf_thread_map *threads);
-void perf_evsel__close(struct evsel *evsel);
+void evsel__close(struct evsel *evsel);
 
 struct perf_sample;