Skip to content

Commit f26d22f

Browse files
captain5050acmel
authored andcommitted
perf pmu: Prefer passing pmu to aliases list
The aliases list is part of the PMU. Rather than pass the aliases list, pass the full PMU simplifying some callbacks. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Gaosheng Cui <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jing Zhang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent edb217f commit f26d22f

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

tools/perf/util/pmu.c

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,12 @@ static void perf_pmu__del_aliases(struct perf_pmu *pmu)
435435
/* Merge an alias, search in alias list. If this name is already
436436
* present merge both of them to combine all information.
437437
*/
438-
static bool perf_pmu_merge_alias(struct perf_pmu_alias *newalias,
439-
struct list_head *alist)
438+
static bool perf_pmu_merge_alias(struct perf_pmu *pmu,
439+
struct perf_pmu_alias *newalias)
440440
{
441441
struct perf_pmu_alias *a;
442442

443-
list_for_each_entry(a, alist, list) {
443+
list_for_each_entry(a, &pmu->aliases, list) {
444444
if (!strcasecmp(newalias->name, a->name)) {
445445
if (newalias->pmu_name && a->pmu_name &&
446446
!strcasecmp(newalias->pmu_name, a->pmu_name)) {
@@ -454,7 +454,7 @@ static bool perf_pmu_merge_alias(struct perf_pmu_alias *newalias,
454454
return false;
455455
}
456456

457-
static int perf_pmu__new_alias(struct list_head *list, int dirfd, const char *name,
457+
static int perf_pmu__new_alias(struct perf_pmu *pmu, int dirfd, const char *name,
458458
const char *desc, const char *val, FILE *val_fd,
459459
const struct pmu_event *pe)
460460
{
@@ -536,8 +536,8 @@ static int perf_pmu__new_alias(struct list_head *list, int dirfd, const char *na
536536
alias->str = strdup(newval);
537537
alias->pmu_name = pmu_name ? strdup(pmu_name) : NULL;
538538

539-
if (!perf_pmu_merge_alias(alias, list))
540-
list_add_tail(&alias->list, list);
539+
if (!perf_pmu_merge_alias(pmu, alias))
540+
list_add_tail(&alias->list, &pmu->aliases);
541541

542542
return 0;
543543
}
@@ -563,7 +563,7 @@ static inline bool pmu_alias_info_file(char *name)
563563
* Process all the sysfs attributes located under the directory
564564
* specified in 'dir' parameter.
565565
*/
566-
static int pmu_aliases_parse(int dirfd, struct list_head *head)
566+
static int pmu_aliases_parse(struct perf_pmu *pmu, int dirfd)
567567
{
568568
struct dirent *evt_ent;
569569
DIR *event_dir;
@@ -597,7 +597,7 @@ static int pmu_aliases_parse(int dirfd, struct list_head *head)
597597
continue;
598598
}
599599

600-
if (perf_pmu__new_alias(head, dirfd, name, /*desc=*/ NULL,
600+
if (perf_pmu__new_alias(pmu, dirfd, name, /*desc=*/ NULL,
601601
/*val=*/ NULL, file, /*pe=*/ NULL) < 0)
602602
pr_debug("Cannot set up %s\n", name);
603603
fclose(file);
@@ -620,7 +620,7 @@ static int pmu_aliases(struct perf_pmu *pmu, int dirfd, const char *name)
620620
return 0;
621621

622622
/* it'll close the fd */
623-
if (pmu_aliases_parse(fd, &pmu->aliases))
623+
if (pmu_aliases_parse(pmu, fd))
624624
return -1;
625625

626626
return 0;
@@ -848,10 +848,9 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
848848
const struct pmu_events_table *table __maybe_unused,
849849
void *vdata)
850850
{
851-
struct list_head *head = vdata;
851+
struct perf_pmu *pmu = vdata;
852852

853-
/* need type casts to override 'const' */
854-
perf_pmu__new_alias(head, -1, pe->name, pe->desc, pe->event, /*val_fd=*/ NULL, pe);
853+
perf_pmu__new_alias(pmu, -1, pe->name, pe->desc, pe->event, /*val_fd=*/ NULL, pe);
855854
return 0;
856855
}
857856

@@ -861,7 +860,7 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
861860
*/
862861
void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table)
863862
{
864-
pmu_events_table__for_each_event(table, pmu, pmu_add_cpu_aliases_map_callback, &pmu->aliases);
863+
pmu_events_table__for_each_event(table, pmu, pmu_add_cpu_aliases_map_callback, pmu);
865864
}
866865

867866
static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
@@ -875,24 +874,18 @@ static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
875874
pmu_add_cpu_aliases_table(pmu, table);
876875
}
877876

878-
struct pmu_sys_event_iter_data {
879-
struct list_head *head;
880-
struct perf_pmu *pmu;
881-
};
882-
883877
static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
884878
const struct pmu_events_table *table __maybe_unused,
885-
void *data)
879+
void *vdata)
886880
{
887-
struct pmu_sys_event_iter_data *idata = data;
888-
struct perf_pmu *pmu = idata->pmu;
881+
struct perf_pmu *pmu = vdata;
889882

890883
if (!pe->compat || !pe->pmu)
891884
return 0;
892885

893886
if (!strcmp(pmu->id, pe->compat) &&
894887
pmu_uncore_alias_match(pe->pmu, pmu->name)) {
895-
perf_pmu__new_alias(idata->head, -1,
888+
perf_pmu__new_alias(pmu, -1,
896889
pe->name,
897890
pe->desc,
898891
pe->event,
@@ -905,15 +898,10 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
905898

906899
void pmu_add_sys_aliases(struct perf_pmu *pmu)
907900
{
908-
struct pmu_sys_event_iter_data idata = {
909-
.head = &pmu->aliases,
910-
.pmu = pmu,
911-
};
912-
913901
if (!pmu->id)
914902
return;
915903

916-
pmu_for_each_sys_event(pmu_add_sys_aliases_iter_fn, &idata);
904+
pmu_for_each_sys_event(pmu_add_sys_aliases_iter_fn, pmu);
917905
}
918906

919907
struct perf_event_attr * __weak

0 commit comments

Comments
 (0)