perf evsel: Remove pmu_name
authorIan Rogers <irogers@google.com>
Thu, 26 Sep 2024 14:48:36 +0000 (15:48 +0100)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 26 Sep 2024 20:26:11 +0000 (13:26 -0700)
"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>
tools/perf/arch/arm64/util/arm-spe.c
tools/perf/arch/x86/util/evsel.c
tools/perf/tests/parse-events.c
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/metricgroup.c
tools/perf/util/parse-events.c
tools/perf/util/stat-shadow.c
tools/perf/util/stat.c

index 2be99fdf997db1676923ea5115a31680f0d7c202..59a85e6f3aa34dfcd633179edaf56922fb2d9b53 100644 (file)
@@ -188,9 +188,9 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 
        evlist__for_each_entry(evlist, evsel) {
                if (evsel__is_aux_event(evsel)) {
-                       if (!strstarts(evsel->pmu_name, ARM_SPE_PMU_NAME)) {
+                       if (!strstarts(evsel->pmu->name, ARM_SPE_PMU_NAME)) {
                                pr_err("Found unexpected auxtrace event: %s\n",
-                                      evsel->pmu_name);
+                                      evsel->pmu->name);
                                return -EINVAL;
                        }
                        opts->full_auxtrace = true;
index ec2ac3bbb76f2cb1cc21fa409e21d8ca2e222490..cf7c116eeb8e41241be519464f6cfd50c3aec654 100644 (file)
@@ -84,7 +84,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size)
                return  scnprintf(bf, size, "%s", event_name);
 
        return scnprintf(bf, size, "%s/%s/",
-                        evsel->pmu_name ? evsel->pmu_name : "cpu",
+                        evsel->pmu ? evsel->pmu->name : "cpu",
                         event_name);
 }
 
@@ -129,7 +129,7 @@ int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size)
                return 0;
 
        if (!evsel->core.attr.precise_ip &&
-           !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)))
+           !(evsel->pmu && !strncmp(evsel->pmu->name, "ibs", 3)))
                return 0;
 
        /* More verbose IBS errors. */
index 9e3086d021508913d24abe98bbc94d7a7a54549e..78e999f03d2d75f41d8deed42e6e3a1d7e1cf839 100644 (file)
@@ -730,7 +730,7 @@ static int test__checkevent_pmu_events(struct evlist *evlist)
 
        TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||
-                                     strcmp(evsel->pmu_name, "cpu"));
+                                     strcmp(evsel->pmu->name, "cpu"));
        TEST_ASSERT_VAL("wrong exclude_user",
                        !evsel->core.attr.exclude_user);
        TEST_ASSERT_VAL("wrong exclude_kernel",
index 7be0800b89d8d57cbdd31b590ca64899ff27aa6f..37d0fc01c180016b109b36016dd8de4926fa2e50 100644 (file)
@@ -2591,7 +2591,8 @@ void evlist__uniquify_name(struct evlist *evlist)
                else
                        attributes = empty_attributes;
 
-               if (asprintf(&new_name, "%s/%s/%s", pos->pmu_name, pos->name, attributes + 1)) {
+               if (asprintf(&new_name, "%s/%s/%s", pos->pmu ? pos->pmu->name : "",
+                            pos->name, attributes + 1)) {
                        free(pos->name);
                        pos->name = new_name;
                } else {
index b9d7b56dfc5e98a5f386300b579bbe3b553a19c6..edfb376f06119460e2052cf460591f2399585d11 100644 (file)
@@ -296,7 +296,6 @@ void evsel__init(struct evsel *evsel,
        evsel->metric_events = NULL;
        evsel->per_pkg_mask  = NULL;
        evsel->collect_stat  = false;
-       evsel->pmu_name      = NULL;
        evsel->group_pmu_name = NULL;
        evsel->skippable     = false;
        evsel->alternate_hw_config = PERF_COUNT_HW_MAX;
@@ -394,11 +393,6 @@ struct evsel *evsel__clone(struct evsel *orig)
                if (evsel->group_name == NULL)
                        goto out_err;
        }
-       if (orig->pmu_name) {
-               evsel->pmu_name = strdup(orig->pmu_name);
-               if (evsel->pmu_name == NULL)
-                       goto out_err;
-       }
        if (orig->group_pmu_name) {
                evsel->group_pmu_name = strdup(orig->group_pmu_name);
                if (evsel->group_pmu_name == NULL)
@@ -1497,7 +1491,6 @@ void evsel__exit(struct evsel *evsel)
        zfree(&evsel->group_name);
        zfree(&evsel->name);
        zfree(&evsel->filter);
-       zfree(&evsel->pmu_name);
        zfree(&evsel->group_pmu_name);
        zfree(&evsel->unit);
        zfree(&evsel->metric_id);
index cf6f11fdfd061dc85b976818d20b71e39541cd94..3e751ea769ac4d3a15a9d1235ad7485a6cf0406a 100644 (file)
@@ -72,7 +72,6 @@ struct evsel {
        struct {
                char                    *name;
                char                    *group_name;
-               const char              *pmu_name;
                const char              *group_pmu_name;
 #ifdef HAVE_LIBTRACEEVENT
                struct tep_event        *tp_format;
@@ -184,7 +183,7 @@ struct evsel {
        unsigned long           open_flags;
        int                     precise_ip_original;
 
-       /* for missing_features */
+       /* The PMU the event is from. Used for missing_features, PMU name, etc. */
        struct perf_pmu         *pmu;
 
        /* For tool events */
index 4dff3e925a47b38d55d20136df412550e198f914..9c6fa6b4f628cba55acb84782842e2d9544f337b 100644 (file)
@@ -297,8 +297,8 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
                struct expr_id_data *val_ptr;
 
                /* Don't match events for the wrong hybrid PMU. */
-               if (!all_pmus && ev->pmu_name && evsel__is_hybrid(ev) &&
-                   strcmp(ev->pmu_name, pmu))
+               if (!all_pmus && ev->pmu && evsel__is_hybrid(ev) &&
+                   strcmp(ev->pmu->name, pmu))
                        continue;
                /*
                 * Check for duplicate events with the same name. For
index fcc4dab618bee4b113afc6dfa6e14bbf53126858..e96cf13dc396193f20cb2c4102b8b3e6fe4fe104 100644 (file)
@@ -263,7 +263,6 @@ __add_event(struct list_head *list, int *idx,
        evsel->core.is_pmu_core = pmu ? pmu->is_core : false;
        evsel->auto_merge_stats = auto_merge_stats;
        evsel->pmu = pmu;
-       evsel->pmu_name = pmu ? strdup(pmu->name) : NULL;
        evsel->alternate_hw_config = alternate_hw_config;
 
        if (name)
index dd709a7315745ba0d9b361c182f0d6982d9829e7..3ce756b8ede50ead4cea4a1c7386fc8857e59e62 100644 (file)
@@ -573,7 +573,7 @@ static void perf_stat__print_metricgroup_header(struct perf_stat_config *config,
 {
        bool need_full_name = perf_pmus__num_core_pmus() > 1;
        static const char *last_name;
-       static const char *last_pmu;
+       static const struct perf_pmu *last_pmu;
        char full_name[64];
 
        /*
@@ -584,21 +584,21 @@ static void perf_stat__print_metricgroup_header(struct perf_stat_config *config,
         * different metric events.
         */
        if (last_name && !strcmp(last_name, name)) {
-               if (!need_full_name || !strcmp(last_pmu, evsel->pmu_name)) {
+               if (!need_full_name || last_pmu != evsel->pmu) {
                        out->print_metricgroup_header(config, ctxp, NULL);
                        return;
                }
        }
 
-       if (need_full_name)
-               scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu_name);
+       if (need_full_name && evsel->pmu)
+               scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu->name);
        else
                scnprintf(full_name, sizeof(full_name), "%s", name);
 
        out->print_metricgroup_header(config, ctxp, full_name);
 
        last_name = name;
-       last_pmu = evsel->pmu_name;
+       last_pmu = evsel->pmu;
 }
 
 /**
index 0bd5467389e462b0b12970a7f777513081fd0d47..7c2ccdcc3fdba333b04005497d0e2e7ba6ad3100 100644 (file)
@@ -553,7 +553,7 @@ static bool evsel__is_alias(struct evsel *evsel_a, struct evsel *evsel_b)
        if (evsel__is_clock(evsel_a) != evsel__is_clock(evsel_b))
                return false;
 
-       return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name);
+       return evsel_a->pmu != evsel_b->pmu;
 }
 
 static void evsel__merge_aliases(struct evsel *evsel)