Skip to contentSkip to conversation

perf/annotate: Use architecture-agnostic register limit

PATCH Applied Suchit Karunakaran 3 participants 3 messages Sep 23, 2025 – Oct 1, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/annotate: Use architecture-agnostic register limit

Remove the arch-specific guard around TYPE_STATE_MAX_REGS and define it as 32 for all architectures. The architecture that perf is built on may not match the architecture that produced the perf.data file, so relying on __powerpc__ or similar is fragile. Using 32 as a fixed upper bound is safe since it is greater than the previous maximum of 16. Add a comment to clarify that TYPE_STATE_MAX_REGS is an arch-independent maximum rather than a build-time choice.

---
 tools/perf/util/annotate-data.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
tools/perf/util/annotate-data.h +8 -5
index 541fee1a5f0a..1f76885facb0 100644
@@ -189,12 +189,15 @@ struct type_state_stack {
 	u8 kind;
 };
 
-/* FIXME: This should be arch-dependent */
-#ifdef __powerpc__
+/*
+ * Maximum number of registers tracked in type_state.
+ *
+ * This limit must cover all supported architectures, since perf
+ * may analyze perf.data files generated on systems with a different
+ * register set. Use 32 as a safe upper bound instead of relying on
+ * build-arch specific values.
+ */
 #define TYPE_STATE_MAX_REGS  32
-#else
-#define TYPE_STATE_MAX_REGS  16
-#endif
 
 /*
  * State table to maintain type info in each register and stack location.
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Suchit Karunakaran

Remove the arch-specific guard around TYPE_STATE_MAX_REGS and define it as 32 for all architectures. The architecture that perf is built on may not match the architecture that produced the perf.data file, so relying on __powerpc__ or similar is fragile. Using 32 as a fixed upper bound is safe since it is greater than the previous maximum of 16. Add a comment to clarify that TYPE_STATE_MAX_REGS is an arch-independent maximum rather than a build-time choice.

Thanks,
Ian

Quoted 32 lines
---
 tools/perf/util/annotate-data.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
tools/perf/util/annotate-data.h +8 -6
index 541fee1a5f0a..1f76885facb0 100644
@@ -189,12 +189,15 @@ struct type_state_stack {
        u8 kind;
 };
 
-/* FIXME: This should be arch-dependent */
-#ifdef __powerpc__
+/*
+ * Maximum number of registers tracked in type_state.
+ *
+ * This limit must cover all supported architectures, since perf
+ * may analyze perf.data files generated on systems with a different
+ * register set. Use 32 as a safe upper bound instead of relying on
+ * build-arch specific values.
+ */
 #define TYPE_STATE_MAX_REGS  32
-#else
-#define TYPE_STATE_MAX_REGS  16
-#endif
 
 /*
  * State table to maintain type info in each register and stack location.
--

2.51.0

maintainer Applied
#2 lore raw
Quoted 11 lines · Ian Rogers
Quoted 9 lines · Suchit Karunakaran

Remove the arch-specific guard around TYPE_STATE_MAX_REGS and define it as 32 for all architectures. The architecture that perf is built on may not match the architecture that produced the perf.data file, so relying on __powerpc__ or similar is fragile. Using 32 as a fixed upper bound is safe since it is greater than the previous maximum of 16. Add a comment to clarify that TYPE_STATE_MAX_REGS is an arch-independent maximum rather than a build-time choice.

Quoted 4 lines
Quoted 2 lines

Thanks, applied to perf-tools-next,

- Arnaldo