Commit 838a8c5f authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf pmu: Pass PMU rather than aliases and format

Pass the pmu so the aliases and format list can be better abstracted
and later lazily loaded.
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: Gaosheng Cui <cuigaosheng1@huawei.com>
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: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
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>
Link: https://lore.kernel.org/r/20230823080828.1460376-9-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent da6a5afd
...@@ -496,26 +496,13 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused, ...@@ -496,26 +496,13 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused,
return 0; return 0;
} }
static struct perf_pmu_alias *find_alias(const char *test_event, struct list_head *aliases)
{
struct perf_pmu_alias *alias;
list_for_each_entry(alias, aliases, list)
if (!strcmp(test_event, alias->name))
return alias;
return NULL;
}
/* Verify aliases are as expected */ /* Verify aliases are as expected */
static int __test_core_pmu_event_aliases(char *pmu_name, int *count) static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
{ {
struct perf_pmu_test_event const **test_event_table; struct perf_pmu_test_event const **test_event_table;
struct perf_pmu *pmu; struct perf_pmu *pmu;
LIST_HEAD(aliases);
int res = 0; int res = 0;
const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu"); const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu");
struct perf_pmu_alias *a, *tmp;
if (!table) if (!table)
return -1; return -1;
...@@ -526,14 +513,18 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) ...@@ -526,14 +513,18 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
if (!pmu) if (!pmu)
return -1; return -1;
pmu->name = pmu_name; INIT_LIST_HEAD(&pmu->format);
INIT_LIST_HEAD(&pmu->aliases);
INIT_LIST_HEAD(&pmu->caps);
INIT_LIST_HEAD(&pmu->list);
pmu->name = strdup(pmu_name);
pmu_add_cpu_aliases_table(&aliases, pmu, table); pmu_add_cpu_aliases_table(pmu, table);
for (; *test_event_table; test_event_table++) { for (; *test_event_table; test_event_table++) {
struct perf_pmu_test_event const *test_event = *test_event_table; struct perf_pmu_test_event const *test_event = *test_event_table;
struct pmu_event const *event = &test_event->event; struct pmu_event const *event = &test_event->event;
struct perf_pmu_alias *alias = find_alias(event->name, &aliases); struct perf_pmu_alias *alias = perf_pmu__find_alias(pmu, event->name);
if (!alias) { if (!alias) {
pr_debug("testing aliases core PMU %s: no alias, alias_table->name=%s\n", pr_debug("testing aliases core PMU %s: no alias, alias_table->name=%s\n",
...@@ -551,12 +542,8 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) ...@@ -551,12 +542,8 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
pr_debug2("testing aliases core PMU %s: matched event %s\n", pr_debug2("testing aliases core PMU %s: matched event %s\n",
pmu_name, alias->name); pmu_name, alias->name);
} }
perf_pmu__delete(pmu);
list_for_each_entry_safe(a, tmp, &aliases, list) {
list_del(&a->list);
perf_pmu_free_alias(a);
}
free(pmu);
return res; return res;
} }
...@@ -568,17 +555,16 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) ...@@ -568,17 +555,16 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
const char *pmu_name = pmu->name; const char *pmu_name = pmu->name;
struct perf_pmu_alias *a, *tmp, *alias; struct perf_pmu_alias *a, *tmp, *alias;
const struct pmu_events_table *events_table; const struct pmu_events_table *events_table;
LIST_HEAD(aliases);
int res = 0; int res = 0;
events_table = find_core_events_table("testarch", "testcpu"); events_table = find_core_events_table("testarch", "testcpu");
if (!events_table) if (!events_table)
return -1; return -1;
pmu_add_cpu_aliases_table(&aliases, pmu, events_table); pmu_add_cpu_aliases_table(pmu, events_table);
pmu_add_sys_aliases(&aliases, pmu); pmu_add_sys_aliases(pmu);
/* Count how many aliases we generated */ /* Count how many aliases we generated */
list_for_each_entry(alias, &aliases, list) list_for_each_entry(alias, &pmu->aliases, list)
alias_count++; alias_count++;
/* Count how many aliases we expect from the known table */ /* Count how many aliases we expect from the known table */
...@@ -592,7 +578,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) ...@@ -592,7 +578,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
goto out; goto out;
} }
list_for_each_entry(alias, &aliases, list) { list_for_each_entry(alias, &pmu->aliases, list) {
bool matched = false; bool matched = false;
for (table = &test_pmu->aliases[0]; *table; table++) { for (table = &test_pmu->aliases[0]; *table; table++) {
...@@ -625,7 +611,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) ...@@ -625,7 +611,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
} }
out: out:
list_for_each_entry_safe(a, tmp, &aliases, list) { list_for_each_entry_safe(a, tmp, &pmu->aliases, list) {
list_del(&a->list); list_del(&a->list);
perf_pmu_free_alias(a); perf_pmu_free_alias(a);
} }
...@@ -732,8 +718,13 @@ static int test__aliases(struct test_suite *test __maybe_unused, ...@@ -732,8 +718,13 @@ static int test__aliases(struct test_suite *test __maybe_unused,
} }
for (i = 0; i < ARRAY_SIZE(test_pmus); i++) { for (i = 0; i < ARRAY_SIZE(test_pmus); i++) {
int res = __test_uncore_pmu_event_aliases(&test_pmus[i]); int res;
INIT_LIST_HEAD(&test_pmus[i].pmu.format);
INIT_LIST_HEAD(&test_pmus[i].pmu.aliases);
INIT_LIST_HEAD(&test_pmus[i].pmu.caps);
res = __test_uncore_pmu_event_aliases(&test_pmus[i]);
if (res) if (res)
return res; return res;
} }
......
...@@ -171,7 +171,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe ...@@ -171,7 +171,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe
} }
pmu->name = strdup("perf-pmu-test"); pmu->name = strdup("perf-pmu-test");
ret = perf_pmu__format_parse(fd, &pmu->format); ret = perf_pmu__format_parse(pmu, fd);
if (ret) if (ret)
goto out; goto out;
......
...@@ -58,7 +58,7 @@ struct perf_pmu_format { ...@@ -58,7 +58,7 @@ struct perf_pmu_format {
* Parse & process all the sysfs attributes located under * Parse & process all the sysfs attributes located under
* the directory specified in 'dir' parameter. * the directory specified in 'dir' parameter.
*/ */
int perf_pmu__format_parse(int dirfd, struct list_head *head) int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd)
{ {
struct dirent *evt_ent; struct dirent *evt_ent;
DIR *format_dir; DIR *format_dir;
...@@ -96,7 +96,7 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head) ...@@ -96,7 +96,7 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head)
} }
perf_pmu_set_in(file, scanner); perf_pmu_set_in(file, scanner);
ret = perf_pmu_parse(head, name, scanner); ret = perf_pmu_parse(&pmu->format, name, scanner);
perf_pmu_lex_destroy(scanner); perf_pmu_lex_destroy(scanner);
fclose(file); fclose(file);
} }
...@@ -110,7 +110,7 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head) ...@@ -110,7 +110,7 @@ int perf_pmu__format_parse(int dirfd, struct list_head *head)
* located at: * located at:
* /sys/bus/event_source/devices/<dev>/format as sysfs group attributes. * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes.
*/ */
static int pmu_format(int dirfd, const char *name, struct list_head *format) static int pmu_format(struct perf_pmu *pmu, int dirfd, const char *name)
{ {
int fd; int fd;
...@@ -119,7 +119,7 @@ static int pmu_format(int dirfd, const char *name, struct list_head *format) ...@@ -119,7 +119,7 @@ static int pmu_format(int dirfd, const char *name, struct list_head *format)
return 0; return 0;
/* it'll close the fd */ /* it'll close the fd */
if (perf_pmu__format_parse(fd, format)) if (perf_pmu__format_parse(pmu, fd))
return -1; return -1;
return 0; return 0;
...@@ -508,7 +508,7 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head) ...@@ -508,7 +508,7 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head)
* Reading the pmu event aliases definition, which should be located at: * Reading the pmu event aliases definition, which should be located at:
* /sys/bus/event_source/devices/<dev>/events as sysfs group attributes. * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes.
*/ */
static int pmu_aliases(int dirfd, const char *name, struct list_head *head) static int pmu_aliases(struct perf_pmu *pmu, int dirfd, const char *name)
{ {
int fd; int fd;
...@@ -517,7 +517,7 @@ static int pmu_aliases(int dirfd, const char *name, struct list_head *head) ...@@ -517,7 +517,7 @@ static int pmu_aliases(int dirfd, const char *name, struct list_head *head)
return 0; return 0;
/* it'll close the fd */ /* it'll close the fd */
if (pmu_aliases_parse(fd, head)) if (pmu_aliases_parse(fd, &pmu->aliases))
return -1; return -1;
return 0; return 0;
...@@ -770,11 +770,10 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, ...@@ -770,11 +770,10 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
* From the pmu_events_table, find the events that correspond to the given * From the pmu_events_table, find the events that correspond to the given
* PMU and add them to the list 'head'. * PMU and add them to the list 'head'.
*/ */
void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu, void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table)
const struct pmu_events_table *table)
{ {
struct pmu_add_cpu_aliases_map_data data = { struct pmu_add_cpu_aliases_map_data data = {
.head = head, .head = &pmu->aliases,
.default_pmu_name = perf_pmus__default_pmu_name(), .default_pmu_name = perf_pmus__default_pmu_name(),
.pmu = pmu, .pmu = pmu,
}; };
...@@ -783,7 +782,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu, ...@@ -783,7 +782,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
free(data.default_pmu_name); free(data.default_pmu_name);
} }
static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
{ {
const struct pmu_events_table *table; const struct pmu_events_table *table;
...@@ -791,7 +790,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) ...@@ -791,7 +790,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
if (!table) if (!table)
return; return;
pmu_add_cpu_aliases_table(head, pmu, table); pmu_add_cpu_aliases_table(pmu, table);
} }
struct pmu_sys_event_iter_data { struct pmu_sys_event_iter_data {
...@@ -821,10 +820,10 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, ...@@ -821,10 +820,10 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
return 0; return 0;
} }
void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu) void pmu_add_sys_aliases(struct perf_pmu *pmu)
{ {
struct pmu_sys_event_iter_data idata = { struct pmu_sys_event_iter_data idata = {
.head = head, .head = &pmu->aliases,
.pmu = pmu, .pmu = pmu,
}; };
...@@ -863,30 +862,33 @@ static int pmu_max_precise(int dirfd, struct perf_pmu *pmu) ...@@ -863,30 +862,33 @@ static int pmu_max_precise(int dirfd, struct perf_pmu *pmu)
struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name) struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name)
{ {
struct perf_pmu *pmu; struct perf_pmu *pmu;
LIST_HEAD(format);
LIST_HEAD(aliases);
__u32 type; __u32 type;
char *name = pmu_find_real_name(lookup_name); char *name = pmu_find_real_name(lookup_name);
char *alias_name; char *alias_name;
pmu = zalloc(sizeof(*pmu));
if (!pmu)
return NULL;
INIT_LIST_HEAD(&pmu->format);
INIT_LIST_HEAD(&pmu->aliases);
INIT_LIST_HEAD(&pmu->caps);
/* /*
* The pmu data we store & need consists of the pmu * The pmu data we store & need consists of the pmu
* type value and format definitions. Load both right * type value and format definitions. Load both right
* now. * now.
*/ */
if (pmu_format(dirfd, name, &format)) if (pmu_format(pmu, dirfd, name)) {
free(pmu);
return NULL; return NULL;
}
/* /*
* Check the aliases first to avoid unnecessary work. * Check the aliases first to avoid unnecessary work.
*/ */
if (pmu_aliases(dirfd, name, &aliases)) if (pmu_aliases(pmu, dirfd, name)) {
return NULL; free(pmu);
pmu = zalloc(sizeof(*pmu));
if (!pmu)
return NULL; return NULL;
}
pmu->is_core = is_pmu_core(name); pmu->is_core = is_pmu_core(name);
pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core); pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core);
pmu->name = strdup(name); pmu->name = strdup(name);
...@@ -909,14 +911,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char ...@@ -909,14 +911,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
if (pmu->is_uncore) if (pmu->is_uncore)
pmu->id = pmu_id(name); pmu->id = pmu_id(name);
pmu->max_precise = pmu_max_precise(dirfd, pmu); pmu->max_precise = pmu_max_precise(dirfd, pmu);
pmu_add_cpu_aliases(&aliases, pmu); pmu_add_cpu_aliases(pmu);
pmu_add_sys_aliases(&aliases, pmu); pmu_add_sys_aliases(pmu);
INIT_LIST_HEAD(&pmu->format);
INIT_LIST_HEAD(&pmu->aliases);
INIT_LIST_HEAD(&pmu->caps);
list_splice(&format, &pmu->format);
list_splice(&aliases, &pmu->aliases);
list_add_tail(&pmu->list, pmus); list_add_tail(&pmu->list, pmus);
pmu->default_config = perf_pmu__get_default_config(pmu); pmu->default_config = perf_pmu__get_default_config(pmu);
...@@ -1397,6 +1393,17 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, ...@@ -1397,6 +1393,17 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
return 0; return 0;
} }
struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu, const char *event)
{
struct perf_pmu_alias *alias;
list_for_each_entry(alias, &pmu->aliases, list)
if (!strcmp(event, alias->name))
return alias;
return NULL;
}
int perf_pmu__new_format(struct list_head *list, char *name, int perf_pmu__new_format(struct list_head *list, char *name,
int config, unsigned long *bits) int config, unsigned long *bits)
{ {
......
...@@ -213,7 +213,7 @@ struct perf_pmu_alias { ...@@ -213,7 +213,7 @@ struct perf_pmu_alias {
char *pmu_name; char *pmu_name;
}; };
void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu); void pmu_add_sys_aliases(struct perf_pmu *pmu);
int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
struct list_head *head_terms, struct list_head *head_terms,
struct parse_events_error *error); struct parse_events_error *error);
...@@ -225,12 +225,11 @@ __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name); ...@@ -225,12 +225,11 @@ __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name);
int perf_pmu__format_type(struct perf_pmu *pmu, const char *name); int perf_pmu__format_type(struct perf_pmu *pmu, const char *name);
int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
struct perf_pmu_info *info); struct perf_pmu_info *info);
struct list_head *perf_pmu__alias(struct perf_pmu *pmu, struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu, const char *event);
struct list_head *head_terms);
int perf_pmu__new_format(struct list_head *list, char *name, int perf_pmu__new_format(struct list_head *list, char *name,
int config, unsigned long *bits); int config, unsigned long *bits);
int perf_pmu__format_parse(int dirfd, struct list_head *head); int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd);
bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name); bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name);
bool is_pmu_core(const char *name); bool is_pmu_core(const char *name);
...@@ -255,7 +254,7 @@ bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name); ...@@ -255,7 +254,7 @@ bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name);
int perf_pmu__test(void); int perf_pmu__test(void);
struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu, void pmu_add_cpu_aliases_table(struct perf_pmu *pmu,
const struct pmu_events_table *table); const struct pmu_events_table *table);
char *perf_pmu__getcpuid(struct perf_pmu *pmu); char *perf_pmu__getcpuid(struct perf_pmu *pmu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment