Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf evsel: Remove pmu_name

"evsel->pmu_name" is only ever assigned a strdup of "pmu->name", a
strdup of "evsel->pmu_name" or NULL. As such, prefer to use
"pmu->name" directly and even to directly compare PMUs than PMU
names. For safety, add some additional NULL tests.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
[ Fix arm-spe.c usage of pmu_name and empty PMU name ]
Acked-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ze Gao <zegao2021@gmail.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: ak@linux.intel.com
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20240926144851.245903-6-james.clark@linaro.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
d7d156fc e2216fac

+16 -24
+2 -2
tools/perf/arch/arm64/util/arm-spe.c
··· 188 188 189 189 evlist__for_each_entry(evlist, evsel) { 190 190 if (evsel__is_aux_event(evsel)) { 191 - if (!strstarts(evsel->pmu_name, ARM_SPE_PMU_NAME)) { 191 + if (!strstarts(evsel->pmu->name, ARM_SPE_PMU_NAME)) { 192 192 pr_err("Found unexpected auxtrace event: %s\n", 193 - evsel->pmu_name); 193 + evsel->pmu->name); 194 194 return -EINVAL; 195 195 } 196 196 opts->full_auxtrace = true;
+2 -2
tools/perf/arch/x86/util/evsel.c
··· 84 84 return scnprintf(bf, size, "%s", event_name); 85 85 86 86 return scnprintf(bf, size, "%s/%s/", 87 - evsel->pmu_name ? evsel->pmu_name : "cpu", 87 + evsel->pmu ? evsel->pmu->name : "cpu", 88 88 event_name); 89 89 } 90 90 ··· 129 129 return 0; 130 130 131 131 if (!evsel->core.attr.precise_ip && 132 - !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3))) 132 + !(evsel->pmu && !strncmp(evsel->pmu->name, "ibs", 3))) 133 133 return 0; 134 134 135 135 /* More verbose IBS errors. */
+1 -1
tools/perf/tests/parse-events.c
··· 730 730 731 731 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); 732 732 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type || 733 - strcmp(evsel->pmu_name, "cpu")); 733 + strcmp(evsel->pmu->name, "cpu")); 734 734 TEST_ASSERT_VAL("wrong exclude_user", 735 735 !evsel->core.attr.exclude_user); 736 736 TEST_ASSERT_VAL("wrong exclude_kernel",
+2 -1
tools/perf/util/evlist.c
··· 2591 2591 else 2592 2592 attributes = empty_attributes; 2593 2593 2594 - if (asprintf(&new_name, "%s/%s/%s", pos->pmu_name, pos->name, attributes + 1)) { 2594 + if (asprintf(&new_name, "%s/%s/%s", pos->pmu ? pos->pmu->name : "", 2595 + pos->name, attributes + 1)) { 2595 2596 free(pos->name); 2596 2597 pos->name = new_name; 2597 2598 } else {
-7
tools/perf/util/evsel.c
··· 296 296 evsel->metric_events = NULL; 297 297 evsel->per_pkg_mask = NULL; 298 298 evsel->collect_stat = false; 299 - evsel->pmu_name = NULL; 300 299 evsel->group_pmu_name = NULL; 301 300 evsel->skippable = false; 302 301 evsel->alternate_hw_config = PERF_COUNT_HW_MAX; ··· 391 392 if (orig->group_name) { 392 393 evsel->group_name = strdup(orig->group_name); 393 394 if (evsel->group_name == NULL) 394 - goto out_err; 395 - } 396 - if (orig->pmu_name) { 397 - evsel->pmu_name = strdup(orig->pmu_name); 398 - if (evsel->pmu_name == NULL) 399 395 goto out_err; 400 396 } 401 397 if (orig->group_pmu_name) { ··· 1491 1497 zfree(&evsel->group_name); 1492 1498 zfree(&evsel->name); 1493 1499 zfree(&evsel->filter); 1494 - zfree(&evsel->pmu_name); 1495 1500 zfree(&evsel->group_pmu_name); 1496 1501 zfree(&evsel->unit); 1497 1502 zfree(&evsel->metric_id);
+1 -2
tools/perf/util/evsel.h
··· 72 72 struct { 73 73 char *name; 74 74 char *group_name; 75 - const char *pmu_name; 76 75 const char *group_pmu_name; 77 76 #ifdef HAVE_LIBTRACEEVENT 78 77 struct tep_event *tp_format; ··· 183 184 unsigned long open_flags; 184 185 int precise_ip_original; 185 186 186 - /* for missing_features */ 187 + /* The PMU the event is from. Used for missing_features, PMU name, etc. */ 187 188 struct perf_pmu *pmu; 188 189 189 190 /* For tool events */
+2 -2
tools/perf/util/metricgroup.c
··· 297 297 struct expr_id_data *val_ptr; 298 298 299 299 /* Don't match events for the wrong hybrid PMU. */ 300 - if (!all_pmus && ev->pmu_name && evsel__is_hybrid(ev) && 301 - strcmp(ev->pmu_name, pmu)) 300 + if (!all_pmus && ev->pmu && evsel__is_hybrid(ev) && 301 + strcmp(ev->pmu->name, pmu)) 302 302 continue; 303 303 /* 304 304 * Check for duplicate events with the same name. For
-1
tools/perf/util/parse-events.c
··· 263 263 evsel->core.is_pmu_core = pmu ? pmu->is_core : false; 264 264 evsel->auto_merge_stats = auto_merge_stats; 265 265 evsel->pmu = pmu; 266 - evsel->pmu_name = pmu ? strdup(pmu->name) : NULL; 267 266 evsel->alternate_hw_config = alternate_hw_config; 268 267 269 268 if (name)
+5 -5
tools/perf/util/stat-shadow.c
··· 573 573 { 574 574 bool need_full_name = perf_pmus__num_core_pmus() > 1; 575 575 static const char *last_name; 576 - static const char *last_pmu; 576 + static const struct perf_pmu *last_pmu; 577 577 char full_name[64]; 578 578 579 579 /* ··· 584 584 * different metric events. 585 585 */ 586 586 if (last_name && !strcmp(last_name, name)) { 587 - if (!need_full_name || !strcmp(last_pmu, evsel->pmu_name)) { 587 + if (!need_full_name || last_pmu != evsel->pmu) { 588 588 out->print_metricgroup_header(config, ctxp, NULL); 589 589 return; 590 590 } 591 591 } 592 592 593 - if (need_full_name) 594 - scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu_name); 593 + if (need_full_name && evsel->pmu) 594 + scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu->name); 595 595 else 596 596 scnprintf(full_name, sizeof(full_name), "%s", name); 597 597 598 598 out->print_metricgroup_header(config, ctxp, full_name); 599 599 600 600 last_name = name; 601 - last_pmu = evsel->pmu_name; 601 + last_pmu = evsel->pmu; 602 602 } 603 603 604 604 /**
+1 -1
tools/perf/util/stat.c
··· 553 553 if (evsel__is_clock(evsel_a) != evsel__is_clock(evsel_b)) 554 554 return false; 555 555 556 - return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); 556 + return evsel_a->pmu != evsel_b->pmu; 557 557 } 558 558 559 559 static void evsel__merge_aliases(struct evsel *evsel)