Skip to content

Commit

Permalink
perf pmu: Separate pmu and pmus
Browse files Browse the repository at this point in the history
Separate and hide the pmus list in pmus.[ch]. Move pmus functionality
out of pmu.[ch] into pmus.[ch] renaming pmus functions which were
prefixed perf_pmu__ to perf_pmus__.

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ali Saidi <alisaidi@amazon.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230527072210.2900565-28-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Ian Rogers authored and Arnaldo Carvalho de Melo committed May 27, 2023
1 parent 875375e commit 1eaf496
Show file tree
Hide file tree
Showing 41 changed files with 533 additions and 506 deletions.
7 changes: 4 additions & 3 deletions tools/perf/arch/arm/util/auxtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../../../util/debug.h"
#include "../../../util/evlist.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"
#include "cs-etm.h"
#include "arm-spe.h"
#include "hisi-ptt.h"
Expand All @@ -40,7 +41,7 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
return NULL;
}

arm_spe_pmus[*nr_spes] = perf_pmu__find(arm_spe_pmu_name);
arm_spe_pmus[*nr_spes] = perf_pmus__find(arm_spe_pmu_name);
if (arm_spe_pmus[*nr_spes]) {
pr_debug2("%s %d: arm_spe_pmu %d type %d name %s\n",
__func__, __LINE__, *nr_spes,
Expand Down Expand Up @@ -87,7 +88,7 @@ static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr_ptts, int *err)
rewinddir(dir);
while ((dent = readdir(dir))) {
if (strstr(dent->d_name, HISI_PTT_PMU_NAME) && idx < *nr_ptts) {
hisi_ptt_pmus[idx] = perf_pmu__find(dent->d_name);
hisi_ptt_pmus[idx] = perf_pmus__find(dent->d_name);
if (hisi_ptt_pmus[idx])
idx++;
}
Expand Down Expand Up @@ -131,7 +132,7 @@ struct auxtrace_record
if (!evlist)
return NULL;

cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME);
cs_etm_pmu = perf_pmus__find(CORESIGHT_ETM_PMU_NAME);
arm_spe_pmus = find_all_arm_spe_pmus(&nr_spes, err);
hisi_ptt_pmus = find_all_hisi_ptt_pmus(&nr_ptts, err);

Expand Down
4 changes: 2 additions & 2 deletions tools/perf/arch/arm/util/cs-etm.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "../../../util/evsel.h"
#include "../../../util/perf_api_probe.h"
#include "../../../util/evsel_config.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"
#include "../../../util/cs-etm.h"
#include <internal/lib.h> // page_size
#include "../../../util/session.h"
Expand Down Expand Up @@ -881,7 +881,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
struct perf_pmu *cs_etm_pmu;
struct cs_etm_recording *ptr;

cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME);
cs_etm_pmu = perf_pmus__find(CORESIGHT_ETM_PMU_NAME);

if (!cs_etm_pmu) {
*err = -EINVAL;
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/arch/arm64/util/pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <internal/cpumap.h>
#include "../../../util/cpumap.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"
#include <api/fs/fs.h>
#include <math.h>

static struct perf_pmu *pmu__find_core_pmu(void)
{
struct perf_pmu *pmu = NULL;

while ((pmu = perf_pmu__scan(pmu))) {
while ((pmu = perf_pmus__scan(pmu))) {
if (!is_pmu_core(pmu->name))
continue;

Expand Down
5 changes: 3 additions & 2 deletions tools/perf/arch/x86/tests/hybrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "evlist.h"
#include "evsel.h"
#include "pmu.h"
#include "pmus.h"
#include "tests/tests.h"

static bool test_config(const struct evsel *evsel, __u64 expected_config)
Expand Down Expand Up @@ -113,7 +114,7 @@ static int test__hybrid_raw1(struct evlist *evlist)
struct perf_evsel *evsel;

perf_evlist__for_each_evsel(&evlist->core, evsel) {
struct perf_pmu *pmu = perf_pmu__find_by_type(evsel->attr.type);
struct perf_pmu *pmu = perf_pmus__find_by_type(evsel->attr.type);

TEST_ASSERT_VAL("missing pmu", pmu);
TEST_ASSERT_VAL("unexpected pmu", !strncmp(pmu->name, "cpu_", 4));
Expand Down Expand Up @@ -280,7 +281,7 @@ static int test_events(const struct evlist_test *events, int cnt)

int test__hybrid(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
if (!perf_pmu__has_hybrid())
if (!perf_pmus__has_hybrid())
return TEST_SKIP;

return test_events(test__hybrid_events, ARRAY_SIZE(test__hybrid_events));
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/arch/x86/util/auxtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../../../util/header.h"
#include "../../../util/debug.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"
#include "../../../util/auxtrace.h"
#include "../../../util/intel-pt.h"
#include "../../../util/intel-bts.h"
Expand All @@ -25,8 +26,8 @@ struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
bool found_pt = false;
bool found_bts = false;

intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
intel_pt_pmu = perf_pmus__find(INTEL_PT_PMU_NAME);
intel_bts_pmu = perf_pmus__find(INTEL_BTS_PMU_NAME);

evlist__for_each_entry(evlist, evsel) {
if (intel_pt_pmu && evsel->core.attr.type == intel_pt_pmu->type)
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/arch/x86/util/evlist.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <stdio.h>
#include "util/pmu.h"
#include "util/pmus.h"
#include "util/evlist.h"
#include "util/parse-events.h"
#include "util/event.h"
Expand All @@ -17,7 +18,7 @@ static int ___evlist__add_default_attrs(struct evlist *evlist,
for (i = 0; i < nr_attrs; i++)
event_attr_init(attrs + i);

if (!perf_pmu__has_hybrid())
if (!perf_pmus__has_hybrid())
return evlist__add_attrs(evlist, attrs, nr_attrs);

for (i = 0; i < nr_attrs; i++) {
Expand All @@ -32,7 +33,7 @@ static int ___evlist__add_default_attrs(struct evlist *evlist,
continue;
}

while ((pmu = perf_pmu__scan(pmu)) != NULL) {
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
struct perf_cpu_map *cpus;
struct evsel *evsel;

Expand Down
7 changes: 4 additions & 3 deletions tools/perf/arch/x86/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "util/evsel.h"
#include "util/env.h"
#include "util/pmu.h"
#include "util/pmus.h"
#include "linux/string.h"
#include "evsel.h"
#include "util/debug.h"
Expand All @@ -30,7 +31,7 @@ bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
* should be good enough to detect the perf metrics feature.
*/
if ((evsel->core.attr.type == PERF_TYPE_RAW) &&
pmu_have_event(pmu_name, "slots"))
perf_pmus__have_event(pmu_name, "slots"))
return true;

return false;
Expand Down Expand Up @@ -98,8 +99,8 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
if (!evsel_pmu)
return;

ibs_fetch_pmu = perf_pmu__find("ibs_fetch");
ibs_op_pmu = perf_pmu__find("ibs_op");
ibs_fetch_pmu = perf_pmus__find("ibs_fetch");
ibs_op_pmu = perf_pmus__find("ibs_op");

if (ibs_fetch_pmu && ibs_fetch_pmu->type == evsel_pmu->type) {
if (attr->config & IBS_FETCH_L3MISSONLY) {
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/arch/x86/util/intel-bts.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "../../../util/evlist.h"
#include "../../../util/mmap.h"
#include "../../../util/session.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"
#include "../../../util/debug.h"
#include "../../../util/record.h"
#include "../../../util/tsc.h"
Expand Down Expand Up @@ -416,7 +416,7 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,

struct auxtrace_record *intel_bts_recording_init(int *err)
{
struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
struct perf_pmu *intel_bts_pmu = perf_pmus__find(INTEL_BTS_PMU_NAME);
struct intel_bts_recording *btsr;

if (!intel_bts_pmu)
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/arch/x86/util/intel-pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "../../../util/mmap.h"
#include <subcmd/parse-options.h>
#include "../../../util/parse-events.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"
#include "../../../util/debug.h"
#include "../../../util/auxtrace.h"
#include "../../../util/perf_api_probe.h"
Expand Down Expand Up @@ -1185,7 +1185,7 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)

struct auxtrace_record *intel_pt_recording_init(int *err)
{
struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
struct perf_pmu *intel_pt_pmu = perf_pmus__find(INTEL_PT_PMU_NAME);
struct intel_pt_recording *ptr;

if (!intel_pt_pmu)
Expand Down
9 changes: 5 additions & 4 deletions tools/perf/arch/x86/util/mem-events.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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"
Expand Down Expand Up @@ -55,12 +56,12 @@ struct perf_mem_event *perf_mem_events__ptr(int i)

bool is_mem_loads_aux_event(struct evsel *leader)
{
struct perf_pmu *pmu = perf_pmu__find("cpu");
struct perf_pmu *pmu = perf_pmus__find("cpu");

if (!pmu)
pmu = perf_pmu__find("cpu_core");
pmu = perf_pmus__find("cpu_core");

if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux"))
if (pmu && !perf_pmu__have_event(pmu, "mem-loads-aux"))
return false;

return leader->core.attr.config == MEM_LOADS_AUX;
Expand All @@ -82,7 +83,7 @@ char *perf_mem_events__name(int i, char *pmu_name)
pmu_name = (char *)"cpu";
}

if (pmu_have_event(pmu_name, "mem-loads-aux")) {
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);
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/arch/x86/util/perf_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../../../util/debug.h"
#include "../../../util/event.h"
#include "../../../util/pmu.h"
#include "../../../util/pmus.h"

const struct sample_reg sample_reg_masks[] = {
SMPL_REG(AX, PERF_REG_X86_AX),
Expand Down Expand Up @@ -291,15 +292,15 @@ uint64_t arch__intr_reg_mask(void)
*/
attr.sample_period = 1;

if (perf_pmu__has_hybrid()) {
if (perf_pmus__has_hybrid()) {
struct perf_pmu *pmu = NULL;
__u64 type = PERF_TYPE_RAW;

/*
* The same register set is supported among different hybrid PMUs.
* Only check the first available one.
*/
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
if (pmu->is_core) {
type = pmu->type;
break;
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/arch/x86/util/topdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "api/fs/fs.h"
#include "util/evsel.h"
#include "util/pmu.h"
#include "util/pmus.h"
#include "util/topdown.h"
#include "topdown.h"
#include "evsel.h"
Expand All @@ -22,8 +23,8 @@ bool topdown_sys_has_perf_metrics(void)
* The slots event is only available when the core PMU
* supports the perf metrics feature.
*/
pmu = perf_pmu__find_by_type(PERF_TYPE_RAW);
if (pmu && pmu_have_event(pmu->name, "slots"))
pmu = perf_pmus__find_by_type(PERF_TYPE_RAW);
if (pmu && perf_pmu__have_event(pmu, "slots"))
has_perf_metrics = true;

cached = true;
Expand Down
10 changes: 5 additions & 5 deletions tools/perf/bench/pmu-scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int save_result(void)
struct list_head *list;
struct pmu_scan_result *r;

while ((pmu = perf_pmu__scan(pmu)) != NULL) {
while ((pmu = perf_pmus__scan(pmu)) != NULL) {
r = realloc(results, (nr_pmus + 1) * sizeof(*r));
if (r == NULL)
return -ENOMEM;
Expand All @@ -68,7 +68,7 @@ static int save_result(void)
nr_pmus++;
}

perf_pmu__destroy();
perf_pmus__destroy();
return 0;
}

Expand All @@ -81,7 +81,7 @@ static int check_result(void)

for (int i = 0; i < nr_pmus; i++) {
r = &results[i];
pmu = perf_pmu__find(r->name);
pmu = perf_pmus__find(r->name);
if (pmu == NULL) {
pr_err("Cannot find PMU %s\n", r->name);
return -1;
Expand Down Expand Up @@ -144,15 +144,15 @@ static int run_pmu_scan(void)

for (i = 0; i < iterations; i++) {
gettimeofday(&start, NULL);
perf_pmu__scan(NULL);
perf_pmus__scan(NULL);
gettimeofday(&end, NULL);

timersub(&end, &start, &diff);
runtime_us = diff.tv_sec * USEC_PER_SEC + diff.tv_usec;
update_stats(&stats, runtime_us);

ret = check_result();
perf_pmu__destroy();
perf_pmus__destroy();
if (ret < 0)
break;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-c2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "symbol.h"
#include "ui/ui.h"
#include "ui/progress.h"
#include "pmu.h"
#include "pmus.h"
#include "string2.h"
#include "util/util.h"

Expand Down Expand Up @@ -3259,7 +3259,7 @@ static int perf_c2c__record(int argc, const char **argv)
PARSE_OPT_KEEP_UNKNOWN);

/* Max number of arguments multiplied by number of PMUs that can support them. */
rec_argc = argc + 11 * perf_pmu__num_mem_pmus();
rec_argc = argc + 11 * perf_pmus__num_mem_pmus();

rec_argv = calloc(rec_argc + 1, sizeof(char *));
if (!rec_argv)
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ int cmd_list(int argc, const char **argv)
strcmp(argv[i], "hwcache") == 0)
print_hwcache_events(&print_cb, ps);
else if (strcmp(argv[i], "pmu") == 0)
print_pmu_events(&print_cb, ps);
perf_pmus__print_pmu_events(&print_cb, ps);
else if (strcmp(argv[i], "sdt") == 0)
print_sdt_events(&print_cb, ps);
else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) {
Expand Down Expand Up @@ -567,7 +567,7 @@ int cmd_list(int argc, const char **argv)
event_symbols_sw, PERF_COUNT_SW_MAX);
print_tool_events(&print_cb, ps);
print_hwcache_events(&print_cb, ps);
print_pmu_events(&print_cb, ps);
perf_pmus__print_pmu_events(&print_cb, ps);
print_tracepoint_events(&print_cb, ps);
print_sdt_events(&print_cb, ps);
default_ps.metrics = true;
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "util/dso.h"
#include "util/map.h"
#include "util/symbol.h"
#include "util/pmu.h"
#include "util/pmus.h"
#include "util/sample.h"
#include "util/string2.h"
#include "util/util.h"
Expand Down Expand Up @@ -93,7 +93,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
PARSE_OPT_KEEP_UNKNOWN);

/* Max number of arguments multiplied by number of PMUs that can support them. */
rec_argc = argc + 9 * perf_pmu__num_mem_pmus();
rec_argc = argc + 9 * perf_pmus__num_mem_pmus();

if (mem->cpu_list)
rec_argc += 2;
Expand Down
Loading

0 comments on commit 1eaf496

Please sign in to comment.