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

perf pmu-events: Hide the pmu_events



Hide that the pmu_event structs are an array with a new wrapper struct.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20220812230949.683239-12-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 660842e4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
#include "../../../util/cpumap.h"
#include "../../../util/pmu.h"

const struct pmu_event *pmu_events_table__find(void)
const struct pmu_events_table *pmu_events_table__find(void)
{
	struct perf_pmu *pmu = NULL;

+24 −20
Original line number Diff line number Diff line
@@ -176,6 +176,10 @@ static const struct pmu_event pme_test_soc_cpu[] = {
	},
};

/* Struct used to make the PMU event table implementation opaque to callers. */
struct pmu_events_table {
	const struct pmu_event *entries;
};

/*
 * Map a CPU to its table of PMU events. The CPU is identified by the
@@ -188,7 +192,7 @@ static const struct pmu_event pme_test_soc_cpu[] = {
struct pmu_events_map {
	const char *arch;
	const char *cpuid;
	const struct pmu_event *table;
	const struct pmu_events_table table;
};

/*
@@ -199,12 +203,12 @@ static const struct pmu_events_map pmu_events_map[] = {
	{
		.arch = "testarch",
		.cpuid = "testcpu",
		.table = pme_test_soc_cpu,
		.table = { pme_test_soc_cpu },
	},
	{
		.arch = 0,
		.cpuid = 0,
		.table = 0,
		.table = { 0 },
	},
};

@@ -234,23 +238,23 @@ static const struct pmu_event pme_test_soc_sys[] = {

struct pmu_sys_events {
	const char *name;
	const struct pmu_event *table;
	const struct pmu_events_table table;
};

static const struct pmu_sys_events pmu_sys_event_tables[] = {
	{
		.table = pme_test_soc_sys,
		.table = { pme_test_soc_sys },
		.name = "pme_test_soc_sys",
	},
	{
		.table = 0
		.table = { 0 }
	},
};

int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
				    void *data)
{
	for (const struct pmu_event *pe = &table[0];
	for (const struct pmu_event *pe = &table->entries[0];
	     pe->name || pe->metric_group || pe->metric_name;
	     pe++) {
		int ret = fn(pe, table, data);
@@ -261,9 +265,9 @@ int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_ite
	return 0;
}

const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
{
	const struct pmu_event *table = NULL;
	const struct pmu_events_table *table = NULL;
	char *cpuid = perf_pmu__getcpuid(pmu);
	int i;

@@ -277,11 +281,11 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
	for (;;) {
		const struct pmu_events_map *map = &pmu_events_map[i++];

		if (!map->table)
		if (!map->cpuid)
			break;

		if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
			table = map->table;
			table = &map->table;
			break;
		}
	}
@@ -289,13 +293,13 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
	return table;
}

const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
{
	for (const struct pmu_events_map *tables = &pmu_events_map[0];
	     tables->table;
	     tables->arch;
	     tables++) {
		if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
			return tables->table;
			return &tables->table;
	}
	return NULL;
}
@@ -303,9 +307,9 @@ const struct pmu_event *find_core_events_table(const char *arch, const char *cpu
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
{
	for (const struct pmu_events_map *tables = &pmu_events_map[0];
	     tables->table;
	     tables->arch;
	     tables++) {
		int ret = pmu_events_table_for_each_event(tables->table, fn, data);
		int ret = pmu_events_table_for_each_event(&tables->table, fn, data);

		if (ret)
			return ret;
@@ -313,13 +317,13 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
	return 0;
}

const struct pmu_event *find_sys_events_table(const char *name)
const struct pmu_events_table *find_sys_events_table(const char *name)
{
	for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
	     tables->name;
	     tables++) {
		if (!strcmp(tables->name, name))
			return tables->table;
			return &tables->table;
	}
	return NULL;
}
@@ -329,7 +333,7 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
	for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
	     tables->name;
	     tables++) {
		int ret = pmu_events_table_for_each_event(tables->table, fn, data);
		int ret = pmu_events_table_for_each_event(&tables->table, fn, data);

		if (ret)
			return ret;
+26 −21
Original line number Diff line number Diff line
@@ -335,6 +335,11 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
def print_mapping_table(archs: Sequence[str]) -> None:
  """Read the mapfile and generate the struct from cpuid string to event table."""
  _args.output_file.write("""
/* Struct used to make the PMU event table implementation opaque to callers. */
struct pmu_events_table {
        const struct pmu_event *entries;
};

/*
 * Map a CPU to its table of PMU events. The CPU is identified by the
 * cpuid field, which is an arch-specific identifier for the CPU.
@@ -346,7 +351,7 @@ def print_mapping_table(archs: Sequence[str]) -> None:
struct pmu_events_map {
        const char *arch;
        const char *cpuid;
        const struct pmu_event *table;
        struct pmu_events_table table;
};

/*
@@ -360,7 +365,7 @@ const struct pmu_events_map pmu_events_map[] = {
      _args.output_file.write("""{
\t.arch = "testarch",
\t.cpuid = "testcpu",
\t.table = pme_test_soc_cpu,
\t.table = { pme_test_soc_cpu },
},
""")
    else:
@@ -375,7 +380,7 @@ const struct pmu_events_map pmu_events_map[] = {
            _args.output_file.write(f"""{{
\t.arch = "{arch}",
\t.cpuid = "{cpuid}",
\t.table = {tblname}
\t.table = {{ {tblname} }}
}},
""")
          first = False
@@ -383,7 +388,7 @@ const struct pmu_events_map pmu_events_map[] = {
  _args.output_file.write("""{
\t.arch = 0,
\t.cpuid = 0,
\t.table = 0,
\t.table = { 0 },
}
};
""")
@@ -394,26 +399,26 @@ def print_system_mapping_table() -> None:
  _args.output_file.write("""
struct pmu_sys_events {
\tconst char *name;
\tconst struct pmu_event *table;
\tstruct pmu_events_table table;
};

static const struct pmu_sys_events pmu_sys_event_tables[] = {
""")
  for tblname in _sys_event_tables:
    _args.output_file.write(f"""\t{{
\t\t.table = {tblname},
\t\t.table = {{ {tblname} }},
\t\t.name = \"{tblname}\",
\t}},
""")
  _args.output_file.write("""\t{
\t\t.table = 0
\t\t.table = { 0 }
\t},
};

int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
                                    void *data)
{
        for (const struct pmu_event *pe = &table[0];
        for (const struct pmu_event *pe = &table->entries[0];
             pe->name || pe->metric_group || pe->metric_name;
             pe++) {
                int ret = fn(pe, table, data);
@@ -424,9 +429,9 @@ int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_ite
        return 0;
}

const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu)
{
        const struct pmu_event *table = NULL;
        const struct pmu_events_table *table = NULL;
        char *cpuid = perf_pmu__getcpuid(pmu);
        int i;

@@ -439,11 +444,11 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
        i = 0;
        for (;;) {
                const struct pmu_events_map *map = &pmu_events_map[i++];
                if (!map->table)
                if (!map->arch)
                        break;

                if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
                        table = map->table;
                        table = &map->table;
                        break;
                }
        }
@@ -451,13 +456,13 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu)
        return table;
}

const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid)
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid)
{
        for (const struct pmu_events_map *tables = &pmu_events_map[0];
             tables->table;
             tables->arch;
             tables++) {
                if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
                        return tables->table;
                        return &tables->table;
        }
        return NULL;
}
@@ -465,9 +470,9 @@ const struct pmu_event *find_core_events_table(const char *arch, const char *cpu
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
{
        for (const struct pmu_events_map *tables = &pmu_events_map[0];
             tables->table;
             tables->arch;
             tables++) {
                int ret = pmu_events_table_for_each_event(tables->table, fn, data);
                int ret = pmu_events_table_for_each_event(&tables->table, fn, data);

                if (ret)
                        return ret;
@@ -475,13 +480,13 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
        return 0;
}

const struct pmu_event *find_sys_events_table(const char *name)
const struct pmu_events_table *find_sys_events_table(const char *name)
{
        for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
             tables->name;
             tables++) {
                if (!strcmp(tables->name, name))
                        return tables->table;
                        return &tables->table;
        }
        return NULL;
}
@@ -491,7 +496,7 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
        for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0];
             tables->name;
             tables++) {
                int ret = pmu_events_table_for_each_event(tables->table, fn, data);
                int ret = pmu_events_table_for_each_event(&tables->table, fn, data);

                if (ret)
                        return ret;
+7 −5
Original line number Diff line number Diff line
@@ -30,18 +30,20 @@ struct pmu_event {
	const char *metric_constraint;
};

struct pmu_events_table;

typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe,
				 const struct pmu_event *table,
				 const struct pmu_events_table *table,
				 void *data);

int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn,
int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
				    void *data);

const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu);
const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid);
const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu);
const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid);
int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data);

const struct pmu_event *find_sys_events_table(const char *name);
const struct pmu_events_table *find_sys_events_table(const char *name);
int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data);

#endif
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ static int expand_metric_events(void)
	struct evlist *evlist;
	struct rblist metric_events;
	const char metric_str[] = "CPI";
	const struct pmu_event *pme_test;
	const struct pmu_events_table *pme_test;

	evlist = evlist__new();
	TEST_ASSERT_VAL("failed to get evlist", evlist);
Loading