[PATCH v4 11/21] perf test attr: Introduce mask_bits(), generalizing hide_core_pmu_type()
From: Arnaldo Carvalho de Melo
Date: Fri Oct 16 2026 - 17:23:31 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
What hide_core_pmu_type() does is take a set of bits out of each of the
'|'-separated alternatives in a value, wildcards included, keeping the
rest of the expression: extract that as mask_bits() and implement
hide_core_pmu_type() in terms of it, a prep for using the same thing to
ignore, when comparing expectations, the sample id bit perf ends up
asking for and the read_format group bit that a PMU count can remove.
No change in behaviour.
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/tests/shell/lib/attr.py | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/tools/perf/tests/shell/lib/attr.py b/tools/perf/tests/shell/lib/attr.py
index fb866fb75175dc95..ee55fbe6f07bd7b5 100644
--- a/tools/perf/tests/shell/lib/attr.py
+++ b/tools/perf/tests/shell/lib/attr.py
@@ -80,24 +80,31 @@ PERF_TYPE_HW_CACHE = 3
# type in its top 32 bits when there is more than one core PMU.
LEGACY_TYPES = (str(PERF_TYPE_HARDWARE), str(PERF_TYPE_HW_CACHE))
-def hide_core_pmu_type(value):
+def mask_bits(value, bits):
"""
- The kernel can be told which core PMU a legacy type event is meant for by
- putting its type in the top 32 bits of 'config', which perf only does when
- there is more than one core PMU, so take those bits out to keep the
- expectations written for the single core PMU case matching on
- heterogeneous machines.
+ Take the bits in 'bits' out of each of the '|'-separated alternatives in
+ 'value', keeping the rest of the expression, wildcards included.
"""
- hidden = []
+ masked = []
for alternative in value.split('|'):
try:
- alternative = str(int(alternative, 0) & 0xffffffff)
+ alternative = str(int(alternative, 0) & ~bits)
except ValueError:
pass
- hidden.append(alternative)
+ masked.append(alternative)
- return '|'.join(hidden)
+ return '|'.join(masked)
+
+def hide_core_pmu_type(value):
+ """
+ The kernel can be told which core PMU a legacy type event is meant for by
+ putting its type in the top 32 bits of 'config', which perf only does when
+ there is more than one core PMU, so take those bits out to keep the
+ expectations written for the single core PMU case matching on
+ heterogeneous machines.
+ """
+ return mask_bits(value, 0xffffffff00000000)
class Fail(Exception):
def __init__(self, test, msg):
--
2.55.0