Fix a few issues with per-thread mode:
- On nVHE, everything looks like guest trace instead of host
- Tracing multiple threads didn't really work
After adding a tests for those, it turns out there were some snapshot
bugs not picked up by the other snapshot tests. That showed that the
different snapshot searches for Intel BTS and Arm SPE were inconsistent
and I think all tracers can benefit from using the same pointer fixup
logic, so that gets refactored into the common auxtrace.c. Then SPE can
just share the Intel BTS search as it was obviously copied from it
originally. IntelPT keeps the more advanced duplicate data search, but
in the future that could probably be made the common one and all tracers
would benefit from using it (except maybe BTS if it always has a very
small buffer, but I doubt the overhead of the duplicate search would be
an issue). For now this is more of a refactor rather than behavioral
change so don't do that yet.
Signed-off-by: James Clark <james.clark(a)linaro.org>
---
Changes in v5:
- Rebase onto tmp.perf-tools-next to resolve conflict with commit
e48155a1bbf1 ("perf intel-bts: Free the old snapshot reference array
after growing it"). The new shared snapshot search also has the fix.
- Drop dependency that has already been applied.
- Link to v4: https://patch.msgid.link/20261105-james-cs-unformatted-per-thread-fix-v4-0-…
Changes in v4:
- Change test snapshot size to 128K for 64K machines
- Put patchset depencency in cover letter text
- Link to v3: https://patch.msgid.link/20261102-james-cs-unformatted-per-thread-fix-v3-0-…
Changes in v3:
- Keep the find_snapshot() callback instead of adding
snapshot_has_wrapped() and monotonic_snapshot_head boolean (Adrian)
- Add auxtrace_record__default_find_snapshot() for the simple search for
BTS and SPE (Adrian)
- Add auxtrace_record__snapshot_fixup() for any snapshot search
implementation to use to update the pointers (Adrian)
- Reword UINT64_MAX timestamp comment (Leo)
- Fix disassembly test after rebasing onto exception sample fixes
- Only take 'perf_guest' into account if there is no PIDFMT_CTXTID2
- Improve decoding of old files by hard coding queue 0 for per-thread
- Link to v2: https://patch.msgid.link/20260821-james-cs-unformatted-per-thread-fix-v2-0-…
Changes in v2:
- Remove stale "may be reset to -1 in per-thread mode" comment
- Set CPU when queueing auxtrace fragments otherwise
auxtrace_queues__add_event() overwrites the queue's CPU
- Link to v1: https://patch.msgid.link/20260811-james-cs-unformatted-per-thread-fix-v1-0-…
---
James Clark (19):
perf cs-etm: Fix nVHE per-thread decoding
perf cs-etm: Warn for invalid timestamp option
perf cs-etm: Turn on context packet timestamps in per-thread mode
perf cs-etm: Use per-CPU queues for per-thread mode
perf test: cs-etm: Increase window size in disassembly test
perf cs-etm: Don't drop previous target for kernel samples
perf python: Expose sample instruction length
perf cs-etm: Use instruction length in disassembly script
perf cs-etm: Increase default timestamp generation period
perf auxtrace: Turn Intel BTS snapshot search into a generic one
perf arm-spe: Use generic snapshot search
perf auxtrace: intel-pt: Use common snapshot pointer fixup
perf cs-etm: Queue partial AUX records
perf cs-etm: Don't print missing buffers in snapshot mode
perf auxtrace: cs-etm: Capture wrapped snapshots
perf test: Allow infinite named_thread loops
perf test: cs-etm: Add test for per-thread mode
perf test: cs-etm: Test multiple per-thread threads
perf test: cs-etm: Increase snapshot size
tools/perf/Documentation/perf-test.txt | 2 +-
tools/perf/arch/arm/util/cs-etm.c | 34 ++++-
tools/perf/arch/arm64/util/arm-spe.c | 147 +--------------------
tools/perf/arch/x86/util/intel-bts.c | 116 +---------------
tools/perf/arch/x86/util/intel-pt.c | 21 +--
tools/perf/python/arm-cs-trace-disasm.py | 22 +--
tools/perf/python/perf.pyi | 1 +
.../perf/tests/shell/coresight/per-thread-multi.sh | 76 +++++++++++
tools/perf/tests/shell/coresight/per-thread.sh | 48 +++++++
.../perf/tests/shell/coresight/raw_dump_stress.sh | 5 -
.../shell/coresight/test_arm_coresight_disasm.sh | 8 +-
tools/perf/tests/workloads/named_threads.c | 7 +-
tools/perf/util/auxtrace.c | 145 +++++++++++++++++++-
tools/perf/util/auxtrace.h | 18 +++
tools/perf/util/cs-etm.c | 113 +++++++++++-----
tools/perf/util/python.c | 1 +
16 files changed, 420 insertions(+), 344 deletions(-)
---
base-commit: 4a7008f739a30ee4c22d9f21af362a5128f2628d
change-id: 20260605-james-cs-unformatted-per-thread-fix-50e723aa7f0e
Best regards,
--
James Clark <james.clark(a)linaro.org>
On 30/11/2026 09:22, Jie Gan wrote:
> The crash data interface is registered after the out label of
> __tmc_probe(), which every error path jumps to. When the probe fails
> while the reserved regions hold valid crash data,
> is_tmc_crashdata_valid() and tmc_prepare_crashdata() log through
> drvdata->csdev, which is then NULL, an error pointer or an unregistered
> device, and register_crash_dev_interface() can register a misc device
> whose driver data is freed when the probe failure is unwound.
>
> Only register the crash data interface once the probe has succeeded.
>
> Fixes: d58a70bdab57 ("coresight: tmc: Add support for reading crash data")
> Reported-by: Sashiko <sashiko-bot(a)kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-f23df7b7-bae5-4fa0-96ef-4e83632058e8
> Signed-off-by: Jie Gan <jie.gan(a)oss.qualcomm.com>
> ---
> drivers/hwtracing/coresight/coresight-tmc-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
> index 0ef4b817b297..754a9b10b7d2 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
> @@ -880,10 +880,10 @@ static int __tmc_probe(struct device *dev, struct resource *res)
> goto out;
> }
>
> -out:
> if (is_tmc_crashdata_valid(drvdata) &&
> !tmc_prepare_crashdata(drvdata))
> register_crash_dev_interface(drvdata, desc.name);
> +out:
> return ret;
> }
>
>
Goto for retuning just the error code, doesn't look like a good
practice. Please could we fix all goto out with return ?
See:
"The goto statement comes in handy when a function exits from multiple
locations and some common work such as cleanup has to be done. *If there
is no cleanup needed then just return directly.*"
https://www.kernel.org/doc/html/latest/process/coding-style.html#centralize…
Cheers
Suzuki
On Fri, Nov 27, 2026 at 06:42:35PM +0000, Will Deacon wrote:
> > @@ -487,8 +487,11 @@ static void arm_spe_pmu_pad_buf(struct perf_output_handle *handle, int len)
> > u64 head = PERF_IDX2OFF(handle->head, buf);
> >
> > memset(buf->base + head, ARM_SPE_BUF_PAD_BYTE, len);
> > - if (!buf->snapshot)
> > + if (!buf->snapshot) {
> > + /* Order the padding stores before publishing the new aux_head. */
> > + smp_wmb();
> > perf_aux_output_skip(handle, len);
> > + }
>
> This looks correct to me, but I wonder if it should be handled by
> perf_aux_output_skip() instead? arm_spe_pmu_pad_buf() is called from a
> bunch of places in the driver, including in conjunction with
> perf_aux_output_end(), which looks like it already has the necessary
> memory barrier. So doing it here seems weird inconsistent to me.
As I mentioned in the cover letter, the choice of barrier depends on the
CPU memory model and the trace hardware. Perf deliberately leaves that
choice to the AUX driver [1].
SPE driver implicitly relies on the dsb(nsh) in
arm_spe_pmu_disable_and_drain_local() to make trace writes visible
before calling perf_aux_output_end(). I kept the barrier in the driver
for perf_aux_output_skip() to follow the same convention.
Thanks,
Leo
[1] https://lore.kernel.org/all/YLUFMzxin1PpgIdZ@hirez.programming.kicks-ass.ne…
This series follows the earlier TRBE buffer refactoring posting [1].
The work is now split into two parts. This first part contains fixes
and refactoring in preparation for wrap and trigger mode support.
Support for those modes will be sent separately.
The patches are grouped as follows for easier review:
Patches 1-5: Minor fixes
Add register definitions, fix the watermark range check, and
improve erratum checks and perf handle validation.
Patches 6-11: Enable/disable lifecycle fixes
Clean up session setup, status clearing and IRQ handle ownership.
Patches 12-17: Refine status classification
Decode stop reasons, report truncation on errors and improve
trace-size accounting.
Patches 18-23: Improve IRQ and overflow handling
Keep the handle in per-CPU data, stabilize status reads, and
improve AUX restarts and trace-gap reporting.
A race also remains between TRBE interrupt handling and AUX pause/resume
from a sampling NMI. This should be resolved as part of the state
machine refactoring in the CoreSight AUX sampling series [2].
[1] https://lore.kernel.org/linux-arm-kernel/20251201-trbe_buffer_refactor_v1-1…
[2] https://lore.kernel.org/linux-arm-kernel/20260915-arm_cs_support_aux_sample…
Signed-off-by: Leo Yan <leo.yan(a)arm.com>
---
Leo Yan (23):
arm64/sysreg: Define TRBSR_EL1.EC event classes
coresight: trbe: Make watermark range check overflow safe in __trbe_normal_offset()
coresight: trbe: Use helpers for checking errata
coresight: trbe: Check the buffer association before IRQ validation
coresight: trbe: Validate perf handle before using sink data
coresight: trbe: Drop redundant disable from enable path
coresight: trbe: Publish the session after successful enable
coresight: trbe: Clear stale external abort status
coresight: trbe: Clear TRBSR status at stop sites
coresight: trbe: Drop redundant disables
coresight: trbe: Assign the perf handle in enable and disable
coresight: trbe: Decode TRBSR status codes
coresight: trbe: Simplify wrap status handling
coresight: trbe: Treat access not allowed stops as fatal
coresight: trbe: Report truncated trace on buffer update errors
coresight: trbe: Always classify TRBSR when updating buffer
coresight: trbe: Calculate trace size across buffer wrap
coresight: trbe: Keep the perf handle in per-CPU data
coresight: trbe: Reload the AUX buffer on overflow restart
coresight: trbe: Add fault action argument to trbe_handle_overflow()
coresight: trbe: Read TRBSR after prohibiting and flushing trace
coresight: trbe: Restart trace source for stopped buffers
coresight: trbe: Report trace gaps with PARTIAL instead of COLLISION
arch/arm64/include/asm/sysreg.h | 6 +
arch/arm64/tools/sysreg | 8 +-
drivers/hwtracing/coresight/coresight-trbe.c | 481 ++++++++++++++++++---------
drivers/hwtracing/coresight/coresight-trbe.h | 8 -
4 files changed, 345 insertions(+), 158 deletions(-)
---
base-commit: 343cfcbb3ecfdb80aa576a428cfa3b65ad783842
change-id: 20261016-trbe_enable_disable_irq_handle_refactor-0a3450f03473
Best regards,
--
Leo Yan <leo.yan(a)arm.com>
On 27/11/2026 11:31, Qianhui Xu wrote:
> Hi,
>
> both the CTCU and the TPDA driver are matched through an ID table, but
> neither exports that table, so building them as modules produces a
> module without an "of:" / "amba:" modalias. udev cannot autoload such a
> module, and the device stays unbound until somebody loads it by hand.
>
> This was found on an SM8750 based phone (mainline v7.3.1,
> CONFIG_CORESIGHT_CTCU=m and CONFIG_CORESIGHT_TPDA=m):
>
> # lsmod | grep -c coresight_ctcu
> 0
> # modinfo -F alias coresight-ctcu
> (empty)
> # modprobe coresight-ctcu && readlink -f /sys/bus/platform/devices/10001000.ctcu/driver
> .../drivers/coresight-ctcu
>
> Five tpda devices behave the same way. With this series applied the
> modules carry "of:N*T*Cqcom,sa8775p-ctcu" and "amba:d???F0F??" aliases,
> and on the next boot both autoload with no modules-load.d help at all:
>
> # lsmod | grep -E 'coresight_(ctcu|tpda)'
> coresight_ctcu 16384 0
> coresight_tpda 24576 0
> # for f in /sys/bus/amba/devices/*; do [ -e $f/driver ] || n=$((n+1)); done; echo $n
> 0
>
> There is no functional change for built-in builds; MODULE_DEVICE_TABLE()
> is only used for module aliases.
>
> *** AI-assistance disclosure ***
> This series was prepared with the help of an LLM coding assistant. The
> author reviewed every line, reproduced the before/after behaviour on
> hardware and is responsible for the content.
>
> Signed-off-by: Qianhui Xu <xiaqinghuan(a)mail.ustc.edu.cn>
>
> Qianhui Xu (2):
> coresight: ctcu: add missing MODULE_DEVICE_TABLE()
> coresight: tpda: add missing MODULE_DEVICE_TABLE()
>
> drivers/hwtracing/coresight/coresight-ctcu-core.c | 1 +
> drivers/hwtracing/coresight/coresight-tpda.c | 1 +
> 2 files changed, 2 insertions(+)
>
Could probably do with fixes: tags for both commits, but:
Reviewed-by: James Clark <james.clark(a)linaro.org>
On 26/11/2026 15:57, Yige Jiang wrote:
> _tnoc_probe() parses the output connections before allocating driver
> data, enabling clocks, mapping registers and setting up the trace ID.
> If any of these steps fails, probe returns before coresight_register()
> can take ownership of the destination fwnode references.
>
> Get the platform data after trace ID setup. On either lookup or
> registration failure, return the ID if the AMBA device acquired one.
> The platform-device variant does not allocate a trace ID.
>
> Codex helped trace the two probe paths and draft their shared cleanup.
>
> Fixes: e54a52a28a36 ("coresight: add coresight Trace Network On Chip driver")
> Suggested-by: James Clark <james.clark(a)linaro.org>
> Signed-off-by: Yige Jiang <yigejiang86(a)gmail.com>
> ---
> v2: Add the TNOC fix identified during review of the TPDM patch.
>
The threading is broken for the patchset. Check out the b4 tools, they
handle patch creation and sending properly.
On 26/11/2026 17:56, Will Deacon wrote:
> On Fri, 16 Oct 2026 17:54:58 +0100, Leo Yan wrote:
>> This series follows the earlier TRBE buffer refactoring posting [1].
>> The work is now split into two parts. This first part contains fixes
>> and refactoring in preparation for wrap and trigger mode support.
>> Support for those modes will be sent separately.
>>
>> The patches are grouped as follows for easier review:
>>
>> [...]
>
> Applied sysregs update to arm64 (for-next/sysregs), thanks!
>
> [01/23] arm64/sysreg: Define TRBSR_EL1.EC event classes
> https://git.kernel.org/arm64/c/9d3009259f0a
>
> NOTE: I included the asm/sysreg.h change from patch 12 as well and added
> a comment noting that the BSC encodings only apply for "Other" buffer
> management events. Ideally, we'd be able to namespace those in the
> sysreg file for each of the MSS2 encodings but I couldn't figure out an
> easy way to do that.
>
> Cheers,
Thank you Will, much appreciated ! We can sort out the auto generation
in a separate patch. I believe we do it for some other sysreg already.
Cheers
Suzuki
On 26/11/2026 15:24, Will Deacon wrote:
> On Thu, Nov 26, 2026 at 10:24:17AM +0000, Suzuki K Poulose wrote:
>> Catalin, Will,
>>
>>
>> On 16/10/2026 17:54, Leo Yan wrote:
>>> TRBSR_EL1.EC identifies the cause of a trace buffer management event,
>>> but the sysreg description does not name its architected values. Define
>>> the five encodings as an unsigned enum so TRBE status handling can
>>> refer to each cause by name.
>>>
>>> The values cover other events, Granule Protection Check faults,
>>> implementation-defined events, and stage 1 and stage 2 Data Aborts on
>>> writes to the trace buffer, as specified by Arm ARM (ARM DDI 0487 M.c).
>>>
>>> Signed-off-by: Leo Yan <leo.yan(a)arm.com>
>>
>> Are you ok with me taking this via the coresight tree ?
>
> The sysregs file gets updated quite regularly, so let me stick this patch
> on a shared branch for you.
>
Thank you Will !
Cheers
Suzuki
> Will
On 26/11/2026 13:29, Yige Jiang wrote:
> coresight_get_platform_data() takes a reference on the fwnode of each
> output connection's destination. These references are not devres
> managed; the core drops them in coresight_release_platform_data(),
Don't _tnoc_probe(), tpda_probe() and smb_register_sink() have the same
problem? We should fix all of these at the same time if you'd like to
send a V2 with a patch for each driver.
It's quite fragile to have to call this in a certain order in every
probe function though. Doesn't seem like it will survive further changes
or refactoring for very long. Longer term, Leo is working on refactoring
the locking and connections. Maybe can do something like make
coresight_fixup_orphan_conns() re-read the firmware for unconnected
ports and re-connect them, rather keeping these long lived references to
fwnodes.
> called by coresight_register() on failure and by coresight_unregister().
> tpdm_probe() gets the platform data first and then returns directly
> when the drvdata allocation, the MMIO mapping, the dataset setup or the
> device name allocation fails, so these references are leaked. The nodes
> come from the base DT, so this only leaves their refcounts unbalanced
> unless they are dynamically allocated.
>
> Get the platform data just before coresight_register(), after the other
> steps that can fail, as the funnel, replicator and TMC drivers already
> do. Nothing before that point uses it.
>
> Fixes: b3c71626a933 ("Coresight: Add coresight TPDM source driver")
> Signed-off-by: Yige Jiang <yigejiang86(a)gmail.com>
> ---
> Based on linux-next next-20261109 (630059a5a632).
> Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_CORESIGHT=m, CONFIG_CORESIGHT_TPDM=m, CONFIG_COMPILE_TEST=y; baseline and patched coresight-tpdm.o, no new warnings.
> No hardware or runtime test was performed.
> The paths need an allocation failure, an MMIO region already claimed, or a dataset setup failure in tpdm_probe() after the output connections were parsed.
>
> drivers/hwtracing/coresight/coresight-tpdm.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-tpdm.c b/drivers/hwtracing/coresight/coresight-tpdm.c
> index 102b8b7edf87..07e19c1a94b6 100644
> --- a/drivers/hwtracing/coresight/coresight-tpdm.c
> +++ b/drivers/hwtracing/coresight/coresight-tpdm.c
> @@ -1404,11 +1404,6 @@ static int tpdm_probe(struct device *dev, struct resource *res)
> struct coresight_desc desc = { 0 };
> int ret;
>
> - pdata = coresight_get_platform_data(dev);
> - if (IS_ERR(pdata))
> - return PTR_ERR(pdata);
> - dev->platform_data = pdata;
> -
> /* driver data*/
> drvdata = devm_kzalloc_obj(dev, *drvdata);
> if (!drvdata)
> @@ -1444,6 +1439,12 @@ static int tpdm_probe(struct device *dev, struct resource *res)
> desc.name = coresight_alloc_device_name("tpdm", dev);
> if (!desc.name)
> return -ENOMEM;
> +
> + pdata = coresight_get_platform_data(dev);
> + if (IS_ERR(pdata))
> + return PTR_ERR(pdata);
> + dev->platform_data = pdata;
> +
> desc.type = CORESIGHT_DEV_TYPE_SOURCE;
> desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_TPDM;
> desc.ops = &tpdm_cs_ops;
>
> base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
This series fixes the GCC 15 build failure reported by Ian Rogers [1]
(thanks, Ian!).
Two follow-up refactoring patches use the packet’s recorded instruction
size for stack events and centralize error checking for frontend
instruction reads.
[1] https://lore.kernel.org/linux-perf-users/20261030-perf_cs_etm_fix_non_taken…
Signed-off-by: Leo Yan <leo.yan(a)arm.com>
---
Leo Yan (3):
perf cs-etm: Initialize the Thumb instruction buffer
perf cs-etm: Use the packet instruction size for stack events
perf cs-etm: Check frontend instruction reads
tools/perf/util/cs-etm.c | 83 +++++++++++++++++++++++++++++-------------------
1 file changed, 51 insertions(+), 32 deletions(-)
---
base-commit: 4af65363b11fc4fe65fcb497f68bbe4f3e3a4d2c
change-id: 20261113-perf_fix_gcc15_failure-1e31233be802
Best regards,
--
Leo Yan <leo.yan(a)arm.com>