[PATCH 2/2] perf list: do not print metrics on s390 zvm systems

From: Thomas Richter
Date: Tue Mar 19 2024 - 05:59:33 EST


On s390 z/VM virtual machines command perf list also displays metrics:

# ./perf list | grep -A 20 'Metric Groups:'
Metric Groups:

No_group:
cpi
[Cycles per Instruction]
est_cpi
[Estimated Instruction Complexity CPI infinite Level 1]
finite_cpi
[Cycles per Instructions from Finite cache/memory]
l1mp
[Level One Miss per 100 Instructions]
l2p
[Percentage sourced from Level 2 cache]
l3p
[Percentage sourced from Level 3 on same chip cache]
l4lp
[Percentage sourced from Level 4 Local cache on same book]
l4rp
[Percentage sourced from Level 4 Remote cache on different book]
memp
[Percentage sourced from memory]
....
#

This is not correct, on s390 z/VM virtual machines the referenced
CPU Counter Measurement facility does not exist. The command

# ./perf stat -M cpi -- true
event syntax error: '{CPU_CYCLES/metric-id=CPU_CYCLES/.....'
\___ Bad event or PMU

Unable to find PMU or event on a PMU of 'CPU_CYCLES'

event syntax error: '{CPU_CYCLES/metric-id=CPU_CYCLES/...'
\___ Cannot find PMU `CPU_CYCLES'.
Missing kernel support?
#

fails.

Perf list should not display the metrics when the referenced
CPU Counter Measurement PMU is not available.

Output after:
# ./perf list | grep -A 20 'Metric Groups:'
#

Fixes: 7f76b3113068 ("perf list: Add IBM z16 event description for s390")
Signed-off-by: Thomas Richter <tmricht@xxxxxxxxxxxxx>
Acked-by: Sumanth Korikkar <sumanthk@xxxxxxxxxxxxx>
---
tools/perf/arch/s390/util/pmu.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/tools/perf/arch/s390/util/pmu.c b/tools/perf/arch/s390/util/pmu.c
index 886c30e001fa..2dc27acc860c 100644
--- a/tools/perf/arch/s390/util/pmu.c
+++ b/tools/perf/arch/s390/util/pmu.c
@@ -8,6 +8,7 @@
#include <string.h>

#include "../../../util/pmu.h"
+#include "../../../util/pmus.h"

#define S390_PMUPAI_CRYPTO "pai_crypto"
#define S390_PMUPAI_EXT "pai_ext"
@@ -20,3 +21,19 @@ void perf_pmu__arch_init(struct perf_pmu *pmu)
!strcmp(pmu->name, S390_PMUCPUM_CF))
pmu->selectable = true;
}
+
+const struct pmu_metrics_table *pmu_metrics_table__find(void)
+{
+ struct perf_pmu *pmu;
+
+ /*
+ * Metrics defined on events from PMU cpum_cf aren't supported
+ * on z/VM. Make sure the PMU exists and return NULL if that
+ * PMU cannot be found.
+ */
+ pmu = perf_pmus__find("cpum_cf");
+ if (pmu)
+ return perf_pmu__find_metrics_table(pmu);
+
+ return NULL;
+}
--
2.44.0