From f854839ba2a546a888159667c5ade96793e5cd10 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 21 Jul 2019 13:23:49 +0200 Subject: perf cpu_map: Rename struct cpu_map to struct perf_cpu_map Rename struct cpu_map to struct perf_cpu_map, so it could be part of libperf. Committer notes: Added fixes for arm64, provided by Jiri. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20190721112506.12306-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/mem2node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/tests/mem2node.c') diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index 520cc91af256..e12eedfba781 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -19,7 +19,7 @@ static struct node { static unsigned long *get_bitmap(const char *str, int nbits) { - struct cpu_map *map = cpu_map__new(str); + struct perf_cpu_map *map = cpu_map__new(str); unsigned long *bm = NULL; int i; -- cgit v1.2.3-59-g8ed1b From 38f01d8da1d8d28678ea16a0a484f4d3eded34b2 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 21 Jul 2019 13:24:17 +0200 Subject: libperf: Add perf_cpu_map__get()/perf_cpu_map__put() Moving the following functions: cpu_map__get() cpu_map__put() to libperf with following names: perf_cpu_map__get() perf_cpu_map__put() Committer notes: Added fixes for arm/arm64 Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20190721112506.12306-31-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/arm/util/cs-etm.c | 6 +++--- tools/perf/arch/arm64/util/header.c | 4 ++-- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-stat.c | 4 ++-- tools/perf/lib/cpumap.c | 24 ++++++++++++++++++++++++ tools/perf/lib/include/perf/cpumap.h | 2 ++ tools/perf/lib/libperf.map | 2 ++ tools/perf/tests/bitmap.c | 2 +- tools/perf/tests/code-reading.c | 4 ++-- tools/perf/tests/cpumap.c | 8 ++++---- tools/perf/tests/event-times.c | 4 ++-- tools/perf/tests/event_update.c | 4 ++-- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mem2node.c | 2 +- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 22 ---------------------- tools/perf/util/cpumap.h | 3 --- tools/perf/util/cputopo.c | 4 ++-- tools/perf/util/env.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/evlist.c | 16 ++++++++-------- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/parse-events.c | 4 ++-- tools/perf/util/pmu.c | 2 +- tools/perf/util/python.c | 2 +- tools/perf/util/record.c | 6 +++--- tools/perf/util/session.c | 2 +- tools/perf/util/svghelper.c | 2 +- 33 files changed, 78 insertions(+), 75 deletions(-) (limited to 'tools/perf/tests/mem2node.c') diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 268fcb31cd53..3a78b38e43ca 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -181,7 +181,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr, err = 0; out: - cpu_map__put(online_cpus); + perf_cpu_map__put(online_cpus); return err; } @@ -517,7 +517,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, } } - cpu_map__put(online_cpus); + perf_cpu_map__put(online_cpus); return (CS_ETM_HEADER_SIZE + (etmv4 * CS_ETMV4_PRIV_SIZE) + @@ -679,7 +679,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, if (cpu_map__has(cpu_map, i)) cs_etm_get_metadata(i, &offset, itr, info); - cpu_map__put(online_cpus); + perf_cpu_map__put(online_cpus); return 0; } diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index b3e73a413f5a..602caf550e7f 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -27,7 +27,7 @@ char *get_cpuid_str(struct perf_pmu *pmu) return NULL; /* read midr from list of cpus mapped to this pmu */ - cpus = cpu_map__get(pmu->cpus); + cpus = perf_cpu_map__get(pmu->cpus); for (cpu = 0; cpu < cpus->nr; cpu++) { scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR, sysfs, cpus->map[cpu]); @@ -60,6 +60,6 @@ char *get_cpuid_str(struct perf_pmu *pmu) buf = NULL; } - cpu_map__put(cpus); + perf_cpu_map__put(cpus); return buf; } diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 105ef2a17a9c..6943352b8d94 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -206,7 +206,7 @@ static int reset_tracing_cpu(void) int ret; ret = set_tracing_cpumask(cpumap); - cpu_map__put(cpumap); + perf_cpu_map__put(cpumap); return ret; } diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 36e66a4f3c57..39bd73d0e06e 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -933,8 +933,8 @@ static int perf_stat_init_aggr_mode(void) static void perf_stat__exit_aggr_mode(void) { - cpu_map__put(stat_config.aggr_map); - cpu_map__put(stat_config.cpus_aggr_map); + perf_cpu_map__put(stat_config.aggr_map); + perf_cpu_map__put(stat_config.cpus_aggr_map); stat_config.aggr_map = NULL; stat_config.cpus_aggr_map = NULL; } diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c index 80d587ab95aa..f3cfb4c71106 100644 --- a/tools/perf/lib/cpumap.c +++ b/tools/perf/lib/cpumap.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include struct perf_cpu_map *perf_cpu_map__dummy_new(void) { @@ -16,3 +18,25 @@ struct perf_cpu_map *perf_cpu_map__dummy_new(void) return cpus; } + +static void cpu_map__delete(struct perf_cpu_map *map) +{ + if (map) { + WARN_ONCE(refcount_read(&map->refcnt) != 0, + "cpu_map refcnt unbalanced\n"); + free(map); + } +} + +struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map) +{ + if (map) + refcount_inc(&map->refcnt); + return map; +} + +void perf_cpu_map__put(struct perf_cpu_map *map) +{ + if (map && refcount_dec_and_test(&map->refcnt)) + cpu_map__delete(map); +} diff --git a/tools/perf/lib/include/perf/cpumap.h b/tools/perf/lib/include/perf/cpumap.h index fa1e5aa9d662..e16c2515a499 100644 --- a/tools/perf/lib/include/perf/cpumap.h +++ b/tools/perf/lib/include/perf/cpumap.h @@ -7,5 +7,7 @@ struct perf_cpu_map; LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); +LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); #endif /* __LIBPERF_CPUMAP_H */ diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map index 65201c6cbe7e..76ce3bc59dd8 100644 --- a/tools/perf/lib/libperf.map +++ b/tools/perf/lib/libperf.map @@ -2,6 +2,8 @@ LIBPERF_0.0.1 { global: libperf_set_print; perf_cpu_map__dummy_new; + perf_cpu_map__get; + perf_cpu_map__put; local: *; }; diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c index 74d0cd32a5c4..95304d29092e 100644 --- a/tools/perf/tests/bitmap.c +++ b/tools/perf/tests/bitmap.c @@ -21,7 +21,7 @@ static unsigned long *get_bitmap(const char *str, int nbits) } if (map) - cpu_map__put(map); + perf_cpu_map__put(map); return bm; } diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index ec4b0bf28270..ce2d3266286a 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -655,7 +655,7 @@ static int do_test_code_reading(bool try_kcore) * and will be freed by following perf_evlist__set_maps * call. Getting refference to keep them alive. */ - cpu_map__get(cpus); + perf_cpu_map__get(cpus); thread_map__get(threads); perf_evlist__set_maps(evlist, NULL, NULL); evlist__delete(evlist); @@ -705,7 +705,7 @@ out_err: if (evlist) { evlist__delete(evlist); } else { - cpu_map__put(cpus); + perf_cpu_map__put(cpus); thread_map__put(threads); } machine__delete_threads(machine); diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 10da4400493d..6c921087b0fe 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -39,7 +39,7 @@ static int process_event_mask(struct perf_tool *tool __maybe_unused, TEST_ASSERT_VAL("wrong cpu", map->map[i] == i); } - cpu_map__put(map); + perf_cpu_map__put(map); return 0; } @@ -68,7 +68,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused, TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1); TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256); TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1); - cpu_map__put(map); + perf_cpu_map__put(map); return 0; } @@ -83,7 +83,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may TEST_ASSERT_VAL("failed to synthesize map", !perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL)); - cpu_map__put(cpus); + perf_cpu_map__put(cpus); /* This one is better stores in cpu values. */ cpus = cpu_map__new("1,256"); @@ -91,7 +91,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may TEST_ASSERT_VAL("failed to synthesize map", !perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL)); - cpu_map__put(cpus); + perf_cpu_map__put(cpus); return 0; } diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index bf00d3d792fb..dcfff4b20c92 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -132,7 +132,7 @@ static int attach__cpu_disabled(struct evlist *evlist) return err; } - cpu_map__put(cpus); + perf_cpu_map__put(cpus); return evsel__enable(evsel); } @@ -154,7 +154,7 @@ static int attach__cpu_enabled(struct evlist *evlist) if (err == -EACCES) return TEST_SKIP; - cpu_map__put(cpus); + perf_cpu_map__put(cpus); return err ? TEST_FAIL : TEST_OK; } diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c index eb0dd359762d..415d12e96834 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -73,7 +73,7 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused, TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); - cpu_map__put(map); + perf_cpu_map__put(map); return 0; } @@ -113,6 +113,6 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu TEST_ASSERT_VAL("failed to synthesize attr update cpus", !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); - cpu_map__put(evsel->own_cpus); + perf_cpu_map__put(evsel->own_cpus); return 0; } diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c index 7bfc859971e5..43e55fe98f8c 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c @@ -149,7 +149,7 @@ out_err: evlist__disable(evlist); evlist__delete(evlist); } else { - cpu_map__put(cpus); + perf_cpu_map__put(cpus); thread_map__put(threads); } diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index e12eedfba781..6fe2c1e7918b 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -32,7 +32,7 @@ static unsigned long *get_bitmap(const char *str, int nbits) } if (map) - cpu_map__put(map); + perf_cpu_map__put(map); else free(bm); diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 40511025208f..d15282174b2e 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -155,7 +155,7 @@ out_delete_evlist: cpus = NULL; threads = NULL; out_free_cpus: - cpu_map__put(cpus); + perf_cpu_map__put(cpus); out_free_threads: thread_map__put(threads); return err; diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c index f96cbd304024..611f6ea9b702 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -120,7 +120,7 @@ out_close_fd: out_evsel_delete: evsel__delete(evsel); out_cpu_map_delete: - cpu_map__put(cpus); + perf_cpu_map__put(cpus); out_thread_map_delete: thread_map__put(threads); return err; diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c index c6d3f4488b73..c464e301ade9 100644 --- a/tools/perf/tests/sw-clock.c +++ b/tools/perf/tests/sw-clock.c @@ -125,7 +125,7 @@ out_init: } out_free_maps: - cpu_map__put(cpus); + perf_cpu_map__put(cpus); thread_map__put(threads); out_delete_evlist: evlist__delete(evlist); diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index d5537edb47db..27af7b7109a3 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -569,7 +569,7 @@ out: evlist__disable(evlist); evlist__delete(evlist); } else { - cpu_map__put(cpus); + perf_cpu_map__put(cpus); thread_map__put(threads); } diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c index c094fb8cc877..f026759a05d7 100644 --- a/tools/perf/tests/task-exit.c +++ b/tools/perf/tests/task-exit.c @@ -135,7 +135,7 @@ out_init: } out_free_maps: - cpu_map__put(cpus); + perf_cpu_map__put(cpus); thread_map__put(threads); out_delete_evlist: evlist__delete(evlist); diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 443d0272ebbd..1b57ded58d59 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -133,7 +133,7 @@ int test__session_topology(struct test *test __maybe_unused, int subtest __maybe } ret = check_cpu_topology(path, map); - cpu_map__put(map); + perf_cpu_map__put(map); free_path: unlink(path); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index acda9bfb4002..44082e5eabde 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -273,28 +273,6 @@ struct perf_cpu_map *cpu_map__empty_new(int nr) return cpus; } -static void cpu_map__delete(struct perf_cpu_map *map) -{ - if (map) { - WARN_ONCE(refcount_read(&map->refcnt) != 0, - "cpu_map refcnt unbalanced\n"); - free(map); - } -} - -struct perf_cpu_map *cpu_map__get(struct perf_cpu_map *map) -{ - if (map) - refcount_inc(&map->refcnt); - return map; -} - -void cpu_map__put(struct perf_cpu_map *map) -{ - if (map && refcount_dec_and_test(&map->refcnt)) - cpu_map__delete(map); -} - static int cpu__get_topology_int(int cpu, const char *name, int *value) { char path[PATH_MAX]; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 0ce3f6bd9449..b7af2cb68c19 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -29,9 +29,6 @@ int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diep int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct perf_cpu_map **corep); const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ -struct perf_cpu_map *cpu_map__get(struct perf_cpu_map *map); -void cpu_map__put(struct perf_cpu_map *map); - static inline int cpu_map__socket(struct perf_cpu_map *sock, int s) { if (!sock || s > sock->nr || s < 0) diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 157b0988435e..0cd99c460cd4 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -219,7 +219,7 @@ struct cpu_topology *cpu_topology__new(void) } out_free: - cpu_map__put(map); + perf_cpu_map__put(map); if (ret) { cpu_topology__delete(tp); tp = NULL; @@ -335,7 +335,7 @@ struct numa_topology *numa_topology__new(void) out: free(buf); fclose(fp); - cpu_map__put(node_map); + perf_cpu_map__put(node_map); return tp; } diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 9909ec40c6d2..d77912b2b5e7 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -179,7 +179,7 @@ void perf_env__exit(struct perf_env *env) zfree(&env->cpu); for (i = 0; i < env->nr_numa_nodes; i++) - cpu_map__put(env->numa_nodes[i].map); + perf_cpu_map__put(env->numa_nodes[i].map); zfree(&env->numa_nodes); for (i = 0; i < env->caches_cnt; i++) diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index f78837788b14..1a3db35f9f7d 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -1403,7 +1403,7 @@ size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp) else ret += fprintf(fp, "failed to get cpumap from event\n"); - cpu_map__put(cpus); + perf_cpu_map__put(cpus); return ret; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 461c1e68e9e7..35020d50f51e 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -141,7 +141,7 @@ void evlist__delete(struct evlist *evlist) perf_evlist__munmap(evlist); evlist__close(evlist); - cpu_map__put(evlist->cpus); + perf_cpu_map__put(evlist->cpus); thread_map__put(evlist->threads); evlist->cpus = NULL; evlist->threads = NULL; @@ -158,11 +158,11 @@ static void __perf_evlist__propagate_maps(struct evlist *evlist, * keep it, if there's no target cpu list defined. */ if (!evsel->own_cpus || evlist->has_user_cpus) { - cpu_map__put(evsel->cpus); - evsel->cpus = cpu_map__get(evlist->cpus); + perf_cpu_map__put(evsel->cpus); + evsel->cpus = perf_cpu_map__get(evlist->cpus); } else if (evsel->cpus != evsel->own_cpus) { - cpu_map__put(evsel->cpus); - evsel->cpus = cpu_map__get(evsel->own_cpus); + perf_cpu_map__put(evsel->cpus); + evsel->cpus = perf_cpu_map__get(evsel->own_cpus); } thread_map__put(evsel->threads); @@ -1115,8 +1115,8 @@ void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus, * the caller to increase the reference count. */ if (cpus != evlist->cpus) { - cpu_map__put(evlist->cpus); - evlist->cpus = cpu_map__get(cpus); + perf_cpu_map__put(evlist->cpus); + evlist->cpus = perf_cpu_map__get(cpus); } if (threads != evlist->threads) { @@ -1383,7 +1383,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist) out: return err; out_put: - cpu_map__put(cpus); + perf_cpu_map__put(cpus); goto out; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a389752840a9..72c0e6948e83 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1325,8 +1325,8 @@ void perf_evsel__exit(struct evsel *evsel) perf_evsel__free_id(evsel); perf_evsel__free_config_terms(evsel); cgroup__put(evsel->cgrp); - cpu_map__put(evsel->cpus); - cpu_map__put(evsel->own_cpus); + perf_cpu_map__put(evsel->cpus); + perf_cpu_map__put(evsel->own_cpus); thread_map__put(evsel->threads); zfree(&evsel->group_name); zfree(&evsel->name); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index decb66d243ca..8c9928feb38a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -332,8 +332,8 @@ __add_event(struct list_head *list, int *idx, return NULL; (*idx)++; - evsel->cpus = cpu_map__get(cpus); - evsel->own_cpus = cpu_map__get(cpus); + evsel->cpus = perf_cpu_map__get(cpus); + evsel->own_cpus = perf_cpu_map__get(cpus); evsel->system_wide = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4929a50c0973..d355f9506a1c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -626,7 +626,7 @@ static bool pmu_is_uncore(const char *name) snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name); cpus = __pmu_cpumask(path); - cpu_map__put(cpus); + perf_cpu_map__put(cpus); return !!cpus; } diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index cc4af99ab190..677c93f91c6c 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -557,7 +557,7 @@ static int pyrf_cpu_map__init(struct pyrf_cpu_map *pcpus, static void pyrf_cpu_map__delete(struct pyrf_cpu_map *pcpus) { - cpu_map__put(pcpus->cpus); + perf_cpu_map__put(pcpus->cpus); Py_TYPE(pcpus)->tp_free((PyObject*)pcpus); } diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 9f8841548539..fecccfd71aa1 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -67,7 +67,7 @@ static bool perf_probe_api(setup_probe_fn_t fn) if (!cpus) return false; cpu = cpus->map[0]; - cpu_map__put(cpus); + perf_cpu_map__put(cpus); do { ret = perf_do_probe_api(fn, cpu, try[i++]); @@ -122,7 +122,7 @@ bool perf_can_record_cpu_wide(void) if (!cpus) return false; cpu = cpus->map[0]; - cpu_map__put(cpus); + perf_cpu_map__put(cpus); fd = sys_perf_event_open(&attr, -1, cpu, -1, 0); if (fd < 0) @@ -278,7 +278,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str) struct perf_cpu_map *cpus = cpu_map__new(NULL); cpu = cpus ? cpus->map[0] : 0; - cpu_map__put(cpus); + perf_cpu_map__put(cpus); } else { cpu = evlist->cpus->map[0]; } diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c191dc152175..62d37440cbee 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2310,7 +2310,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, err = 0; out_delete_map: - cpu_map__put(map); + perf_cpu_map__put(map); return err; } diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 99132c6a30a6..a9ca5c4fffee 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -745,7 +745,7 @@ static int str_to_bitmap(char *s, cpumask_t *b) set_bit(c, cpumask_bits(b)); } - cpu_map__put(m); + perf_cpu_map__put(m); return ret; } -- cgit v1.2.3-59-g8ed1b From 9c3516d1b850ea938b074df33e4c86d721c77720 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 21 Jul 2019 13:24:30 +0200 Subject: libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions Moving the following functions from tools/perf: cpu_map__new() cpu_map__read() to libperf with the following names: perf_cpu_map__new() perf_cpu_map__read() Committer notes: Fixed up this one: tools/perf/arch/arm/util/cs-etm.c Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20190721112506.12306-44-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/arm/util/cs-etm.c | 6 +- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 3 +- tools/perf/bench/epoll-ctl.c | 3 +- tools/perf/bench/epoll-wait.c | 3 +- tools/perf/bench/futex-hash.c | 3 +- tools/perf/bench/futex-lock-pi.c | 3 +- tools/perf/bench/futex-requeue.c | 3 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 3 +- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-sched.c | 4 +- tools/perf/lib/cpumap.c | 184 +++++++++++++++++++++++++++ tools/perf/lib/include/internal/cpumap.h | 4 + tools/perf/lib/include/perf/cpumap.h | 3 + tools/perf/lib/libperf.map | 2 + tools/perf/tests/bitmap.c | 3 +- tools/perf/tests/code-reading.c | 5 +- tools/perf/tests/cpumap.c | 7 +- tools/perf/tests/event-times.c | 9 +- tools/perf/tests/event_update.c | 3 +- tools/perf/tests/keep-tracking.c | 3 +- tools/perf/tests/mem2node.c | 3 +- tools/perf/tests/mmap-basic.c | 3 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/switch-tracking.c | 5 +- tools/perf/tests/topology.c | 3 +- tools/perf/util/cpumap.c | 181 +------------------------- tools/perf/util/cpumap.h | 2 - tools/perf/util/cputopo.c | 5 +- tools/perf/util/evlist.c | 5 +- tools/perf/util/header.c | 3 +- tools/perf/util/parse-events.c | 3 +- tools/perf/util/pmu.c | 3 +- tools/perf/util/python.c | 3 +- tools/perf/util/record.c | 7 +- tools/perf/util/session.c | 3 +- tools/perf/util/svghelper.c | 3 +- 37 files changed, 265 insertions(+), 227 deletions(-) (limited to 'tools/perf/tests/mem2node.c') diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index f5aafdec7f50..c25bc1528b96 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -156,7 +156,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr, { int i, err = -EINVAL; struct perf_cpu_map *event_cpus = evsel->evlist->cpus; - struct perf_cpu_map *online_cpus = cpu_map__new(NULL); + struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); /* Set option of each CPU we have */ for (i = 0; i < cpu__max_cpu(); i++) { @@ -490,7 +490,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, int i; int etmv3 = 0, etmv4 = 0; struct perf_cpu_map *event_cpus = evlist->cpus; - struct perf_cpu_map *online_cpus = cpu_map__new(NULL); + struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); /* cpu map is not empty, we have specific CPUs to work with */ if (!cpu_map__empty(event_cpus)) { @@ -637,7 +637,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, u64 nr_cpu, type; struct perf_cpu_map *cpu_map; struct perf_cpu_map *event_cpus = session->evlist->cpus; - struct perf_cpu_map *online_cpus = cpu_map__new(NULL); + struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL); struct cs_etm_recording *ptr = container_of(itr, struct cs_etm_recording, itr); struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c index 07129e007eb0..261bdd680651 100644 --- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c +++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "parse-events.h" #include "evlist.h" @@ -65,7 +66,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe threads = thread_map__new(-1, getpid(), UINT_MAX); CHECK_NOT_NULL__(threads); - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); CHECK_NOT_NULL__(cpus); evlist = evlist__new(); diff --git a/tools/perf/bench/epoll-ctl.c b/tools/perf/bench/epoll-ctl.c index 1fd724f1d48b..84658d45f349 100644 --- a/tools/perf/bench/epoll-ctl.c +++ b/tools/perf/bench/epoll-ctl.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "../util/stat.h" #include @@ -315,7 +316,7 @@ int bench_epoll_ctl(int argc, const char **argv) act.sa_sigaction = toggle_done; sigaction(SIGINT, &act, NULL); - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) goto errmem; diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c index 79a254fff2d1..c27a65639cfb 100644 --- a/tools/perf/bench/epoll-wait.c +++ b/tools/perf/bench/epoll-wait.c @@ -75,6 +75,7 @@ #include #include #include +#include #include "../util/stat.h" #include @@ -429,7 +430,7 @@ int bench_epoll_wait(int argc, const char **argv) act.sa_sigaction = toggle_done; sigaction(SIGINT, &act, NULL); - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) goto errmem; diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index b4fea8e3a368..80e138904c66 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "../util/stat.h" #include @@ -132,7 +133,7 @@ int bench_futex_hash(int argc, const char **argv) exit(EXIT_FAILURE); } - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) goto errmem; diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c index 596769924709..c5d6d0abbaa9 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "bench.h" #include "futex.h" #include "cpumap.h" @@ -156,7 +157,7 @@ int bench_futex_lock_pi(int argc, const char **argv) if (argc) goto err; - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) err(EXIT_FAILURE, "calloc"); diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index 1fd32a4f9c14..75d3418c1a88 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "bench.h" #include "futex.h" #include "cpumap.h" @@ -123,7 +124,7 @@ int bench_futex_requeue(int argc, const char **argv) if (argc) goto err; - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) err(EXIT_FAILURE, "cpu_map__new"); diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index 884c73e5bd1b..163fe16c275a 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c @@ -237,7 +237,7 @@ int bench_futex_wake_parallel(int argc, const char **argv) act.sa_sigaction = toggle_done; sigaction(SIGINT, &act, NULL); - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) err(EXIT_FAILURE, "calloc"); diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index 2288fa8412ff..77dcdc13618a 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "bench.h" #include "futex.h" #include "cpumap.h" @@ -131,7 +132,7 @@ int bench_futex_wake(int argc, const char **argv) exit(EXIT_FAILURE); } - cpu = cpu_map__new(NULL); + cpu = perf_cpu_map__new(NULL); if (!cpu) err(EXIT_FAILURE, "calloc"); diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 6943352b8d94..77989254fdd8 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -202,7 +202,7 @@ static int set_tracing_cpu(struct perf_ftrace *ftrace) static int reset_tracing_cpu(void) { - struct perf_cpu_map *cpumap = cpu_map__new(NULL); + struct perf_cpu_map *cpumap = perf_cpu_map__new(NULL); int ret; ret = set_tracing_cpumask(cpumap); diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 897d11c8ca2e..0d6b4c3b1a51 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -3183,7 +3183,7 @@ static int setup_map_cpus(struct perf_sched *sched) if (!sched->map.cpus_str) return 0; - map = cpu_map__new(sched->map.cpus_str); + map = perf_cpu_map__new(sched->map.cpus_str); if (!map) { pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); return -1; @@ -3217,7 +3217,7 @@ static int setup_color_cpus(struct perf_sched *sched) if (!sched->map.color_cpus_str) return 0; - map = cpu_map__new(sched->map.color_cpus_str); + map = perf_cpu_map__new(sched->map.color_cpus_str); if (!map) { pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str); return -1; diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c index f3cfb4c71106..a5d4f7ff7174 100644 --- a/tools/perf/lib/cpumap.c +++ b/tools/perf/lib/cpumap.c @@ -5,6 +5,10 @@ #include #include #include +#include +#include +#include +#include struct perf_cpu_map *perf_cpu_map__dummy_new(void) { @@ -40,3 +44,183 @@ void perf_cpu_map__put(struct perf_cpu_map *map) if (map && refcount_dec_and_test(&map->refcnt)) cpu_map__delete(map); } + +static struct perf_cpu_map *cpu_map__default_new(void) +{ + struct perf_cpu_map *cpus; + int nr_cpus; + + nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (nr_cpus < 0) + return NULL; + + cpus = malloc(sizeof(*cpus) + nr_cpus * sizeof(int)); + if (cpus != NULL) { + int i; + + for (i = 0; i < nr_cpus; ++i) + cpus->map[i] = i; + + cpus->nr = nr_cpus; + refcount_set(&cpus->refcnt, 1); + } + + return cpus; +} + +static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) +{ + size_t payload_size = nr_cpus * sizeof(int); + struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + payload_size); + + if (cpus != NULL) { + cpus->nr = nr_cpus; + memcpy(cpus->map, tmp_cpus, payload_size); + refcount_set(&cpus->refcnt, 1); + } + + return cpus; +} + +struct perf_cpu_map *perf_cpu_map__read(FILE *file) +{ + struct perf_cpu_map *cpus = NULL; + int nr_cpus = 0; + int *tmp_cpus = NULL, *tmp; + int max_entries = 0; + int n, cpu, prev; + char sep; + + sep = 0; + prev = -1; + for (;;) { + n = fscanf(file, "%u%c", &cpu, &sep); + if (n <= 0) + break; + if (prev >= 0) { + int new_max = nr_cpus + cpu - prev - 1; + + if (new_max >= max_entries) { + max_entries = new_max + MAX_NR_CPUS / 2; + tmp = realloc(tmp_cpus, max_entries * sizeof(int)); + if (tmp == NULL) + goto out_free_tmp; + tmp_cpus = tmp; + } + + while (++prev < cpu) + tmp_cpus[nr_cpus++] = prev; + } + if (nr_cpus == max_entries) { + max_entries += MAX_NR_CPUS; + tmp = realloc(tmp_cpus, max_entries * sizeof(int)); + if (tmp == NULL) + goto out_free_tmp; + tmp_cpus = tmp; + } + + tmp_cpus[nr_cpus++] = cpu; + if (n == 2 && sep == '-') + prev = cpu; + else + prev = -1; + if (n == 1 || sep == '\n') + break; + } + + if (nr_cpus > 0) + cpus = cpu_map__trim_new(nr_cpus, tmp_cpus); + else + cpus = cpu_map__default_new(); +out_free_tmp: + free(tmp_cpus); + return cpus; +} + +static struct perf_cpu_map *cpu_map__read_all_cpu_map(void) +{ + struct perf_cpu_map *cpus = NULL; + FILE *onlnf; + + onlnf = fopen("/sys/devices/system/cpu/online", "r"); + if (!onlnf) + return cpu_map__default_new(); + + cpus = perf_cpu_map__read(onlnf); + fclose(onlnf); + return cpus; +} + +struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) +{ + struct perf_cpu_map *cpus = NULL; + unsigned long start_cpu, end_cpu = 0; + char *p = NULL; + int i, nr_cpus = 0; + int *tmp_cpus = NULL, *tmp; + int max_entries = 0; + + if (!cpu_list) + return cpu_map__read_all_cpu_map(); + + /* + * must handle the case of empty cpumap to cover + * TOPOLOGY header for NUMA nodes with no CPU + * ( e.g., because of CPU hotplug) + */ + if (!isdigit(*cpu_list) && *cpu_list != '\0') + goto out; + + while (isdigit(*cpu_list)) { + p = NULL; + start_cpu = strtoul(cpu_list, &p, 0); + if (start_cpu >= INT_MAX + || (*p != '\0' && *p != ',' && *p != '-')) + goto invalid; + + if (*p == '-') { + cpu_list = ++p; + p = NULL; + end_cpu = strtoul(cpu_list, &p, 0); + + if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',')) + goto invalid; + + if (end_cpu < start_cpu) + goto invalid; + } else { + end_cpu = start_cpu; + } + + for (; start_cpu <= end_cpu; start_cpu++) { + /* check for duplicates */ + for (i = 0; i < nr_cpus; i++) + if (tmp_cpus[i] == (int)start_cpu) + goto invalid; + + if (nr_cpus == max_entries) { + max_entries += MAX_NR_CPUS; + tmp = realloc(tmp_cpus, max_entries * sizeof(int)); + if (tmp == NULL) + goto invalid; + tmp_cpus = tmp; + } + tmp_cpus[nr_cpus++] = (int)start_cpu; + } + if (*p) + ++p; + + cpu_list = p; + } + + if (nr_cpus > 0) + cpus = cpu_map__trim_new(nr_cpus, tmp_cpus); + else if (*cpu_list != '\0') + cpus = cpu_map__default_new(); + else + cpus = perf_cpu_map__dummy_new(); +invalid: + free(tmp_cpus); +out: + return cpus; +} diff --git a/tools/perf/lib/include/internal/cpumap.h b/tools/perf/lib/include/internal/cpumap.h index 53ce95374b05..3306319f7df8 100644 --- a/tools/perf/lib/include/internal/cpumap.h +++ b/tools/perf/lib/include/internal/cpumap.h @@ -10,4 +10,8 @@ struct perf_cpu_map { int map[]; }; +#ifndef MAX_NR_CPUS +#define MAX_NR_CPUS 2048 +#endif + #endif /* __LIBPERF_INTERNAL_CPUMAP_H */ diff --git a/tools/perf/lib/include/perf/cpumap.h b/tools/perf/lib/include/perf/cpumap.h index e16c2515a499..b4a9283a5dfa 100644 --- a/tools/perf/lib/include/perf/cpumap.h +++ b/tools/perf/lib/include/perf/cpumap.h @@ -3,10 +3,13 @@ #define __LIBPERF_CPUMAP_H #include +#include struct perf_cpu_map; LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map index 168339f89a2e..e38473a8f32f 100644 --- a/tools/perf/lib/libperf.map +++ b/tools/perf/lib/libperf.map @@ -4,6 +4,8 @@ LIBPERF_0.0.1 { perf_cpu_map__dummy_new; perf_cpu_map__get; perf_cpu_map__put; + perf_cpu_map__new; + perf_cpu_map__read; perf_thread_map__new_dummy; perf_thread_map__set_pid; perf_thread_map__comm; diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c index 95304d29092e..db2aadff3708 100644 --- a/tools/perf/tests/bitmap.c +++ b/tools/perf/tests/bitmap.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "tests.h" #include "cpumap.h" #include "debug.h" @@ -9,7 +10,7 @@ static unsigned long *get_bitmap(const char *str, int nbits) { - struct perf_cpu_map *map = cpu_map__new(str); + struct perf_cpu_map *map = perf_cpu_map__new(str); unsigned long *bm = NULL; int i; diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 131bbeec62d2..bfaf22c2023c 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "parse-events.h" #include "evlist.h" @@ -613,9 +614,9 @@ static int do_test_code_reading(bool try_kcore) goto out_put; } - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (!cpus) { - pr_debug("cpu_map__new failed\n"); + pr_debug("perf_cpu_map__new failed\n"); goto out_put; } diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 6c921087b0fe..b71fe09a8087 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -5,6 +5,7 @@ #include "event.h" #include #include +#include #include "debug.h" struct machine; @@ -78,7 +79,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may struct perf_cpu_map *cpus; /* This one is better stores in mask. */ - cpus = cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19"); + cpus = perf_cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19"); TEST_ASSERT_VAL("failed to synthesize map", !perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL)); @@ -86,7 +87,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may perf_cpu_map__put(cpus); /* This one is better stores in cpu values. */ - cpus = cpu_map__new("1,256"); + cpus = perf_cpu_map__new("1,256"); TEST_ASSERT_VAL("failed to synthesize map", !perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL)); @@ -97,7 +98,7 @@ int test__cpu_map_synthesize(struct test *test __maybe_unused, int subtest __may static int cpu_map_print(const char *str) { - struct perf_cpu_map *map = cpu_map__new(str); + struct perf_cpu_map *map = perf_cpu_map__new(str); char buf[100]; if (!map) diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index 165534f62036..00adba86403b 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "tests.h" #include "evlist.h" #include "evsel.h" @@ -115,9 +116,9 @@ static int attach__cpu_disabled(struct evlist *evlist) pr_debug("attaching to CPU 0 as enabled\n"); - cpus = cpu_map__new("0"); + cpus = perf_cpu_map__new("0"); if (cpus == NULL) { - pr_debug("failed to call cpu_map__new\n"); + pr_debug("failed to call perf_cpu_map__new\n"); return -1; } @@ -144,9 +145,9 @@ static int attach__cpu_enabled(struct evlist *evlist) pr_debug("attaching to CPU 0 as enabled\n"); - cpus = cpu_map__new("0"); + cpus = perf_cpu_map__new("0"); if (cpus == NULL) { - pr_debug("failed to call cpu_map__new\n"); + pr_debug("failed to call perf_cpu_map__new\n"); return -1; } diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c index 415d12e96834..2bc5145284c0 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include "evlist.h" #include "evsel.h" #include "machine.h" @@ -108,7 +109,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu TEST_ASSERT_VAL("failed to synthesize attr update name", !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); - evsel->own_cpus = cpu_map__new("1,2,3"); + evsel->own_cpus = perf_cpu_map__new("1,2,3"); TEST_ASSERT_VAL("failed to synthesize attr update cpus", !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c index 4fc7b3b4e153..46478ba1ed16 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "parse-events.h" #include "evlist.h" @@ -75,7 +76,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un threads = thread_map__new(-1, getpid(), UINT_MAX); CHECK_NOT_NULL__(threads); - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); CHECK_NOT_NULL__(cpus); evlist = evlist__new(); diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index 6fe2c1e7918b..5ec193f7968d 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "cpumap.h" #include "mem2node.h" #include "tests.h" @@ -19,7 +20,7 @@ static struct node { static unsigned long *get_bitmap(const char *str, int nbits) { - struct perf_cpu_map *map = cpu_map__new(str); + struct perf_cpu_map *map = perf_cpu_map__new(str); unsigned long *bm = NULL; int i; diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 9d8eb43b12cb..aa792aebd7f0 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -3,6 +3,7 @@ #include /* For the CLR_() macros */ #include +#include #include "evlist.h" #include "evsel.h" @@ -46,7 +47,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse return -1; } - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (cpus == NULL) { pr_debug("cpu_map__new\n"); goto out_free_threads; diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c index 674b0fa035ec..d161b1a78703 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -33,7 +33,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int return -1; } - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (cpus == NULL) { pr_debug("cpu_map__new\n"); goto out_thread_map_delete; diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index dd07acced4af..9e0bbea15005 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "parse-events.h" #include "evlist.h" @@ -341,9 +342,9 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_ goto out_err; } - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (!cpus) { - pr_debug("cpu_map__new failed!\n"); + pr_debug("perf_cpu_map__new failed!\n"); goto out_err; } diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 1b57ded58d59..a4f9f5182b47 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "tests.h" #include "util.h" #include "session.h" @@ -126,7 +127,7 @@ int test__session_topology(struct test *test __maybe_unused, int subtest __maybe if (session_write_header(path)) goto free_path; - map = cpu_map__new(NULL); + map = perf_cpu_map__new(NULL); if (map == NULL) { pr_debug("failed to get system cpumap\n"); goto free_path; diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 44082e5eabde..71d4d7b35a57 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -17,185 +17,6 @@ static int max_present_cpu_num; static int max_node_num; static int *cpunode_map; -static struct perf_cpu_map *cpu_map__default_new(void) -{ - struct perf_cpu_map *cpus; - int nr_cpus; - - nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); - if (nr_cpus < 0) - return NULL; - - cpus = malloc(sizeof(*cpus) + nr_cpus * sizeof(int)); - if (cpus != NULL) { - int i; - for (i = 0; i < nr_cpus; ++i) - cpus->map[i] = i; - - cpus->nr = nr_cpus; - refcount_set(&cpus->refcnt, 1); - } - - return cpus; -} - -static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) -{ - size_t payload_size = nr_cpus * sizeof(int); - struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + payload_size); - - if (cpus != NULL) { - cpus->nr = nr_cpus; - memcpy(cpus->map, tmp_cpus, payload_size); - refcount_set(&cpus->refcnt, 1); - } - - return cpus; -} - -struct perf_cpu_map *cpu_map__read(FILE *file) -{ - struct perf_cpu_map *cpus = NULL; - int nr_cpus = 0; - int *tmp_cpus = NULL, *tmp; - int max_entries = 0; - int n, cpu, prev; - char sep; - - sep = 0; - prev = -1; - for (;;) { - n = fscanf(file, "%u%c", &cpu, &sep); - if (n <= 0) - break; - if (prev >= 0) { - int new_max = nr_cpus + cpu - prev - 1; - - if (new_max >= max_entries) { - max_entries = new_max + MAX_NR_CPUS / 2; - tmp = realloc(tmp_cpus, max_entries * sizeof(int)); - if (tmp == NULL) - goto out_free_tmp; - tmp_cpus = tmp; - } - - while (++prev < cpu) - tmp_cpus[nr_cpus++] = prev; - } - if (nr_cpus == max_entries) { - max_entries += MAX_NR_CPUS; - tmp = realloc(tmp_cpus, max_entries * sizeof(int)); - if (tmp == NULL) - goto out_free_tmp; - tmp_cpus = tmp; - } - - tmp_cpus[nr_cpus++] = cpu; - if (n == 2 && sep == '-') - prev = cpu; - else - prev = -1; - if (n == 1 || sep == '\n') - break; - } - - if (nr_cpus > 0) - cpus = cpu_map__trim_new(nr_cpus, tmp_cpus); - else - cpus = cpu_map__default_new(); -out_free_tmp: - free(tmp_cpus); - return cpus; -} - -static struct perf_cpu_map *cpu_map__read_all_cpu_map(void) -{ - struct perf_cpu_map *cpus = NULL; - FILE *onlnf; - - onlnf = fopen("/sys/devices/system/cpu/online", "r"); - if (!onlnf) - return cpu_map__default_new(); - - cpus = cpu_map__read(onlnf); - fclose(onlnf); - return cpus; -} - -struct perf_cpu_map *cpu_map__new(const char *cpu_list) -{ - struct perf_cpu_map *cpus = NULL; - unsigned long start_cpu, end_cpu = 0; - char *p = NULL; - int i, nr_cpus = 0; - int *tmp_cpus = NULL, *tmp; - int max_entries = 0; - - if (!cpu_list) - return cpu_map__read_all_cpu_map(); - - /* - * must handle the case of empty cpumap to cover - * TOPOLOGY header for NUMA nodes with no CPU - * ( e.g., because of CPU hotplug) - */ - if (!isdigit(*cpu_list) && *cpu_list != '\0') - goto out; - - while (isdigit(*cpu_list)) { - p = NULL; - start_cpu = strtoul(cpu_list, &p, 0); - if (start_cpu >= INT_MAX - || (*p != '\0' && *p != ',' && *p != '-')) - goto invalid; - - if (*p == '-') { - cpu_list = ++p; - p = NULL; - end_cpu = strtoul(cpu_list, &p, 0); - - if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',')) - goto invalid; - - if (end_cpu < start_cpu) - goto invalid; - } else { - end_cpu = start_cpu; - } - - for (; start_cpu <= end_cpu; start_cpu++) { - /* check for duplicates */ - for (i = 0; i < nr_cpus; i++) - if (tmp_cpus[i] == (int)start_cpu) - goto invalid; - - if (nr_cpus == max_entries) { - max_entries += MAX_NR_CPUS; - tmp = realloc(tmp_cpus, max_entries * sizeof(int)); - if (tmp == NULL) - goto invalid; - tmp_cpus = tmp; - } - tmp_cpus[nr_cpus++] = (int)start_cpu; - } - if (*p) - ++p; - - cpu_list = p; - } - - if (nr_cpus > 0) - cpus = cpu_map__trim_new(nr_cpus, tmp_cpus); - else if (*cpu_list != '\0') - cpus = cpu_map__default_new(); - else - cpus = perf_cpu_map__dummy_new(); -invalid: - free(tmp_cpus); -out: - return cpus; -} - static struct perf_cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus) { struct perf_cpu_map *map; @@ -751,7 +572,7 @@ const struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */ static const struct perf_cpu_map *online = NULL; if (!online) - online = cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */ + online = perf_cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */ return online; } diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index b7af2cb68c19..a3d27f4131be 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -11,10 +11,8 @@ #include "perf.h" #include "util/debug.h" -struct perf_cpu_map *cpu_map__new(const char *cpu_list); struct perf_cpu_map *cpu_map__empty_new(int nr); struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data); -struct perf_cpu_map *cpu_map__read(FILE *file); size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size); size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 0cd99c460cd4..4f70155eaf83 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "cputopo.h" #include "cpumap.h" @@ -182,7 +183,7 @@ struct cpu_topology *cpu_topology__new(void) ncpus = cpu__max_present_cpu(); /* build online CPU map */ - map = cpu_map__new(NULL); + map = perf_cpu_map__new(NULL); if (map == NULL) { pr_debug("failed to get system cpumap\n"); return NULL; @@ -312,7 +313,7 @@ struct numa_topology *numa_topology__new(void) if (c) *c = '\0'; - node_map = cpu_map__new(buf); + node_map = perf_cpu_map__new(buf); if (!node_map) goto out; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ae75777a0ba4..67c67e9a38cd 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef LACKS_SIGQUEUE_PROTOTYPE int sigqueue(pid_t pid, int sig, const union sigval value); @@ -1089,7 +1090,7 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target) if (target__uses_dummy_map(target)) cpus = perf_cpu_map__dummy_new(); else - cpus = cpu_map__new(target->cpu_list); + cpus = perf_cpu_map__new(target->cpu_list); if (!cpus) goto out_delete_threads; @@ -1372,7 +1373,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist) * error, and we may not want to do that fallback to a * default cpu identity map :-\ */ - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (!cpus) goto out; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index d81afe56392c..fa914ba8cd56 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "evlist.h" #include "evsel.h" @@ -2348,7 +2349,7 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused) if (!str) goto error; - n->map = cpu_map__new(str); + n->map = perf_cpu_map__new(str); if (!n->map) goto error; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ec7ce18b999a..db2460d6b625 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -24,6 +24,7 @@ #include "bpf-loader.h" #include "debug.h" #include +#include #include "parse-events-bison.h" #define YY_EXTRA_TYPE int #include "parse-events-flex.h" @@ -323,7 +324,7 @@ __add_event(struct list_head *list, int *idx, { struct evsel *evsel; struct perf_cpu_map *cpus = pmu ? pmu->cpus : - cpu_list ? cpu_map__new(cpu_list) : NULL; + cpu_list ? perf_cpu_map__new(cpu_list) : NULL; event_attr_init(attr); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index d355f9506a1c..b7da21a7d627 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "pmu.h" #include "parse-events.h" #include "cpumap.h" @@ -581,7 +582,7 @@ static struct perf_cpu_map *__pmu_cpumask(const char *path) if (!file) return NULL; - cpus = cpu_map__read(file); + cpus = perf_cpu_map__read(file); fclose(file); return cpus; } diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 23a4fa13b92d..75ecc32a4427 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "evlist.h" #include "callchain.h" #include "evsel.h" @@ -549,7 +550,7 @@ static int pyrf_cpu_map__init(struct pyrf_cpu_map *pcpus, kwlist, &cpustr)) return -1; - pcpus->cpus = cpu_map__new(cpustr); + pcpus->cpus = perf_cpu_map__new(cpustr); if (pcpus->cpus == NULL) return -1; return 0; diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 445788819969..03dcdb3f33a7 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "util.h" #include "cloexec.h" @@ -63,7 +64,7 @@ static bool perf_probe_api(setup_probe_fn_t fn) struct perf_cpu_map *cpus; int cpu, ret, i = 0; - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (!cpus) return false; cpu = cpus->map[0]; @@ -118,7 +119,7 @@ bool perf_can_record_cpu_wide(void) struct perf_cpu_map *cpus; int cpu, fd; - cpus = cpu_map__new(NULL); + cpus = perf_cpu_map__new(NULL); if (!cpus) return false; cpu = cpus->map[0]; @@ -275,7 +276,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str) evsel = perf_evlist__last(temp_evlist); if (!evlist || cpu_map__empty(evlist->cpus)) { - struct perf_cpu_map *cpus = cpu_map__new(NULL); + struct perf_cpu_map *cpus = perf_cpu_map__new(NULL); cpu = cpus ? cpus->map[0] : 0; perf_cpu_map__put(cpus); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 1f3dc7a8cee6..11e6093c941b 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "evlist.h" #include "evsel.h" @@ -2289,7 +2290,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, } } - map = cpu_map__new(cpu_list); + map = perf_cpu_map__new(cpu_list); if (map == NULL) { pr_err("Invalid cpu_list\n"); return -1; diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index a9ca5c4fffee..ae6a534a7a80 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "perf.h" #include "svghelper.h" @@ -731,7 +732,7 @@ static int str_to_bitmap(char *s, cpumask_t *b) struct perf_cpu_map *m; int c; - m = cpu_map__new(s); + m = perf_cpu_map__new(s); if (!m) return -1; -- cgit v1.2.3-59-g8ed1b From 5e51b0bb245d963f5ce750256c504be95201e38c Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 22 Aug 2019 10:48:31 -0300 Subject: perf cpumap: Remove needless includes from cpumap.h The util/cpumap.h file doesn't use anything in refcount.h not in debug.h, it needs just a forward reference to 'struct cpu_map_data', that is defined in util/event.h and cpumap.h was getting indirectly via, of all things, debug.h Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Link: https://lkml.kernel.org/n/tip-mtjww98yptt4ppo6g2blavg5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/x86/util/header.c | 1 + tools/perf/tests/mem2node.c | 1 + tools/perf/util/cpumap.c | 2 ++ tools/perf/util/cpumap.h | 4 ++-- tools/perf/util/cputopo.c | 2 ++ tools/perf/util/env.c | 1 + tools/perf/util/mem2node.c | 1 + tools/perf/util/pmu.c | 1 + tools/perf/util/svghelper.c | 1 + 9 files changed, 12 insertions(+), 2 deletions(-) (limited to 'tools/perf/tests/mem2node.c') diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c index af9a9f2600be..662ecf84a421 100644 --- a/tools/perf/arch/x86/util/header.c +++ b/tools/perf/arch/x86/util/header.c @@ -6,6 +6,7 @@ #include #include +#include "../../util/debug.h" #include "../../util/header.h" static inline void diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index 5ec193f7968d..73b2855acaf4 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -4,6 +4,7 @@ #include #include #include "cpumap.h" +#include "debug.h" #include "mem2node.h" #include "tests.h" diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 8e6c2cbffedc..f5c21184e1fc 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -2,6 +2,8 @@ #include #include "../perf.h" #include "cpumap.h" +#include "debug.h" +#include "event.h" #include #include #include diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 8dbedda7af45..d0c5bbfd91af 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -4,12 +4,12 @@ #include #include -#include #include #include #include "perf.h" -#include "util/debug.h" + +struct cpu_map_data; struct perf_cpu_map *perf_cpu_map__empty_new(int nr); struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data); diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 4f70155eaf83..1b52402a8923 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -3,12 +3,14 @@ #include #include #include +#include #include #include #include #include "cputopo.h" #include "cpumap.h" +#include "debug.h" #include "env.h" #define CORE_SIB_FMT \ diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index d77912b2b5e7..571efb4f0351 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "cpumap.h" +#include "debug.h" #include "env.h" #include #include diff --git a/tools/perf/util/mem2node.c b/tools/perf/util/mem2node.c index cacc2fc4dcbd..14fb9e72aeeb 100644 --- a/tools/perf/util/mem2node.c +++ b/tools/perf/util/mem2node.c @@ -2,6 +2,7 @@ #include #include #include +#include "debug.h" #include "mem2node.h" struct phys_entry { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b7da21a7d627..9807be6f09bb 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -16,6 +16,7 @@ #include #include #include +#include "debug.h" #include "pmu.h" #include "parse-events.h" #include "cpumap.h" diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index ae6a534a7a80..bbdd87163285 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3-59-g8ed1b From b6b5574b80d6ce6ca87ae3ea1e97cff1bf730f2e Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 29 Aug 2019 17:10:59 -0300 Subject: perf env: Remove env.h from other headers where just a fwd decl is needed And fixup the fallout of c files not building due to now missing headers. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Link: https://lkml.kernel.org/n/tip-sw8k3kpla98pr3rqypbjk9hf@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/common.h | 4 +++- tools/perf/tests/mem2node.c | 2 ++ tools/perf/util/cputopo.h | 1 - tools/perf/util/mem2node.c | 2 ++ tools/perf/util/mem2node.h | 3 ++- 5 files changed, 9 insertions(+), 3 deletions(-) (limited to 'tools/perf/tests/mem2node.c') diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h index c298a446d1f6..e965ed8bb328 100644 --- a/tools/perf/arch/common.h +++ b/tools/perf/arch/common.h @@ -2,7 +2,9 @@ #ifndef ARCH_PERF_COMMON_H #define ARCH_PERF_COMMON_H -#include "../util/env.h" +#include + +struct perf_env; int perf_env__lookup_objdump(struct perf_env *env, const char **path); bool perf_env__single_address_space(struct perf_env *env); diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index 73b2855acaf4..7672ade70f20 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include "cpumap.h" #include "debug.h" +#include "env.h" #include "mem2node.h" #include "tests.h" diff --git a/tools/perf/util/cputopo.h b/tools/perf/util/cputopo.h index bae2f1d41856..7bf6b811f715 100644 --- a/tools/perf/util/cputopo.h +++ b/tools/perf/util/cputopo.h @@ -3,7 +3,6 @@ #define __PERF_CPUTOPO_H #include -#include "env.h" struct cpu_topology { u32 core_sib; diff --git a/tools/perf/util/mem2node.c b/tools/perf/util/mem2node.c index 14fb9e72aeeb..797d86a1ab09 100644 --- a/tools/perf/util/mem2node.c +++ b/tools/perf/util/mem2node.c @@ -1,8 +1,10 @@ #include #include #include +#include #include #include "debug.h" +#include "env.h" #include "mem2node.h" struct phys_entry { diff --git a/tools/perf/util/mem2node.h b/tools/perf/util/mem2node.h index 59c4752a2181..8dfa2b58d0cd 100644 --- a/tools/perf/util/mem2node.h +++ b/tools/perf/util/mem2node.h @@ -2,8 +2,9 @@ #define __MEM2NODE_H #include -#include "env.h" +#include +struct perf_env; struct phys_entry; struct mem2node { -- cgit v1.2.3-59-g8ed1b