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: Ian 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: Arnaldo Carvalho de Melo <acme@redhat.com>
93 lines
2.2 KiB
C
93 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "util/pmu.h"
|
|
#include "util/pmus.h"
|
|
#include "util/env.h"
|
|
#include "map_symbol.h"
|
|
#include "mem-events.h"
|
|
#include "linux/string.h"
|
|
#include "env.h"
|
|
|
|
static char mem_loads_name[100];
|
|
static bool mem_loads_name__init;
|
|
static char mem_stores_name[100];
|
|
|
|
#define MEM_LOADS_AUX 0x8203
|
|
#define MEM_LOADS_AUX_NAME "{%s/mem-loads-aux/,%s/mem-loads,ldlat=%u/}:P"
|
|
|
|
#define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
|
|
|
|
static struct perf_mem_event perf_mem_events_intel[PERF_MEM_EVENTS__MAX] = {
|
|
E("ldlat-loads", "%s/mem-loads,ldlat=%u/P", "%s/events/mem-loads"),
|
|
E("ldlat-stores", "%s/mem-stores/P", "%s/events/mem-stores"),
|
|
E(NULL, NULL, NULL),
|
|
};
|
|
|
|
static struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
|
|
E(NULL, NULL, NULL),
|
|
E(NULL, NULL, NULL),
|
|
E("mem-ldst", "ibs_op//", "ibs_op"),
|
|
};
|
|
|
|
struct perf_mem_event *perf_mem_events__ptr(int i)
|
|
{
|
|
if (i >= PERF_MEM_EVENTS__MAX)
|
|
return NULL;
|
|
|
|
if (x86__is_amd_cpu())
|
|
return &perf_mem_events_amd[i];
|
|
|
|
return &perf_mem_events_intel[i];
|
|
}
|
|
|
|
bool is_mem_loads_aux_event(struct evsel *leader)
|
|
{
|
|
struct perf_pmu *pmu = perf_pmus__find("cpu");
|
|
|
|
if (!pmu)
|
|
pmu = perf_pmus__find("cpu_core");
|
|
|
|
if (pmu && !perf_pmu__have_event(pmu, "mem-loads-aux"))
|
|
return false;
|
|
|
|
return leader->core.attr.config == MEM_LOADS_AUX;
|
|
}
|
|
|
|
const char *perf_mem_events__name(int i, const char *pmu_name)
|
|
{
|
|
struct perf_mem_event *e = perf_mem_events__ptr(i);
|
|
|
|
if (!e)
|
|
return NULL;
|
|
|
|
if (i == PERF_MEM_EVENTS__LOAD) {
|
|
if (mem_loads_name__init && !pmu_name)
|
|
return mem_loads_name;
|
|
|
|
if (!pmu_name) {
|
|
mem_loads_name__init = true;
|
|
pmu_name = "cpu";
|
|
}
|
|
|
|
if (perf_pmus__have_event(pmu_name, "mem-loads-aux")) {
|
|
scnprintf(mem_loads_name, sizeof(mem_loads_name),
|
|
MEM_LOADS_AUX_NAME, pmu_name, pmu_name,
|
|
perf_mem_events__loads_ldlat);
|
|
} else {
|
|
scnprintf(mem_loads_name, sizeof(mem_loads_name),
|
|
e->name, pmu_name,
|
|
perf_mem_events__loads_ldlat);
|
|
}
|
|
return mem_loads_name;
|
|
}
|
|
|
|
if (i == PERF_MEM_EVENTS__STORE) {
|
|
if (!pmu_name)
|
|
pmu_name = "cpu";
|
|
|
|
scnprintf(mem_stores_name, sizeof(mem_stores_name),
|
|
e->name, pmu_name);
|
|
return mem_stores_name;
|
|
}
|
|
|
|
return e->name;
|
|
}
|