Commit d7d156fc authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

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: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarIan Rogers <irogers@google.com>
[ Fix arm-spe.c usage of pmu_name and empty PMU name ]
Acked-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarJames 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: default avatarNamhyung Kim <namhyung@kernel.org>
parent e2216fac
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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. */
+1 −1
Original line number Diff line number Diff line
@@ -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",
+2 −1
Original line number Diff line number Diff line
@@ -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 {
+0 −7
Original line number Diff line number Diff line
@@ -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);
Loading