[PATCH 1/6] perf jevents: Process model files before sys subdirectories

From: Besar Wicaksono

Date: Mon Oct 19 2026 - 14:15:51 EST


jevents walks each directory in name order, mixing files and
subdirectories. When it reaches a sys/ directory inside a model
directory, process_one_file() flushes the model's pending tables and
switches the pending table name to the sys table. After the walk
returns from sys/, nothing switches it back, so model JSON files whose
names sort after "sys" (for example tlb.json) are added to the sys
table. Sys tables are only matched by Compat against uncore PMU
identifiers, so these core events are lost: perf list doesn't show
them and perf stat rejects them.

Visit the files of a directory before its subdirectories, so that all
of a model's JSON files are added to the model's table before a sys/
subdirectory is processed. The generated pmu-events.c is unchanged for
the existing event directories.

Signed-off-by: Besar Wicaksono <bwicaksono@xxxxxxxxxx>
---
tools/perf/pmu-events/jevents.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index cc143f7e7cdf..ba974b2784b0 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -1463,7 +1463,9 @@ def main() -> None:
action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
"""Replicate the directory/file walking behavior of C's file tree walk."""
assert _args is not None
- for item in sorted(os.scandir(path), key=lambda e: e.name):
+ # Visit a directory's files before its subdirectories, because
+ # entering a subdirectory switches the table that files are added to.
+ for item in sorted(os.scandir(path), key=lambda e: (e.is_dir(), e.name)):
if _args.model != 'all' and item.is_dir():
# Check if the model matches one in _args.model.
if len(parents) == _args.model.split(',')[0].count('/'):
--
2.43.0