Perf tools: Support eGPRs/SSP/SIMD registers sampling
Subsystems (2)
v10 cover Perf tools: Support eGPRs/SSP/SIMD registers sampling
Patch layout:
- Patches 1-2: Fix two bugs in DWARF register bounds checking and event attribute printing/swapping.
- Patches 3-4: Sync tools and perf headers with the kernel sources.
- Patches 5-8: Add SIMD/eGPR/SSP sampling and dump support.
- Patches 9-10: Add unit tests for SIMD/eGPR/SSP sampling.
Changes since v9:
- Patch 05/10: Fix the issue that cpu-clock/task-clock fails to sample GPRs.
- Patch 06/10: Ensure sample_intr_{pred|vec}_regs and sample_user_{pred|vec}_regs to keep identical if both are set since they share sample_{pred|vec}_reg_qwords.
Changes since v8:
- Patch 01/10: Fix incorrect DWARF register bounds checking.
- Patch 02/10: Add missing event attribute printing and swapping support (Sashiko).
- Patch 07/10: Remove dead code ([idx++]) in SIMD register dumping (Sashiko).
- Patch 08/10: Restore the original x86 libdw_frame_nregs value (17), as libdw still lacks x86 SIMD/eGPR support (Ian).
- Patch 09/10: Add x86 eGPR/SSP sampling unit tests (Ian).
- Patch 10/10: Add x86 SIMD register sampling unit tests (Ian).
Changes since v7:
- Address Sashiko's comments including,
* documents are not update availably; SIMD registers bitmask may be overwritten by shorter mask; u16 type in sample meta-data break the cross-endian conversion, etc.
- Add SIMD/eGPRs/SSP support in dwarf-regs (Ian).
- Misc enhancements.
Changes since v6:
- Address Ian's comments including,
* Add more comments for newly added register indexes (patch 1/4).
* Several minor enhancements in patch 4/4.
- Limit dwarf minimal regs to legacy GPRs (excluding APX eGPRs) (patch 2/4).
Changes since v5:
- Split the sampling support for eGPRs/SSP registers and SIMD registers into 2 patches.
- Address Ian's comments including,
* Convert the architecture dependent functions into regular architectural independent functions, like whatperf_reg_name() does.
* Refine the functions name to represent what the functions really do.
* Add comments for some key functions arguments.
* Misc enhancements.
This patch-set adds sampling support for x86 eGPRs/SSP/SIMD registers in perf tools base on the corresponding sampling support for eGPRs/SSP/SIMD registers in kernel[1]. In versions before v6, these perf-tools patches are integrated as a whole patch-set with the kernel patches, but it's split and posted to an independent perf-tools patch-set for convenient review.
History:
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
Ref:
[1] Kernel patches of supporting eGPRs/SSP/SIMD registers sampling:
https://lore.kernel.org/all/[email protected]/
Dapeng Mi (10):
perf dwarf-regs: Fix DWARF register index bounds check perf util: Add missed fields in _attr__fprintf() and __attr_swap() tools headers: Sync x86 headers with kernel sources
perf headers: Sync perf_event.h/perf_regs.h with the kernel headers perf regs: Support x86 eGPRs/SSP sampling
perf regs: Support x86 SIMD registers sampling
perf regs: Enable dumping of SIMD registers
perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers perf tests: Add x86 eGPRs/SSP registers sampling test perf tests: Add SIMD registers sampling test
tools/arch/x86/include/asm/msr-index.h | 7 + tools/arch/x86/include/uapi/asm/perf_regs.h | 53 +++ tools/include/uapi/linux/perf_event.h | 49 +- tools/perf/Documentation/perf-record.txt | 10 +- tools/perf/builtin-script.c | 93 +++- tools/perf/tests/shell/record.sh | 257 +++++++++++ .../util/dwarf-regs-arch/dwarf-regs-csky.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-powerpc.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-s390.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-x86.c | 140 +++++- tools/perf/util/dwarf-regs.c | 9 +- tools/perf/util/evsel.c | 106 ++++- tools/perf/util/evsel.h | 7 + tools/perf/util/header.c | 3 +- tools/perf/util/include/dwarf-regs.h | 7 +- tools/perf/util/parse-regs-options.c | 210 ++++++++- .../perf/util/perf-regs-arch/perf_regs_x86.c | 436 +++++++++++++++++- tools/perf/util/perf_event_attr_fprintf.c | 13 + tools/perf/util/perf_regs.c | 84 +++- tools/perf/util/perf_regs.h | 21 +- tools/perf/util/record.h | 7 + tools/perf/util/sample.h | 5 + .../scripting-engines/trace-event-python.c | 127 ++++- tools/perf/util/session.c | 112 ++++- tools/perf/util/synthetic-events.c | 38 ++ tools/perf/util/unwind-libdw.c | 6 +- 26 files changed, 1696 insertions(+), 110 deletions(-)
base-commit: e01c7bd5b1eece254bcbf282db066b12c4815d21
Signature · 1 line
2.34.1
PATCH v10 1/10 perf dwarf-regs: Fix DWARF register index bounds check
Tighten bounds validation in __get_dwarf_regnum_for_perf_regnum_xxx() helpers by changing perf_regnum > ARRAY_SIZE() to perf_regnum >= ARRAY_SIZE().
This fixes an off-by-one condition where perf_regnum == ARRAY_SIZE() could pass validation and cause out-of-bounds access for dwarf_xxx_regnums[].
--- tools/perf/util/dwarf-regs-arch/dwarf-regs-csky.c | 2 +- tools/perf/util/dwarf-regs-arch/dwarf-regs-powerpc.c | 2 +- tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 2 +- tools/perf/util/dwarf-regs-arch/dwarf-regs-x86.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-csky.c +1 -1
@@ -118,7 +118,7 @@ int __get_dwarf_regnum_for_perf_regnum_csky(int perf_regnum, unsigned int flags)if (flags &EF_CSKY_ABIV2 ) idx++; -if (perf_regnum <0 || perf_regnum > (int )ARRAY_SIZE (dwarf_csky_regnums) || +if (perf_regnum <0 || perf_regnum >= (int )ARRAY_SIZE (dwarf_csky_regnums) || dwarf_csky_regnums[perf_regnum][idx] ==0 )return -ENOENT ;
tools/perf/util/dwarf-regs-arch/dwarf-regs-powerpc.c +1 -1
@@ -128,7 +128,7 @@ int __get_dwarf_regnum_for_perf_regnum_powerpc(int perf_regnum)if (perf_regnum ==0 )return 0 ; -if (perf_regnum <0 || perf_regnum > (int )ARRAY_SIZE (dwarf_powerpc_regnums) || +if (perf_regnum <0 || perf_regnum >= (int )ARRAY_SIZE (dwarf_powerpc_regnums) || dwarf_powerpc_regnums[perf_regnum] ==0 )return -ENOENT ;
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)if (perf_regnum ==0 )return 0 ; -if (perf_regnum <0 || perf_regnum > (int )ARRAY_SIZE (dwarf_s390_regnums) || +if (perf_regnum <0 || perf_regnum >= (int )ARRAY_SIZE (dwarf_s390_regnums) || dwarf_s390_regnums[perf_regnum] ==0 )return -ENOENT ;
tools/perf/util/dwarf-regs-arch/dwarf-regs-x86.c +2 -2
@@ -197,7 +197,7 @@ int __get_dwarf_regnum_for_perf_regnum_i386(int perf_regnum)if (perf_regnum ==0 )return 0 ; -if (perf_regnum <0 || perf_regnum > (int )ARRAY_SIZE (dwarf_i386_regnums) || +if (perf_regnum <0 || perf_regnum >= (int )ARRAY_SIZE (dwarf_i386_regnums) || dwarf_i386_regnums[perf_regnum] ==0 )return -ENOENT ;
@@ -252,7 +252,7 @@ int __get_dwarf_regnum_for_perf_regnum_x86_64(int perf_regnum)if (perf_regnum ==0 )return 0 ; -if (perf_regnum <0 || perf_regnum > (int )ARRAY_SIZE (dwarf_x86_64_regnums) || +if (perf_regnum <0 || perf_regnum >= (int )ARRAY_SIZE (dwarf_x86_64_regnums) || dwarf_x86_64_regnums[perf_regnum] ==0 )return -ENOENT ;
Signature · 1 line
2.34.1
PATCH v10 2/10 perf util: Add missed fields in _attr__fprintf() and __attr_swap()
In reply to Dapeng MiSome new introduced perf_event_attr fields, like config3 and config4, are forgotten to add into perf_event_attr__fprintf() and perf_event__attr_swap() helpers. Add these missed fields into these 2 helpers.
The aux_action is an exception. aux_action aliases bitfields (e.g. aux_start_paused) in a union. Bitfields and plain u32 fields follow different endian rules, so both views cannot be swapped correctly at the same time. Leave aux_action unswapped until the ABI is represented in a byte-order-safe form.
--- tools/perf/util/perf_event_attr_fprintf.c | 4 ++++ tools/perf/util/session.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
tools/perf/util/perf_event_attr_fprintf.c +4 -0
@@ -405,6 +405,10 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,PRINT_ATTRf_bf (aux_pause, p_unsigned);PRINT_ATTRf_bf (aux_resume, p_unsigned); } +if (attr_size >= offsetof(struct perf_event_attr , config4)) +PRINT_ATTRf (config3, p_hex); +if (attr_size > offsetof(struct perf_event_attr , config4)) +PRINT_ATTRf (config4, p_hex);return ret; }
tools/perf/util/session.c +10 -0
@@ -629,6 +629,16 @@ do { \bswap_field_32 (aux_watermark);bswap_field_16 (sample_max_stack);bswap_field_32 (aux_sample_size); +/* +* aux_action aliases bitfields (e.g. aux_start_paused) in a union. +* Bitfields and plain u32 fields follow different endian rules, so +* both views cannot be swapped correctly at the same time. +* Leave aux_action unswapped until the ABI is represented in a +* byte-order-safe form. +*/ +bswap_field_64 (sig_data); +bswap_field_64 (config3); +bswap_field_64 (config4);/* * After read_format are bitfields. Check read_format because
Signature · 1 line
2.34.1
PATCH v10 3/10 tools headers: Sync x86 headers with kernel sources
In reply to Dapeng MiSync newly introduced ARCH_PEBS_VECR_xxx macros from kernel.
--- tools/arch/x86/include/asm/msr-index.h | 7 +++++++ 1 file changed, 7 insertions(+)
tools/arch/x86/include/asm/msr-index.h +7 -0
@@ -350,6 +350,13 @@#define ARCH_PEBS_LBR_SHIFT 40#define ARCH_PEBS_LBR (0x3ull << ARCH_PEBS_LBR_SHIFT)#define ARCH_PEBS_VECR_XMM BIT_ULL(49) +#define ARCH_PEBS_VECR_YMMH BIT_ULL(50) +#define ARCH_PEBS_VECR_EGPRS BIT_ULL(51) +#define ARCH_PEBS_VECR_OPMASK BIT_ULL(53) +#define ARCH_PEBS_VECR_ZMMH BIT_ULL(54) +#define ARCH_PEBS_VECR_H16ZMM BIT_ULL(55) +#define ARCH_PEBS_VECR_EXT_SHIFT 49 +#define ARCH_PEBS_VECR_EXT (0x7full << ARCH_PEBS_VECR_EXT_SHIFT)#define ARCH_PEBS_GPR BIT_ULL(61)#define ARCH_PEBS_AUX BIT_ULL(62)#define ARCH_PEBS_EN BIT_ULL(63)
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [Patch v10 03/10] tools headers: Sync x86 headers with kernel sources
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Header synchronization mismatch: tools/arch/x86/include/asm/msr-index.h introduces macros not…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Header synchronization mismatch: tools/arch/x86/include/asm/msr-index.h introduces macros not present in the core kernel header. --
--- Patch [3]: [Patch v10 03/10] tools headers: Sync x86 headers with kernel sources --- commit a80378c4387abdba00fb87b0094f51fec90aa452
Author: Dapeng Mi <[email protected]>
tools headers: Sync x86 headers with kernel sources
This commit adds ARCH_PEBS_VECR_xxx macros to the tools version of the x86 msr-index.h header to sync with the main kernel sources.
Quoted 5 lines
tools/arch/x86/include/asm/msr-index.h +0
-0
tools/arch/x86/include/asm/msr-index.h line 359
Quoted 10 lines
tools/arch/x86/include/asm/msr-index.h +7
-0@@ -350,6 +350,13 @@#define ARCH_PEBS_LBR_SHIFT 40#define ARCH_PEBS_LBR (0x3ull << ARCH_PEBS_LBR_SHIFT)#define ARCH_PEBS_VECR_XMM BIT_ULL(49) +#define ARCH_PEBS_VECR_YMMH BIT_ULL(50) +#define ARCH_PEBS_VECR_EGPRS BIT_ULL(51) +#define ARCH_PEBS_VECR_OPMASK BIT_ULL(53) +#define ARCH_PEBS_VECR_ZMMH BIT_ULL(54) +#define ARCH_PEBS_VECR_H16ZMM BIT_ULL(55) +#define ARCH_PEBS_VECR_EXT_SHIFT 49 +#define ARCH_PEBS_VECR_EXT (0x7full << ARCH_PEBS_VECR_EXT_SHIFT)
[Severity: Medium]
The commit message states "Sync newly introduced ARCH_PEBS_VECR_xxx macros from kernel". Are these macros actually present in the main kernel tree?
Looking at the core kernel version of arch/x86/include/asm/msr-index.h, these definitions do not appear to exist.
If they are missing from the main kernel header, won't this cause a divergence between the tools header and the core kernel header, resulting in warnings from tools/perf/check-headers.sh during the perf build?
Quoted 3 lines
tools/arch/x86/include/asm/msr-index.h +0
-0#define ARCH_PEBS_GPR BIT_ULL(61)#define ARCH_PEBS_AUX BIT_ULL(62)#define ARCH_PEBS_EN BIT_ULL(63)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [Patch v10 03/10] tools headers: Sync x86 headers with kernel sources
Quoted 32 lines · On 7/21/2026 3:39 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Header synchronization mismatch:tools/arch/x86/include/asm/msr-index.hintroduces macros not present in the core kernel header. ----- Patch [3]: [Patch v10 03/10] tools headers: Sync x86 headers with kernel sources --- commit
a80378c4387abdba00fb87b0094f51fec90aa452
Author: Dapeng Mi <[email protected]>tools headers: Sync x86 headers with kernel sources
This commit adds
ARCH_PEBS_VECR_xxxmacros to the tools version of the x86msr-index.hheader to sync with the main kernel sources.Quoted 5 lines
tools/arch/x86/include/asm/msr-index.h +0
-0tools/arch/x86/include/asm/msr-index.h line 359
Quoted 10 lines
tools/arch/x86/include/asm/msr-index.h +7
-0@@ -350,6 +350,13 @@#define ARCH_PEBS_LBR_SHIFT 40#define ARCH_PEBS_LBR (0x3ull << ARCH_PEBS_LBR_SHIFT)#define ARCH_PEBS_VECR_XMM BIT_ULL(49) +#define ARCH_PEBS_VECR_YMMH BIT_ULL(50) +#define ARCH_PEBS_VECR_EGPRS BIT_ULL(51) +#define ARCH_PEBS_VECR_OPMASK BIT_ULL(53) +#define ARCH_PEBS_VECR_ZMMH BIT_ULL(54) +#define ARCH_PEBS_VECR_H16ZMM BIT_ULL(55) +#define ARCH_PEBS_VECR_EXT_SHIFT 49 +#define ARCH_PEBS_VECR_EXT (0x7full << ARCH_PEBS_VECR_EXT_SHIFT)[Severity: Medium]
The commit message states "Sync newly introducedARCH_PEBS_VECR_xxxmacros from kernel". Are these macros actually present in the main kernel tree?
Quoted 6 lines
Looking at the core kernel version of
arch/x86/include/asm/msr-index.h, these definitions do not appear to exist.If they are missing from the main kernel header, won't this cause a divergence between the tools header and the core kernel header, resulting in warnings from
tools/perf/check-headers.shduring the perf build?
The kerne header change is in a separate patch. Thanks.
https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
Quoted 4 lines
tools/arch/x86/include/asm/msr-index.h +0
-0#define ARCH_PEBS_GPR BIT_ULL(61)#define ARCH_PEBS_AUX BIT_ULL(62)#define ARCH_PEBS_EN BIT_ULL(63)
PATCH v10 4/10 perf headers: Sync perf_event.h/perf_regs.h with the kernel headers
In reply to Dapeng MiSync the UAPI header changes of supporting SIMD/eGPRs/SSP sampling into corresponding tools UAPI headers.
Additionally, support the new introduced perf_event_attr fields in the perf_event_attr__fprintf and perf_event__attr_swap() helpers, and add sanity check for the new introduced __reserved_4 field in perf_attr_check().
--- tools/arch/x86/include/uapi/asm/perf_regs.h | 53 +++++++++++++++++++++ tools/include/uapi/linux/perf_event.h | 49 +++++++++++++++++-- tools/perf/util/header.c | 3 +- tools/perf/util/perf_event_attr_fprintf.c | 11 ++++- tools/perf/util/session.c | 7 +++ 5 files changed, 117 insertions(+), 6 deletions(-)
tools/arch/x86/include/uapi/asm/perf_regs.h +53 -0
@@ -2,6 +2,8 @@#ifndef _ASM_X86_PERF_REGS_H#define _ASM_X86_PERF_REGS_H +#include <linux/bits.h> +enum perf_event_x86_regs {PERF_REG_X86_AX , PERF_REG_X86_BX,
@@ -27,9 +29,35 @@ enum perf_event_x86_regs {PERF_REG_X86_R13 ,PERF_REG_X86_R14 ,PERF_REG_X86_R15 , +/* +* The eGPRs/SSP and XMM have overlaps. Only one can be used +* at a time. The ABI PERF_SAMPLE_REGS_ABI_SIMD is used to +* distinguish which one is used. If PERF_SAMPLE_REGS_ABI_SIMD +* is set, then eGPRs/SSP is used, otherwise, XMM is used. +* +* Extended GPRs (eGPRs) +*/ +PERF_REG_X86_R16 , +PERF_REG_X86_R17 , +PERF_REG_X86_R18 , +PERF_REG_X86_R19 , +PERF_REG_X86_R20 , +PERF_REG_X86_R21 , +PERF_REG_X86_R22 , +PERF_REG_X86_R23 , +PERF_REG_X86_R24 , +PERF_REG_X86_R25 , +PERF_REG_X86_R26 , +PERF_REG_X86_R27 , +PERF_REG_X86_R28 , +PERF_REG_X86_R29 , +PERF_REG_X86_R30 , +PERF_REG_X86_R31 , +PERF_REG_X86_SSP ,/* These are the limits for the GPRs. */ PERF_REG_X86_32_MAX =PERF_REG_X86_GS +1 ,PERF_REG_X86_64_MAX =PERF_REG_X86_R15 +1 , +PERF_REG_MISC_MAX =PERF_REG_X86_SSP +1 ,/* These all need two bits set because they are 128bit */ PERF_REG_X86_XMM0 = 32,
@@ -54,5 +82,30 @@ enum perf_event_x86_regs { };#define PERF_REG_EXTENDED_MASK (~((1ULL << PERF_REG_X86_XMM0) - 1)) +#define PERF_X86_EGPRS_MASK __GENMASK_ULL(PERF_REG_X86_R31, PERF_REG_X86_R16) + +enum { +PERF_X86_SIMD_XMM_REGS =16 , +PERF_X86_SIMD_YMM_REGS =16 , +PERF_X86_SIMD_ZMM_REGS =32 , +PERF_X86_SIMD_VEC_REGS_MAX =PERF_X86_SIMD_ZMM_REGS , + +PERF_X86_SIMD_OPMASK_REGS =8 , +PERF_X86_SIMD_PRED_REGS_MAX =PERF_X86_SIMD_OPMASK_REGS , +}; + +#define PERF_X86_SIMD_PRED_MASK __GENMASK(PERF_X86_SIMD_PRED_REGS_MAX - 1, 0) +#define PERF_X86_SIMD_VEC_MASK __GENMASK_ULL(PERF_X86_SIMD_VEC_REGS_MAX - 1, 0) + +#define PERF_X86_H16ZMM_BASE 16 + +enum { +/* 1 qword = 8 bytes */ +PERF_X86_OPMASK_QWORDS =1 , +PERF_X86_XMM_QWORDS =2 , +PERF_X86_YMM_QWORDS =4 , +PERF_X86_ZMM_QWORDS =8 , +PERF_X86_SIMD_QWORDS_MAX =PERF_X86_ZMM_QWORDS , +};#endif /* _ASM_X86_PERF_REGS_H */
tools/include/uapi/linux/perf_event.h +45 -4
79 lines not on this page · raw message
tools/perf/util/header.c +2 -1
@@ -2162,7 +2162,8 @@ static void free_event_desc(struct evsel *events)static bool perf_attr_check (struct perf_event_attr *attr) { -if (attr->__reserved_1 || attr->__reserved_2 || attr->__reserved_3) { +if (attr->__reserved_1 || attr->__reserved_2 || + attr->__reserved_3 || attr->__reserved_4) {pr_warning ("Reserved bits are set unexpectedly. " "Please update perf tool.\n" );return false;
tools/perf/util/perf_event_attr_fprintf.c +10 -1
@@ -407,8 +407,17 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, }if (attr_size >= offsetof(struct perf_event_attr , config4))PRINT_ATTRf (config3, p_hex); -if (attr_size > offsetof(struct perf_event_attr , config4)) +if (attr_size >= offsetof(struct perf_event_attr , sample_simd_regs_enabled))PRINT_ATTRf (config4, p_hex); +if (attr_size > offsetof(struct perf_event_attr , sample_simd_vec_reg_user)) { +PRINT_ATTRf (sample_simd_regs_enabled, p_unsigned); +PRINT_ATTRf (sample_simd_pred_reg_qwords, p_unsigned); +PRINT_ATTRf (sample_simd_pred_reg_intr, p_hex); +PRINT_ATTRf (sample_simd_pred_reg_user, p_hex); +PRINT_ATTRf (sample_simd_vec_reg_qwords, p_unsigned); +PRINT_ATTRf (sample_simd_vec_reg_intr, p_hex); +PRINT_ATTRf (sample_simd_vec_reg_user, p_hex); + }return ret; }
tools/perf/util/session.c +7 -0
@@ -639,6 +639,13 @@ do { \bswap_field_64 (sig_data);bswap_field_64 (config3);bswap_field_64 (config4); +bswap_field_16 (sample_simd_regs_enabled); +bswap_field_16 (sample_simd_pred_reg_qwords); +bswap_field_16 (sample_simd_vec_reg_qwords); +bswap_field_32 (sample_simd_pred_reg_intr); +bswap_field_32 (sample_simd_pred_reg_user); +bswap_field_64 (sample_simd_vec_reg_intr); +bswap_field_64 (sample_simd_vec_reg_user);/* * After read_format are bitfields. Check read_format because
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [Patch v10 04/10] perf headers: Sync perf_event.h/perf_regs.h with the kernel headers
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] evsel__parse_sample() fails to parse or skip the newly appended SIMD payload, corrupting…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] evsel__parse_sample() fails to parse or skip the newly appended SIMD payload, corrupting subsequent sample field parsing.
- [Medium] The condition to print the new SIMD attribute fields in perf_event_attr__fprintf() uses the offset of the last field instead of the first field, hiding valid intermediate fields.
- [Medium] regs_dump_abi() incorrectly reports 'unknown' for all samples with SIMD registers enabled.
--
--- Patch [4]: [Patch v10 04/10] perf headers: Sync perf_event.h/perf_regs.h with the kernel headers --- commit 8b5325e2c0e1de39cce1b1704639159d2e039a47
Author: Dapeng Mi <[email protected]>
perf headers: Sync perf_event.h/perf_regs.h with the kernel headers
This commit syncs UAPI header changes supporting SIMD/eGPRs/SSP sampling into the corresponding tools UAPI headers. It also updates the print and swap helpers to support the newly introduced perf_event_attr fields.
Quoted 4 lines
tools/include/uapi/linux/perf_event.h +0
-0
[ ... ]
tools/include/uapi/linux/perf_event.h enum { · line 320
Quoted 10 lines
tools/include/uapi/linux/perf_event.h +3
-2@@ -314,8 +314,9 @@ enum {*/ enum perf_sample_regs_abi {PERF_SAMPLE_REGS_ABI_NONE =0 , -PERF_SAMPLE_REGS_ABI_32 =1 , -PERF_SAMPLE_REGS_ABI_64 =2 , +PERF_SAMPLE_REGS_ABI_32 = (1 <<0 ), +PERF_SAMPLE_REGS_ABI_64 = (1 <<1 ), +PERF_SAMPLE_REGS_ABI_SIMD = (1 <<2 ), };
[Severity: Medium]
By changing the ABI values to bitwise flags, will this break the existing regs_dump_abi() in tools/perf/util/session.c?
When the PERF_SAMPLE_REGS_ABI_SIMD bit is set, the combined mask is at least 4. This triggers the fallback in regs_dump_abi():
static inline const char *regs_dump_abi(struct regs_dump *d)
{
if (d->abi > PERF_SAMPLE_REGS_ABI_64)
return "unknown";
return regs_abi[d->abi];
}Should this logic be updated to handle the new bitmasks so valid SIMD samples aren't displayed as unknown?
[ ... ]
Quoted 4 lines
tools/include/uapi/linux/perf_event.h +0
-0@@ -1020,7 +1045,15 @@ enum perf_event_type {* } && PERF_SAMPLE_BRANCH_STACK * * { u64 abi; # enum perf_sample_regs_abi
tools/include/uapi/linux/perf_event.h enum perf_event_type { · line 1056
Quoted 10 lines
tools/include/uapi/linux/perf_event.h +9
-1-* u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER +* u64 regs[weight(mask)]; +* struct { +* u64 nr_vectors; # 0 ... weight(sample_simd_vec_reg_user) +* u64 vector_qwords; # 0 ... sample_simd_vec_reg_qwords +* u64 nr_pred; # 0 ... weight(sample_simd_pred_reg_user) +* u64 pred_qwords; # 0 ... sample_simd_pred_reg_qwords +* u64 data[nr_vectors * vector_qwords + nr_pred * pred_qwords]; +* } && (abi & PERF_SAMPLE_REGS_ABI_SIMD) +* } && PERF_SAMPLE_REGS_USER
[Severity: High]
Does evsel__parse_sample() need to be updated to parse or skip this newly appended SIMD payload?
Looking at tools/perf/util/evsel.c:__evsel__parse_sample(), it currently only advances the array pointer by the basic register mask weight:
if (regs->abi) {
u64 mask = evsel->core.attr.sample_regs_user;
sz = hweight64(mask) * sizeof(u64);
OVERFLOW_CHECK(array, sz, max_size);
regs->mask = mask;
regs->regs = (u64 *)array;
array = (void *)array + sz;
}If the array pointer isn't advanced past the new SIMD data, will the parser misinterpret the SIMD payload as subsequent sample fields and result in parsing errors?
[ ... ]
Quoted 5 lines
tools/perf/util/perf_event_attr_fprintf.c +0
-0
tools/perf/util/perf_event_attr_fprintf.c int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, · line 415
Quoted 10 lines
tools/perf/util/perf_event_attr_fprintf.c +5
-1@@ -407,8 +407,17 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, }if (attr_size >= offsetof(struct perf_event_attr , config4))PRINT_ATTRf (config3, p_hex); -if (attr_size > offsetof(struct perf_event_attr , config4)) +if (attr_size >= offsetof(struct perf_event_attr , sample_simd_regs_enabled))PRINT_ATTRf (config4, p_hex); +if (attr_size > offsetof(struct perf_event_attr , sample_simd_vec_reg_user)) { +PRINT_ATTRf (sample_simd_regs_enabled, p_unsigned); +PRINT_ATTRf (sample_simd_pred_reg_qwords, p_unsigned); +PRINT_ATTRf (sample_simd_pred_reg_intr, p_hex);
[Severity: Medium]
Is this conditional too restrictive for the intermediate SIMD fields?
If the tools encounter an attr_size that encompasses some of the new SIMD fields (like sample_simd_regs_enabled) but is strictly less than the offset of sample_simd_vec_reg_user, it evaluates to false. Will this inadvertently skip printing those intermediate fields even though they are present in the struct?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [Patch v10 04/10] perf headers: Sync perf_event.h/perf_regs.h with the kernel headers
Quoted 46 lines · On 7/21/2026 3:47 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High]evsel__parse_sample()fails to parse or skip the newly appended SIMD payload, corrupting subsequent sample field parsing.
- [Medium] The condition to print the new SIMD attribute fields inperf_event_attr__fprintf()uses the offset of the last field instead of the first field, hiding valid intermediate fields.
- [Medium]regs_dump_abi()incorrectly reports 'unknown' for all samples with SIMD registers enabled.
----- Patch [4]: [Patch v10 04/10] perf headers: Sync
perf_event.h/perf_regs.hwith the kernel headers --- commit8b5325e2c0e1de39cce1b1704639159d2e039a47
Author: Dapeng Mi <[email protected]>perf headers: Sync
perf_event.h/perf_regs.hwith the kernel headersThis commit syncs UAPI header changes supporting SIMD/eGPRs/SSP sampling into the corresponding tools UAPI headers. It also updates the print and swap helpers to support the newly introduced
perf_event_attrfields.Quoted 4 lines
tools/include/uapi/linux/perf_event.h +0
-0[ ... ]
tools/include/uapi/linux/perf_event.h enum { · line 320
Quoted 10 lines
tools/include/uapi/linux/perf_event.h +3
-2@@ -314,8 +314,9 @@ enum {*/ enum perf_sample_regs_abi {PERF_SAMPLE_REGS_ABI_NONE =0 , -PERF_SAMPLE_REGS_ABI_32 =1 , -PERF_SAMPLE_REGS_ABI_64 =2 , +PERF_SAMPLE_REGS_ABI_32 = (1 <<0 ), +PERF_SAMPLE_REGS_ABI_64 = (1 <<1 ), +PERF_SAMPLE_REGS_ABI_SIMD = (1 <<2 ), };[Severity: Medium]
By changing the ABI values to bitwise flags, will this break the existingregs_dump_abi()intools/perf/util/session.c?When the
PERF_SAMPLE_REGS_ABI_SIMDbit is set, the combined mask is at least 4. This triggers the fallback inregs_dump_abi():static inline const char *regs_dump_abi(struct
regs_dump*d){ if (d->abi > PERF_SAMPLE_REGS_ABI_64) return "unknown"; return regs_abi[d->abi]; }
Quoted 2 lines
Should this logic be updated to handle the new bitmasks so valid SIMD samples aren't displayed as unknown?
regs_dump_abi() is extended to support these new ABI flags in the patch 05/10 "perf regs: Support x86 eGPRs/SSP sampling".
Quoted 32 lines
[ ... ]
Quoted 4 lines
tools/include/uapi/linux/perf_event.h +0
-0@@ -1020,7 +1045,15 @@ enum perf_event_type {* } && PERF_SAMPLE_BRANCH_STACK * * { u64 abi; # enum perf_sample_regs_abi tools/include/uapi/linux/perf_event.h enum perf_event_type { · line 1056
Quoted 10 lines
tools/include/uapi/linux/perf_event.h +9
-1-* u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER +* u64 regs[weight(mask)]; +* struct { +* u64 nr_vectors; # 0 ... weight(sample_simd_vec_reg_user) +* u64 vector_qwords; # 0 ... sample_simd_vec_reg_qwords +* u64 nr_pred; # 0 ... weight(sample_simd_pred_reg_user) +* u64 pred_qwords; # 0 ... sample_simd_pred_reg_qwords +* u64 data[nr_vectors * vector_qwords + nr_pred * pred_qwords]; +* } && (abi & PERF_SAMPLE_REGS_ABI_SIMD) +* } && PERF_SAMPLE_REGS_USER [Severity: High]
Doesevsel__parse_sample()need to be updated to parse or skip this newly appended SIMD payload?Looking at tools/perf/util/evsel.c:__evsel__parse_sample(), it currently only advances the array pointer by the basic register mask weight:
if (regs->abi) { u64 mask = evsel->core.attr.sample_regs_user; sz = hweight64(mask) * sizeof(u64); OVERFLOW_CHECK(array, sz, max_size); regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; }
Quoted 3 lines
If the array pointer isn't advanced past the new SIMD data, will the parser misinterpret the SIMD payload as subsequent sample fields and result in parsing errors?
Similarly, __evsel__parse_sample() is extended to support these new SIMD fields in subsequent patch "perf regs: Enable dumping of SIMD registers".
Quoted 19 lines
[ ... ]
Quoted 5 lines
tools/perf/util/perf_event_attr_fprintf.c +0
-0tools/perf/util/perf_event_attr_fprintf.c int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, · line 415
Quoted 10 lines
tools/perf/util/perf_event_attr_fprintf.c +5
-1@@ -407,8 +407,17 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, }if (attr_size >= offsetof(struct perf_event_attr , config4))PRINT_ATTRf (config3, p_hex); -if (attr_size > offsetof(struct perf_event_attr , config4)) +if (attr_size >= offsetof(struct perf_event_attr , sample_simd_regs_enabled))PRINT_ATTRf (config4, p_hex); +if (attr_size > offsetof(struct perf_event_attr , sample_simd_vec_reg_user)) { +PRINT_ATTRf (sample_simd_regs_enabled, p_unsigned); +PRINT_ATTRf (sample_simd_pred_reg_qwords, p_unsigned); +PRINT_ATTRf (sample_simd_pred_reg_intr, p_hex);[Severity: Medium]
Is this conditional too restrictive for the intermediate SIMD fields?
Quoted 5 lines
If the tools encounter an
attr_sizethat encompasses some of the new SIMD fields (likesample_simd_regs_enabled) but is strictly less than the offset ofsample_simd_vec_reg_user, it evaluates to false. Will this inadvertently skip printing those intermediate fields even though they are present in the struct?
That would never happen since all these SIMD fields are always introduced together. Thanks.
PATCH v10 5/10 perf regs: Support x86 eGPRs/SSP sampling
In reply to Dapeng MiAdd support for sampling x86 extended GP registers (R16-R31) and the shadow stack pointer (SSP) register.
The original XMM registers space in sample_regs_user/sample_regs_intr is reclaimed to represent the eGPRs and SSP when SIMD registers sampling is supported with the new SIMD sampling fields in the perf_event_attr structure. This necessitates a way to distinguish which register layout is used for the sample_regs_user/sample_regs_intr bitmap.
To address this, a new "abi" argument is added to the helpers perf_intr_reg_mask(), perf_user_reg_mask(), and perf_reg_name(). When "abi & PERF_SAMPLE_REGS_ABI_SIMD" is true, it indicates the eGPRs and SSP layout is represented; otherwise, the legacy XMM registers are represented.
Please note that PERF_SAMPLE_REGS_ABI_SIMD is set by default on platforms that support SIMD register sampling, even when no eGPR or SSP register is requested (for example, -Iax). As a result, sample_regs_intr and sample_regs_usr always use the new GPR layout on platforms with SIMD register sampling support.
The patch only supports eGPRs and SSP sampling, the complete SIMD registers sampling would be supported in the next patch.
--- tools/perf/builtin-script.c | 2 +- tools/perf/util/evsel.c | 25 +++- tools/perf/util/evsel.h | 7 + tools/perf/util/parse-regs-options.c | 35 +++-- .../perf/util/perf-regs-arch/perf_regs_x86.c | 124 +++++++++++++++--- tools/perf/util/perf_regs.c | 12 +- tools/perf/util/perf_regs.h | 10 +- tools/perf/util/record.h | 7 + .../scripting-engines/trace-event-python.c | 2 +- tools/perf/util/session.c | 13 +- tools/perf/util/synthetic-events.c | 4 + 11 files changed, 196 insertions(+), 45 deletions(-)
tools/perf/builtin-script.c +1 -1
@@ -734,7 +734,7 @@ static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask,for_each_set_bit (r, (unsigned long *) &mask,sizeof (mask) *8 ) {u64 val = regs->regs[i++]; printed +=fprintf (fp,"%5s:0x%" PRIx64" " , -perf_reg_name (r, e_machine, e_flags), +perf_reg_name (r, e_machine, e_flags, regs->abi), val); }
tools/perf/util/evsel.c +23 -2
@@ -1123,19 +1123,22 @@ static void __evsel__config_callchain(struct evsel *evsel, const struct record_o }if (param->record_mode ==CALLCHAIN_DWARF ) { +int abi =-1 ;/* -1 indicates only basic GPRs are needed. */ +if (!function) {uint16_t e_machine =evsel__e_machine (evsel,/*e_flags=*/ NULL );evsel__set_sample_bit (evsel,REGS_USER );evsel__set_sample_bit (evsel,STACK_USER );if (opts->sample_user_regs && -DWARF_MINIMAL_REGS (e_machine) !=perf_user_reg_mask (EM_HOST )) { +DWARF_MINIMAL_REGS (e_machine) !=perf_user_reg_mask (EM_HOST , &abi)) { attr->sample_regs_user |=DWARF_MINIMAL_REGS (e_machine);pr_warning ("WARNING: The use of --call-graph=dwarf may require all the user registers, " "specifying a subset with --user-regs may render DWARF unwinding unreliable, " "so the minimal registers set (IP, SP) is explicitly forced.\n" ); }else { - attr->sample_regs_user |=perf_user_reg_mask (EM_HOST ); + abi =-1 ; + attr->sample_regs_user |=perf_user_reg_mask (EM_HOST , &abi); } attr->sample_stack_user = param->dump_size; attr->exclude_callchain_user =1 ;
@@ -1661,12 +1664,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,if (opts->sample_intr_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_intr = opts->sample_intr_regs; + attr->sample_simd_regs_enabled =evsel__is_hardware_event (evsel) ? + !!opts->sample_simd_regs_enabled :0 ;evsel__set_sample_bit (evsel,REGS_INTR ); }if (opts->sample_user_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_user |= opts->sample_user_regs; + attr->sample_simd_regs_enabled =evsel__is_hardware_event (evsel) ? + !!opts->sample_simd_regs_enabled :0 ;evsel__set_sample_bit (evsel,REGS_USER ); }
@@ -3679,6 +3686,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; + +if (regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { +/* Skip SIMD-regs header. */ + sz =4 *sizeof (u64); +OVERFLOW_CHECK (array, sz, max_size); + array = (void *)array + sz; + } } }
@@ -3736,6 +3750,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; + +if (regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { +/* Skip SIMD-regs header. */ + sz =4 *sizeof (u64); +OVERFLOW_CHECK (array, sz, max_size); + array = (void *)array + sz; + } } }
tools/perf/util/evsel.h +7 -0
@@ -581,6 +581,13 @@ static inline bool evsel__is_dummy_event(struct evsel *evsel) (evsel->core.attr.config ==PERF_COUNT_SW_DUMMY ); } +static inline bool evsel__is_hardware_event (struct evsel *evsel) +{ +return (evsel->core.attr.type ==PERF_TYPE_HARDWARE ) || + (evsel->core.attr.type ==PERF_TYPE_HW_CACHE ) || + (evsel->core.attr.type ==PERF_TYPE_RAW ); +} +struct perf_session *evsel__session (struct evsel *evsel);struct perf_env *evsel__env (struct evsel *evsel);uint16_t evsel__e_machine (struct evsel *evsel,uint32_t *e_flags);
tools/perf/util/parse-regs-options.c +25 -10
@@ -6,11 +6,14 @@#include <stdio.h> #include "util/debug.h" #include <dwarf-regs.h> +#include <sys/param.h> #include <subcmd/parse-options.h> #include "util/perf_regs.h" #include "util/parse-regs-options.h" +#include "record.h" -static void list_perf_regs (FILE *fp,uint64_t mask) +static void +list_perf_regs (FILE *fp,uint64_t mask,int abi) {const char *last_name =NULL ;
@@ -21,7 +24,7 @@ static void list_perf_regs(FILE *fp, uint64_t mask)if (((1ULL << reg) & mask) ==0 )continue ; - name =perf_reg_name (reg,EM_HOST ,EF_HOST ); + name =perf_reg_name (reg,EM_HOST ,EF_HOST , abi);if (name && (!last_name ||strcmp (last_name, name)))fprintf (fp,"%s%s" , reg >0 ?" " :"" , name); last_name = name;
@@ -29,7 +32,8 @@ static void list_perf_regs(FILE *fp, uint64_t mask)fputc ('\n' , fp); } -static uint64_t name_to_perf_reg_mask (const char *to_match,uint64_t mask) +static uint64_t +name_to_perf_reg_mask (const char *to_match,uint64_t mask,int abi) {uint64_t reg_mask =0 ;
@@ -39,7 +43,7 @@ static uint64_t name_to_perf_reg_mask(const char *to_match, uint64_t mask)if (((1ULL << reg) & mask) ==0 )continue ; - name =perf_reg_name (reg,EM_HOST ,EF_HOST ); + name =perf_reg_name (reg,EM_HOST ,EF_HOST , abi);if (!name)continue ;
@@ -53,9 +57,12 @@ static int __parse_regs(const struct option *opt, const char *str, int unset, bool intr) { uint64_t *mode = (uint64_t *)opt->value; +struct record_opts *opts;char *s, *os =NULL , *p; +const char *warn;int ret =-1 ;uint64_t mask; +int abi =0 ;if (unset)return 0 ;
@@ -66,11 +73,16 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)if (*mode)return -1 ; - mask = intr ?perf_intr_reg_mask (EM_HOST ) :perf_user_reg_mask (EM_HOST ); + mask = intr ?perf_intr_reg_mask (EM_HOST , &abi) : +perf_user_reg_mask (EM_HOST , &abi); + opts = intr ? container_of(opt->value, struct record_opts, sample_intr_regs) : + container_of(opt->value, struct record_opts, sample_user_regs);/* str may be NULL in case no arg is passed to -I */ if (!str) { *mode = mask; +if (abi &PERF_SAMPLE_REGS_ABI_SIMD ) + opts->sample_simd_regs_enabled =1 ;return 0 ; }
@@ -79,6 +91,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)if (!s)return -1 ; + warn ="Unknown register \"%s\", check man page or run \"perf record %s?\"\n" ;for (;;) {uint64_t reg_mask;
@@ -87,14 +100,16 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr) *p ='\0' ;if (!strcmp (s,"?" )) { -list_perf_regs (stderr, mask); +list_perf_regs (stderr, mask, abi); goto error; } - reg_mask =name_to_perf_reg_mask (s, mask); -if (reg_mask ==0 ) { -ui__warning ("Unknown register \"%s\", check man page or run \"perf record %s?\"\n" , - s, intr ?"-I" :"--user-regs=" ); + reg_mask =name_to_perf_reg_mask (s, mask, abi); +if (reg_mask) { +if (abi &PERF_SAMPLE_REGS_ABI_SIMD ) + opts->sample_simd_regs_enabled =1 ; + }else { +ui__warning (warn, s, intr ?"-I" :"--user-regs=" ); goto error; } *mode |= reg_mask;
tools/perf/util/perf-regs-arch/perf_regs_x86.c +109 -15
161 lines not on this page · raw message
tools/perf/util/perf_regs.c +6 -6
@@ -38,7 +38,7 @@ int perf_sdt_arg_parse_op(uint16_t e_machine, char *old_op, char **new_op)return ret; } -uint64_t perf_intr_reg_mask (uint16_t e_machine) +uint64_t perf_intr_reg_mask (uint16_t e_machine,int *abi/*inout*/ ) {uint64_t mask =0 ;
@@ -70,7 +70,7 @@ uint64_t perf_intr_reg_mask(uint16_t e_machine)break ;case EM_386 :case EM_X86_64 : - mask =__perf_reg_mask_x86 (/*intr=*/ true); + mask =__perf_reg_mask_x86 (/*intr=*/ true, abi);break ;default : pr_debug("Unknown ELF machine %d, interrupt sampling register mask will be empty.\n",
@@ -81,7 +81,7 @@ uint64_t perf_intr_reg_mask(uint16_t e_machine)return mask; } -uint64_t perf_user_reg_mask (uint16_t e_machine) +uint64_t perf_user_reg_mask (uint16_t e_machine,int *abi/*inout*/ ) {uint64_t mask =0 ;
@@ -113,7 +113,7 @@ uint64_t perf_user_reg_mask(uint16_t e_machine)break ;case EM_386 :case EM_X86_64 : - mask =__perf_reg_mask_x86 (/*intr=*/ false); + mask =__perf_reg_mask_x86 (/*intr=*/ false, abi);break ;default : pr_debug("Unknown ELF machine %d, user sampling register mask will be empty.\n",
@@ -124,7 +124,7 @@ uint64_t perf_user_reg_mask(uint16_t e_machine)return mask; } -const char *perf_reg_name (int id,uint16_t e_machine,uint32_t e_flags) +const char *perf_reg_name (int id,uint16_t e_machine,uint32_t e_flags,int abi) {const char *reg_name =NULL ;
@@ -156,7 +156,7 @@ const char *perf_reg_name(int id, uint16_t e_machine, uint32_t e_flags)break ;case EM_386 :case EM_X86_64 : - reg_name =__perf_reg_name_x86 (id); + reg_name =__perf_reg_name_x86 (id, abi);break ;default :break ;
tools/perf/util/perf_regs.h +5 -5
@@ -13,10 +13,10 @@ enum { };int perf_sdt_arg_parse_op (uint16_t e_machine,char *old_op,char **new_op); -uint64_t perf_intr_reg_mask (uint16_t e_machine); -uint64_t perf_user_reg_mask (uint16_t e_machine); +uint64_t perf_intr_reg_mask (uint16_t e_machine,int *abi/*inout*/ ); +uint64_t perf_user_reg_mask (uint16_t e_machine,int *abi/*inout*/ ); -const char *perf_reg_name (int id,uint16_t e_machine,uint32_t e_flags); +const char *perf_reg_name (int id,uint16_t e_machine,uint32_t e_flags,int abi);int perf_reg_value (u64 *valp,struct regs_dump *regs,int id);uint64_t perf_arch_reg_ip (uint16_t e_machine);uint64_t perf_arch_reg_sp (uint16_t e_machine);
@@ -66,8 +66,8 @@ uint64_t __perf_reg_sp_s390(void);int __perf_sdt_arg_parse_op_s390 (char *old_op,char **new_op);int __perf_sdt_arg_parse_op_x86 (char *old_op,char **new_op); -uint64_t __perf_reg_mask_x86 (bool intr); -const char *__perf_reg_name_x86 (int id); +uint64_t __perf_reg_mask_x86 (bool intr,int *abi); +const char *__perf_reg_name_x86 (int id,int abi);uint64_t __perf_reg_ip_x86 (void );uint64_t __perf_reg_sp_x86 (void );
tools/perf/util/record.h +7 -0
@@ -62,6 +62,13 @@ struct record_opts {u64 branch_stack;u64 sample_intr_regs;u64 sample_user_regs; +u16 sample_simd_regs_enabled; +u16 sample_vec_reg_qwords; +u16 sample_pred_reg_qwords; +u32 sample_intr_pred_regs; +u32 sample_user_pred_regs; +u64 sample_intr_vec_regs; +u64 sample_user_vec_regs;u64 default_interval;u64 user_interval;size_t auxtrace_snapshot_size;
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -730,7 +730,7 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, uint16_t e_machine, printed +=scnprintf (bf + printed, size - printed,"%5s:0x%" PRIx64" " , -perf_reg_name (r, e_machine, e_flags), val); +perf_reg_name (r, e_machine, e_flags, regs->abi), val); } }
tools/perf/util/session.c +8 -5
@@ -1433,15 +1433,16 @@ static void branch_stack__printf(struct perf_sample *sample, } } -static void regs_dump__printf (u64 mask,u64 *regs,uint16_t e_machine,uint32_t e_flags) +static void regs_dump__printf (u64 mask,struct regs_dump *regs, +uint16_t e_machine,uint32_t e_flags) {unsigned rid, i =0 ;for_each_set_bit (rid, (unsigned long *) &mask,sizeof (mask) *8 ) { -u64 val = regs[i++]; +u64 val = regs->regs[i++];printf (".... %-5s 0x%016" PRIx64"\n" , -perf_reg_name (rid, e_machine, e_flags), val); +perf_reg_name (rid, e_machine, e_flags, regs->abi), val); } }
@@ -1449,11 +1450,13 @@ static const char *regs_abi[] = { [PERF_SAMPLE_REGS_ABI_NONE] = "none", [PERF_SAMPLE_REGS_ABI_32] = "32-bit", [PERF_SAMPLE_REGS_ABI_64] = "64-bit", + [PERF_SAMPLE_REGS_ABI_SIMD | PERF_SAMPLE_REGS_ABI_32] = "32-bit SIMD", + [PERF_SAMPLE_REGS_ABI_SIMD | PERF_SAMPLE_REGS_ABI_64] = "64-bit SIMD", };static inline const char *regs_dump_abi (struct regs_dump *d) { -if (d->abi >PERF_SAMPLE_REGS_ABI_64 ) +if (d->abi >=ARRAY_SIZE (regs_abi) || !regs_abi[d->abi])return "unknown" ;return regs_abi[d->abi];
@@ -1469,7 +1472,7 @@ static void regs__printf(const char *type, struct regs_dump *regs, mask, regs_dump_abi(regs)); -regs_dump__printf (mask, regs->regs, e_machine, e_flags); +regs_dump__printf (mask, regs, e_machine, e_flags); }static void regs_user__printf (struct perf_sample *sample,uint16_t e_machine,uint32_t e_flags)
tools/perf/util/synthetic-events.c +4 -0
@@ -1527,6 +1527,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->user_regs && sample->user_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->user_regs->mask) *sizeof (u64); +if (sample->user_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) + sz +=4 *sizeof (u64); result += sz; }else { result +=sizeof (u64);
@@ -1555,6 +1557,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->intr_regs && sample->intr_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->intr_regs->mask) *sizeof (u64); +if (sample->intr_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) + sz +=4 *sizeof (u64); result += sz; }else { result +=sizeof (u64);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Hardcoded 32-byte SIMD header skip in `__evsel__parse_sample` corrupts parsing of future…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Hardcoded 32-byte SIMD header skip in __evsel__parse_sample corrupts parsing of future perf.data files containing actual SIMD data payloads.
- [High] perf_event__synthesize_sample fails to write the SIMD register header, leading to uninitialized memory leaks and corruption of synthesized events.
- [High] Silently substituting requested eGPRs with legacy XMM registers on non-hardware events.
--
--- Patch [5]: [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling --- commit 8930556b90beb6ec5b6f4e43ddaf5145e6dda06d
Author: Dapeng Mi <[email protected]>
perf regs: Support x86 eGPRs/SSP sampling
This commit adds support for sampling x86 extended GP registers (R16-R31) and the shadow stack pointer (SSP) register. It reclaims the original XMM registers space in the sampling masks to represent eGPRs and SSP when SIMD sampling is supported, distinguishing them with a new abi flag.
Quoted 4 lines
tools/perf/util/evsel.c +0
-0
[ ... ]
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1668
Quoted 6 lines
tools/perf/util/evsel.c +2
-0@@ -1661,12 +1664,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,if (opts->sample_intr_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_intr = opts->sample_intr_regs; + attr->sample_simd_regs_enabled =evsel__is_hardware_event (evsel) ? + !!opts->sample_simd_regs_enabled :0 ;
[Severity: High]
Does clearing the sample_simd_regs_enabled flag for non-hardware events cause the kernel to misinterpret the bits as legacy XMM requests?
If a user requests sampling of eGPRs on a software event, this flag is forcibly cleared, but the opts->sample_intr_regs bitmask is preserved. Because eGPR definitions alias legacy XMM definitions, wouldn't the kernel see the bits set alongside sample_simd_regs_enabled = 0 and dump legacy XMM data instead?
The tool might then read it back without the SIMD ABI flag and print it as XMM, silently losing the user's intent to capture eGPRs. Should the aliasing eGPR bits be masked out from the sample_regs mask when clearing the SIMD flag?
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1676
Quoted 8 lines
tools/perf/util/evsel.c +2
-0evsel__set_sample_bit (evsel,REGS_INTR ); }if (opts->sample_user_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_user |= opts->sample_user_regs; + attr->sample_simd_regs_enabled =evsel__is_hardware_event (evsel) ? + !!opts->sample_simd_regs_enabled :0 ;
[Severity: High]
This seems to have the same aliasing issue as above where eGPR requests on non-hardware events will be silently interpreted as legacy XMM registers.
Quoted 2 lines
tools/perf/util/evsel.c +0
-0evsel__set_sample_bit (evsel,REGS_USER ); }
[ ... ]
tools/perf/util/evsel.c int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, · line 3697
Quoted 13 lines
tools/perf/util/evsel.c +7
-0@@ -3679,6 +3686,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; + +if (regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { +/* Skip SIMD-regs header. */ + sz =4 *sizeof (u64); +OVERFLOW_CHECK (array, sz, max_size); + array = (void *)array + sz; + } } }
[Severity: High]
Will this hardcoded 32-byte header skip corrupt parsing for files containing actual SIMD data payloads?
The parser unconditionally skips exactly 4 u64s for the SIMD header, but it doesn't dynamically compute and skip the variable-length SIMD payload that might follow it in future files. This would misalign the array pointer for subsequent fields like STACK_USER, causing garbage reads and triggering OVERFLOW_CHECK aborts.
[ ... ]
tools/perf/util/evsel.c int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, · line 3761
Quoted 13 lines
tools/perf/util/evsel.c +7
-0@@ -3736,6 +3750,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; + +if (regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { +/* Skip SIMD-regs header. */ + sz =4 *sizeof (u64); +OVERFLOW_CHECK (array, sz, max_size); + array = (void *)array + sz; + } } }
[Severity: High]
This appears to have the same issue with skipping the SIMD header without handling the variable-length payload.
tools/perf/util/synthetic-events.c size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, · line 1531
Quoted 10 lines
tools/perf/util/synthetic-events.c +2
-0@@ -1527,6 +1527,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->user_regs && sample->user_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->user_regs->mask) *sizeof (u64); +if (sample->user_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) + sz +=4 *sizeof (u64);
[Severity: High]
Does perf_event__synthesize_sample() also need to be updated to write these 32 bytes?
Since perf_event__sample_event_size() allocates 32 extra bytes for the SIMD header here, if perf_event__synthesize_sample() doesn't write them, subsequent fields could be written 32 bytes early.
When the malformed event is parsed by __evsel__parse_sample(), the parser will skip 32 bytes after the registers, completely missing the early-written subsequent fields and corrupting the stream. The final 32 bytes of the event buffer would remain uninitialized heap memory, leaking information when emitted.
tools/perf/util/synthetic-events.c size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, · line 1561
Quoted 9 lines
tools/perf/util/synthetic-events.c +2
-0result += sz; }else { result +=sizeof (u64);@@ -1555,6 +1557,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->intr_regs && sample->intr_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->intr_regs->mask) *sizeof (u64); +if (sample->intr_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) + sz +=4 *sizeof (u64);
[Severity: High]
This appears to have the same issue as above, where the allocated SIMD header bytes might not be written by perf_event__synthesize_sample().
Quoted 3 lines
tools/perf/util/synthetic-events.c +0
-0result += sz; }else { result +=sizeof (u64);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling
Quoted 39 lines · On 7/21/2026 3:52 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Hardcoded 32-byte SIMD header skip in__evsel__parse_samplecorrupts parsing of futureperf.datafiles containing actual SIMD data payloads.
- [High]perf_event__synthesize_samplefails to write the SIMD register header, leading to uninitialized memory leaks and corruption of synthesized events.
- [High] Silently substituting requested eGPRs with legacy XMM registers on non-hardware events.
----- Patch [5]: [Patch v10 05/10] perf regs: Support x86 eGPRs/SSP sampling --- commit
8930556b90beb6ec5b6f4e43ddaf5145e6dda06d
Author: Dapeng Mi <[email protected]>perf regs: Support x86 eGPRs/SSP sampling
This commit adds support for sampling x86 extended GP registers (R16-R31) and the shadow stack pointer (SSP) register. It reclaims the original XMM registers space in the sampling masks to represent eGPRs and SSP when SIMD sampling is supported, distinguishing them with a new abi flag.
Quoted 4 lines
tools/perf/util/evsel.c +0
-0[ ... ]
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1668
Quoted 6 lines
tools/perf/util/evsel.c +2
-0@@ -1661,12 +1664,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,if (opts->sample_intr_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_intr = opts->sample_intr_regs; + attr->sample_simd_regs_enabled =evsel__is_hardware_event (evsel) ? + !!opts->sample_simd_regs_enabled :0 ;[Severity: High]
Does clearing thesample_simd_regs_enabledflag for non-hardware events cause the kernel to misinterpret the bits as legacy XMM requests?If a user requests sampling of eGPRs on a software event, this flag is forcibly cleared, but the
opts->sample_intr_regsbitmask is preserved. Because eGPR definitions alias legacy XMM definitions, wouldn't the kernel see the bits set alongsidesample_simd_regs_enabled= 0 and dump legacy XMM data instead?
Quoted 4 lines
The tool might then read it back without the SIMD ABI flag and print it as XMM, silently losing the user's intent to capture eGPRs. Should the aliasing eGPR bits be masked out from the
sample_regsmask when clearing the SIMD flag?
All software events can only sample these legacy GPRs and can't support these new added advanced registers regardless of SIMD or APX eGPRs. So the issue can't really occur.
Quoted 4 lines
Quoted 4 lines
tools/perf/util/evsel.c +0
-0evsel__set_sample_bit (evsel,REGS_INTR ); }
Quoted 8 lines
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1676
Quoted 5 lines
tools/perf/util/evsel.c +2
-0if (opts->sample_user_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_user |= opts->sample_user_regs; + attr->sample_simd_regs_enabled =evsel__is_hardware_event (evsel) ? + !!opts->sample_simd_regs_enabled :0 ;[Severity: High]
This seems to have the same aliasing issue as above where eGPR requests on non-hardware events will be silently interpreted as legacy XMM registers.
Ditto.
Quoted 22 lines
Quoted 3 lines
tools/perf/util/evsel.c +0
-0evsel__set_sample_bit (evsel,REGS_USER ); }[ ... ]
tools/perf/util/evsel.c int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, · line 3697
Quoted 13 lines
tools/perf/util/evsel.c +7
-0@@ -3679,6 +3686,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; + +if (regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { +/* Skip SIMD-regs header. */ + sz =4 *sizeof (u64); +OVERFLOW_CHECK (array, sz, max_size); + array = (void *)array + sz; + } } }[Severity: High]
Will this hardcoded 32-byte header skip corrupt parsing for files containing actual SIMD data payloads?
Quoted 5 lines
The parser unconditionally skips exactly 4 u64s for the SIMD header, but it doesn't dynamically compute and skip the variable-length SIMD payload that might follow it in future files. This would misalign the array pointer for subsequent fields like
STACK_USER, causing garbage reads and triggeringOVERFLOW_CHECKaborts.
The extra SIMD registers payload would be parsed in subsequent patch 07/10 "perf regs: Enable dumping of SIMD registers".
Quoted 38 lines
[ ... ]
tools/perf/util/evsel.c int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, · line 3761
Quoted 13 lines
tools/perf/util/evsel.c +7
-0@@ -3736,6 +3750,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, regs->mask = mask; regs->regs = (u64 *)array; array = (void *)array + sz; + +if (regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { +/* Skip SIMD-regs header. */ + sz =4 *sizeof (u64); +OVERFLOW_CHECK (array, sz, max_size); + array = (void *)array + sz; + } } }[Severity: High]
This appears to have the same issue with skipping the SIMD header without handling the variable-length payload.tools/perf/util/synthetic-events.c size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, · line 1531
Quoted 10 lines
tools/perf/util/synthetic-events.c +2
-0@@ -1527,6 +1527,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->user_regs && sample->user_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->user_regs->mask) *sizeof (u64); +if (sample->user_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) + sz +=4 *sizeof (u64);[Severity: High]
Doesperf_event__synthesize_sample()also need to be updated to write these 32 bytes?Since
perf_event__sample_event_size()allocates 32 extra bytes for the SIMD header here, ifperf_event__synthesize_sample()doesn't write them, subsequent fields could be written 32 bytes early.
Quoted 5 lines
When the malformed event is parsed by
__evsel__parse_sample(), the parser will skip 32 bytes after the registers, completely missing the early-written subsequent fields and corrupting the stream. The final 32 bytes of the event buffer would remain uninitialized heap memory, leaking information when emitted.
Ditto.
Quoted 4 lines
Quoted 4 lines
tools/perf/util/synthetic-events.c +0
-0result += sz; }else { result +=sizeof (u64);@@ -1555,6 +1557,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
Quoted 8 lines
tools/perf/util/synthetic-events.c size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, · line 1561
Quoted 5 lines
tools/perf/util/synthetic-events.c +2
-0if (sample->intr_regs && sample->intr_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->intr_regs->mask) *sizeof (u64); +if (sample->intr_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) + sz +=4 *sizeof (u64);[Severity: High]
This appears to have the same issue as above, where the allocated SIMD header bytes might not be written byperf_event__synthesize_sample().
Ditto.
Thanks.
Quoted 4 lines
Quoted 4 lines
tools/perf/util/synthetic-events.c +0
-0result += sz; }else { result +=sizeof (u64);
PATCH v10 6/10 perf regs: Support x86 SIMD registers sampling
In reply to Dapeng MiAdd support for the newly introduced SIMD register sampling format by adding the following 5 functions:
uint64_t perf_intr_simd_reg_class_mask(uint16_t e_machine, bool pred); uint64_t perf_user_simd_reg_class_mask(uint16_t e_machine, bool pred); uint64_t perf_intr_simd_reg_class_bitmap_qwords(uint16_t e_machine, int reg_c,
uint16_t *qwords, bool pred); uint64_t perf_user_simd_reg_class_bitmap_qwords(uint16_t e_machine, int reg_c, uint16_t *qwords, bool pred);
const char *perf_simd_reg_class_name(uint16_t e_machine, int id, bool pred);
The perf_{intr|user}_simd_reg_class_mask() functions retrieve the bitmap of kernel supported SIMD/PRED register classes on current platform for intr-regs and user-regs sampling, such as OPMASK/XMM/YMM/ZMM on x86 platforms.
The perf_{intr|user}_simd_reg_class_bitmap_qwords() functions retrieve the bitmap and qwords length of a certain class of SIMD/PRED register on current platform for intr-regs and user-regs sampling. For example, for the XMM registers on x86 platforms, the returned bitmap is 0xffff (XMM0 ~ XMM15) and the qwords length is 2 (128 bits for each XMM register).
The perf_simd_reg_class_name() function gets the register class name for a certain register class index.
Additionally, the function __parse_regs() is enhanced to support parsing these newly introduced SIMD/PRED registers. Currently, each class of register can only be sampled collectively; sampling a specific SIMD register is not supported. For example, all XMM registers are sampled together rather than sampling only XMM0.
When multiple overlapping register types, such as XMM and YMM, are sampled simultaneously, only the superset (YMM registers) is sampled.
With this patch, all supported sampling registers on x86 platforms are displayed as follows.
$perf record --intr-regs=?
available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 R27 R28 R29 R30 R31 SSP XMM0-15 YMM0-15 ZMM0-31 OPMASK0-7
$perf record --user-regs=?
available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 R27 R28 R29 R30 R31 SSP XMM0-15 YMM0-15 ZMM0-31 OPMASK0-7
--- tools/perf/Documentation/perf-record.txt | 10 +- tools/perf/util/evsel.c | 21 ++ tools/perf/util/parse-regs-options.c | 185 +++++++++- .../perf/util/perf-regs-arch/perf_regs_x86.c | 316 +++++++++++++++++- tools/perf/util/perf_regs.c | 72 ++++ tools/perf/util/perf_regs.h | 11 + 6 files changed, 596 insertions(+), 19 deletions(-)
tools/perf/Documentation/perf-record.txt +7 -3
@@ -513,12 +513,16 @@ Capture machine state (registers) at interrupt, i.e., on counter overflows for each sample. List of captured registers depends on the architecture. This option is off by default. It is possible to select the registers to sample using their symbolic names, e.g. on x86, ax, si. To list the available registers use ---intr-regs=\?. To name registers, pass a comma separated list such as ---intr-regs=ax,bx. The list of register is architecture dependent. +--intr-regs=\?. On supported architectures, SIMD registers are displayed as +groups (e.g., on x86: XMM0-15,YMM0-15,ZMM0-31). To name registers, pass a comma +separated list such as --intr-regs=ax,bx,zmm. Please notice SIMD registers must +be assigned as a complete set, sampling individual SIMD registers (e.g., zmm0) +is not supported. The list of register is architecture dependent. --user-regs:: Similar to -I, but capture user registers at sample time. To list the available -user registers use --user-regs=\?. +user registers use --user-regs=\?. For SIMD registers, only complete register +sets are allowed like -I. --running-time:: Record running and enabled time for read events (:S)
tools/perf/util/evsel.c +21 -0
@@ -29,6 +29,7 @@#include <sys/resource.h> #include <sys/syscall.h> #include <sys/types.h> +#include <sys/param.h> #include <api/fs/fs.h> #include <api/fs/tracing_path.h>
@@ -1669,6 +1670,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,evsel__set_sample_bit (evsel,REGS_INTR ); } +if ((opts->sample_intr_vec_regs || opts->sample_intr_pred_regs) && + !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { + attr->sample_simd_regs_enabled = !!opts->sample_simd_regs_enabled; + attr->sample_simd_vec_reg_intr = opts->sample_intr_vec_regs; + attr->sample_simd_vec_reg_qwords = opts->sample_vec_reg_qwords; + attr->sample_simd_pred_reg_intr = opts->sample_intr_pred_regs; + attr->sample_simd_pred_reg_qwords = opts->sample_pred_reg_qwords; +evsel__set_sample_bit (evsel,REGS_INTR ); + } +if (opts->sample_user_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_user |= opts->sample_user_regs;
@@ -1677,6 +1688,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,evsel__set_sample_bit (evsel,REGS_USER ); } +if ((opts->sample_user_vec_regs || opts->sample_user_pred_regs) && + !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { + attr->sample_simd_regs_enabled = !!opts->sample_simd_regs_enabled; + attr->sample_simd_vec_reg_user = opts->sample_user_vec_regs; + attr->sample_simd_vec_reg_qwords = opts->sample_vec_reg_qwords; + attr->sample_simd_pred_reg_user = opts->sample_user_pred_regs; + attr->sample_simd_pred_reg_qwords = opts->sample_pred_reg_qwords; +evsel__set_sample_bit (evsel,REGS_USER ); + } +if (target__has_cpu (&opts->target) || opts->sample_cpu)evsel__set_sample_bit (evsel,CPU );
tools/perf/util/parse-regs-options.c +171 -14
245 lines not on this page · raw message
tools/perf/util/perf-regs-arch/perf_regs_x86.c +314 -2
331 lines not on this page · raw message
tools/perf/util/perf_regs.c +72 -0
75 lines not on this page · raw message
tools/perf/util/perf_regs.h +11 -0
@@ -20,6 +20,13 @@ const char *perf_reg_name(int id, uint16_t e_machine, uint32_t e_flags, int abi)int perf_reg_value (u64 *valp,struct regs_dump *regs,int id);uint64_t perf_arch_reg_ip (uint16_t e_machine);uint64_t perf_arch_reg_sp (uint16_t e_machine); +uint64_t perf_intr_simd_reg_class_mask (uint16_t e_machine,bool pred); +uint64_t perf_user_simd_reg_class_mask (uint16_t e_machine,bool pred); +uint64_t perf_intr_simd_reg_class_bitmap_qwords (uint16_t e_machine,int reg_c, +uint16_t *qwords,bool pred); +uint64_t perf_user_simd_reg_class_bitmap_qwords (uint16_t e_machine,int reg_c, +uint16_t *qwords,bool pred); +const char *perf_simd_reg_class_name (uint16_t e_machine,int id,bool pred);int __perf_sdt_arg_parse_op_arm64 (char *old_op,char **new_op);uint64_t __perf_reg_mask_arm64 (bool intr);
@@ -70,6 +77,10 @@ uint64_t __perf_reg_mask_x86(bool intr, int *abi);const char *__perf_reg_name_x86 (int id,int abi);uint64_t __perf_reg_ip_x86 (void );uint64_t __perf_reg_sp_x86 (void ); +uint64_t __perf_simd_reg_class_mask_x86 (bool intr,bool pred); +uint64_t __perf_simd_reg_class_bitmap_qwords_x86 (int reg_c,uint16_t *qwords, +bool intr,bool pred); +const char *__perf_simd_reg_class_name_x86 (int id,bool pred);static inline uint64_t DWARF_MINIMAL_REGS (uint16_t e_machine) {
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [Patch v10 06/10] perf regs: Support x86 SIMD registers sampling
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The sample parser fails to skip the SIMD register data payload, corrupting subsequent sample…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The sample parser fails to skip the SIMD register data payload, corrupting subsequent sample fields.
- [Medium] Silently synchronizing SIMD register masks between intr and user modes bypasses architectural capability checks.
- [Medium] Bypassing hardware event check for SIMD register sampling enables it for unsupported software events. --
--- Patch [6]: [Patch v10 06/10] perf regs: Support x86 SIMD registers sampling --- commit 511dc4506d241eccda5990483afe081741ffbdb5
Author: Dapeng Mi <[email protected]>
perf regs: Support x86 SIMD registers sampling
This commit adds support for the SIMD register sampling format on x86 platforms. It introduces functions to retrieve register class masks, names, and lengths for both interrupt and user registers, and updates command-line parsing to handle groups like XMM, YMM, ZMM, and OPMASK.
Quoted 4 lines
tools/perf/util/evsel.c +0
-0
[ ... ]
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1675
Quoted 7 lines
tools/perf/util/evsel.c +3
-0@@ -1669,6 +1670,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,evsel__set_sample_bit (evsel,REGS_INTR ); } +if ((opts->sample_intr_vec_regs || opts->sample_intr_pred_regs) && + !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { + attr->sample_simd_regs_enabled = !!opts->sample_simd_regs_enabled;
[Severity: Medium]
When SIMD registers are enabled here, should there be a check to verify it is a hardware event?
For regular registers, this is guarded with evsel__is_hardware_event(evsel), but here it seems to unconditionally enable SIMD registers for software events. Could this cause the kernel to reject the event with -EINVAL?
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1681
Quoted 6 lines
tools/perf/util/evsel.c +6
-0+ attr->sample_simd_vec_reg_intr = opts->sample_intr_vec_regs; + attr->sample_simd_vec_reg_qwords = opts->sample_vec_reg_qwords; + attr->sample_simd_pred_reg_intr = opts->sample_intr_pred_regs; + attr->sample_simd_pred_reg_qwords = opts->sample_pred_reg_qwords; +evsel__set_sample_bit (evsel,REGS_INTR ); + }
[Severity: High]
If SIMD sampling is enabled, does the parser in __evsel__parse_sample() properly skip the SIMD data payload?
It appears that __evsel__parse_sample() only skips the 4 header elements but misses the variable-length SIMD data array that follows:
__evsel__parse_sample() {
...
if (regs->abi & PERF_SAMPLE_REGS_ABI_SIMD) {
/* Skip SIMD-regs header. */
sz = 4 * sizeof(u64);
OVERFLOW_CHECK(array, sz, max_size);
array = (void *)array + sz;
}
...
}Will this leave the array pointer pointing at register data instead of the next field (like PERF_SAMPLE_STACK_USER), potentially corrupting subsequent fields and failing to parse the event?
Quoted 25 lines
tools/perf/util/evsel.c +11
-0+if (opts->sample_user_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_user |= opts->sample_user_regs;@@ -1677,6 +1688,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,evsel__set_sample_bit (evsel,REGS_USER ); } +if ((opts->sample_user_vec_regs || opts->sample_user_pred_regs) && + !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { + attr->sample_simd_regs_enabled = !!opts->sample_simd_regs_enabled; + attr->sample_simd_vec_reg_user = opts->sample_user_vec_regs; + attr->sample_simd_vec_reg_qwords = opts->sample_vec_reg_qwords; + attr->sample_simd_pred_reg_user = opts->sample_user_pred_regs; + attr->sample_simd_pred_reg_qwords = opts->sample_pred_reg_qwords; +evsel__set_sample_bit (evsel,REGS_USER ); + } +if (target__has_cpu (&opts->target) || opts->sample_cpu)evsel__set_sample_bit (evsel,CPU );tools/perf/util/parse-regs-options.c +0
-0
[ ... ]
Quoted 8 lines
tools/perf/util/parse-regs-options.c +4
-0@@ -53,26 +106,116 @@ name_to_perf_reg_mask(const char *to_match, uint64_t mask, int abi)return reg_mask; } +static bool +name_to_simd_reg_mask (struct record_opts *opts,const char *to_match, +uint64_t mask,bool intr,bool pred) +{
[ ... ]
Quoted 14 lines
tools/perf/util/parse-regs-options.c +14
-0+/* +* sample_intr_pred_regs and sample_user_pred_regs share +* sample_pred_reg_qwords. If both are set, keep their bitmaps identical. +*/ +if (opts->sample_intr_pred_regs && opts->sample_user_pred_regs) { +uint64_t max_pred_regs =MAX (opts->sample_intr_pred_regs, + opts->sample_user_pred_regs); + + opts->sample_intr_pred_regs = max_pred_regs; + opts->sample_user_pred_regs = max_pred_regs; + } + }else { + opts->sample_vec_reg_qwords = +MAX (qwords, opts->sample_vec_reg_qwords);
[ ... ]
tools/perf/util/parse-regs-options.c name_to_perf_reg_mask(const char *to_match, uint64_t mask, int abi) · line 194
Quoted 12 lines
tools/perf/util/parse-regs-options.c +12
-0+/* +* sample_intr_vec_regs and sample_user_vec_regs share +* sample_vec_reg_qwords. If both are set, keep their bitmaps identical. +*/ +if (opts->sample_intr_vec_regs && opts->sample_user_vec_regs) { +uint64_t max_vec_regs =MAX (opts->sample_intr_vec_regs, + opts->sample_user_vec_regs); + + opts->sample_intr_vec_regs = max_vec_regs; + opts->sample_user_vec_regs = max_vec_regs; + } + }
[Severity: Medium]
Does synchronizing the SIMD register masks between intr and user modes bypass architectural capability checks?
If a user specifies different sets for INTR and USER mode SIMD registers (e.g., -I XMM --user-regs ZMM), forcing both masks to the maximum might violate the capability check retrieved by perf_intr_simd_reg_class_bitmap_qwords().
Will this cause perf record to pass an unsupported register bitmask and fail with -EINVAL from the kernel?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [Patch v10 06/10] perf regs: Support x86 SIMD registers sampling
Quoted 33 lines · On 7/21/2026 3:50 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The sample parser fails to skip the SIMD register data payload, corrupting subsequent sample fields.
- [Medium] Silently synchronizing SIMD register masks between intr and user modes bypasses architectural capability checks.
- [Medium] Bypassing hardware event check for SIMD register sampling enables it for unsupported software events. ----- Patch [6]: [Patch v10 06/10] perf regs: Support x86 SIMD registers sampling --- commit
511dc4506d241eccda5990483afe081741ffbdb5
Author: Dapeng Mi <[email protected]>perf regs: Support x86 SIMD registers sampling
This commit adds support for the SIMD register sampling format on x86 platforms. It introduces functions to retrieve register class masks, names, and lengths for both interrupt and user registers, and updates command-line parsing to handle groups like XMM, YMM, ZMM, and OPMASK.
Quoted 4 lines
tools/perf/util/evsel.c +0
-0[ ... ]
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1675
Quoted 7 lines
tools/perf/util/evsel.c +3
-0@@ -1669,6 +1670,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,evsel__set_sample_bit (evsel,REGS_INTR ); } +if ((opts->sample_intr_vec_regs || opts->sample_intr_pred_regs) && + !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { + attr->sample_simd_regs_enabled = !!opts->sample_simd_regs_enabled;[Severity: Medium]
When SIMD registers are enabled here, should there be a check to verify it is a hardware event?
Quoted 3 lines
For regular registers, this is guarded with
evsel__is_hardware_event(evsel), but here it seems to unconditionally enable SIMD registers for software events. Could this cause the kernel to reject the event with-EINVAL?
No, sample_simd_regs_enabled must be set for SIMD register sampling. Software event can't sample these SIMD/eGPRs registers, the event creation would fail if it wants to sample these SIMD/eGPRs registers.
Quoted 25 lines
tools/perf/util/evsel.c void evsel__config(struct evsel *evsel, const struct record_opts *opts, · line 1681
Quoted 7 lines
tools/perf/util/evsel.c +6
-0+ attr->sample_simd_vec_reg_intr = opts->sample_intr_vec_regs; + attr->sample_simd_vec_reg_qwords = opts->sample_vec_reg_qwords; + attr->sample_simd_pred_reg_intr = opts->sample_intr_pred_regs; + attr->sample_simd_pred_reg_qwords = opts->sample_pred_reg_qwords; +evsel__set_sample_bit (evsel,REGS_INTR ); + }[Severity: High]
If SIMD sampling is enabled, does the parser in__evsel__parse_sample()properly skip the SIMD data payload?It appears that
__evsel__parse_sample()only skips the 4 header elements but misses the variable-length SIMD data array that follows:__evsel__parse_sample() { ... if (regs->abi & PERF_SAMPLE_REGS_ABI_SIMD) { /* Skip SIMD-regs header. */ sz = 4 * sizeof(u64); OVERFLOW_CHECK(array, sz, max_size); array = (void *)array + sz; } ... }
Quoted 3 lines
Will this leave the array pointer pointing at register data instead of the next field (like
PERF_SAMPLE_STACK_USER), potentially corrupting subsequent fields and failing to parse the event?
Similarly, __evsel__parse_sample() would be extended to support these SIMD registers in subsequent patch 07/10 "perf regs: Enable dumping of SIMD registers".
Quoted 67 lines
Quoted 26 lines
tools/perf/util/evsel.c +11
-0+if (opts->sample_user_regs && !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { attr->sample_regs_user |= opts->sample_user_regs;@@ -1677,6 +1688,16 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts,evsel__set_sample_bit (evsel,REGS_USER ); } +if ((opts->sample_user_vec_regs || opts->sample_user_pred_regs) && + !evsel->no_aux_samples && !evsel__is_dummy_event (evsel)) { + attr->sample_simd_regs_enabled = !!opts->sample_simd_regs_enabled; + attr->sample_simd_vec_reg_user = opts->sample_user_vec_regs; + attr->sample_simd_vec_reg_qwords = opts->sample_vec_reg_qwords; + attr->sample_simd_pred_reg_user = opts->sample_user_pred_regs; + attr->sample_simd_pred_reg_qwords = opts->sample_pred_reg_qwords; +evsel__set_sample_bit (evsel,REGS_USER ); + } +if (target__has_cpu (&opts->target) || opts->sample_cpu)evsel__set_sample_bit (evsel,CPU );tools/perf/util/parse-regs-options.c +0
-0[ ... ]
Quoted 8 lines
tools/perf/util/parse-regs-options.c +4
-0@@ -53,26 +106,116 @@ name_to_perf_reg_mask(const char *to_match, uint64_t mask, int abi)return reg_mask; } +static bool +name_to_simd_reg_mask (struct record_opts *opts,const char *to_match, +uint64_t mask,bool intr,bool pred) +{[ ... ]
Quoted 14 lines
tools/perf/util/parse-regs-options.c +14
-0+/* +* sample_intr_pred_regs and sample_user_pred_regs share +* sample_pred_reg_qwords. If both are set, keep their bitmaps identical. +*/ +if (opts->sample_intr_pred_regs && opts->sample_user_pred_regs) { +uint64_t max_pred_regs =MAX (opts->sample_intr_pred_regs, + opts->sample_user_pred_regs); + + opts->sample_intr_pred_regs = max_pred_regs; + opts->sample_user_pred_regs = max_pred_regs; + } + }else { + opts->sample_vec_reg_qwords = +MAX (qwords, opts->sample_vec_reg_qwords);[ ... ]
tools/perf/util/parse-regs-options.c name_to_perf_reg_mask(const char *to_match, uint64_t mask, int abi) · line 194
Quoted 12 lines
tools/perf/util/parse-regs-options.c +12
-0+/* +* sample_intr_vec_regs and sample_user_vec_regs share +* sample_vec_reg_qwords. If both are set, keep their bitmaps identical. +*/ +if (opts->sample_intr_vec_regs && opts->sample_user_vec_regs) { +uint64_t max_vec_regs =MAX (opts->sample_intr_vec_regs, + opts->sample_user_vec_regs); + + opts->sample_intr_vec_regs = max_vec_regs; + opts->sample_user_vec_regs = max_vec_regs; + } + }[Severity: Medium]
Does synchronizing the SIMD register masks between intr and user modes bypass architectural capability checks?
Quoted 7 lines
If a user specifies different sets for INTR and USER mode SIMD registers (e.g., -I XMM --user-regs ZMM), forcing both masks to the maximum might violate the capability check retrieved by
perf_intr_simd_reg_class_bitmap_qwords().Will this cause perf record to pass an unsupported register bitmask and fail with
-EINVALfrom the kernel?
No, currently perf/x86 code would validate if the full-register sampling is required. If not, the event creation would fail. Since sample_intr_vec_regs and sample_user_vec_regs share sample_vec_reg_qwords, it won't really violate perf_intr_simd_reg_class_bitmap_qwords().
Thanks.
Quoted 1 line
PATCH v10 7/10 perf regs: Enable dumping of SIMD registers
In reply to Dapeng MiSupport dumping of SIMD registers with the new PERF_SAMPLE_REGS_ABI_SIMD ABI.
Currently, the XMM, YMM, ZMM, OPMASK, eGPRs, and SSP registers on x86 platforms are supported with the PERF_SAMPLE_REGS_ABI_SIMD ABI.
An example of the raw format output is displayed below.
Example:
$perf record -e cycles:p -Iax,bx,r8,r16,r31,ssp,xmm,ymm,zmm,opmask ./test $perf report -D
... ...
3342715685845 0x3afe8 [0xbc8]: PERF_RECORD_SAMPLE(IP, 0x1):
27776/27776: 0xffffffff91d7c18f period: 10000 addr: 0
... intr regs: mask 0x18001010003 ABI 64-bit SIMD
.... AX 0xffffed102de1a606 .... BX 0xffffed102de1a606 .... R8 0x0000000000000001 .... R16 0x0000000000000000 .... R31 0x0000000000000000 .... SSP 0x0000000000000000
... SIMD ABI nr_vectors 32 vector_qwords 8 nr_pred 8 pred_qwords 1 .... ZMM[0][0] 0x616c2f656d6f682f
.... ZMM[0][1] 0x696c2f7265737562
.... ZMM[0][2] 0x0000000000000000
.... ZMM[0][3] 0x0000000000000000
.... ZMM[0][4] 0x0000000000000000
.... ZMM[0][5] 0x0000000000000000
.... ZMM[0][6] 0x0000000000000000
.... ZMM[0][7] 0x0000000000000000
.... ZMM[1][0] 0x702f636578656269
.... ZMM[1][1] 0x65726f632d667265
.... ZMM[1][2] 0x0000000000000000
.... ZMM[1][3] 0x0000000000000000
.... ZMM[1][4] 0x0000000000000000
.... ZMM[1][5] 0x0000000000000000
.... ZMM[1][6] 0x0000000000000000
.... ZMM[1][7] 0x0000000000000000
... ...
.... ZMM[31][0] 0x0000000000000000
.... ZMM[31][1] 0x0000000000000000
.... ZMM[31][2] 0x0000000000000000
.... ZMM[31][3] 0x0000000000000000
.... ZMM[31][4] 0x0000000000000000
.... ZMM[31][5] 0x0000000000000000
.... ZMM[31][6] 0x0000000000000000
.... ZMM[31][7] 0x0000000000000000
.... OPMASK[0] 0x0000000000100221
.... OPMASK[1] 0x0000000000000020
.... OPMASK[2] 0x000000007fffffff
.... OPMASK[3] 0x0000000000000000
.... OPMASK[4] 0x0000000000000000
.... OPMASK[5] 0x0000000000000000
.... OPMASK[6] 0x0000000000000000
.... OPMASK[7] 0x0000000000000000
... ...
--- tools/perf/builtin-script.c | 91 +++++++++++-- tools/perf/util/evsel.c | 68 +++++++++- tools/perf/util/sample.h | 5 + .../scripting-engines/trace-event-python.c | 125 ++++++++++++++++-- tools/perf/util/session.c | 82 ++++++++++++ tools/perf/util/synthetic-events.c | 38 +++++- 6 files changed, 387 insertions(+), 22 deletions(-)
tools/perf/builtin-script.c +83 -8
@@ -719,23 +719,96 @@ static int perf_session__check_output_opt(struct perf_session *session)return 0 ; } -static int perf_sample__fprintf_regs (struct regs_dump *regs,uint64_t mask, +static int perf_sample__fprintf_regs (struct regs_dump *regs, +struct perf_event_attr *attr,uint16_t e_machine,uint32_t e_flags, -FILE *fp) +FILE *fp,bool intr) { -unsigned i =0 , r; +const char *name ="unknown" ; +int reg_c, idx, pred_base; +unsigned int i =0 , j, r; +uint16_t qwords;int printed =0 ; +uint64_t mask; -if (!regs || !regs->regs) +if (!regs || (!regs->regs && !regs->simd_data))return 0 ; printed +=fprintf (fp," ABI:%" PRIu64" " , regs->abi); + mask = intr ? attr->sample_regs_intr : attr->sample_regs_user;for_each_set_bit (r, (unsigned long *) &mask,sizeof (mask) *8 ) { -u64 val = regs->regs[i++]; +if (!regs->regs) +break ; printed +=fprintf (fp,"%5s:0x%" PRIx64" " ,perf_reg_name (r, e_machine, e_flags, regs->abi), - val); + regs->regs[i++]); + } + +if (!regs->simd_data) +return printed; + +if (!regs->nr_vectors && !regs->nr_pred) +return printed; + +for (reg_c =0 ; reg_c <64 ; reg_c++) { +if (!regs->nr_vectors) +break ; +if (intr) { +perf_intr_simd_reg_class_bitmap_qwords (e_machine, reg_c, + &qwords,/*pred=*/ false); + }else { +perf_user_simd_reg_class_bitmap_qwords (e_machine, reg_c, + &qwords,/*pred=*/ false); + } +if (regs->vector_qwords == qwords) { + name =perf_simd_reg_class_name (e_machine, reg_c,/*pred=*/ false); +break ; + } + } + +for (i =0 ; i < regs->nr_vectors; i++) { +for (j =0 ; j < regs->vector_qwords; j++) { + idx = i * regs->vector_qwords + j; +if (regs->vector_qwords >1 ) { + printed +=fprintf (fp,"%5s[%d][%d]:0x%" PRIx64" " , + name, i, j, regs->simd_data[idx]); + }else { + printed +=fprintf (fp,"%5s[%d]:0x%" PRIx64" " , + name, i, regs->simd_data[idx]); + } + } + } + + name ="unknown" ; +for (reg_c =0 ; reg_c <64 ; reg_c++) { +if (!regs->nr_pred) +break ; +if (intr) { +perf_intr_simd_reg_class_bitmap_qwords (e_machine, reg_c, + &qwords,/*pred=*/ true); + }else { +perf_user_simd_reg_class_bitmap_qwords (e_machine, reg_c, + &qwords,/*pred=*/ true); + } +if (regs->pred_qwords == qwords) { + name =perf_simd_reg_class_name (e_machine, reg_c,/*pred=*/ true); +break ; + } + } + + pred_base = regs->nr_vectors * regs->vector_qwords; +for (i =0 ; i < regs->nr_pred; i++) { +for (j =0 ; j < regs->pred_qwords; j++) { + idx = pred_base + i * regs->pred_qwords + j; +if (regs->pred_qwords >1 ) { + printed +=fprintf (fp,"%5s[%d][%d]:0x%" PRIx64" " , + name, i, j, regs->simd_data[idx]); + }else { + printed +=fprintf (fp,"%5s[%d]:0x%" PRIx64" " , + name, i, regs->simd_data[idx]); + } + } }return printed;
@@ -801,7 +874,8 @@ static int perf_sample__fprintf_iregs(struct perf_sample *sample,return 0 ;return perf_sample__fprintf_regs (perf_sample__intr_regs (sample), - attr->sample_regs_intr, e_machine, e_flags, fp); + attr, e_machine, e_flags, fp, +/*intr=*/ true); } static int perf_sample__fprintf_uregs(struct perf_sample *sample,
@@ -814,7 +888,8 @@ static int perf_sample__fprintf_uregs(struct perf_sample *sample,return 0 ;return perf_sample__fprintf_regs (perf_sample__user_regs (sample), - attr->sample_regs_user, e_machine, e_flags, fp); + attr, e_machine, e_flags, fp, +/*intr=*/ false); } static int perf_sample__fprintf_start(struct perf_script *script,
tools/perf/util/evsel.c +64 -4
82 lines not on this page · raw message
tools/perf/util/sample.h +5 -0
@@ -16,6 +16,11 @@ struct regs_dump {u64 abi;u64 mask;u64 *regs; +u64 nr_vectors; +u64 vector_qwords; +u64 nr_pred; +u64 pred_qwords; +u64 *simd_data;/* Cached values/mask filled by first register access. */ u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE ];
tools/perf/util/scripting-engines/trace-event-python.c +117 -8
164 lines not on this page · raw message
tools/perf/util/session.c +82 -0
100 lines not on this page · raw message
tools/perf/util/synthetic-events.c +36 -2
@@ -1527,8 +1527,13 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->user_regs && sample->user_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->user_regs->mask) *sizeof (u64); -if (sample->user_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) +if (sample->user_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { sz +=4 *sizeof (u64); + sz += (sample->user_regs->nr_vectors * + sample->user_regs->vector_qwords + + sample->user_regs->nr_pred * + sample->user_regs->pred_qwords) *sizeof (u64); + } result += sz; }else { result +=sizeof (u64);
@@ -1557,8 +1562,13 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (sample->intr_regs && sample->intr_regs->abi) { result +=sizeof (u64); sz =hweight64 (sample->intr_regs->mask) *sizeof (u64); -if (sample->intr_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) +if (sample->intr_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { sz +=4 *sizeof (u64); + sz += (sample->intr_regs->nr_vectors * + sample->intr_regs->vector_qwords + + sample->intr_regs->nr_pred * + sample->intr_regs->pred_qwords) *sizeof (u64); + } result += sz; }else { result +=sizeof (u64);
@@ -1746,6 +1756,18 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo sz =hweight64 (sample->user_regs->mask) *sizeof (u64);memcpy (array, sample->user_regs->regs, sz); array = (void *)array + sz; +if (sample->user_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { + *array++ = sample->user_regs->nr_vectors; + *array++ = sample->user_regs->vector_qwords; + *array++ = sample->user_regs->nr_pred; + *array++ = sample->user_regs->pred_qwords; + sz = (sample->user_regs->nr_vectors * + sample->user_regs->vector_qwords + + sample->user_regs->nr_pred * + sample->user_regs->pred_qwords) *sizeof (u64); +memcpy (array, sample->user_regs->simd_data, sz); + array = (void *)array + sz; + } }else { *array++ =0 ; }
@@ -1782,6 +1804,18 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo sz =hweight64 (sample->intr_regs->mask) *sizeof (u64);memcpy (array, sample->intr_regs->regs, sz); array = (void *)array + sz; +if (sample->intr_regs->abi &PERF_SAMPLE_REGS_ABI_SIMD ) { + *array++ = sample->intr_regs->nr_vectors; + *array++ = sample->intr_regs->vector_qwords; + *array++ = sample->intr_regs->nr_pred; + *array++ = sample->intr_regs->pred_qwords; + sz = (sample->intr_regs->nr_vectors * + sample->intr_regs->vector_qwords + + sample->intr_regs->nr_pred * + sample->intr_regs->pred_qwords) *sizeof (u64); +memcpy (array, sample->intr_regs->simd_data, sz); + array = (void *)array + sz; + } }else { *array++ =0 ; }
Signature · 1 line
2.34.1
PATCH v10 8/10 perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers
In reply to Dapeng MiEnhance the x86-specific DWARF register handling by adding support for SIMD and eGPRs registers.
This update is based on the "DWARF Register Number Mapping" table from the "System V Application Binary Interface AMD64 Architecture Processor Supplement" (version 1.0).
Modifications include:
- Updating the x86_64_regidx_table[] array to incorporate SIMD and eGPRs registers.
- Enhancing the __get_dwarf_regnum_for_perf_regnum_x86_64() function to retrieve the DWARF register index for eGPRs.
Since currently libdw doesn't support SIMD and APX eGPRs registers yet, still keep the original return value for get_libdw_frame_nregs() helper.
--- .../util/dwarf-regs-arch/dwarf-regs-x86.c | 138 +++++++++++++++--- tools/perf/util/dwarf-regs.c | 9 +- tools/perf/util/include/dwarf-regs.h | 7 +- tools/perf/util/unwind-libdw.c | 6 +- 4 files changed, 132 insertions(+), 28 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-x86.c +117 -21
@@ -90,22 +90,22 @@ static const struct dwarf_regs_idx x86_64_regidx_table[] = { { "r14", 14 }, { "r14d", 14 }, { "r14w", 14 }, { "r14b", 14 }, { "r15", 15 }, { "r15d", 15 }, { "r15w", 15 }, { "r15b", 15 },// 16 - Return Address RA - { "xmm0", 17}, - { "xmm1", 18}, - { "xmm2", 19}, - { "xmm3", 20}, - { "xmm4", 21}, - { "xmm5", 22}, - { "xmm6", 23}, - { "xmm7", 24}, - { "xmm8", 25}, - { "xmm9", 26}, - { "xmm10", 27}, - { "xmm11", 28}, - { "xmm12", 29}, - { "xmm13", 30}, - { "xmm14", 31}, - { "xmm15", 32}, + { "zmm0", 17 }, { "ymm0", 17 }, { "xmm0", 17 }, + { "zmm1", 18 }, { "ymm1", 18 }, { "xmm1", 18 }, + { "zmm2", 19 }, { "ymm2", 19 }, { "xmm2", 19 }, + { "zmm3", 20 }, { "ymm3", 20 }, { "xmm3", 20 }, + { "zmm4", 21 }, { "ymm4", 21 }, { "xmm4", 21 }, + { "zmm5", 22 }, { "ymm5", 22 }, { "xmm5", 22 }, + { "zmm6", 23 }, { "ymm6", 23 }, { "xmm6", 23 }, + { "zmm7", 24 }, { "ymm7", 24 }, { "xmm7", 24 }, + { "zmm8", 25 }, { "ymm8", 25 }, { "xmm8", 25 }, + { "zmm9", 26 }, { "ymm9", 26 }, { "xmm9", 26 }, + { "zmm10", 27 }, { "ymm10", 27 }, { "xmm10", 27 }, + { "zmm11", 28 }, { "ymm11", 28 }, { "xmm11", 28 }, + { "zmm12", 29 }, { "ymm12", 29 }, { "xmm12", 29 }, + { "zmm13", 30 }, { "ymm13", 30 }, { "xmm13", 30 }, + { "zmm14", 31 }, { "ymm14", 31 }, { "xmm14", 31 }, + { "zmm15", 32 }, { "ymm15", 32 }, { "xmm15", 32 }, { "st0", 33}, { "st1", 34}, { "st2", 35},
@@ -129,7 +129,7 @@ static const struct dwarf_regs_idx x86_64_regidx_table[] = { { "ds", 53}, { "fs", 54}, { "gs", 55}, -// 56-47 - reserved +// 56-57 - reserved { "fs.base", 58}, { "gs.base", 59},// 60-61 - reserved
@@ -138,6 +138,49 @@ static const struct dwarf_regs_idx x86_64_regidx_table[] = { { "mxcsr", 64}, // 128-bit Media Control and Status { "fcw", 65}, // x87 Control Word { "fsw", 66}, // x87 Status Word +// 67-82 - Upper Vector Registers 16–31 + { "zmm16", 67 }, { "ymm16", 67 }, { "xmm16", 67 }, + { "zmm17", 68 }, { "ymm17", 68 }, { "xmm17", 68 }, + { "zmm18", 69 }, { "ymm18", 69 }, { "xmm18", 69 }, + { "zmm19", 70 }, { "ymm19", 70 }, { "xmm19", 70 }, + { "zmm20", 71 }, { "ymm20", 71 }, { "xmm20", 71 }, + { "zmm21", 72 }, { "ymm21", 72 }, { "xmm21", 72 }, + { "zmm22", 73 }, { "ymm22", 73 }, { "xmm22", 73 }, + { "zmm23", 74 }, { "ymm23", 74 }, { "xmm23", 74 }, + { "zmm24", 75 }, { "ymm24", 75 }, { "xmm24", 75 }, + { "zmm25", 76 }, { "ymm25", 76 }, { "xmm25", 76 }, + { "zmm26", 77 }, { "ymm26", 77 }, { "xmm26", 77 }, + { "zmm27", 78 }, { "ymm27", 78 }, { "xmm27", 78 }, + { "zmm28", 79 }, { "ymm28", 79 }, { "xmm28", 79 }, + { "zmm29", 80 }, { "ymm29", 80 }, { "xmm29", 80 }, + { "zmm30", 81 }, { "ymm30", 81 }, { "xmm30", 81 }, + { "zmm31", 82 }, { "ymm31", 82 }, { "xmm31", 82 }, +// 118-125 - Vector Mask Registers 0–7 + { "k0", 118 }, + { "k1", 119 }, + { "k2", 120 }, + { "k3", 121 }, + { "k4", 122 }, + { "k5", 123 }, + { "k6", 124 }, + { "k7", 125 }, +// 130-145 - APX Integer Registers 16-31 + { "r16", 130 }, { "r16d", 130 }, { "r16w", 130 }, { "r16b", 130 }, + { "r17", 131 }, { "r17d", 131 }, { "r17w", 131 }, { "r17b", 131 }, + { "r18", 132 }, { "r18d", 132 }, { "r18w", 132 }, { "r18b", 132 }, + { "r19", 133 }, { "r19d", 133 }, { "r19w", 133 }, { "r19b", 133 }, + { "r20", 134 }, { "r20d", 134 }, { "r20w", 134 }, { "r20b", 134 }, + { "r21", 135 }, { "r21d", 135 }, { "r21w", 135 }, { "r21b", 135 }, + { "r22", 136 }, { "r22d", 136 }, { "r22w", 136 }, { "r22b", 136 }, + { "r23", 137 }, { "r23d", 137 }, { "r23w", 137 }, { "r23b", 137 }, + { "r24", 138 }, { "r24d", 138 }, { "r24w", 138 }, { "r24b", 138 }, + { "r25", 139 }, { "r25d", 139 }, { "r25w", 139 }, { "r25b", 139 }, + { "r26", 140 }, { "r26d", 140 }, { "r26w", 140 }, { "r26b", 140 }, + { "r27", 141 }, { "r27d", 141 }, { "r27w", 141 }, { "r27b", 141 }, + { "r28", 142 }, { "r28d", 142 }, { "r28w", 142 }, { "r28b", 142 }, + { "r29", 143 }, { "r29d", 143 }, { "r29w", 143 }, { "r29b", 143 }, + { "r30", 144 }, { "r30d", 144 }, { "r30w", 144 }, { "r30b", 144 }, + { "r31", 145 }, { "r31d", 145 }, { "r31w", 145 }, { "r31b", 145 },// End of regular dwarf registers. { "rip", DWARF_REG_PC }, { "eip", DWARF_REG_PC }, { "ip", DWARF_REG_PC }, };
@@ -204,7 +247,7 @@ int __get_dwarf_regnum_for_perf_regnum_i386(int perf_regnum)return dwarf_i386_regnums[perf_regnum]; } -int __get_dwarf_regnum_for_perf_regnum_x86_64 (int perf_regnum) +int __get_dwarf_regnum_for_perf_regnum_x86_64 (int perf_regnum,int abi) {static const int dwarf_x86_64_regnums[] = { [PERF_REG_X86_AX ] =0 ,
@@ -248,13 +291,66 @@ int __get_dwarf_regnum_for_perf_regnum_x86_64(int perf_regnum) [PERF_REG_X86_XMM14] = 31, [PERF_REG_X86_XMM15] = 32, }; +static const int dwarf_x86_64_regnums_apx[] = { + [PERF_REG_X86_AX ] =0 , + [PERF_REG_X86_BX ] =3 , + [PERF_REG_X86_CX ] =2 , + [PERF_REG_X86_DX ] =1 , + [PERF_REG_X86_SI ] =4 , + [PERF_REG_X86_DI ] =5 , + [PERF_REG_X86_BP ] =6 , + [PERF_REG_X86_SP ] =7 , + [PERF_REG_X86_IP ] =16 , + [PERF_REG_X86_FLAGS ] =49 , + [PERF_REG_X86_CS ] =51 , + [PERF_REG_X86_SS ] =52 , + [PERF_REG_X86_DS ] =53 , + [PERF_REG_X86_ES ] =50 , + [PERF_REG_X86_FS ] =54 , + [PERF_REG_X86_GS ] =55 , + [PERF_REG_X86_R8 ] =8 , + [PERF_REG_X86_R9 ] =9 , + [PERF_REG_X86_R10 ] =10 , + [PERF_REG_X86_R11 ] =11 , + [PERF_REG_X86_R12 ] =12 , + [PERF_REG_X86_R13 ] =13 , + [PERF_REG_X86_R14 ] =14 , + [PERF_REG_X86_R15 ] =15 , + [PERF_REG_X86_R16 ] =130 , + [PERF_REG_X86_R17 ] =131 , + [PERF_REG_X86_R18 ] =132 , + [PERF_REG_X86_R19 ] =133 , + [PERF_REG_X86_R20 ] =134 , + [PERF_REG_X86_R21 ] =135 , + [PERF_REG_X86_R22 ] =136 , + [PERF_REG_X86_R23 ] =137 , + [PERF_REG_X86_R24 ] =138 , + [PERF_REG_X86_R25 ] =139 , + [PERF_REG_X86_R26 ] =140 , + [PERF_REG_X86_R27 ] =141 , + [PERF_REG_X86_R28 ] =142 , + [PERF_REG_X86_R29 ] =143 , + [PERF_REG_X86_R30 ] =144 , + [PERF_REG_X86_R31 ] =145 , + };if (perf_regnum ==0 )return 0 ; -if (perf_regnum <0 || perf_regnum >= (int )ARRAY_SIZE (dwarf_x86_64_regnums) || - dwarf_x86_64_regnums[perf_regnum] ==0 ) +if (perf_regnum <0 ) +return -ENOENT ; + +if (!(abi &PERF_SAMPLE_REGS_ABI_SIMD ) && + (perf_regnum >= (int )ARRAY_SIZE (dwarf_x86_64_regnums) || + dwarf_x86_64_regnums[perf_regnum] ==0 )) +return -ENOENT ; + +if ((abi &PERF_SAMPLE_REGS_ABI_SIMD ) && + (perf_regnum >= (int )ARRAY_SIZE (dwarf_x86_64_regnums_apx) || + dwarf_x86_64_regnums_apx[perf_regnum] ==0 ))return -ENOENT ; -return dwarf_x86_64_regnums[perf_regnum]; +return abi &PERF_SAMPLE_REGS_ABI_SIMD ? + dwarf_x86_64_regnums_apx[perf_regnum] : + dwarf_x86_64_regnums[perf_regnum]; }
tools/perf/util/dwarf-regs.c +7 -2
@@ -158,6 +158,10 @@ static int get_libdw_frame_nregs(unsigned int machine, unsigned int flags __mayb {switch (machine) {case EM_X86_64 : +/* +* Since libdw doesn't support SIMD and APX eGPR register yet, +* still keep nregs to 17. +*/ return 17 ;case EM_386 :return 9 ;
@@ -187,13 +191,14 @@ static int get_libdw_frame_nregs(unsigned int machine, unsigned int flags __mayb }int get_dwarf_regnum_for_perf_regnum (int perf_regnum,unsigned int machine, -unsigned int flags,bool only_libdw_supported) +unsigned int flags, +bool only_libdw_supported,int abi) {int reg;switch (machine) {case EM_X86_64 : - reg =__get_dwarf_regnum_for_perf_regnum_x86_64 (perf_regnum); + reg =__get_dwarf_regnum_for_perf_regnum_x86_64 (perf_regnum, abi);break ;case EM_386 : reg =__get_dwarf_regnum_for_perf_regnum_i386 (perf_regnum);
tools/perf/util/include/dwarf-regs.h +4 -3
@@ -103,7 +103,7 @@ int __get_csky_regnum(const char *name, unsigned int flags);int __get_dwarf_regnum_i386 (const char *name);int __get_dwarf_regnum_x86_64 (const char *name);int __get_dwarf_regnum_for_perf_regnum_i386 (int perf_regnum); -int __get_dwarf_regnum_for_perf_regnum_x86_64 (int perf_regnum); +int __get_dwarf_regnum_for_perf_regnum_x86_64 (int perf_regnum,int abi);int __get_dwarf_regnum_for_perf_regnum_arm (int perf_regnum);int __get_dwarf_regnum_for_perf_regnum_arm64 (int perf_regnum);
@@ -125,8 +125,9 @@ int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags)/* * get_dwarf_regnum - Returns DWARF regnum from perf register number. */ -int get_dwarf_regnum_for_perf_regnum (int perf_regnum,unsigned int machine,unsigned int flags, -bool only_libdw_supported); +int get_dwarf_regnum_for_perf_regnum (int perf_regnum,unsigned int machine, +unsigned int flags, +bool only_libdw_supported,int abi);void get_powerpc_regs (u32 raw_insn,int is_source,struct annotated_op_loc *op_loc);
tools/perf/util/unwind-libdw.c +4 -2
@@ -273,7 +273,8 @@ static bool libdw_set_initial_registers(Dwfl_Thread *thread, void *arg)int dwarf_reg =get_dwarf_regnum_for_perf_regnum (perf_reg, e_machine, e_flags, -/*only_libdw_supported=*/ true); +/*only_libdw_supported=*/ true, + user_regs->abi);if (dwarf_reg > max_dwarf_reg) max_dwarf_reg = dwarf_reg; }
@@ -288,7 +289,8 @@ static bool libdw_set_initial_registers(Dwfl_Thread *thread, void *arg)int dwarf_reg =get_dwarf_regnum_for_perf_regnum (perf_reg, e_machine, e_flags, -/*only_libdw_supported=*/ true); +/*only_libdw_supported=*/ true, + user_regs->abi);if (dwarf_reg >=0 ) { val =0 ;if (perf_reg_value (&val, user_regs, perf_reg) ==0 )
Signature · 1 line
2.34.1
PATCH v10 9/10 perf tests: Add x86 eGPRs/SSP registers sampling test
In reply to Dapeng MiValidate that eGPRs (extended general purpose registers) and SSP (shadow stack pointer) registers can be sampled correctly on x86 platforms with hardware support.
--- tools/perf/tests/shell/record.sh | 126 +++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+)
tools/perf/tests/shell/record.sh +126 -0
@@ -127,6 +127,131 @@ test_register_capture() { echo "Register capture test [Success]" } +has_required_regs() { + local regs_output="$1" + shift + + for reg in "$@" + do + if ! echo "${regs_output}" | grep -q -i "${reg}" + then + return 1 + fi + done + + return 0 +} + +validate_gp_reg_sampling() { + local regs_opt="$1" + local regs_value="$2" + local script_field="$3" + local sample_output + shift 3 + + if ! sample_output=$(perf record -o - "${regs_opt}=${regs_value}" \ + -e br_inst_retired.near_call -c 1000 --per-thread ${testprog} 2> /dev/null \ + | perf script -F ip,sym,"${script_field}" -i - 2> /dev/null) + then + return 1 + fi + + if ! has_required_regs "${sample_output}" "$@" + then + return 1 + fi + + return 0 +} + +test_egpr_register_capture() { + local arch + local intr_regs + local user_regs + local tested=0 + + echo "eGPR/SSP register capture test" + + arch=$(uname -m) + case ${arch} in + x86_64|i386) + ;; + *) + echo "eGPR/SSP register capture test [Skipped non-x86 platform]" + return + ;; + esac + + if ! perf list pmu | grep -q 'br_inst_retired.near_call' + then + echo "eGPR/SSP register capture test [Skipped missing event]" + return + fi + + intr_regs=$(perf record --intr-regs=\? 2>&1 || true) + user_regs=$(perf record --user-regs=\? 2>&1 || true) + + if has_required_regs "${intr_regs}" R16 R31 + then + if ! validate_gp_reg_sampling "--intr-regs" "r16,r31" "iregs" "R16:" "R31:" + then + echo "eGPR/SSP register capture test [Failed eGPR intr-regs validation]" + err=1 + return + fi + tested=1 + else + echo "eGPR/SSP register capture test [Skipped missing eGPR intr-regs (R16/R31)]" + fi + + if has_required_regs "${user_regs}" R16 R31 + then + if ! validate_gp_reg_sampling "--user-regs" "r16,r31" "uregs" "R16:" "R31:" + then + echo "eGPR/SSP register capture test [Failed eGPR user-regs validation]" + err=1 + return + fi + tested=1 + else + echo "eGPR/SSP register capture test [Skipped missing eGPR user-regs (R16/R31)]" + fi + + if has_required_regs "${intr_regs}" SSP + then + if ! validate_gp_reg_sampling "--intr-regs" "ssp" "iregs" "SSP:" + then + echo "eGPR/SSP register capture test [Failed SSP intr-regs validation]" + err=1 + return + fi + tested=1 + else + echo "eGPR/SSP register capture test [Skipped missing SSP intr-regs]" + fi + + if has_required_regs "${user_regs}" SSP + then + if ! validate_gp_reg_sampling "--user-regs" "ssp" "uregs" "SSP:" + then + echo "eGPR/SSP register capture test [Failed SSP user-regs validation]" + err=1 + return + fi + tested=1 + else + echo "eGPR/SSP register capture test [Skipped missing SSP user-regs]" + fi + + if [ ${tested} -eq 0 ] + then + echo "eGPR/SSP register capture test [Skipped missing eGPR/SSP registers]" + return + fi + + echo "eGPR/SSP register capture test [Success]" +} + check_system_wide() { perf report -i "${perfdata}" -q | grep -q "${testsym}" }
@@ -491,6 +616,7 @@ fi test_per_thread test_register_capture +test_egpr_register_capture test_system_wide test_workload test_branch_counter
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [Patch v10 09/10] perf tests: Add x86 eGPRs/SSP registers sampling test
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly added validation function `validate_gp_reg_sampling` executes a single-shot pipeline…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added validation function validate_gp_reg_sampling executes a single-shot pipeline for perf record, bypassing the established perf_record_with_retry wrapper. This makes the test susceptible to intermittent failures (flakiness) in CI environments and prevents it from utilizing the fast-path optimization. --
--- Patch [9]: [Patch v10 09/10] perf tests: Add x86 eGPRs/SSP registers sampling test --- commit a4a8e0ee768722ad01317e4cd04c08a71c39eecf
Author: Dapeng Mi <[email protected]>
perf tests: Add x86 eGPRs/SSP registers sampling test
Validate that eGPRs (extended general purpose registers) and SSP (shadow stack pointer) registers can be sampled correctly on x86 platforms with hardware support.
Quoted 4 lines
tools/perf/tests/shell/record.sh +0
-0
[ ... ]
tools/perf/tests/shell/record.sh test_register_capture() { · line 154
Quoted 10 lines
tools/perf/tests/shell/record.sh +10
-0+validate_gp_reg_sampling() { + local regs_opt="$1" + local regs_value="$2" + local script_field="$3" + local sample_output + shift 3 + + if ! sample_output=$(perf record -o - "${regs_opt}=${regs_value}" \ + -e br_inst_retired.near_call -c 1000 --per-thread ${testprog} 2> /dev/null \ + | perf script -F ip,sym,"${script_field}" -i - 2> /dev/null)
[Severity: Medium]
Will this single-shot pipeline cause intermittent failures in CI environments under heavy load?
Other tests in this file appear to use the perf_record_with_retry wrapper to mitigate flakiness. That wrapper provides a fast-path optimization and scales up the recording duration if the system load prevents sufficient hardware events from being generated immediately.
Since validate_gp_reg_sampling() executes perf record directly without a retry loop, could it fail spuriously if the workload doesn't generate enough events in the initial window?
Quoted 3 lines
tools/perf/tests/shell/record.sh +3
-0+ then + return 1 + fi
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [Patch v10 09/10] perf tests: Add x86 eGPRs/SSP registers sampling test
Quoted 34 lines · On 7/21/2026 3:42 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added validation functionvalidate_gp_reg_samplingexecutes a single-shot pipeline forperf record, bypassing the establishedperf_record_with_retrywrapper. This makes the test susceptible to intermittent failures (flakiness) in CI environments and prevents it from utilizing the fast-path optimization. ----- Patch [9]: [Patch v10 09/10] perf tests: Add x86 eGPRs/SSP registers sampling test --- commit
a4a8e0ee768722ad01317e4cd04c08a71c39eecf
Author: Dapeng Mi <[email protected]>perf tests: Add x86 eGPRs/SSP registers sampling test
Validate that eGPRs (extended general purpose registers) and SSP (shadow stack pointer) registers can be sampled correctly on x86 platforms with hardware support.
Quoted 4 lines
tools/perf/tests/shell/record.sh +0
-0[ ... ]
tools/perf/tests/shell/record.sh test_register_capture() { · line 154
Quoted 10 lines
tools/perf/tests/shell/record.sh +10
-0+validate_gp_reg_sampling() { + local regs_opt="$1" + local regs_value="$2" + local script_field="$3" + local sample_output + shift 3 + + if ! sample_output=$(perf record -o - "${regs_opt}=${regs_value}" \ + -e br_inst_retired.near_call -c 1000 --per-thread ${testprog} 2> /dev/null \ + | perf script -F ip,sym,"${script_field}" -i - 2> /dev/null)[Severity: Medium]
Will this single-shot pipeline cause intermittent failures in CI environments under heavy load?
Quoted 8 lines
Other tests in this file appear to use the
perf_record_with_retrywrapper to mitigate flakiness. That wrapper provides a fast-path optimization and scales up the recording duration if the system load prevents sufficient hardware events from being generated immediately.Since
validate_gp_reg_sampling()executes perf record directly without a retry loop, could it fail spuriously if the workload doesn't generate enough events in the initial window?
Ok. It seems perf_record_with_retry() was just added into the tree about 4 weeks ago. It didn't exist when developing this patch.
Anyway, would use perf_record_with_retry() to replace current raw "perf record" command.
Thanks.
Quoted 4 lines
Quoted 4 lines
tools/perf/tests/shell/record.sh +3
-0+ then + return 1 + fi
PATCH v10 10/10 perf tests: Add SIMD registers sampling test
In reply to Dapeng MiValidate that SIMD registers (XMM/YMM/ZMM on x86) can be sampled correctly with hardware support.
--- tools/perf/tests/shell/record.sh | 131 +++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+)
tools/perf/tests/shell/record.sh +131 -0
@@ -252,6 +252,136 @@ test_egpr_register_capture() { echo "eGPR/SSP register capture test [Success]" } +extract_x86_advertised_simd_classes() { + local regs_output="$1" + + echo "${regs_output}" \ + | grep -oE '(ZMM|YMM|XMM|OPMASK)[0-9]+-[0-9]+' \ + | sed -E 's/[0-9]+-[0-9]+$//' \ + | tr '[:upper:]' '[:lower:]' \ + | sort -u +} + +ordered_x86_simd_classes() { + local advertised_classes="$1" + local simd_classes="" + + if echo "${advertised_classes}" | grep -qw zmm + then + simd_classes="${simd_classes} zmm" + fi + if echo "${advertised_classes}" | grep -qw ymm + then + simd_classes="${simd_classes} ymm" + fi + if echo "${advertised_classes}" | grep -qw xmm + then + simd_classes="${simd_classes} xmm" + fi + if echo "${advertised_classes}" | grep -qw opmask + then + simd_classes="${simd_classes} opmask" + fi + + echo "${simd_classes}" | xargs +} + +validate_simd_sampling_mode() { + local regs_opt="$1" + local simd_classes="$2" + local script_field="$3" + local simd_class + local sample_output + + for simd_class in ${simd_classes} + do + if ! sample_output=$(perf record -o - "${regs_opt}=${simd_class}" \ + -e br_inst_retired.near_call -c 1000 --per-thread ${testprog} 2> /dev/null \ + | perf script -F ip,sym,"${script_field}" -i - 2> /dev/null) + then + echo "SIMD register capture test [Failed record ${regs_opt}=${simd_class}]" + return 1 + fi + + if ! has_required_regs "${sample_output}" "${simd_class}" + then + echo "SIMD register capture test [Failed missing ${simd_class} sampling data]" + return 1 + fi + done + + return 0 +} + +test_simd_register_capture() { + local arch + local intr_regs + local user_regs + local simd_classes + local user_simd_classes + local advertised_intr_classes + local advertised_user_classes + local tested=0 + + echo "SIMD register capture test" + if ! perf list pmu | grep -q 'br_inst_retired.near_call' + then + echo "SIMD register capture test [Skipped missing event]" + return + fi + + intr_regs=$(perf record --intr-regs=\? 2>&1 || true) + user_regs=$(perf record --user-regs=\? 2>&1 || true) + + simd_classes="" + user_simd_classes="" + + arch=$(uname -m) + case ${arch} in + x86_64|i386) + advertised_intr_classes=$(extract_x86_advertised_simd_classes "${intr_regs}") + advertised_user_classes=$(extract_x86_advertised_simd_classes "${user_regs}") + + simd_classes=$(ordered_x86_simd_classes "${advertised_intr_classes}") + user_simd_classes=$(ordered_x86_simd_classes "${advertised_user_classes}") + ;; + *) + ;; + esac + + if [ -z "${simd_classes}" ] + then + echo "SIMD register capture test [Skipped missing intr SIMD registers]" + elif ! validate_simd_sampling_mode "--intr-regs" "${simd_classes}" "iregs" + then + echo "SIMD register capture test [Failed missing intr SIMD register sampling data]" + err=1 + return + else + tested=1 + fi + + if [ -z "${user_simd_classes}" ] + then + echo "SIMD register capture test [Skipped missing user SIMD registers]" + elif ! validate_simd_sampling_mode "--user-regs" "${user_simd_classes}" "uregs" + then + echo "SIMD register capture test [Failed missing user SIMD register sampling data]" + err=1 + return + else + tested=1 + fi + + if [ ${tested} -eq 0 ] + then + echo "SIMD register capture test [Skipped missing SIMD registers]" + return + fi + + echo "SIMD register capture test [Success]" +} + check_system_wide() { perf report -i "${perfdata}" -q | grep -q "${testsym}" }
@@ -617,6 +747,7 @@ fi test_per_thread test_register_capture test_egpr_register_capture +test_simd_register_capture test_system_wide test_workload test_branch_counter
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [Patch v10 10/10] perf tests: Add SIMD registers sampling test
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The test validation logic for SIMD register sampling uses a loose grep pattern that can falsely…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The test validation logic for SIMD register sampling uses a loose grep pattern that can falsely report success if a sampled symbol contains the register class name. --
--- Patch [10]: [Patch v10 10/10] perf tests: Add SIMD registers sampling test --- commit 1c34ec145d62a684219e4898c8fe2a820402bef2
Author: Dapeng Mi <[email protected]>
perf tests: Add SIMD registers sampling test
Validate that SIMD registers (XMM/YMM/ZMM on x86) can be sampled correctly with hardware support.
Quoted 4 lines
tools/perf/tests/shell/record.sh +0
-0
[ ... ]
Quoted 1 line
tools/perf/tests/shell/record.sh +0
-0@@ -252,6 +252,136 @@ test_egpr_register_capture() {
[ ... ]
Quoted 8 lines
tools/perf/tests/shell/record.sh +8
-0+validate_simd_sampling_mode() { + local regs_opt="$1" + local simd_classes="$2" + local script_field="$3" + local simd_class + local sample_output + + for simd_class in ${simd_classes}
tools/perf/tests/shell/record.sh test_egpr_register_capture() { · line 306
Quoted 10 lines
tools/perf/tests/shell/record.sh +10
-0+ do + if ! sample_output=$(perf record -o - "${regs_opt}=${simd_class}" \ + -e br_inst_retired.near_call -c 1000 --per-thread ${testprog} 2> /dev/null \ + | perf script -F ip,sym,"${script_field}" -i - 2> /dev/null) + then + echo "SIMD register capture test [Failed record ${regs_opt}=${simd_class}]" + return 1 + fi + + if ! has_required_regs "${sample_output}" "${simd_class}"
[Severity: Medium]
Will this search pattern mistakenly match symbol names instead of the actual register dump?
When perf script outputs symbol names alongside the registers, passing the raw class name without delimiters to has_required_regs might falsely match C library routines like __memcmp_sse4_1_xmm or __memcpy_avx_unaligned_erms_ymm.
Could this check be made more strict, perhaps by including delimiters to ensure it only matches the register dump data and not the sampled symbol names?
Quoted 8 lines
tools/perf/tests/shell/record.sh +8
-0+ then + echo "SIMD register capture test [Failed missing ${simd_class} sampling data]" + return 1 + fi + done + + return 0 +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [Patch v10 10/10] perf tests: Add SIMD registers sampling test
Quoted 44 lines · On 7/21/2026 3:48 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The test validation logic for SIMD register sampling uses a loose grep pattern that can falsely report success if a sampled symbol contains the register class name. ----- Patch [10]: [Patch v10 10/10] perf tests: Add SIMD registers sampling test --- commit
1c34ec145d62a684219e4898c8fe2a820402bef2
Author: Dapeng Mi <[email protected]>perf tests: Add SIMD registers sampling test
Validate that SIMD registers (XMM/YMM/ZMM on x86) can be sampled correctly with hardware support.
Quoted 4 lines
tools/perf/tests/shell/record.sh +0
-0[ ... ]
Quoted 1 line
tools/perf/tests/shell/record.sh +0
-0@@ -252,6 +252,136 @@ test_egpr_register_capture() {[ ... ]
Quoted 8 lines
tools/perf/tests/shell/record.sh +8
-0+validate_simd_sampling_mode() { + local regs_opt="$1" + local simd_classes="$2" + local script_field="$3" + local simd_class + local sample_output + + for simd_class in ${simd_classes}tools/perf/tests/shell/record.sh test_egpr_register_capture() { · line 306
Quoted 10 lines
tools/perf/tests/shell/record.sh +10
-0+ do + if ! sample_output=$(perf record -o - "${regs_opt}=${simd_class}" \ + -e br_inst_retired.near_call -c 1000 --per-thread ${testprog} 2> /dev/null \ + | perf script -F ip,sym,"${script_field}" -i - 2> /dev/null) + then + echo "SIMD register capture test [Failed record ${regs_opt}=${simd_class}]" + return 1 + fi + + if ! has_required_regs "${sample_output}" "${simd_class}"[Severity: Medium]
Will this search pattern mistakenly match symbol names instead of the actual register dump?
Quoted 7 lines
When perf script outputs symbol names alongside the registers, passing the raw class name without delimiters to
has_required_regsmight falsely match C library routines like__memcmp_sse4_1_xmmor__memcpy_avx_unaligned_erms_ymm.Could this check be made more strict, perhaps by including delimiters to ensure it only matches the register dump data and not the sampled symbol names?
Sure. Thanks.
Quoted 9 lines
Quoted 9 lines
tools/perf/tests/shell/record.sh +8
-0+ then + echo "SIMD register capture test [Failed missing ${simd_class} sampling data]" + return 1 + fi + done + + return 0 +}
Peter queued the dependent perf patches into the tip perf/core tree.
https://lore.kernel.org/all/[email protected]/
But since there are UAPI changes, these perf-tools patches would lead to errors without the corresponding perf patches.
@Arnaldo, @Namhyung, @Ian how would we handle such kind of dependency issues generally? Wait for the dependent perf patches merged into mainline and then merge the perf-tools patches?
Thanks.
Quoted 114 lines · Dapeng Mi
Patch layout:
- Patches 1-2: Fix two bugs in DWARF register bounds checking and event attribute printing/swapping.
- Patches 3-4: Sync tools and perf headers with the kernel sources.
- Patches 5-8: Add SIMD/eGPR/SSP sampling and dump support.
- Patches 9-10: Add unit tests for SIMD/eGPR/SSP sampling.Changes since v9:
- Patch 05/10: Fix the issue that cpu-clock/task-clock fails to sample GPRs.
- Patch 06/10: Ensure sample_intr_{pred|vec}_regs and sample_user_{pred|vec}_regs to keep identical if both are set since they share sample_{pred|vec}_reg_qwords.Changes since v8:
- Patch 01/10: Fix incorrect DWARF register bounds checking.
- Patch 02/10: Add missing event attribute printing and swapping support (Sashiko).
- Patch 07/10: Remove dead code ([idx++]) in SIMD register dumping (Sashiko).
- Patch 08/10: Restore the original x86libdw_frame_nregsvalue (17), as libdw still lacks x86 SIMD/eGPR support (Ian).
- Patch 09/10: Add x86 eGPR/SSP sampling unit tests (Ian).
- Patch 10/10: Add x86 SIMD register sampling unit tests (Ian).Changes since v7:
- Address Sashiko's comments including,
* documents are not update availably; SIMD registers bitmask may be overwritten by shorter mask; u16 type in sample meta-data break the cross-endian conversion, etc.
- Add SIMD/eGPRs/SSP support in dwarf-regs (Ian).
- Misc enhancements.Changes since v6:
- Address Ian's comments including,
* Add more comments for newly added register indexes (patch 1/4).
* Several minor enhancements in patch 4/4.
- Limit dwarf minimal regs to legacy GPRs (excluding APX eGPRs) (patch 2/4).Changes since v5:
- Split the sampling support for eGPRs/SSP registers and SIMD registers into 2 patches.
- Address Ian's comments including,
* Convert the architecture dependent functions into regular architectural independent functions, likewhatperf_reg_name()does.
* Refine the functions name to represent what the functions really do.
* Add comments for some key functions arguments.
* Misc enhancements.This patch-set adds sampling support for x86 eGPRs/SSP/SIMD registers in perf tools base on the corresponding sampling support for eGPRs/SSP/SIMD registers in kernel[1]. In versions before v6, these perf-tools patches are integrated as a whole patch-set with the kernel patches, but it's split and posted to an independent perf-tools patch-set for convenient review.
History:
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/Ref:
[1] Kernel patches of supporting eGPRs/SSP/SIMD registers sampling:
https://lore.kernel.org/all/[email protected]/Dapeng Mi (10):
perf dwarf-regs: Fix DWARF register index bounds check perf util: Add missed fields in_attr__fprintf()and__attr_swap()tools headers: Sync x86 headers with kernel sources
perf headers: Syncperf_event.h/perf_regs.hwith the kernel headers perf regs: Support x86 eGPRs/SSP sampling
perf regs: Support x86 SIMD registers sampling
perf regs: Enable dumping of SIMD registers
perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers perf tests: Add x86 eGPRs/SSP registers sampling test perf tests: Add SIMD registers sampling testtools/arch/x86/include/asm/msr-index.h | 7 + tools/arch/x86/include/uapi/asm/perf_regs.h | 53 +++ tools/include/uapi/linux/perf_event.h | 49 +- tools/perf/Documentation/perf-record.txt | 10 +- tools/perf/builtin-script.c | 93 +++- tools/perf/tests/shell/record.sh | 257 +++++++++++ .../util/dwarf-regs-arch/dwarf-regs-csky.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-powerpc.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-s390.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-x86.c | 140 +++++- tools/perf/util/dwarf-regs.c | 9 +- tools/perf/util/evsel.c | 106 ++++- tools/perf/util/evsel.h | 7 + tools/perf/util/header.c | 3 +- tools/perf/util/include/dwarf-regs.h | 7 +- tools/perf/util/parse-regs-options.c | 210 ++++++++- .../perf/util/perf-regs-arch/perf_regs_x86.c | 436 +++++++++++++++++- tools/perf/util/perf_event_attr_fprintf.c | 13 + tools/perf/util/perf_regs.c | 84 +++- tools/perf/util/perf_regs.h | 21 +- tools/perf/util/record.h | 7 + tools/perf/util/sample.h | 5 + .../scripting-engines/trace-event-python.c | 127 ++++- tools/perf/util/session.c | 112 ++++- tools/perf/util/synthetic-events.c | 38 ++ tools/perf/util/unwind-libdw.c | 6 +- 26 files changed, 1696 insertions(+), 110 deletions(-)base-commit:
e01c7bd5b1eece254bcbf282db066b12c4815d21
Quoted 6 lines · Dapeng
Peter queued the dependent perf patches into the tip perf/core tree.
https://lore.kernel.org/all/[email protected]/
But since there are UAPI changes, these perf-tools patches would lead to errors without the corresponding perf patches.
The statement looks wrong. I tried to run these perf tools patches on DMR with the old kernel, no issues are found.
# ./perf record -I? available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15 XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15
# ./perf record --user-regs=? available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15
The copy_struct_from_user() in perf_copy_attr() would reject any new non-zero field in user space perf_event_attr structure and this would ensure perf tools falls back to the legacy register list.
So it looks we don't need to wait for next release cycle and I would rebase and send new patch series.
Thanks.
Quoted 123 lines
@Arnaldo, @Namhyung, @Ian how would we handle such kind of dependency issues generally? Wait for the dependent perf patches merged into mainline and then merge the perf-tools patches?
Thanks.
Quoted 114 lines · Dapeng Mi
Patch layout:
- Patches 1-2: Fix two bugs in DWARF register bounds checking and event attribute printing/swapping.
- Patches 3-4: Sync tools and perf headers with the kernel sources.
- Patches 5-8: Add SIMD/eGPR/SSP sampling and dump support.
- Patches 9-10: Add unit tests for SIMD/eGPR/SSP sampling.Changes since v9:
- Patch 05/10: Fix the issue that cpu-clock/task-clock fails to sample GPRs.
- Patch 06/10: Ensure sample_intr_{pred|vec}_regs and sample_user_{pred|vec}_regs to keep identical if both are set since they share sample_{pred|vec}_reg_qwords.Changes since v8:
- Patch 01/10: Fix incorrect DWARF register bounds checking.
- Patch 02/10: Add missing event attribute printing and swapping support (Sashiko).
- Patch 07/10: Remove dead code ([idx++]) in SIMD register dumping (Sashiko).
- Patch 08/10: Restore the original x86libdw_frame_nregsvalue (17), as libdw still lacks x86 SIMD/eGPR support (Ian).
- Patch 09/10: Add x86 eGPR/SSP sampling unit tests (Ian).
- Patch 10/10: Add x86 SIMD register sampling unit tests (Ian).Changes since v7:
- Address Sashiko's comments including,
* documents are not update availably; SIMD registers bitmask may be overwritten by shorter mask; u16 type in sample meta-data break the cross-endian conversion, etc.
- Add SIMD/eGPRs/SSP support in dwarf-regs (Ian).
- Misc enhancements.Changes since v6:
- Address Ian's comments including,
* Add more comments for newly added register indexes (patch 1/4).
* Several minor enhancements in patch 4/4.
- Limit dwarf minimal regs to legacy GPRs (excluding APX eGPRs) (patch 2/4).Changes since v5:
- Split the sampling support for eGPRs/SSP registers and SIMD registers into 2 patches.
- Address Ian's comments including,
* Convert the architecture dependent functions into regular architectural independent functions, likewhatperf_reg_name()does.
* Refine the functions name to represent what the functions really do.
* Add comments for some key functions arguments.
* Misc enhancements.This patch-set adds sampling support for x86 eGPRs/SSP/SIMD registers in perf tools base on the corresponding sampling support for eGPRs/SSP/SIMD registers in kernel[1]. In versions before v6, these perf-tools patches are integrated as a whole patch-set with the kernel patches, but it's split and posted to an independent perf-tools patch-set for convenient review.
History:
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/Ref:
[1] Kernel patches of supporting eGPRs/SSP/SIMD registers sampling:
https://lore.kernel.org/all/[email protected]/Dapeng Mi (10):
perf dwarf-regs: Fix DWARF register index bounds check perf util: Add missed fields in_attr__fprintf()and__attr_swap()tools headers: Sync x86 headers with kernel sources
perf headers: Syncperf_event.h/perf_regs.hwith the kernel headers perf regs: Support x86 eGPRs/SSP sampling
perf regs: Support x86 SIMD registers sampling
perf regs: Enable dumping of SIMD registers
perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers perf tests: Add x86 eGPRs/SSP registers sampling test perf tests: Add SIMD registers sampling testtools/arch/x86/include/asm/msr-index.h | 7 + tools/arch/x86/include/uapi/asm/perf_regs.h | 53 +++ tools/include/uapi/linux/perf_event.h | 49 +- tools/perf/Documentation/perf-record.txt | 10 +- tools/perf/builtin-script.c | 93 +++- tools/perf/tests/shell/record.sh | 257 +++++++++++ .../util/dwarf-regs-arch/dwarf-regs-csky.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-powerpc.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-s390.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-x86.c | 140 +++++- tools/perf/util/dwarf-regs.c | 9 +- tools/perf/util/evsel.c | 106 ++++- tools/perf/util/evsel.h | 7 + tools/perf/util/header.c | 3 +- tools/perf/util/include/dwarf-regs.h | 7 +- tools/perf/util/parse-regs-options.c | 210 ++++++++- .../perf/util/perf-regs-arch/perf_regs_x86.c | 436 +++++++++++++++++- tools/perf/util/perf_event_attr_fprintf.c | 13 + tools/perf/util/perf_regs.c | 84 +++- tools/perf/util/perf_regs.h | 21 +- tools/perf/util/record.h | 7 + tools/perf/util/sample.h | 5 + .../scripting-engines/trace-event-python.c | 127 ++++- tools/perf/util/session.c | 112 ++++- tools/perf/util/synthetic-events.c | 38 ++ tools/perf/util/unwind-libdw.c | 6 +- 26 files changed, 1696 insertions(+), 110 deletions(-)base-commit:
e01c7bd5b1eece254bcbf282db066b12c4815d21
Arnaldo Carvalho de Melo
maintainerQuoted 10 lines · Dapeng
Peter queued the dependent perf patches into the tip perf/core tree.
https://lore.kernel.org/all/[email protected]/
But since there are UAPI changes, these perf-tools patches would lead to errors without the corresponding perf patches.
@Arnaldo, @Namhyung, @Ian how would we handle such kind of dependency issues generally? Wait for the dependent perf patches merged into mainline and then merge the perf-tools patches?
That would slow down development, if it made perf kernel upstream, even if not yet to Linus, we can update the header in perf-tools-next, the check_headers script will warn about it, but now it is not running by default so no distracting warning and if when we decide to run it we got advanced warning that it will take some time to sort out, i.e. when the perf kernel UAPI header hits upstream and perf-tools-next merges with it.
So send perf kernel patches to Peter and the tooling ones to me and Namhyung.
- Arnaldo
Quoted 118 lines
Thanks.
Quoted 114 lines · Dapeng Mi
Patch layout:
- Patches 1-2: Fix two bugs in DWARF register bounds checking and event attribute printing/swapping.
- Patches 3-4: Sync tools and perf headers with the kernel sources.
- Patches 5-8: Add SIMD/eGPR/SSP sampling and dump support.
- Patches 9-10: Add unit tests for SIMD/eGPR/SSP sampling.Changes since v9:
- Patch 05/10: Fix the issue that cpu-clock/task-clock fails to sample GPRs.
- Patch 06/10: Ensure sample_intr_{pred|vec}_regs and sample_user_{pred|vec}_regs to keep identical if both are set since they share sample_{pred|vec}_reg_qwords.Changes since v8:
- Patch 01/10: Fix incorrect DWARF register bounds checking.
- Patch 02/10: Add missing event attribute printing and swapping support (Sashiko).
- Patch 07/10: Remove dead code ([idx++]) in SIMD register dumping (Sashiko).
- Patch 08/10: Restore the original x86libdw_frame_nregsvalue (17), as libdw still lacks x86 SIMD/eGPR support (Ian).
- Patch 09/10: Add x86 eGPR/SSP sampling unit tests (Ian).
- Patch 10/10: Add x86 SIMD register sampling unit tests (Ian).Changes since v7:
- Address Sashiko's comments including,
* documents are not update availably; SIMD registers bitmask may be overwritten by shorter mask; u16 type in sample meta-data break the cross-endian conversion, etc.
- Add SIMD/eGPRs/SSP support in dwarf-regs (Ian).
- Misc enhancements.Changes since v6:
- Address Ian's comments including,
* Add more comments for newly added register indexes (patch 1/4).
* Several minor enhancements in patch 4/4.
- Limit dwarf minimal regs to legacy GPRs (excluding APX eGPRs) (patch 2/4).Changes since v5:
- Split the sampling support for eGPRs/SSP registers and SIMD registers into 2 patches.
- Address Ian's comments including,
* Convert the architecture dependent functions into regular architectural independent functions, likewhatperf_reg_name()does.
* Refine the functions name to represent what the functions really do.
* Add comments for some key functions arguments.
* Misc enhancements.This patch-set adds sampling support for x86 eGPRs/SSP/SIMD registers in perf tools base on the corresponding sampling support for eGPRs/SSP/SIMD registers in kernel[1]. In versions before v6, these perf-tools patches are integrated as a whole patch-set with the kernel patches, but it's split and posted to an independent perf-tools patch-set for convenient review.
History:
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/Ref:
[1] Kernel patches of supporting eGPRs/SSP/SIMD registers sampling:
https://lore.kernel.org/all/[email protected]/Dapeng Mi (10):
perf dwarf-regs: Fix DWARF register index bounds check perf util: Add missed fields in_attr__fprintf()and__attr_swap()tools headers: Sync x86 headers with kernel sources
perf headers: Syncperf_event.h/perf_regs.hwith the kernel headers perf regs: Support x86 eGPRs/SSP sampling
perf regs: Support x86 SIMD registers sampling
perf regs: Enable dumping of SIMD registers
perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers perf tests: Add x86 eGPRs/SSP registers sampling test perf tests: Add SIMD registers sampling testtools/arch/x86/include/asm/msr-index.h | 7 + tools/arch/x86/include/uapi/asm/perf_regs.h | 53 +++ tools/include/uapi/linux/perf_event.h | 49 +- tools/perf/Documentation/perf-record.txt | 10 +- tools/perf/builtin-script.c | 93 +++- tools/perf/tests/shell/record.sh | 257 +++++++++++ .../util/dwarf-regs-arch/dwarf-regs-csky.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-powerpc.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-s390.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-x86.c | 140 +++++- tools/perf/util/dwarf-regs.c | 9 +- tools/perf/util/evsel.c | 106 ++++- tools/perf/util/evsel.h | 7 + tools/perf/util/header.c | 3 +- tools/perf/util/include/dwarf-regs.h | 7 +- tools/perf/util/parse-regs-options.c | 210 ++++++++- .../perf/util/perf-regs-arch/perf_regs_x86.c | 436 +++++++++++++++++- tools/perf/util/perf_event_attr_fprintf.c | 13 + tools/perf/util/perf_regs.c | 84 +++- tools/perf/util/perf_regs.h | 21 +- tools/perf/util/record.h | 7 + tools/perf/util/sample.h | 5 + .../scripting-engines/trace-event-python.c | 127 ++++- tools/perf/util/session.c | 112 ++++- tools/perf/util/synthetic-events.c | 38 ++ tools/perf/util/unwind-libdw.c | 6 +- 26 files changed, 1696 insertions(+), 110 deletions(-)base-commit:
e01c7bd5b1eece254bcbf282db066b12c4815d21
Peter Zijlstra
maintainerQuoted 20 lines · Arnaldo Carvalho de Melo
Quoted 10 lines · Dapeng
Peter queued the dependent perf patches into the tip perf/core tree.
https://lore.kernel.org/all/[email protected]/
But since there are UAPI changes, these perf-tools patches would lead to errors without the corresponding perf patches.
@Arnaldo, @Namhyung, @Ian how would we handle such kind of dependency issues generally? Wait for the dependent perf patches merged into mainline and then merge the perf-tools patches?
That would slow down development, if it made perf kernel upstream, even if not yet to Linus, we can update the header in perf-tools-next, the
check_headersscript will warn about it, but now it is not running by default so no distracting warning and if when we decide to run it we got advanced warning that it will take some time to sort out, i.e. when the perf kernel UAPI header hits upstream and perf-tools-next merges with it.
Quoted 3 lines
So send perf kernel patches to Peter and the tooling ones to me and Namhyung.
Patches are in tip/perf/core.
Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 10 lines · Dapeng
Peter queued the dependent perf patches into the tip perf/core tree.
https://lore.kernel.org/all/[email protected]/
But since there are UAPI changes, these perf-tools patches would lead to errors without the corresponding perf patches.
@Arnaldo, @Namhyung, @Ian how would we handle such kind of dependency issues generally? Wait for the dependent perf patches merged into mainline and then merge the perf-tools patches?
That would slow down development, if it made perf kernel upstream, even if not yet to Linus, we can update the header in perf-tools-next, the
check_headersscript will warn about it, but now it is not running by default so no distracting warning and if when we decide to run it we got advanced warning that it will take some time to sort out, i.e. when the perf kernel UAPI header hits upstream and perf-tools-next merges with it.
Quoted 2 lines
So send perf kernel patches to Peter and the tooling ones to me and Namhyung.
Got it. Thanks for the explanations. I would send the new version patch series soon.
BTW, since the size check in copy_struct_from_user() for user space perf_event_attr structure, the UAPI changes in the patches won't really break the current register sampling. :)
Quoted 121 lines
- Arnaldo
Quoted 118 lines
Thanks.
Quoted 114 lines · Dapeng Mi
Patch layout:
- Patches 1-2: Fix two bugs in DWARF register bounds checking and event attribute printing/swapping.
- Patches 3-4: Sync tools and perf headers with the kernel sources.
- Patches 5-8: Add SIMD/eGPR/SSP sampling and dump support.
- Patches 9-10: Add unit tests for SIMD/eGPR/SSP sampling.Changes since v9:
- Patch 05/10: Fix the issue that cpu-clock/task-clock fails to sample GPRs.
- Patch 06/10: Ensure sample_intr_{pred|vec}_regs and sample_user_{pred|vec}_regs to keep identical if both are set since they share sample_{pred|vec}_reg_qwords.Changes since v8:
- Patch 01/10: Fix incorrect DWARF register bounds checking.
- Patch 02/10: Add missing event attribute printing and swapping support (Sashiko).
- Patch 07/10: Remove dead code ([idx++]) in SIMD register dumping (Sashiko).
- Patch 08/10: Restore the original x86libdw_frame_nregsvalue (17), as libdw still lacks x86 SIMD/eGPR support (Ian).
- Patch 09/10: Add x86 eGPR/SSP sampling unit tests (Ian).
- Patch 10/10: Add x86 SIMD register sampling unit tests (Ian).Changes since v7:
- Address Sashiko's comments including,
* documents are not update availably; SIMD registers bitmask may be overwritten by shorter mask; u16 type in sample meta-data break the cross-endian conversion, etc.
- Add SIMD/eGPRs/SSP support in dwarf-regs (Ian).
- Misc enhancements.Changes since v6:
- Address Ian's comments including,
* Add more comments for newly added register indexes (patch 1/4).
* Several minor enhancements in patch 4/4.
- Limit dwarf minimal regs to legacy GPRs (excluding APX eGPRs) (patch 2/4).Changes since v5:
- Split the sampling support for eGPRs/SSP registers and SIMD registers into 2 patches.
- Address Ian's comments including,
* Convert the architecture dependent functions into regular architectural independent functions, likewhatperf_reg_name()does.
* Refine the functions name to represent what the functions really do.
* Add comments for some key functions arguments.
* Misc enhancements.This patch-set adds sampling support for x86 eGPRs/SSP/SIMD registers in perf tools base on the corresponding sampling support for eGPRs/SSP/SIMD registers in kernel[1]. In versions before v6, these perf-tools patches are integrated as a whole patch-set with the kernel patches, but it's split and posted to an independent perf-tools patch-set for convenient review.
History:
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/Ref:
[1] Kernel patches of supporting eGPRs/SSP/SIMD registers sampling:
https://lore.kernel.org/all/[email protected]/Dapeng Mi (10):
perf dwarf-regs: Fix DWARF register index bounds check perf util: Add missed fields in_attr__fprintf()and__attr_swap()tools headers: Sync x86 headers with kernel sources
perf headers: Syncperf_event.h/perf_regs.hwith the kernel headers perf regs: Support x86 eGPRs/SSP sampling
perf regs: Support x86 SIMD registers sampling
perf regs: Enable dumping of SIMD registers
perf dwarf-regs: Add SIMD/eGPRs support for x86 DWARF registers perf tests: Add x86 eGPRs/SSP registers sampling test perf tests: Add SIMD registers sampling testtools/arch/x86/include/asm/msr-index.h | 7 + tools/arch/x86/include/uapi/asm/perf_regs.h | 53 +++ tools/include/uapi/linux/perf_event.h | 49 +- tools/perf/Documentation/perf-record.txt | 10 +- tools/perf/builtin-script.c | 93 +++- tools/perf/tests/shell/record.sh | 257 +++++++++++ .../util/dwarf-regs-arch/dwarf-regs-csky.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-powerpc.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-s390.c | 2 +- .../util/dwarf-regs-arch/dwarf-regs-x86.c | 140 +++++- tools/perf/util/dwarf-regs.c | 9 +- tools/perf/util/evsel.c | 106 ++++- tools/perf/util/evsel.h | 7 + tools/perf/util/header.c | 3 +- tools/perf/util/include/dwarf-regs.h | 7 +- tools/perf/util/parse-regs-options.c | 210 ++++++++- .../perf/util/perf-regs-arch/perf_regs_x86.c | 436 +++++++++++++++++- tools/perf/util/perf_event_attr_fprintf.c | 13 + tools/perf/util/perf_regs.c | 84 +++- tools/perf/util/perf_regs.h | 21 +- tools/perf/util/record.h | 7 + tools/perf/util/sample.h | 5 + .../scripting-engines/trace-event-python.c | 127 ++++- tools/perf/util/session.c | 112 ++++- tools/perf/util/synthetic-events.c | 38 ++ tools/perf/util/unwind-libdw.c | 6 +- 26 files changed, 1696 insertions(+), 110 deletions(-)base-commit:
e01c7bd5b1eece254bcbf282db066b12c4815d21