[RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks

Stian Halseth posted 3 patches 1 day, 3 hours ago
.../features/perf/perf-regs/arch-support.txt  |  2 +-
.../perf/perf-stackdump/arch-support.txt      |  2 +-
arch/sparc/Kconfig                            |  2 +
arch/sparc/include/asm/perf_event.h           |  5 ++
arch/sparc/include/uapi/asm/perf_regs.h       | 34 +++++++++
arch/sparc/kernel/Makefile                    |  2 +-
arch/sparc/kernel/perf_regs.c                 | 74 +++++++++++++++++++
include/linux/perf_event.h                    | 11 +++
kernel/events/core.c                          |  2 +
kernel/events/internal.h                      |  2 +-
tools/arch/sparc/include/uapi/asm/perf_regs.h | 34 +++++++++
tools/perf/arch/sparc/include/perf_regs.h     | 18 +++++
tools/perf/check-headers.sh                   |  1 +
tools/perf/util/dwarf-regs-arch/Build         |  1 +
.../util/dwarf-regs-arch/dwarf-regs-sparc.c   | 12 +++
tools/perf/util/dwarf-regs.c                  |  4 +
tools/perf/util/include/dwarf-regs.h          |  1 +
tools/perf/util/perf-regs-arch/Build          |  1 +
.../util/perf-regs-arch/perf_regs_sparc.c     | 67 +++++++++++++++++
tools/perf/util/perf_regs.c                   | 18 +++++
tools/perf/util/perf_regs.h                   |  5 ++
tools/perf/util/unwind-libdw.c                | 37 ++++++++++
22 files changed, 331 insertions(+), 4 deletions(-)
create mode 100644 arch/sparc/include/uapi/asm/perf_regs.h
create mode 100644 arch/sparc/kernel/perf_regs.c
create mode 100644 tools/arch/sparc/include/uapi/asm/perf_regs.h
create mode 100644 tools/perf/arch/sparc/include/perf_regs.h
create mode 100644 tools/perf/util/dwarf-regs-arch/dwarf-regs-sparc.c
create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_sparc.c
[RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks
Posted by Stian Halseth 1 day, 3 hours ago
This adds HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP to sparc64, so
that perf record --call-graph dwarf and elfutils' eu-stackprof work
there.

Two things about the user stack dump do not fit in arch code. The
sampled register window's %l/%i registers, which hold the frame pointer
and return address the unwinder starts from, stay in the register file
until a window spills. The kernel already flushes them wherever it
exposes user stack memory (perf_callchain_user(), ptrace), but the stack
dump has no arch entry point where that could happen. And a 64-bit
sparc stack pointer is biased by 2047, so a dump that starts at the
register value begins 2047 bytes below the frame, and is empty when that
page has never been touched.

Patch 1 therefore adds two hooks in the style of perf_arch_misc_flags(),
both no-ops by default. Patch 2 is the sparc64 implementation and their
user. Patch 3 teaches tools/perf the sparc registers and DWARF unwinding
from the dump. The matching elfutils changes are attached to the
tracking issue:

  https://github.com/sparclinux/issues/issues/99

Tested on an UltraSPARC T4-1 on 7.3-rc4: register values check out
against known contents, --call-graph dwarf unwinds correctly for both
cycles and cpu-clock, as does eu-stackprof, and perf stat/record/record
-g are unchanged. Starting the dump at the stack's actual address
matters in practice: with the dump at the biased register value, 94% of
the user samples of xz -T4 had an empty stack dump; with this series,
none do.

Changes since v2:
- Patch 1: add perf_arch_user_stack_pointer(), so an arch can start the
  dump at the stack's actual address (sashiko review).
- Patch 2: drop %g0 from the uapi, as trap entry does not save it; the
  PC takes its slot, as on mips and loongarch (sashiko review).
- Patch 2: start the dump at %sp + 2047 for a 64-bit stack (sashiko
  review).
- Patch 3: follow both, and comment the max_dwarf_reg adjustment (Ian).
  Drop the memcpy() change to memory_read(), which the unbiased dump
  start makes unnecessary.

v2: https://lore.kernel.org/all/20260922201507.1719668-1-stian@itx.no/
v1: https://lore.kernel.org/all/20260922135653.1622301-1-stian@itx.no/

Stian Halseth (3):
  perf/core: Let an arch prepare and locate the user stack dump
  sparc64: Support PERF_SAMPLE_REGS_USER and PERF_SAMPLE_STACK_USER
  perf tools: Support sparc user register samples and dwarf unwinding

 .../features/perf/perf-regs/arch-support.txt  |  2 +-
 .../perf/perf-stackdump/arch-support.txt      |  2 +-
 arch/sparc/Kconfig                            |  2 +
 arch/sparc/include/asm/perf_event.h           |  5 ++
 arch/sparc/include/uapi/asm/perf_regs.h       | 34 +++++++++
 arch/sparc/kernel/Makefile                    |  2 +-
 arch/sparc/kernel/perf_regs.c                 | 74 +++++++++++++++++++
 include/linux/perf_event.h                    | 11 +++
 kernel/events/core.c                          |  2 +
 kernel/events/internal.h                      |  2 +-
 tools/arch/sparc/include/uapi/asm/perf_regs.h | 34 +++++++++
 tools/perf/arch/sparc/include/perf_regs.h     | 18 +++++
 tools/perf/check-headers.sh                   |  1 +
 tools/perf/util/dwarf-regs-arch/Build         |  1 +
 .../util/dwarf-regs-arch/dwarf-regs-sparc.c   | 12 +++
 tools/perf/util/dwarf-regs.c                  |  4 +
 tools/perf/util/include/dwarf-regs.h          |  1 +
 tools/perf/util/perf-regs-arch/Build          |  1 +
 .../util/perf-regs-arch/perf_regs_sparc.c     | 67 +++++++++++++++++
 tools/perf/util/perf_regs.c                   | 18 +++++
 tools/perf/util/perf_regs.h                   |  5 ++
 tools/perf/util/unwind-libdw.c                | 37 ++++++++++
 22 files changed, 331 insertions(+), 4 deletions(-)
 create mode 100644 arch/sparc/include/uapi/asm/perf_regs.h
 create mode 100644 arch/sparc/kernel/perf_regs.c
 create mode 100644 tools/arch/sparc/include/uapi/asm/perf_regs.h
 create mode 100644 tools/perf/arch/sparc/include/perf_regs.h
 create mode 100644 tools/perf/util/dwarf-regs-arch/dwarf-regs-sparc.c
 create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_sparc.c

-- 
2.55.0
Re: [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks
Posted by Magnus Lindholm 13 hours ago
Hi Stian,

On Wed, Sep 23, 2026 at 11:04 AM Stian Halseth <stian@itx.no> wrote:
>
> This adds HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP to sparc64, so
> that perf record --call-graph dwarf and elfutils' eu-stackprof work
> there.
>
> Two things about the user stack dump do not fit in arch code. The
> sampled register window's %l/%i registers, which hold the frame pointer
> and return address the unwinder starts from, stay in the register file
> until a window spills. The kernel already flushes them wherever it
> exposes user stack memory (perf_callchain_user(), ptrace), but the stack
> dump has no arch entry point where that could happen. And a 64-bit
> sparc stack pointer is biased by 2047, so a dump that starts at the
> register value begins 2047 bytes below the frame, and is empty when that
> page has never been touched.
>
> Patch 1 therefore adds two hooks in the style of perf_arch_misc_flags(),
> both no-ops by default. Patch 2 is the sparc64 implementation and their
> user. Patch 3 teaches tools/perf the sparc registers and DWARF unwinding
> from the dump. The matching elfutils changes are attached to the
> tracking issue:
>
>   https://github.com/sparclinux/issues/issues/99
>
> Tested on an UltraSPARC T4-1 on 7.3-rc4: register values check out
> against known contents, --call-graph dwarf unwinds correctly for both
> cycles and cpu-clock, as does eu-stackprof, and perf stat/record/record
> -g are unchanged. Starting the dump at the stack's actual address
> matters in practice: with the dump at the biased register value, 94% of
> the user samples of xz -T4 had an empty stack dump; with this series,
> none do.
>
> Changes since v2:
> - Patch 1: add perf_arch_user_stack_pointer(), so an arch can start the
>   dump at the stack's actual address (sashiko review).
> - Patch 2: drop %g0 from the uapi, as trap entry does not save it; the
>   PC takes its slot, as on mips and loongarch (sashiko review).
> - Patch 2: start the dump at %sp + 2047 for a 64-bit stack (sashiko
>   review).
> - Patch 3: follow both, and comment the max_dwarf_reg adjustment (Ian).
>   Drop the memcpy() change to memory_read(), which the unbiased dump
>   start makes unnecessary.
>
> v2: https://lore.kernel.org/all/20260922201507.1719668-1-stian@itx.no/
> v1: https://lore.kernel.org/all/20260922135653.1622301-1-stian@itx.no/
>
> Stian Halseth (3):
>   perf/core: Let an arch prepare and locate the user stack dump
>   sparc64: Support PERF_SAMPLE_REGS_USER and PERF_SAMPLE_STACK_USER
>   perf tools: Support sparc user register samples and dwarf unwinding
>
>  .../features/perf/perf-regs/arch-support.txt  |  2 +-
>  .../perf/perf-stackdump/arch-support.txt      |  2 +-
>  arch/sparc/Kconfig                            |  2 +
>  arch/sparc/include/asm/perf_event.h           |  5 ++
>  arch/sparc/include/uapi/asm/perf_regs.h       | 34 +++++++++
>  arch/sparc/kernel/Makefile                    |  2 +-
>  arch/sparc/kernel/perf_regs.c                 | 74 +++++++++++++++++++
>  include/linux/perf_event.h                    | 11 +++
>  kernel/events/core.c                          |  2 +
>  kernel/events/internal.h                      |  2 +-
>  tools/arch/sparc/include/uapi/asm/perf_regs.h | 34 +++++++++
>  tools/perf/arch/sparc/include/perf_regs.h     | 18 +++++
>  tools/perf/check-headers.sh                   |  1 +
>  tools/perf/util/dwarf-regs-arch/Build         |  1 +
>  .../util/dwarf-regs-arch/dwarf-regs-sparc.c   | 12 +++
>  tools/perf/util/dwarf-regs.c                  |  4 +
>  tools/perf/util/include/dwarf-regs.h          |  1 +
>  tools/perf/util/perf-regs-arch/Build          |  1 +
>  .../util/perf-regs-arch/perf_regs_sparc.c     | 67 +++++++++++++++++
>  tools/perf/util/perf_regs.c                   | 18 +++++
>  tools/perf/util/perf_regs.h                   |  5 ++
>  tools/perf/util/unwind-libdw.c                | 37 ++++++++++
>  22 files changed, 331 insertions(+), 4 deletions(-)
>  create mode 100644 arch/sparc/include/uapi/asm/perf_regs.h
>  create mode 100644 arch/sparc/kernel/perf_regs.c
>  create mode 100644 tools/arch/sparc/include/uapi/asm/perf_regs.h
>  create mode 100644 tools/perf/arch/sparc/include/perf_regs.h
>  create mode 100644 tools/perf/util/dwarf-regs-arch/dwarf-regs-sparc.c
>  create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_sparc.c
>
> --
> 2.55.0
>

Hi Stian,

I tested v3 on real hardware. I haven't noticed any regressions.
I built tools/perf from this series and tested the new functionality
with software cpu-clock events.

Basic perf stat/record and the existing frame-pointer callchain mode
worked normally.

PERF_SAMPLE_REGS_USER also worked, with perf successfully recording
and decoding the SPARC register set.

I then tested:

  perf record -e '1:0:u' -F 99 --call-graph dwarf,8192 ...

This recorded 443 samples with PERF_SAMPLE_REGS_USER and
PERF_SAMPLE_STACK_USER, using the full 0x7ffff register mask and an
8192-byte stack dump. perf script and perf report were both able to
unwind the resulting callchains, and no samples were reported lost.

I haven't tested 32-bit compat tasks or hardware-cycle sampling.

Tested-by: Magnus Lindholm <linmag7@gmail.com>

Thanks,
Magnus
Re: [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks
Posted by Stian Halseth 4 hours ago
Hi Magnus,

On Thu, 2026-09-24 at 01:10 +0200, Magnus Lindholm wrote:
> 
> Hi Stian,
> 
> I tested v3 on real hardware. I haven't noticed any regressions.
> I built tools/perf from this series and tested the new functionality
> with software cpu-clock events.
> 
> Basic perf stat/record and the existing frame-pointer callchain mode
> worked normally.
> 
> PERF_SAMPLE_REGS_USER also worked, with perf successfully recording
> and decoding the SPARC register set.
> 
> I then tested:
> 
>   perf record -e '1:0:u' -F 99 --call-graph dwarf,8192 ...
> 
> This recorded 443 samples with PERF_SAMPLE_REGS_USER and
> PERF_SAMPLE_STACK_USER, using the full 0x7ffff register mask and an
> 8192-byte stack dump. perf script and perf report were both able to
> unwind the resulting callchains, and no samples were reported lost.
> 
> I haven't tested 32-bit compat tasks or hardware-cycle sampling.
> 
> Tested-by: Magnus Lindholm <linmag7@gmail.com>
> 
> Thanks,
> Magnus

Thanks for testing,
Stian
Re: [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks
Posted by Ian Rogers 16 hours ago
On Wed, Sep 23, 2026 at 2:04 AM Stian Halseth <stian@itx.no> wrote:
>
> This adds HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP to sparc64, so
> that perf record --call-graph dwarf and elfutils' eu-stackprof work
> there.
>
> Two things about the user stack dump do not fit in arch code. The
> sampled register window's %l/%i registers, which hold the frame pointer
> and return address the unwinder starts from, stay in the register file
> until a window spills. The kernel already flushes them wherever it
> exposes user stack memory (perf_callchain_user(), ptrace), but the stack
> dump has no arch entry point where that could happen. And a 64-bit
> sparc stack pointer is biased by 2047, so a dump that starts at the
> register value begins 2047 bytes below the frame, and is empty when that
> page has never been touched.
>
> Patch 1 therefore adds two hooks in the style of perf_arch_misc_flags(),
> both no-ops by default. Patch 2 is the sparc64 implementation and their
> user. Patch 3 teaches tools/perf the sparc registers and DWARF unwinding
> from the dump. The matching elfutils changes are attached to the
> tracking issue:
>
>   https://github.com/sparclinux/issues/issues/99
>
> Tested on an UltraSPARC T4-1 on 7.3-rc4: register values check out
> against known contents, --call-graph dwarf unwinds correctly for both
> cycles and cpu-clock, as does eu-stackprof, and perf stat/record/record
> -g are unchanged. Starting the dump at the stack's actual address
> matters in practice: with the dump at the biased register value, 94% of
> the user samples of xz -T4 had an empty stack dump; with this series,
> none do.
>
> Changes since v2:
> - Patch 1: add perf_arch_user_stack_pointer(), so an arch can start the
>   dump at the stack's actual address (sashiko review).
> - Patch 2: drop %g0 from the uapi, as trap entry does not save it; the
>   PC takes its slot, as on mips and loongarch (sashiko review).
> - Patch 2: start the dump at %sp + 2047 for a 64-bit stack (sashiko
>   review).
> - Patch 3: follow both, and comment the max_dwarf_reg adjustment (Ian).
>   Drop the memcpy() change to memory_read(), which the unbiased dump
>   start makes unnecessary.
>
> v2: https://lore.kernel.org/all/20260922201507.1719668-1-stian@itx.no/
> v1: https://lore.kernel.org/all/20260922135653.1622301-1-stian@itx.no/
>
> Stian Halseth (3):
>   perf/core: Let an arch prepare and locate the user stack dump
>   sparc64: Support PERF_SAMPLE_REGS_USER and PERF_SAMPLE_STACK_USER
>   perf tools: Support sparc user register samples and dwarf unwinding

For the series:

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks!
Ian

>  .../features/perf/perf-regs/arch-support.txt  |  2 +-
>  .../perf/perf-stackdump/arch-support.txt      |  2 +-
>  arch/sparc/Kconfig                            |  2 +
>  arch/sparc/include/asm/perf_event.h           |  5 ++
>  arch/sparc/include/uapi/asm/perf_regs.h       | 34 +++++++++
>  arch/sparc/kernel/Makefile                    |  2 +-
>  arch/sparc/kernel/perf_regs.c                 | 74 +++++++++++++++++++
>  include/linux/perf_event.h                    | 11 +++
>  kernel/events/core.c                          |  2 +
>  kernel/events/internal.h                      |  2 +-
>  tools/arch/sparc/include/uapi/asm/perf_regs.h | 34 +++++++++
>  tools/perf/arch/sparc/include/perf_regs.h     | 18 +++++
>  tools/perf/check-headers.sh                   |  1 +
>  tools/perf/util/dwarf-regs-arch/Build         |  1 +
>  .../util/dwarf-regs-arch/dwarf-regs-sparc.c   | 12 +++
>  tools/perf/util/dwarf-regs.c                  |  4 +
>  tools/perf/util/include/dwarf-regs.h          |  1 +
>  tools/perf/util/perf-regs-arch/Build          |  1 +
>  .../util/perf-regs-arch/perf_regs_sparc.c     | 67 +++++++++++++++++
>  tools/perf/util/perf_regs.c                   | 18 +++++
>  tools/perf/util/perf_regs.h                   |  5 ++
>  tools/perf/util/unwind-libdw.c                | 37 ++++++++++
>  22 files changed, 331 insertions(+), 4 deletions(-)
>  create mode 100644 arch/sparc/include/uapi/asm/perf_regs.h
>  create mode 100644 arch/sparc/kernel/perf_regs.c
>  create mode 100644 tools/arch/sparc/include/uapi/asm/perf_regs.h
>  create mode 100644 tools/perf/arch/sparc/include/perf_regs.h
>  create mode 100644 tools/perf/util/dwarf-regs-arch/dwarf-regs-sparc.c
>  create mode 100644 tools/perf/util/perf-regs-arch/perf_regs_sparc.c
>
> --
> 2.55.0
>
Re: [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks
Posted by Stian Halseth 16 hours ago
Hi Ian,

On Wed, 2026-09-23 at 13:38 -0700, Ian Rogers wrote:
> 
> 
> For the series:
> 
> Reviewed-by: Ian Rogers <irogers@google.com>
> 

Since this series is still marked RFC, should I resend it as a regular
PATCH v4 with your Reviewed-by, or wait for additional maintainer
feedback?

And thank you so much for the reviews!

Stian
Re: [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks
Posted by Ian Rogers 15 hours ago
On Wed, Sep 23, 2026 at 1:57 PM Stian Halseth <stian@itx.no> wrote:
>
> Hi Ian,
>
> On Wed, 2026-09-23 at 13:38 -0700, Ian Rogers wrote:
> >
> >
> > For the series:
> >
> > Reviewed-by: Ian Rogers <irogers@google.com>
> >
>
> Since this series is still marked RFC, should I resend it as a regular
> PATCH v4 with your Reviewed-by, or wait for additional maintainer
> feedback?
>
> And thank you so much for the reviews!

I think we have everything we need but the kernel changes are really
up to Peter and Ingo, and the tool changes are up to Arnaldo and
Namhyung.

Thanks,
Ian

> Stian