libperf: Add perf_thread_map__get()/perf_thread_map__put()
authorJiri Olsa <jolsa@kernel.org>
Sun, 21 Jul 2019 11:24:20 +0000 (13:24 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 29 Jul 2019 21:34:44 +0000 (18:34 -0300)
Move the following functions:

  thread_map__get()
  thread_map__put()
  thread_map__comm()

to libperf with the following names:

  perf_thread_map__get()
  perf_thread_map__put()
  perf_thread_map__comm()

Add the perf_thread_map__comm() function for it to work/compile.

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-34-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
23 files changed:
tools/perf/builtin-record.c
tools/perf/lib/include/perf/threadmap.h
tools/perf/lib/libperf.map
tools/perf/lib/threadmap.c
tools/perf/tests/code-reading.c
tools/perf/tests/event-times.c
tools/perf/tests/keep-tracking.c
tools/perf/tests/mmap-basic.c
tools/perf/tests/mmap-thread-lookup.c
tools/perf/tests/openat-syscall-all-cpus.c
tools/perf/tests/openat-syscall.c
tools/perf/tests/sw-clock.c
tools/perf/tests/switch-tracking.c
tools/perf/tests/task-exit.c
tools/perf/tests/thread-map.c
tools/perf/util/event.c
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/parse-events.c
tools/perf/util/python.c
tools/perf/util/stat-display.c
tools/perf/util/thread_map.c
tools/perf/util/thread_map.h

index c0962ddfad049893b56c34eaa4c10f9b852a5c92..03fbe4600ca0b5392cd1a19e6da9862fd0e5e38f 100644 (file)
@@ -1060,7 +1060,7 @@ static int record__synthesize_workload(struct record *rec, bool tail)
                                                 process_synthesized_event,
                                                 &rec->session->machines.host,
                                                 rec->opts.sample_address);
-       thread_map__put(thread_map);
+       perf_thread_map__put(thread_map);
        return err;
 }
 
index 34ed7f5871010ffdd7a5a5fed42e92e2fb8fee51..456295273daa24025cda47c583f2a5680c6358ed 100644 (file)
@@ -10,5 +10,9 @@ struct perf_thread_map;
 LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
 
 LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid);
+LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int thread);
+
+LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
+LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
 
 #endif /* __LIBPERF_THREADMAP_H */
index 6b4ec1c4d3f3e1424291012f1217f04839ea2260..c4f611010ccc4fba9b6cc07b59febd901c13708f 100644 (file)
@@ -6,6 +6,9 @@ LIBPERF_0.0.1 {
                perf_cpu_map__put;
                perf_thread_map__new_dummy;
                perf_thread_map__set_pid;
+               perf_thread_map__comm;
+               perf_thread_map__get;
+               perf_thread_map__put;
        local:
                *;
 };
index 23e628a1437a977747aec067557b00dabd97fa51..4865b73e258612593c412c1da364221e61decfa8 100644 (file)
@@ -4,6 +4,8 @@
 #include <linux/refcount.h>
 #include <internal/threadmap.h>
 #include <string.h>
+#include <asm/bug.h>
+#include <stdio.h>
 
 static void perf_thread_map__reset(struct perf_thread_map *map, int start, int nr)
 {
@@ -35,6 +37,11 @@ void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t pid
        map->map[thread].pid = pid;
 }
 
+char *perf_thread_map__comm(struct perf_thread_map *map, int thread)
+{
+       return map->map[thread].comm;
+}
+
 struct perf_thread_map *perf_thread_map__new_dummy(void)
 {
        struct perf_thread_map *threads = thread_map__alloc(1);
@@ -46,3 +53,29 @@ struct perf_thread_map *perf_thread_map__new_dummy(void)
        }
        return threads;
 }
+
+static void perf_thread_map__delete(struct perf_thread_map *threads)
+{
+       if (threads) {
+               int i;
+
+               WARN_ONCE(refcount_read(&threads->refcnt) != 0,
+                         "thread map refcnt unbalanced\n");
+               for (i = 0; i < threads->nr; i++)
+                       free(perf_thread_map__comm(threads, i));
+               free(threads);
+       }
+}
+
+struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map)
+{
+       if (map)
+               refcount_inc(&map->refcnt);
+       return map;
+}
+
+void perf_thread_map__put(struct perf_thread_map *map)
+{
+       if (map && refcount_dec_and_test(&map->refcnt))
+               perf_thread_map__delete(map);
+}
index ce2d3266286abe242ce1934961a75df4a582bf97..7b26be1dfb4755566f3c4ad6876057d0dafb3d56 100644 (file)
@@ -656,7 +656,7 @@ static int do_test_code_reading(bool try_kcore)
                                 * call. Getting refference to keep them alive.
                                 */
                                perf_cpu_map__get(cpus);
-                               thread_map__get(threads);
+                               perf_thread_map__get(threads);
                                perf_evlist__set_maps(evlist, NULL, NULL);
                                evlist__delete(evlist);
                                evlist = NULL;
@@ -706,7 +706,7 @@ out_err:
                evlist__delete(evlist);
        } else {
                perf_cpu_map__put(cpus);
-               thread_map__put(threads);
+               perf_thread_map__put(threads);
        }
        machine__delete_threads(machine);
        machine__delete(machine);
index dcfff4b20c926b3dab4dbb6e5021cb7ae5934d78..9238180416b08e470010060c9d95c237f4958d04 100644 (file)
@@ -76,7 +76,7 @@ static int attach__current_disabled(struct evlist *evlist)
                return err;
        }
 
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return evsel__enable(evsel) == 0 ? TEST_OK : TEST_FAIL;
 }
 
@@ -96,7 +96,7 @@ static int attach__current_enabled(struct evlist *evlist)
 
        err = perf_evsel__open_per_thread(evsel, threads);
 
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return err == 0 ? TEST_OK : TEST_FAIL;
 }
 
index 43e55fe98f8c21e24a677ec20f40c91878defa97..830fb3d7ea2efbc62e8fa219282ee6f0a2c790a7 100644 (file)
@@ -150,7 +150,7 @@ out_err:
                evlist__delete(evlist);
        } else {
                perf_cpu_map__put(cpus);
-               thread_map__put(threads);
+               perf_thread_map__put(threads);
        }
 
        return err;
index d15282174b2e82c50c1a0a0b9a95bda589321980..72fbf55f4fc3d3b64a238a4e5ffbc2c33a2d1288 100644 (file)
@@ -157,6 +157,6 @@ out_delete_evlist:
 out_free_cpus:
        perf_cpu_map__put(cpus);
 out_free_threads:
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return err;
 }
index ad6ca943e568589634cb41d2f506bc9a35103627..360d70deb85504f6acab8596fc5c067d627af568 100644 (file)
@@ -147,7 +147,7 @@ static int synth_process(struct machine *machine)
                                                perf_event__process,
                                                machine, 0);
 
-       thread_map__put(map);
+       perf_thread_map__put(map);
        return err;
 }
 
index 611f6ea9b702e71b17345106df452586661c4414..674b0fa035ec1c1b219aaa7dc59f8030f1cd367e 100644 (file)
@@ -122,6 +122,6 @@ out_evsel_delete:
 out_cpu_map_delete:
        perf_cpu_map__put(cpus);
 out_thread_map_delete:
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return err;
 }
index 20e353fbfdd09e0f717007837819f84422c80e1b..87c21254576737950716a8926612e17579880d72 100644 (file)
@@ -61,6 +61,6 @@ out_close_fd:
 out_evsel_delete:
        evsel__delete(evsel);
 out_thread_map_delete:
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return err;
 }
index c464e301ade9c4de5c16959d320524432719c640..2decda2d4c17ffce9a26231f513fbfc55e3cd3d7 100644 (file)
@@ -126,7 +126,7 @@ out_init:
 
 out_free_maps:
        perf_cpu_map__put(cpus);
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
 out_delete_evlist:
        evlist__delete(evlist);
        return err;
index 27af7b7109a3c9006442f49512089f806f7b8ea4..0935a5a1ecaabefb2c1b3567ac545b3b9b2e2ebe 100644 (file)
@@ -570,7 +570,7 @@ out:
                evlist__delete(evlist);
        } else {
                perf_cpu_map__put(cpus);
-               thread_map__put(threads);
+               perf_thread_map__put(threads);
        }
 
        return err;
index f026759a05d7b290a09cd02972626b2e08c8e1e7..24257285844b54a171b6480af3ba3daf524f46a7 100644 (file)
@@ -136,7 +136,7 @@ out_init:
 
 out_free_maps:
        perf_cpu_map__put(cpus);
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
 out_delete_evlist:
        evlist__delete(evlist);
        return err;
index 73bc404ed390555195f5abb7aa5848c6e12ed88b..d61773cacf0be939faa972cd167a78e15500c785 100644 (file)
@@ -28,11 +28,11 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
        TEST_ASSERT_VAL("wrong pid",
                        thread_map__pid(map, 0) == getpid());
        TEST_ASSERT_VAL("wrong comm",
-                       thread_map__comm(map, 0) &&
-                       !strcmp(thread_map__comm(map, 0), NAME));
+                       perf_thread_map__comm(map, 0) &&
+                       !strcmp(perf_thread_map__comm(map, 0), NAME));
        TEST_ASSERT_VAL("wrong refcnt",
                        refcount_read(&map->refcnt) == 1);
-       thread_map__put(map);
+       perf_thread_map__put(map);
 
        /* test dummy pid */
        map = perf_thread_map__new_dummy();
@@ -43,11 +43,11 @@ int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unuse
        TEST_ASSERT_VAL("wrong nr", map->nr == 1);
        TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
        TEST_ASSERT_VAL("wrong comm",
-                       thread_map__comm(map, 0) &&
-                       !strcmp(thread_map__comm(map, 0), "dummy"));
+                       perf_thread_map__comm(map, 0) &&
+                       !strcmp(perf_thread_map__comm(map, 0), "dummy"));
        TEST_ASSERT_VAL("wrong refcnt",
                        refcount_read(&map->refcnt) == 1);
-       thread_map__put(map);
+       perf_thread_map__put(map);
        return 0;
 }
 
@@ -70,11 +70,11 @@ static int process_event(struct perf_tool *tool __maybe_unused,
        TEST_ASSERT_VAL("wrong pid",
                        thread_map__pid(threads, 0) == getpid());
        TEST_ASSERT_VAL("wrong comm",
-                       thread_map__comm(threads, 0) &&
-                       !strcmp(thread_map__comm(threads, 0), NAME));
+                       perf_thread_map__comm(threads, 0) &&
+                       !strcmp(perf_thread_map__comm(threads, 0), NAME));
        TEST_ASSERT_VAL("wrong refcnt",
                        refcount_read(&threads->refcnt) == 1);
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return 0;
 }
 
index 1a3db35f9f7d56ffa3c9ffe7f6cca80207a830b6..f440fdc3e95358c67de5b7ae3af6028afd6f4085 100644 (file)
@@ -992,7 +992,7 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,
 
        for (i = 0; i < threads->nr; i++) {
                struct thread_map_event_entry *entry = &event->thread_map.entries[i];
-               char *comm = thread_map__comm(threads, i);
+               char *comm = perf_thread_map__comm(threads, i);
 
                if (!comm)
                        comm = (char *) "";
@@ -1387,7 +1387,7 @@ size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp)
        else
                ret += fprintf(fp, "failed to get threads from event\n");
 
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return ret;
 }
 
index 88d131769df4d1ce230a61e7c5d651cfa9f196b8..38a3c6d16b4bc53c6b59f974513000836e962d71 100644 (file)
@@ -142,7 +142,7 @@ void evlist__delete(struct evlist *evlist)
        perf_evlist__munmap(evlist);
        evlist__close(evlist);
        perf_cpu_map__put(evlist->cpus);
-       thread_map__put(evlist->threads);
+       perf_thread_map__put(evlist->threads);
        evlist->cpus = NULL;
        evlist->threads = NULL;
        perf_evlist__purge(evlist);
@@ -165,8 +165,8 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist,
                evsel->cpus = perf_cpu_map__get(evsel->own_cpus);
        }
 
-       thread_map__put(evsel->threads);
-       evsel->threads = thread_map__get(evlist->threads);
+       perf_thread_map__put(evsel->threads);
+       evsel->threads = perf_thread_map__get(evlist->threads);
 }
 
 static void perf_evlist__propagate_maps(struct evlist *evlist)
@@ -1100,7 +1100,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
        return 0;
 
 out_delete_threads:
-       thread_map__put(threads);
+       perf_thread_map__put(threads);
        return -1;
 }
 
@@ -1120,8 +1120,8 @@ void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus,
        }
 
        if (threads != evlist->threads) {
-               thread_map__put(evlist->threads);
-               evlist->threads = thread_map__get(threads);
+               perf_thread_map__put(evlist->threads);
+               evlist->threads = perf_thread_map__get(threads);
        }
 
        perf_evlist__propagate_maps(evlist);
index 72c0e6948e832ec7a9ed591254d6e99e46c44ae8..652e53279b28384639a10102e3cfe1b52a66c818 100644 (file)
@@ -1327,7 +1327,7 @@ void perf_evsel__exit(struct evsel *evsel)
        cgroup__put(evsel->cgrp);
        perf_cpu_map__put(evsel->cpus);
        perf_cpu_map__put(evsel->own_cpus);
-       thread_map__put(evsel->threads);
+       perf_thread_map__put(evsel->threads);
        zfree(&evsel->group_name);
        zfree(&evsel->name);
        perf_evsel__object.fini(evsel);
index 8c9928feb38a1666b9c8bec5a4f93a5f848261c7..38eeca6fa1fcdad04957609147fe9ecb6465ef54 100644 (file)
@@ -2337,7 +2337,7 @@ static bool is_event_supported(u8 type, unsigned config)
                evsel__delete(evsel);
        }
 
-       thread_map__put(tmap);
+       perf_thread_map__put(tmap);
        return ret;
 }
 
index 677c93f91c6c14358bad64902993279784963565..19d2feee91d57b4ff059b8c06962322d9f10b382 100644 (file)
@@ -626,7 +626,7 @@ static int pyrf_thread_map__init(struct pyrf_thread_map *pthreads,
 
 static void pyrf_thread_map__delete(struct pyrf_thread_map *pthreads)
 {
-       thread_map__put(pthreads->threads);
+       perf_thread_map__put(pthreads->threads);
        Py_TYPE(pthreads)->tp_free((PyObject*)pthreads);
 }
 
index f7666d2e6e0c11a068eb3fe703d4d9c68c5d9d62..1f099823a1f9a598b82542978ea52c819ea0c698 100644 (file)
@@ -116,7 +116,7 @@ static void aggr_printout(struct perf_stat_config *config,
        case AGGR_THREAD:
                fprintf(config->output, "%*s-%*d%s",
                        config->csv_output ? 0 : 16,
-                       thread_map__comm(evsel->threads, id),
+                       perf_thread_map__comm(evsel->threads, id),
                        config->csv_output ? 0 : -8,
                        thread_map__pid(evsel->threads, id),
                        config->csv_sep);
index 06dd9f2e4ce537eb6500dd5efd44e11002a164c1..c58385ea05be463d0eac67b602d08cf688700489 100644 (file)
@@ -304,32 +304,6 @@ struct perf_thread_map *thread_map__new_str(const char *pid, const char *tid,
        return thread_map__new_by_tid_str(tid);
 }
 
-static void thread_map__delete(struct perf_thread_map *threads)
-{
-       if (threads) {
-               int i;
-
-               WARN_ONCE(refcount_read(&threads->refcnt) != 0,
-                         "thread map refcnt unbalanced\n");
-               for (i = 0; i < threads->nr; i++)
-                       free(thread_map__comm(threads, i));
-               free(threads);
-       }
-}
-
-struct perf_thread_map *thread_map__get(struct perf_thread_map *map)
-{
-       if (map)
-               refcount_inc(&map->refcnt);
-       return map;
-}
-
-void thread_map__put(struct perf_thread_map *map)
-{
-       if (map && refcount_dec_and_test(&map->refcnt))
-               thread_map__delete(map);
-}
-
 size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp)
 {
        int i;
index 94a1f9565f5e05594551c82a9138b9d789fcb835..ba45c760be724f26aad7874cae03cb4c0398de95 100644 (file)
@@ -18,9 +18,6 @@ struct perf_thread_map *thread_map__new_all_cpus(void);
 struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
 struct perf_thread_map *thread_map__new_event(struct thread_map_event *event);
 
-struct perf_thread_map *thread_map__get(struct perf_thread_map *map);
-void thread_map__put(struct perf_thread_map *map);
-
 struct perf_thread_map *thread_map__new_str(const char *pid,
                const char *tid, uid_t uid, bool all_threads);
 
@@ -38,11 +35,6 @@ static inline pid_t thread_map__pid(struct perf_thread_map *map, int thread)
        return map->map[thread].pid;
 }
 
-static inline char *thread_map__comm(struct perf_thread_map *map, int thread)
-{
-       return map->map[thread].comm;
-}
-
 void thread_map__read_comms(struct perf_thread_map *threads);
 bool thread_map__has(struct perf_thread_map *threads, pid_t pid);
 int thread_map__remove(struct perf_thread_map *threads, int idx);