From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792506951; b=sRYwyVmgOoIFfRLraylxxoQjJp7YwW4oC6ENA2W6zot5NDFwgVqd5RVCpMfCjYrXoBbi G3f+BsJBv13o1ht+pKcKLNLnNcUqDqCFvZlUH++Td3eLTAx3grfx3Gu8OnFOuNNgQCLvK M7Y3y4RitMEhkfba4JGmTGrFcf0wMCLGtX6wF+BdziXOJr6ZenIReVuLL8QAPxxcypJho vNhns9CbANBr9x0j6fDuaCLSioe2qVdKCQKEn7BPGq/8ukT3uALBWyhMbygiP9JdYn2Ur MW4dfPF77p9yv2Xg94VP3YPfuvIh05EeBowkkNPDJ9ykcSap/Tfg6OxSjpjYEARiZTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792506951; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=v4Iip/s7oVuzCnYoFEs3DZuJtsQZW95G7/pZOVyPUeg=; b=fvXwquD94cCFpQdy7jzo+wjMiTUSqEQ252YfDhqbhEyN6RECBsCy5/oN2VpsNXZdS+8Z qmkXM5QF0QG8Wq70MoNemEbZwcdk/7KXnq1eOG7NLdEnvf9Sz6aDQIljEcpL4Pg4fJGBH 21nD+ijvNq1XGg3MPPbGDwruhe3B5zO6XfikHwp0firn71HU+S6BLFjEDlRZ6nojS3Vhg gevMApgqB+qb5yILw4Bge7m99qlikq4IO8mEVJHopzd1x7YU6dcTuFcYcQiQhk+DLjj2l F77wjHPuxbMCswYQSirj8APoZwNOeY4+Y7E/UHFj9Jrtk/6QOyyuKnz1ISEc2s4BdTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b="Crh/ID8A"; arc=none smtp.remote-ip=209.85.128.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B20DE606A31C for ; Tue, 20 Oct 2026 14:35:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B20DE606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Crh/ID8A Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4a1cef0439aso36554215e9.0 for ; Tue, 20 Oct 2026 07:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1792506944; x=1793111744; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=v4Iip/s7oVuzCnYoFEs3DZuJtsQZW95G7/pZOVyPUeg=; b=Crh/ID8Ae/mzmaKeyac7ZP6EU8IT41BFrMx83893X+9GKQ/4/sNMSub7qoxtpc6PG2 6m8nyvMShtOtuG8PglZayW9ZC20K8aBxUW9ZnrETWBjnRAJx054aTSvOMZ9/DquOCe8V //W8RY/1bu7/oJgXw/rzX6osp4vPiZ+/okA5I3PnL7yVoAYddKGJJTK/4A07b7nmcf1N a2raJUfdcCOx97Yc6BVkEoO3hi7nE9yzRpJ/L7gmUTWs7HZIcTprsTULjzmjka22E3AC Bqw+TJf11lg1BUbe/RTeWDkwj1yLorw6KjuY2eXVLPuyCejS4VruRX/k4qHQmT8Wya6J Rg6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792506944; x=1793111744; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=v4Iip/s7oVuzCnYoFEs3DZuJtsQZW95G7/pZOVyPUeg=; b=UhVCjcxEAuOFtwWPdb4Oe8C+ZURlNMQml1L8RZdHRCf+OfAknVQXyVPP+94eoSpmbL DwPfuSdowPfICAjI4xAy5tMX3HRSEkZjK9iJuZYfwkJXnGx0DUqAJuLwGlYFyd8cTJ9x GGMKbRxRrdrs9hB2czFtHtF8l5sMgSriBe76VaYlodO1/b+2bOxuEAo933z6DzoLq0YG l71iDl8Mjwn+K0JB2G/4H0B3bMcOTQJhmlqNHrVfvzUM+/kwjIb2E40RQbw0+sW8M47k oN6dK3vkBrAITqDU5RM7Pi7YN8CW6ctFPIRtFwx5X79MPDo6SNLNEIy8FJSMABBk141/ G8Vw== X-Forwarded-Encrypted: i=1; AKwUvBxd5oFAiy2D76figpWi2j2jTnYOsaR9uzDrYAWzchU0ierZ9voIvcSdI6mQ8uhh6W89BHoj5guyhrg=@vger.kernel.org X-Gm-Message-State: AFq9FYJX1CsnbpXgXsAKW5w1OT42LY3jBlX27SnSUfYlr7ZKY+RN61ui GdqvGLCVAlq6DTefoAiiun7KhnQpD8RRTOS7KyaCah8ASRLyg6cd+A0KnVj2cKOzUHo= X-Gm-Gg: AYBFou2EYSMXi8M91nrbioiJLWKkTXXZHPIK4Iu4firMS5YfPhudApsfomAeJU5oiWi RiyewRgin7clgFWgdFJMOzlVfT1IWtV2+ifXV7nYCayzdlaEuKsUDjjkytasxHCj/LRpw+qGFet Mu6XByBnt3A4kcux/Ov2BJMhjrtjjeOSfOoHI/RHzlj918yvY5gMZ2d/cBKC9hQbe+l6H0ygxzd Odo7V8K3GpkEizt3J7DnCWuLJD8nuKbm/DOq9TeVlni3vyEH4ITJ/avGe8cCLljTXccr0zg3GmM v0lbO1+Y0ZbOA4Ue0neO5sGRfnjXAW50rAgquYb5ZOxzKqtKhXnMzHRrJwe++GfgWoXCS3B7G+7 J88GmKmYjG4wOSpq+qgZSBKKRMOy4Nwr/bNUBDE5yhXaW2wgdR802zGQrQVAB1qfaUmF6LfL2at hjA4E0+WBD4aMZQMiS4XqsRxBSpk8OEAOlDvdUE8nZ4EuAEX0KlDqCG2iZi5A3Y0pHmP3aHmr3u WZG21Gzvt76xA== X-Received: by 2002:a05:600c:8709:b0:4a1:7b05:3a6d with SMTP id 5b1f17b1804b1-4a1d75e6fa6mr206342555e9.8.1792506943206; Tue, 20 Oct 2026 07:35:43 -0700 (PDT) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a1f2d6e2dbsm82506805e9.13.2026.10.20.07.35.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Oct 2026 07:35:42 -0700 (PDT) Message-ID: <0792487e-b6fc-4b9d-8120-83281a15217c@linaro.org> Date: Tue, 20 Oct 2026 15:35:41 +0100 X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 24/25] perf test: Add CoreSight AUX sample decoding test To: Leo Yan Cc: Ingo Molnar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , Anshuman Khandual , Yeoreum Yun , Jonathan Corbet , Suyash Mahar , Amir Ayupov References: <20260915-arm_cs_support_aux_sample-v1-0-35cf6f297d20@arm.com> <20260915-arm_cs_support_aux_sample-v1-24-35cf6f297d20@arm.com> Content-Language: en-US From: James Clark In-Reply-To: <20260915-arm_cs_support_aux_sample-v1-24-35cf6f297d20@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 15/09/2026 16:49, Leo Yan wrote: > Add a shell test that records the brstack workload with 8 KiB AUX > samples attached to cycle events. Pin the workload to a CPU with a TRBE > sink and use per-thread recording with trace timestamps and context IDs > disabled, exercising decoding with the owning sample's context. > > Check branch stacks and callchains with --itrace=L4, L64, G3 and G3L64. > Require at least one sample to reach both requested depths, with all > callchain frames belonging to the workload, and reject samples exceeding > either limit. Use a callchain depth of three to match the nested calls > in brstack. > > Compare with AUX decoding enabled and disabled to verify that adding > history preserves the original PMU samples. > > Assisted-by: Codex:gpt-6 > Signed-off-by: Leo Yan > --- > tools/perf/tests/shell/coresight/aux_sample.sh | 189 +++++++++++++++++++++++++ > 1 file changed, 189 insertions(+) > > diff --git a/tools/perf/tests/shell/coresight/aux_sample.sh b/tools/perf/tests/shell/coresight/aux_sample.sh > new file mode 100755 > index 0000000000000000000000000000000000000000..887ad6a085eacdfd192db3863fbb61dae1aa19b5 > --- /dev/null > +++ b/tools/perf/tests/shell/coresight/aux_sample.sh > @@ -0,0 +1,189 @@ > +#!/bin/bash -e > +# SPDX-License-Identifier: GPL-2.0 > +# CoreSight AUX samples with callchains and branch stacks (exclusive) > + > +export LC_ALL=C > + > +skip() > +{ > + echo "[Skip] $1" > + exit 2 > +} > + > +perf list pmu | grep -q 'cs_etm//' || skip "cs_etm is not available" > +perf check feature -q libopencsd || skip "perf was built without OpenCSD" > +[ "$(id -u)" = 0 ] || skip "No root permission" > +command -v taskset >/dev/null || skip "taskset is not available" > + > +# AUX sample now supports per CPU sink (e.g., TRBE). Select a usable CPU > +# and name its sink explicitly to avoid a shared sink. > +sink= > +for dev in /sys/bus/coresight/devices/trbe[0-9]*; do > + [ -d "$dev" ] || continue > + name=${dev##*/} > + cpu=${name#trbe} > + [ -e "/sys/bus/event_source/devices/cs_etm/cpu$cpu" ] || continue > + if taskset -c "$cpu" true 2>/dev/null; then > + sink=$name > + break > + fi > +done > +[ -n "$sink" ] || skip "No usable TRBE CPU is available" > + > +tmpdir=$(mktemp -d /tmp/perf-cs-aux-sample.XXXXXX) > + > +cleanup() > +{ > + rm -rf "$tmpdir" > +} > + > +trap cleanup EXIT > +trap 'exit 1' TERM INT > + > +fail() > +{ > + echo "$1" >&2 > + cat "$tmpdir/stderr" >&2 > + exit 1 > +} > + > +cf="$tmpdir/ctl" > +af="$tmpdir/ack" > +mkfifo "$cf" "$af" > + > +# Disable trace timestamps and context IDs to use the owning sample's context. > +# Use a per-thread mmap so the explicit sink is only used on the pinned CPU. > +if ! taskset -c "$cpu" perf record -o "$tmpdir/data" --aux-sample=8192 \ > + -e "{cs_etm/@$sink,timestamp=0,contextid=0/u,cycles/period=100003/u}" \ > + --per-thread -D -1 --control fifo:"$cf","$af" -- \ Minor nit, but on "[PATCH 00/14] perf cs-etm: Per-thread mode fixes and snapshot wrap support" I just did: +if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then + echo "No TRBE sinks, skipping output validation" + exit 0 +fi I know looking up the actual sink, passing it in and also using --per-thread mode is "technically correct", but I think we can assume that any normal record command will work on any system with TRBE. Otherwise, we should re-write all of the tests to only target CPUs with known loaded ETM instances instead of hard coding CPU 0 etc. Other than that LGTM: Reviewed-by: James Clark > + perf test --record-ctl fifo:"$cf","$af" -w brstack 1000000 \ > + >/dev/null 2>"$tmpdir/stderr"; then > + # Kernels without snapshot_aux reject the sampling event at open time. > + if grep -Eq 'sys_perf_event_open.*event \(.*cycles.*\): Invalid argument' \ > + "$tmpdir/stderr"; then > + skip "Kernel does not accept CoreSight AUX sampling" > + fi > + fail "Failed to record CoreSight AUX samples" > +fi > + > +perf evlist -v -i "$tmpdir/data" >"$tmpdir/evlist" 2>"$tmpdir/stderr" || > + fail "Failed to read AUX sample attributes" > +grep -Eq 'sample_type:.*\|AUX(,|\|).*aux_sample_size: 8192(,|$)' \ > + "$tmpdir/evlist" || fail "Missing AUX sample attributes" > + > +check_history() > +{ > + local options=$1 > + local max_branches=$2 > + local max_callchains=$3 > + local output="$tmpdir/script-$options" > + > + perf script -i "$tmpdir/data" --itrace="$options" \ > + -F comm,pid,tid,cpu,event,ip,sym,brstack >"$output" \ > + 2>"$tmpdir/stderr" || fail "Failed to decode AUX samples with $options" > + > + # Some windows may contain incomplete trace. Require at least one cycle > + # sample to reach both requested depths, and reject any that exceed them. > + if ! awk -v max_branches="$max_branches" \ > + -v max_callchains="$max_callchains" ' > + function check_sample() { > + if (in_sample == 0) { > + return > + } > + > + if (branch_entries > max_branches || callchain_frames > max_callchains) { > + depth_exceeded = 1 > + } > + > + # Both depths must be reached in the same sample, with all > + # callchain frames belonging to the brstack workload. > + if (branch_entries == max_branches && > + callchain_frames == max_callchains && > + workload_frames == max_callchains) { > + found_sample = 1 > + } > + > + branch_entries = 0 > + callchain_frames = 0 > + workload_frames = 0 > + in_sample = 0 > + } > + { > + # A blank line marks the end of a sample. > + if (NF == 0) { > + check_sample() > + next > + } > + > + # Sample header: comm pid/tid [cpu] event ... > + # The event may include a PMU prefix and configuration terms. > + if ($4 ~ /(^|\/)cycles([,\/:]|$)/) { > + check_sample() > + in_sample = 1 > + } > + if (in_sample == 0) { > + next > + } > + > + # Each branch entry is a field in 0xFROM/0xTO/... form. > + for (i = 1; i <= NF; i++) { > + if ($i ~ /^0x[[:xdigit:]]+\/0x[[:xdigit:]]+\//) { > + branch_entries++ > + } > + } > + > + # Callchain rows start with a hexadecimal IP, then a symbol. > + if ($1 ~ /^[[:xdigit:]]+$/) { > + callchain_frames++ > + if ($2 ~ /^brstack(_|$)/) { > + workload_frames++ > + } > + } > + } > + END { > + # Account for the last sample even without a trailing blank line. > + check_sample() > + > + if (depth_exceeded != 0) { > + print "AUX sample history exceeds the requested depth" > "/dev/stderr" > + exit 1 > + } > + if (found_sample == 0) { > + printf "No sample has %d branches and %d workload callchain frames\n", \ > + max_branches, max_callchains > "/dev/stderr" > + exit 1 > + } > + exit 0 > + } > + ' "$output"; then > + head -n 80 "$output" >&2 > + fail "Missing AUX sample history or incorrect depth with $options" > + fi > +} > + > +check_sample_identity() > +{ > + local fields=comm,pid,tid,cpu,event,ip > + > + # Hiding history must leave exactly the original PMU samples, including > + # their PID/TID, CPU and sampled IP, with no synthesized events. Per-thread > + # recording does not require sample timestamps. > + perf script -i "$tmpdir/data" --no-itrace -F "$fields" \ > + >"$tmpdir/original" 2>"$tmpdir/stderr" || fail "Failed to read cycle samples" > + perf script -i "$tmpdir/data" --itrace=L4 -F "$fields" \ > + >"$tmpdir/decoded" 2>"$tmpdir/stderr" || fail "Failed to decode cycle samples" > + diff -u "$tmpdir/original" "$tmpdir/decoded" || > + fail "AUX decoding changed the original cycle samples" > +} > + > +check_history L4 4 0 > +check_history L64 64 0 > + > +# brstack -> brstack_bench -> brstack_foo -> brstack_bar provides three > +# nested calls whose caller frames can be reconstructed from an AUX window. > +check_history G3 0 3 > +check_history G3L64 64 3 > + > +check_sample_identity > + > +echo "CoreSight AUX sample decoding: PASS" >