Skip to content

Commit 7afbf90

Browse files
James-A-Clarknamhyung
authored andcommitted
perf pmu: Don't de-duplicate core PMUs
Arm PMUs have a suffix, either a single decimal (armv8_pmuv3_0) or 3 hex digits which (armv8_cortex_a53) which Perf assumes are both strippable suffixes for the purposes of deduplication. S390 "cpum_cf" is a similarly suffixed core PMU but is only two characters so is not treated as strippable because the rules are a minimum of 3 hex characters or 1 decimal character. There are two paths involved in listing PMU events: * HW/cache event printing assumes core PMUs don't have suffixes so doesn't try to strip. * Sysfs PMU events share the printing function with uncore PMUs which strips. This results in slightly inconsistent Perf list behavior if a core PMU has a suffix: # perf list ... armv8_pmuv3_0/branch-load-misses/ armv8_pmuv3/l3d_cache_wb/ [Kernel PMU event] ... Fix it by partially reverting back to the old list behavior where stripping was only done for uncore PMUs. For example commit 8d9f514 ("perf pmus: Sort pmus by name then suffix") mentions that only PMUs starting 'uncore_' are considered to have a potential suffix. This change doesn't go back that far, but does only strip PMUs that are !is_core. This keeps the desirable behavior where the many possibly duplicated uncore PMUs aren't repeated, but it doesn't break listing for core PMUs. Searching for a PMU continues to use the new stripped comparison functions, meaning that it's still possible to request an event by specifying the common part of a PMU name, or even open events on multiple similarly named PMUs. For example: # perf stat -e armv8_cortex/inst_retired/ 5777173628 armv8_cortex_a53/inst_retired/ (99.93%) 7469626951 armv8_cortex_a57/inst_retired/ (49.88%) Fixes: 3241d46 ("perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu") Suggested-by: Ian Rogers <[email protected]> Signed-off-by: James Clark <[email protected]> Reviewed-by: Ian Rogers <[email protected]> Cc: [email protected] Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3e0bf9f commit 7afbf90

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tools/perf/util/pmu.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,23 @@ __weak const struct pmu_metrics_table *pmu_metrics_table__find(void)
847847
return perf_pmu__find_metrics_table(NULL);
848848
}
849849

850+
/**
851+
* Return the length of the PMU name not including the suffix for uncore PMUs.
852+
*
853+
* We want to deduplicate many similar uncore PMUs by stripping their suffixes,
854+
* but there are never going to be too many core PMUs and the suffixes might be
855+
* interesting. "arm_cortex_a53" vs "arm_cortex_a57" or "cpum_cf" for example.
856+
*
857+
* @skip_duplicate_pmus: False in verbose mode so all uncore PMUs are visible
858+
*/
859+
static size_t pmu_deduped_name_len(const struct perf_pmu *pmu, const char *name,
860+
bool skip_duplicate_pmus)
861+
{
862+
return skip_duplicate_pmus && !pmu->is_core
863+
? pmu_name_len_no_suffix(name)
864+
: strlen(name);
865+
}
866+
850867
/**
851868
* perf_pmu__match_ignoring_suffix - Does the pmu_name match tok ignoring any
852869
* trailing suffix? The Suffix must be in form
@@ -1796,9 +1813,8 @@ static char *format_alias(char *buf, int len, const struct perf_pmu *pmu,
17961813
const struct perf_pmu_alias *alias, bool skip_duplicate_pmus)
17971814
{
17981815
struct parse_events_term *term;
1799-
size_t pmu_name_len = skip_duplicate_pmus
1800-
? pmu_name_len_no_suffix(pmu->name)
1801-
: strlen(pmu->name);
1816+
size_t pmu_name_len = pmu_deduped_name_len(pmu, pmu->name,
1817+
skip_duplicate_pmus);
18021818
int used = snprintf(buf, len, "%.*s/%s", (int)pmu_name_len, pmu->name, alias->name);
18031819

18041820
list_for_each_entry(term, &alias->terms.terms, list) {
@@ -1839,9 +1855,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
18391855
size_t buf_used, pmu_name_len;
18401856

18411857
info.pmu_name = event->pmu_name ?: pmu->name;
1842-
pmu_name_len = skip_duplicate_pmus
1843-
? pmu_name_len_no_suffix(info.pmu_name)
1844-
: strlen(info.pmu_name);
1858+
pmu_name_len = pmu_deduped_name_len(pmu, info.pmu_name,
1859+
skip_duplicate_pmus);
18451860
info.alias = NULL;
18461861
if (event->desc) {
18471862
info.name = event->name;

0 commit comments

Comments
 (0)