Skip to content

Commit 7c52f10

Browse files
captain5050acmel
authored andcommitted
perf pmu: Cache JSON events table
Cache the JSON events table so that finding it isn't done per event/alias. Change the events table find so that when the PMU is given, if the PMU has no JSON events return null. Update usage to always use the PMU variable. 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 f63a536 commit 7c52f10

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

tools/perf/pmu-events/jevents.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def print_system_mapping_table() -> None:
948948
{
949949
const struct pmu_events_table *table = NULL;
950950
char *cpuid = perf_pmu__getcpuid(pmu);
951-
int i;
951+
size_t i;
952952
953953
/* on some platforms which uses cpus map, cpuid can be NULL for
954954
* PMUs other than CORE PMUs.
@@ -968,7 +968,17 @@ def print_system_mapping_table() -> None:
968968
}
969969
}
970970
free(cpuid);
971-
return table;
971+
if (!pmu)
972+
return table;
973+
974+
for (i = 0; i < table->num_pmus; i++) {
975+
const struct pmu_table_entry *table_pmu = &table->pmus[i];
976+
const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
977+
978+
if (pmu__name_match(pmu, pmu_name))
979+
return table;
980+
}
981+
return NULL;
972982
}
973983
974984
const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu)

tools/perf/tests/pmu-events.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
544544
INIT_LIST_HEAD(&pmu->list);
545545
pmu->name = strdup(pmu_name);
546546

547+
pmu->events_table = table;
547548
pmu_add_cpu_aliases_table(pmu, table);
548549

549550
res = pmu_events_table__find_event(table, pmu, "bp_l1_btb_correct", NULL, NULL);
@@ -583,6 +584,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
583584
events_table = find_core_events_table("testarch", "testcpu");
584585
if (!events_table)
585586
return -1;
587+
pmu->events_table = events_table;
586588
pmu_add_cpu_aliases_table(pmu, events_table);
587589
pmu_add_sys_aliases(pmu);
588590

tools/perf/util/pmu.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, int dirfd, const char *name
522522
}
523523
if (!pe) {
524524
/* Update an event from sysfs with json data. */
525-
const struct pmu_events_table *table = perf_pmu__find_events_table(pmu);
526-
527-
if (table)
528-
pmu_events_table__find_event(table, pmu, name, update_alias, alias);
525+
if (pmu->events_table) {
526+
pmu_events_table__find_event(pmu->events_table, pmu, name,
527+
update_alias, alias);
528+
}
529529
}
530530

531531
/* Scan event and remove leading zeroes, spaces, newlines, some
@@ -875,13 +875,10 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_tab
875875

876876
static void pmu_add_cpu_aliases(struct perf_pmu *pmu)
877877
{
878-
const struct pmu_events_table *table;
879-
880-
table = perf_pmu__find_events_table(pmu);
881-
if (!table)
878+
if (!pmu->events_table)
882879
return;
883880

884-
pmu_add_cpu_aliases_table(pmu, table);
881+
pmu_add_cpu_aliases_table(pmu, pmu->events_table);
885882
}
886883

887884
static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
@@ -992,6 +989,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
992989
if (pmu->is_uncore)
993990
pmu->id = pmu_id(name);
994991
pmu->max_precise = pmu_max_precise(dirfd, pmu);
992+
pmu->events_table = perf_pmu__find_events_table(pmu);
995993
pmu_add_cpu_aliases(pmu);
996994
pmu_add_sys_aliases(pmu);
997995
list_add_tail(&pmu->list, pmus);

tools/perf/util/pmu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ struct perf_pmu {
114114
* from json events in pmu-events.c.
115115
*/
116116
struct list_head aliases;
117+
/**
118+
* @events_table: The events table for json events in pmu-events.c.
119+
*/
120+
const struct pmu_events_table *events_table;
117121
/** @caps_initialized: Has the list caps been initialized? */
118122
bool caps_initialized;
119123
/** @nr_caps: The length of the list caps. */

0 commit comments

Comments
 (0)