Commit c091ee90 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf pmu: Remove logic for PMU name being NULL



The PMU name could be NULL in the case of the fake_pmu. Initialize the
name for the fake_pmu to "fake" so that all other logic can assume it
is initialized. Add a const to the type of name so that a literal can
be used to avoid additional initialization code. Propagate the cost
through related routines and remove now unnecessary "(char *)"
casts. Doing this located a bug in builtin-list for the pmu_glob that
was missing a strdup.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20230825024002.801955-3-irogers@google.com


Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: James Clark <james.clark@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Wei Li <liwei391@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Ming Wang <wangming01@loongson.cn>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9897009e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ struct perf_mem_event *perf_mem_events__ptr(int i)
	return &perf_mem_events[i];
}

char *perf_mem_events__name(int i, char *pmu_name __maybe_unused)
const char *perf_mem_events__name(int i, const char *pmu_name __maybe_unused)
{
	struct perf_mem_event *e = perf_mem_events__ptr(i);

+3 −3
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
#include "mem-events.h"

/* PowerPC does not support 'ldlat' parameter. */
char *perf_mem_events__name(int i, char *pmu_name __maybe_unused)
const char *perf_mem_events__name(int i, const char *pmu_name __maybe_unused)
{
	if (i == PERF_MEM_EVENTS__LOAD)
		return (char *) "cpu/mem-loads/";
		return "cpu/mem-loads/";

	return (char *) "cpu/mem-stores/";
	return "cpu/mem-stores/";
}
+4 −4
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ bool is_mem_loads_aux_event(struct evsel *leader)
	return leader->core.attr.config == MEM_LOADS_AUX;
}

char *perf_mem_events__name(int i, char *pmu_name)
const char *perf_mem_events__name(int i, const char *pmu_name)
{
	struct perf_mem_event *e = perf_mem_events__ptr(i);

@@ -65,7 +65,7 @@ char *perf_mem_events__name(int i, char *pmu_name)

		if (!pmu_name) {
			mem_loads_name__init = true;
			pmu_name = (char *)"cpu";
			pmu_name = "cpu";
		}

		if (perf_pmus__have_event(pmu_name, "mem-loads-aux")) {
@@ -82,12 +82,12 @@ char *perf_mem_events__name(int i, char *pmu_name)

	if (i == PERF_MEM_EVENTS__STORE) {
		if (!pmu_name)
			pmu_name = (char *)"cpu";
			pmu_name = "cpu";

		scnprintf(mem_stores_name, sizeof(mem_stores_name),
			  e->name, pmu_name);
		return mem_stores_name;
	}

	return (char *)e->name;
	return e->name;
}
+5 −5
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ static int setup_pmu_alias_list(void)
	return ret;
}

static char *__pmu_find_real_name(const char *name)
static const char *__pmu_find_real_name(const char *name)
{
	struct pmu_alias *pmu_alias;

@@ -135,10 +135,10 @@ static char *__pmu_find_real_name(const char *name)
			return pmu_alias->name;
	}

	return (char *)name;
	return name;
}

char *pmu_find_real_name(const char *name)
const char *pmu_find_real_name(const char *name)
{
	if (cached_list)
		return __pmu_find_real_name(name);
@@ -149,7 +149,7 @@ char *pmu_find_real_name(const char *name)
	return __pmu_find_real_name(name);
}

static char *__pmu_find_alias_name(const char *name)
static const char *__pmu_find_alias_name(const char *name)
{
	struct pmu_alias *pmu_alias;

@@ -160,7 +160,7 @@ static char *__pmu_find_alias_name(const char *name)
	return NULL;
}

char *pmu_find_alias_name(const char *name)
const char *pmu_find_alias_name(const char *name)
{
	if (cached_list)
		return __pmu_find_alias_name(name);
+1 −1
Original line number Diff line number Diff line
@@ -513,7 +513,7 @@ int cmd_list(int argc, const char **argv)
				ret = -1;
				goto out;
			}
			default_ps.pmu_glob = pmu->name;
			default_ps.pmu_glob = strdup(pmu->name);
		}
	}
	print_cb.print_start(ps);
Loading