perf cpumap: Increment reference count for online cpumap
Ian Rogers
reviewerPATCH 1/1 perf cpumap: Increment reference count for online cpumap
Thomas Richter <[email protected]> reported a double put on the cpumap for the placeholder core PMU:
https://lore.kernel.org/lkml/[email protected]/
Requiring the caller to get the cpumap is not how these things are usually done, switch cpu_map__online to do the get and then fix up any use cases where a put is needed.
--- tools/perf/arch/arm/util/pmu.c | 5 +++-- tools/perf/util/cpumap.c | 2 +- tools/perf/util/evlist.c | 5 +++-- tools/perf/util/mem-events.c | 5 ++++- tools/perf/util/mmap.c | 4 ++-- tools/perf/util/pmu.c | 2 +- tools/perf/util/tool_pmu.c | 1 + 7 files changed, 15 insertions(+), 9 deletions(-)
tools/perf/arch/arm/util/pmu.c +3 -2
@@ -18,7 +18,7 @@void perf_pmu__arch_init (struct perf_pmu *pmu) { -struct perf_cpu_map *intersect; +struct perf_cpu_map *intersect, *online =cpu_map__online ();#ifdef HAVE_AUXTRACE_SUPPORT if (!strcmp (pmu->name,CORESIGHT_ETM_PMU_NAME )) {
@@ -41,7 +41,8 @@ void perf_pmu__arch_init(struct perf_pmu *pmu) }#endif /* Workaround some ARM PMU's failing to correctly set CPU maps for online processors. */ - intersect =perf_cpu_map__intersect (cpu_map__online (), pmu->cpus); + intersect =perf_cpu_map__intersect (online, pmu->cpus); +perf_cpu_map__put (online);perf_cpu_map__put (pmu->cpus); pmu->cpus = intersect; }
tools/perf/util/cpumap.c +1 -1
@@ -722,7 +722,7 @@ struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */if (!online) online =perf_cpu_map__new_online_cpus ();/* from /sys/devices/system/cpu/online */ -return online; +return perf_cpu_map__get (online); }bool aggr_cpu_id__equal (const struct aggr_cpu_id *a,const struct aggr_cpu_id *b)
tools/perf/util/evlist.c +3 -2
@@ -2534,10 +2534,10 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lisreturn ;evlist__for_each_entry (evlist, pos) { -struct perf_cpu_map *intersect, *to_test; +struct perf_cpu_map *intersect, *to_test, *online =cpu_map__online ();const struct perf_pmu *pmu =evsel__find_pmu (pos); - to_test = pmu && pmu->is_core ? pmu->cpus :cpu_map__online (); + to_test = pmu && pmu->is_core ? pmu->cpus : online; intersect =perf_cpu_map__intersect (to_test, user_requested_cpus);if (!perf_cpu_map__equal (intersect, user_requested_cpus)) {char buf[128 ];
@@ -2547,6 +2547,7 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lis cpu_list, pmu ? pmu->name : "cpu", buf, evsel__name(pos)); }perf_cpu_map__put (intersect); +perf_cpu_map__put (online); }perf_cpu_map__put (user_requested_cpus); }
tools/perf/util/mem-events.c +4 -1
@@ -303,12 +303,15 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr, char **eve }if (cpu_map) { -if (!perf_cpu_map__equal (cpu_map,cpu_map__online ())) { +struct perf_cpu_map *online =cpu_map__online (); + +if (!perf_cpu_map__equal (cpu_map, online)) {char buf[200 ];cpu_map__snprint (cpu_map, buf,sizeof (buf));pr_warning ("Memory events are enabled on a subset of CPUs: %s\n" , buf); } +perf_cpu_map__put (online);perf_cpu_map__put (cpu_map); }
tools/perf/util/mmap.c +2 -2
@@ -244,9 +244,8 @@ static void build_node_mask(int node, struct mmap_cpu_mask *mask) {int idx, nr_cpus;struct perf_cpu cpu; -const struct perf_cpu_map *cpu_map =NULL ; +struct perf_cpu_map *cpu_map =cpu_map__online (); - cpu_map =cpu_map__online ();if (!cpu_map)return ;
@@ -256,6 +255,7 @@ static void build_node_mask(int node, struct mmap_cpu_mask *mask)if (cpu__get_node (cpu) == node)__set_bit (cpu.cpu, mask->bits); } +perf_cpu_map__put (cpu_map); }static int perf_mmap__setup_affinity_mask (struct mmap *map,struct mmap_params *mp)
tools/perf/util/pmu.c +1 -1
@@ -779,7 +779,7 @@ static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *pmu_name, bool is }/* Nothing found, for core PMUs assume this means all CPUs. */ -return is_core ?perf_cpu_map__get (cpu_map__online ()) :NULL ; +return is_core ?cpu_map__online () :NULL ; }static bool pmu_is_uncore (int dirfd,const char *name)
tools/perf/util/tool_pmu.c +1 -0
@@ -355,6 +355,7 @@ bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result)if (online) { *result =perf_cpu_map__nr (online); +perf_cpu_map__put (online);return true; }return false;
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Quoted 8 lines · Ian Rogers
Thomas Richter <[email protected]> reported a double put on the cpumap for the placeholder core PMU:
https://lore.kernel.org/lkml/[email protected]/
Requiring the caller to get the cpumap is not how these things are usually done, switchcpu_map__onlineto do the get and then fix up any use cases where a put is needed.Signed-off-by Ian Rogers <[email protected]>
Ian,
thanks for fixing this. Here are the results on s390 z/VM:
# ./perf bench internals pmu-scan # Running 'internals/pmu-scan' benchmark: Computing performance of sysfs PMU event scan for 100 times Average core PMU scanning took: 6.340 usec (+- 0.050 usec) Average PMU scanning took: 93.785 usec (+- 6.210 usec) #
Signature · 9 lines
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany -- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Wolfgang Wendt Geschäftsführung: David Faller Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
Quoted 8 lines · Ian Rogers
Thomas Richter <[email protected]> reported a double put on the cpumap for the placeholder core PMU:
https://lore.kernel.org/lkml/[email protected]/
Requiring the caller to get the cpumap is not how these things are usually done, switchcpu_map__onlineto do the get and then fix up any use cases where a put is needed.[...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung