From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BA2C3B1ED1 for ; Tue, 11 Aug 2026 15:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462250; cv=none; b=IpNwBI9K9q7Lg9Tr9+eUpnQl1YZDMtDkUgJfXbrlvEaA/9DrennCxYtVYeC4OM32IF2NAGUaoWiaRkgAHkAoDD3Nh1uRU0UmuIVVMlmt+mROnrPMCWqIOUaa0YarSh0ywS7zOT9h2KNlQPcwDaDoem4Q6qcD05jHPtAqSVVUf1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462250; c=relaxed/simple; bh=Zl8zJhePqsl4XxqWo/nMyVaX7NU6Mei8MsQZ1ECwbYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=h8txJ8E0LWdFSJPpagvNXKsXmAL/tVKRhqPCdcFtCHe2NpRyL0071+s0oU110La2q2H7MEeHiQglRsNxUnKDzT/UPiN7iQjzM4r+ydZYVgeXX+cmymNBp7oLrMhcg4yZUg27Ft1foWJXBd9Q6N+ipFQhJIpebjZs2z4TQfcFgHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=LePHVWpx; arc=none smtp.client-ip=209.85.128.50 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) header.d=linaro.org header.i=@linaro.org header.b="LePHVWpx" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4980fe6b3beso9187805e9.0 for ; Tue, 11 Aug 2026 08:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462248; x=1787067048; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8eAS2yWgoyXdx0wzQOuU1GOQ+foCx6winuzdwJ7kHsY=; b=LePHVWpxkYLyKCWTO+74rzZi8/hUTt7reO4ljIEy2tECBXg70l1+GQ8hlgpSfrMvL9 CcWRLZsE4IW1WLmKLQIlZTTRu4zfGAhRmpxMwzuVRaFOle2bk2qI7723tikA5EWdZMnm TE+OL9/7gjQEg3NALD36FkONH8V3owsP+evCVwlsWVs414uwWI8rdqdKAU2R69CXRl/1 Eazj+q9rZiKUrCDqhhznN4txqqB4/ce/27wcVAcxzN15vX+jY+hPgOyM3acHZr27BxXy F/TiQADgYQrEchq/V1ZAeTiKaWPY37UGPv+mhZPrsoh1+Vxg5SE4+KnWks5b+TAOoVyJ MdvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462248; x=1787067048; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8eAS2yWgoyXdx0wzQOuU1GOQ+foCx6winuzdwJ7kHsY=; b=l7gYguyiTvxG9XysMuhvEEul4L8UEDgRfcGSGXd1XLhWzwK7CvuxOrPAEFJDxeJZ3v zDOJvLHJJTqmzXG1dBJqiBcPhnEyB9/Pu4l35edl1Yqj8UTnT7OMt6V4U0ZNOkymvqL/ skGcH8SyBrDjPVmUs3gJArAADVXrvzH/xvgYhyNRX9y/o0sy7lN5RI2rB0E3ZFe55W0A enmcAtC/LKB1MqQ0xabKKvHtUmDfCT4n6obbT+PXk7iKOcee+lqm/vsMOcPV4srgLPgn qqzia7EfATWvaEkyeKbS2VpGyXsjM1Inpy2odhTacpdYIn+v6prAfi9avCU2jc7bFRKw ewBQ== X-Forwarded-Encrypted: i=1; AHgh+RqlF/rpjMwYxQ5fAg17LLv4vIFGgWemONM45KF+qfM/HQ0bsA1HPhaDUYytam9+qtmlvbsD+n9/CIbcPYs=@vger.kernel.org X-Gm-Message-State: AOJu0YweY2FljK8La25mT3qqhcMotSy0KMd6VjVdwzHrG/ojQ2ZGuOer 4qQdeYjoDqZ0YGePWOXG4vYeyLXp9AK5FgBwycRSmyGX+4IBc8Sss6p0cgBZlPTNMu0= X-Gm-Gg: AR+sD12EIUS8ZSjbVYIV1GLekkVSt8e3sAdRHKkoVRLlmFCaf0YVu3SCmeQn0D3vMSw KBm27F/0WfhEvnlN35NCi2vhPYvi0BuwEnI71aWqWP9bsLJyKETl1/CfiyoFh3sNVtSOUR4YtBB aKJQz+ktGBRd6BEbzd4vv/bqtB8zrLBNFVA6rjZTL8ytSTxW3x/vmOSdzsc6mmjtwwDp0kTVHri 15FsegWmDJLw02Mf7jgYPwx7KlXXDFigEbxD2pQzUMg7TSZ/KL4b8xLTo1O2jdLhbne7B48oy2n n0KRWaaVX7F9iZqjgDsrVwVjeH0BjYyE5gyHJF/pMghZ/0ofB0DezMG59JkgRFkcXst4laxxuen 3Jx6IS7+mdDn9DK77Oqb6fL0mx1U/QODQbekxDP9XcU6UOSudX9e8E0LyfrFXJS1QhFvGT4i0ZK O4qaSKVV+MKHMSlJ1IsrcP49WF0Ljdtdz77EcySQmBANDr21a1QJADlEdVPnMIxPpZ X-Received: by 2002:a05:600c:8b63:b0:495:69eb:27d3 with SMTP id 5b1f17b1804b1-4997a71648fmr13439405e9.8.1786462247498; Tue, 11 Aug 2026 08:30:47 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:46 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:04 +0100 Subject: [PATCH 01/14] perf cs-etm: Fix nVHE per-thread decoding Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-1-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 pid_fmt is unset in per-thread mode because we don't need PIDs, so we can't use it as a hint to determine which EL the host is running at. That results in falling though to the next part where EL1 is treated as guest, which is wrong for nVHE. Fix it by only returning a guest machine when run from perf kvm where a guest image would be provided, which matches existing behavior in other parts of Perf. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 114b3cd2da49..d423f1cb408f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1071,6 +1071,18 @@ static struct machine *cs_etm__get_machine(struct cs= _etm_queue *etmq, if (pid_fmt =3D=3D CS_ETM_PIDFMT_CTXTID) return &etmq->etm->session->machines.host; =20 + /* + * If guest processing hasn't been enabled, also assume everything is + * the host. + * + * This matches Perf's guest handling in machines__find_for_cpumode() + * etc where guest machines are only created and used when perf_guest is + * set. This also guards against accidentally using guest machines when + * pid_fmt can't be used as a hint (per-thread mode). + */ + if (!perf_guest) + return &etmq->etm->session->machines.host; + /* * Not perfect, but otherwise assume anything in EL1 is the default * guest, and everything else is the host. Distinguishing between guest --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE62B3B3C11 for ; Tue, 11 Aug 2026 15:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462252; cv=none; b=EjUgxnqmg7TX5SXKof5Q+ImFba/LM32bWPlT56K8x16c62WdLjRgS7Ej0caEFfpwDcKfH/VnOG/005xVX/nef84h4/87r6ZS/AeePUZqpfY/F36fh7mSL3kboYyrEElOdcR4ybnwv7L63XNALjV8JJbk3+ZWvKzmBp+5CX4QR0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462252; c=relaxed/simple; bh=h2Q0M74fb6yudEF8zDu1K70Lt8wJfWd+FJHyFrYnfK0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mc/2iAIQEVSE0++50FcI3mJFYqAqLhOl+ZP4sEYgFZ3jdc/hofr9FkR+c02djjBanAro2MpGi6EjoiwnPgPrVRMQHup/Idbu+qXkjWMibzesS0uXgMFkXxcrKF5VEu8HBenkKqh8ydlP/eHVLn6Pgmn0Jqa2Fb4uIAjuhXHtW0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=QJXDIZ6t; arc=none smtp.client-ip=209.85.221.53 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) header.d=linaro.org header.i=@linaro.org header.b="QJXDIZ6t" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-47f7027ca11so2123155f8f.3 for ; Tue, 11 Aug 2026 08:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462249; x=1787067049; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zjkcq8l0GSb9YOwXmla3++8CiBcoyxIkWo/FH5SvfOY=; b=QJXDIZ6t38strAA327eSP6Z3PLF7JSiXgA4QSw772UKuiXGsqa5gOM+a+ecxUWo33U 8KlP/0QGdogiLtwxCkvY2kW6d/ujTEkCuxBn/zIAmvIXzrg1J6Px79rMAyHCfRyYNjvx gleuqwC2H55UN/JmdxPq90LBebBYDhyqGymS4doBkMdjNjyTBiBQ5SJqKfaJL6FiGGLV PC4KUS5zzqhHGrKh5y9DPRY74lq6o8Go68feppvTdVenCYrXj1bW6nt+japP/PUUIBQH Gb2Sm8T48bo2usH9nlQQ4TE7gMWNr6g/HAUCOsSUY4Qiu0vKH+GLV++468p6s4A5+VFm sZRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462249; x=1787067049; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zjkcq8l0GSb9YOwXmla3++8CiBcoyxIkWo/FH5SvfOY=; b=kf3OMaEC5+ZqXhQU+SLaHO0SciUrXJUrC/kMDE92W2s9HuZjkyP2umWDlnl80soYSx C3prQZBgoWBPK/APcm4ML+VhJxsWniPkuOpkcxxFJD5pVT0a9P0jwPOUCVsSZ+1RIewu X8ADyNTKAWLgAZBKhdI+MRnVKbilmn1Z7SvjMrwNkze2nkJcd4iaEMAphUOlkgrzocLV zK5Rj4pSOFSo1KEbczMcLCmi7A8sJozOdgTFxN+DbjWzx/m8xkfx2lzAbRFSkYQiYdqB coxNGKGhRNryS89bS9kYdl67UJG2fAuO/wX8X5oUvIUzInPmrGQ3WIvrHdr1MABsYbCX OYKA== X-Forwarded-Encrypted: i=1; AHgh+RqZqP8KKO42mIWEIO7O3ZWQad+mxalhlNXybVn7/ieI4bbYf8ZP5j0zLyfj4j8F0mUK8Vk8Gn0q8oSh5YM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxb4rCIvcNPIwU4PWef/KqTgQtHpLcCdo4ZV5pwdUXsDl9Xlew3 yS7ZKUDdUQ64LsTbeICPDZYKMzKjIplpyQG1GjDk3SU0DD/UlChCvv+WUXOztuZZyG4= X-Gm-Gg: AR+sD11FVjKD+E29l+wCZ9jQ1ctlwJx19GaueJmFE/3fkAowhwLDiMj2LzX9WFKgkSA 6O8m2AH2Sbz28aSEGY5a17P5BzKxkx7fbzY5oy3n0/LOnXtx2y586U2GLpv8A7SL8PIuw4qn++s krRPOb4Xo8hiP1b8X7nzi7hY99KXwXIzFAmiRcnIsVfh4c+ryudg6muD6MarrQ3eZWbOMRulRzS lbzbnjaYBTCXZToj0W7ZVfMKis6OYV9setpB/bZ8QVtIGzB+aH0Moq876UVzdy1L24GAED41Rbl zfnA40XnhdMTNEZZW7oZu9Nw9dy+GKdoIcdhjba1z8t/v4TdNuki8yQYxvxUOceQIErGekN/9ID f7jlRDEkiKHTtLZHuLTAZ8B8yai6L2sxpd8QK+gFA41zVYOrqjjZTT3bG3cUXB/p9pCW1gpg6Nm e/KKeApWWAuzGx2evP47kBzeI0hEhLYZ4fS+qM9fOWrbABh9zwe0Ujo0nm4YtXUL0B X-Received: by 2002:a05:600c:4513:b0:495:3e08:ad19 with SMTP id 5b1f17b1804b1-49978468c2bmr59898875e9.9.1786462248915; Tue, 11 Aug 2026 08:30:48 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:48 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:05 +0100 Subject: [PATCH 02/14] perf cs-etm: Warn for invalid timestamp option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-2-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 Instead of silently returning an error, print a useful warning. Signed-off-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index d2861d66a661..acfdb3f53821 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -176,8 +176,11 @@ static int cs_etm_validate_timestamp(struct perf_pmu *= cs_etm_pmu, struct evsel * * 0b01000 Implementation supports a maximum timestamp of 64bits. */ trcidr0 &=3D GENMASK(28, 24); - if (!trcidr0) + if (!trcidr0) { + pr_err("%s: timestamp not supported by HW, disable with %s/timestamp=3D0= /\n", + CORESIGHT_ETM_PMU_NAME, CORESIGHT_ETM_PMU_NAME); return -EINVAL; + } =20 return 0; } --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EB193B7776 for ; Tue, 11 Aug 2026 15:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462254; cv=none; b=PW7yFASebSiUmsaBvax4rLhdA9kUlsv0Sk21zTcwTR8+Rn8rGDM33uEXquexE3klqgjKx1/cgrFwstXMaAlR03tiU/YVrd18MBm480jQi8x0awDP7J3KvmgJJQrmpP/sRAeYJldxeFbGmqRs12T9upmmGOYy5wAZMbs3+aAkdJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462254; c=relaxed/simple; bh=fP2IfPP/3FxAZdBFPU46BWk56GVJBXw30IVSIBNxU7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I3zBd/8A/NUJDcg3wzlIPBNhLUIGJ2l/wN5qv2esIyjEjg2f2apV3IPSEIzQp6gYyKP9FdlarcAgcb9DC8KsOLIZdHMxx5ObmmccJjIstLpSTbFgWh9PlRb4h3nnUUlt1+0SlDcPcRzKeyoyxriyA7aKV2KzDlGn7KAJtrkjzc8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=qByNlg0R; arc=none smtp.client-ip=209.85.128.45 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) header.d=linaro.org header.i=@linaro.org header.b="qByNlg0R" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-49954b88fffso35230695e9.0 for ; Tue, 11 Aug 2026 08:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462250; x=1787067050; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SdlWRdH/H8iL8QSy1QmXwkvjy5+5wNnPwJoBbpgZwJA=; b=qByNlg0RehNdU0PIGepICwOUkqvYcrNh7Rz8af9UL/+NdixtzxN7mpIQqt1x2Ksolp VJB54Fn4U253Sqcb2FQ+SZCcsdjhpKT5TEVQKivr17ziZ5fpVDRlnQ7hHTzRUFZpLlPp MCZsPdUtROdqS0P+9aaVCRbY4zPpCe/IaQTy5THzbcJhrwNMMNiD5ijulHAYgrLR9yQ1 upSPwRH1ydIGraK8WhRwqjiRlCo1+tBqP/Z82mFZZmnmN9rGQmRMe+MpbSiy62xzi7An 826RUgHLvWGmG4N8mkPyeBTZGDCzi5g1vxMp1FQTYgNhnQL/U/nmgCdrolaYOcM64uzW KQCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462250; x=1787067050; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SdlWRdH/H8iL8QSy1QmXwkvjy5+5wNnPwJoBbpgZwJA=; b=BxnYRQbHM75xIDfBbP5yZisJ/jsQGRoGS4AESGBIyQ3BJFkOkwqYbSmUG1YK9DkoLw CT5u90brj2yIDMI20LjSJQfl0Y9pJLEmrYhTHUIdcqD/jcW67+FEh7/29rG2/LsqKo5Y x7+pmr9DnC5Adiih8dN+rEnzSu5bxYrEwJOcYz/gAKfNNZW5gySK8C2gokF7sW1xd64g ruaIPMCNvEdWn5Jkb76fgjn+/+F0OdEPD/gzQWu9c/+md72SI1uPJ00PYS/tksEgF3Y/ aFHk+7ow+yQzhaKpFGJVv5rfg82jlGq9OMcaYoeu8Ae61GeW3LcIv0hVZfIBlphDpnz4 RjRw== X-Forwarded-Encrypted: i=1; AHgh+RrONg77jTqa6uke4vUg1bMap9FpZUUD35odC+qz0eNpDDWR9vfLrKyfNBonaJ5ZYEIqGVVBBTh8erhTOuA=@vger.kernel.org X-Gm-Message-State: AOJu0YzB681MDW0AuVMbJeBcW5F6IHCbmzYhcUkX8lU3yGoIat4/HAUy LDqqU4k6MSohG2OSs6cbn771/eLMuyeM1jkgGeV5hzul0LQ9EAsfugF+v0gy3cj118qow/0Pr1x ffrHbxtM= X-Gm-Gg: AR+sD113E/JJHfANq1gjtOP6GLWR/zI+nC/FHeufAIfaeBYHwDXI9mLRGDsxJNhbbof XHa44Cnp22CpMk1CXUohg1bte+jjLeX3ygsVcVKFpr6CDl1i+pLqDFnIbQZ/DmAffM5MQaq+m75 LJa4g4Sh9i85ZDg/nxiROq5Zt0L2Ha+oqf7R4EWTxc6H9+vw3xRHc6AGtAjIUs6SXLuQxayYJks XsDWy9I1kgM9RxepdeT48t05ZLGZSHMbzHz8JUCTFyNqi9sCkkfImf8Nr9s+AILPZ8AVCfXwPue NxYi6A4Ylga6zEmYv6NpNGHbARz/1WPClx96JRz5td8YkN+UELovZ5otHBE2vSztWukX1evdKpl 8Iqz9VNDt7gVU8npVv2LKGDx8AkU7jBXAj3r9Z9b9BXFlXH8rT8SKC6ENIpc7Ro56S2ZDE8/2CP pTlw6t9ZtRSOl0d12iDRrkWIL4vKaR3YWfTkd8CxDiRcoYQodqqHTP+ZYTS7/siUCc X-Received: by 2002:a05:600c:310f:b0:499:737c:ce4c with SMTP id 5b1f17b1804b1-4997843703cmr53727915e9.6.1786462250133; Tue, 11 Aug 2026 08:30:50 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:49 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:06 +0100 Subject: [PATCH 03/14] perf cs-etm: Turn on context packet timestamps in per-thread mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-3-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 Practically this costs nothing and preempts future changes that will be made to support decoding trace in order with Perf MMAP and JIT events. It also helps keep samples in order when we add support for multiple per-thread mode threads in the next commit. Signed-off-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index acfdb3f53821..d0486a164a70 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -453,13 +453,22 @@ static int cs_etm_recording_options(struct auxtrace_r= ecord *itr, */ evsel__set_sample_bit(cs_etm_evsel, CPU); =20 - /* - * Also the case of per-cpu mmaps, need the contextID in order to be noti= fied - * when a context switch happened. - */ if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { + /* + * Timestamps are required to interleave samples from different + * CPUs. + */ evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1); + /* Context IDs are required to associate trace to a process */ evsel__set_config_if_unset(cs_etm_evsel, "contextid", 1); + } else { + /* + * Enable context packet timestamps only (no periodic + * timestamps). Even in per-thread mode with a single process we + * still need to correlate trace to a specific mmap around + * execs, which can be done with just context packet timestamps. + */ + evsel__set_config_if_unset(cs_etm_evsel, "timestamp", UINT64_MAX); } =20 /* --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D2563B14CD for ; Tue, 11 Aug 2026 15:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462256; cv=none; b=QdmmLu/8BuPvbJb4ZBhq869Q/+/ws06C5bT5dodrnzLf0DUYUu4ZHEX5vXWc6AVBlfkW6hIBLczOGGhTLddcPhjKmh55iCaGjNFteiNYL6YPb4sQlQz0q7MVXWfYjiqD/dNq4QmHtN4m3TD41RYp4mgTL4m1XDLZwaXZ/Oz0zCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462256; c=relaxed/simple; bh=Uk3MecH/GWSUCO4iYoK2aoC9xkOIm2VEOmSDFrmBCc0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dr393J8OtgUHyLb8LFN3QlPz7vsOt1gXJF+8F0/6nqy4U9qeGf5EuMZN1M58BG0kOH5XwGRNVohfDezZoss7y8Ssd2Pe4JalB+kY2absqEuD7XOmGcEil2EdH58ncFi9ZdM7E4qCQrIaf/An41e+SjDKnkJ3+0uHHJxuMy5bV30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rHyCsOd9; arc=none smtp.client-ip=209.85.128.41 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) header.d=linaro.org header.i=@linaro.org header.b="rHyCsOd9" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4957eefd361so25126115e9.1 for ; Tue, 11 Aug 2026 08:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462252; x=1787067052; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ne4dLz1fWz978dK33mNbt0k4ckMaGsbkZeA7j/BD+8s=; b=rHyCsOd9A0eLIxwpU9fZcQ2DcoBEkxqdyOfX7AGFTnPl5GxUnmldYU/5P9UVuF7VTT GNcpesAvQSL36LwaRpp4u9Y5I/nWBlTRGKn009U66zR51G374LliPJbE5eDhqf1tX8Ca 87Dc6q8V725XsoMgrncYgD7kIFDX78+2SNXRxhGn3LHYNA/Vz+IiSjANnsNKsQcfdpHx YbuPAhVe261SpWOBkkk/qkRebEcU7eDkFprUXZHnCBtp8s8d8jKqyBzGB7rrjdEbBERN Ec9qW8AQ5DTSwLhodQiE2VQo9Wtrad+YuiosFSkFicTo+UxfM+uqI6Ii6FRUK+BQq39p gLqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462252; x=1787067052; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ne4dLz1fWz978dK33mNbt0k4ckMaGsbkZeA7j/BD+8s=; b=HGJ1IAS5V9PkC3mtEWRdoLpOads2rHTql9nmQ0AbRULEbWyB9x1HEpMFSJUZItHqAi eHgxud0Z5Sq+rHB2LMmbsaTS2alrO0ZHs150+Q9ln+ZeyMdk4q4Gm14j1geVNU2WDkwJ qPzhWSymj7XtaGRTF4iS6RXjGCDl7ZXfEyeZEbP7N8FBVo+hwm7fj0HBcd/YBvb84U1W gq/BOsfVHk6CXqPjjkLVgsdMocujBYuBi2/7B1vjGeuSFYbovvuKU1CAi5i9vA5cbRL1 158oyF72d5NsZPcrUBevlyFMxPjkkYhrw7KuIEYJQY+2FebdxoHDc6fRg60PnShjEd4l 8Wqw== X-Forwarded-Encrypted: i=1; AHgh+RrSPaDMZNKhdKBKfb6sRtsfKWxkNpwsdp552wzVIGYmGggbSeVT9+krB1UEgLMywCyZ9ocecrWlo9mJLLE=@vger.kernel.org X-Gm-Message-State: AOJu0YwjbEe85npDzWCIm+3AlCDyzlcBcy1NX/RWwXZTWw9QQ14qJmhS r8v84OY2X3Diizbfsf8V91jRpDIY085xh6XnvmNSsMxiqu2SI3h1HgQz6cXUqFFtlYQ= X-Gm-Gg: AR+sD10wSW51GkVLKJlpO6axBjuWysh6SjNkrKVHDdWLZD+ln72uYQ59KkB8s4z3kQa 0xbxPm1flzvepcL1AI/PBjM42KW4WMfhx55eZfRYjebVyAIZ5RZ++MrDIKO/7YXgK0pUKeFHP3U gEepZSQkYqls9yI8wkU+yXuC8owLndiwGVA6hnneNnJt+ZqOdV7GAB1kgdC6tXOop32m8hKrIMw qUM+YX7TzkYS+lZYvkLJERiRd2xv42IGb55kiPrE+SBbuGKuyE/TeparAE6nZc3I/PTmg30syIh QwNz39deWD4kq6FZHAvXZyKxGOh6jQ+sZMKeIsoOyVGP/n/Q/jYXY/Pb/QNBE2+ZT5f57c+yPWH /U/jTCMc7ck097k77q7AArGLUh0Mj45Jj8K6NZt39BjBEruR+2lmEMvis6p9izF4AiWv7LmpbI0 1GSxhsOI+Y/8NN7U6ZBtv2iypYDyxnSP6xCFYqbUeStQlGJNXyDXZYGjsC76Y2dpFdFBDnnkerZ Lc= X-Received: by 2002:a05:600c:190d:b0:493:bd2a:93be with SMTP id 5b1f17b1804b1-49978e1a90emr57210825e9.6.1786462251684; Tue, 11 Aug 2026 08:30:51 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:51 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:07 +0100 Subject: [PATCH 04/14] perf cs-etm: Use per-CPU queues for per-thread mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-4-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 This fixes two problems, firstly per-thread mode didn't support multiple threads well or at all because we always use queue 0 and assumed it was for a single thread. However, Perf attaches to all child threads of one process or allows multiple threads to be specified on the commandline. This meant that trace before a context packet could use the wrong MMAP for decoding, and threads running concurrently wouldn't be interleaved properly. The second problem is that we'd put all HW_IDs into queue 0, so if a thread runs on multiple CPUs then it would receive multiple HW_IDs and trigger the assert that unformatted trace should only have 1 decoder per-CPU: $ perf record --per-thread -e cs_etm//u -- taskset --cpu-list 0 \ taskset --cpu-list 1 true $ perf script perf: util/cs-etm.c:3381: cs_etm__create_queue_decoders: Assertion `decod= ers =3D=3D 1' failed. Fixes: 9182f04a85b2 ("perf cs-etm: Pass unformatted flag to decoder") Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index d423f1cb408f..28f5ce63ba80 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -295,9 +295,6 @@ static int cs_etm__insert_trace_id_node(struct cs_etm_q= ueue *etmq, =20 static struct cs_etm_queue *cs_etm__get_queue(struct cs_etm_auxtrace *etm,= int cpu) { - if (etm->per_thread_decoding) - return etm->queues.queue_array[0].priv; - if (cpu < 0 || cpu >=3D (int)etm->queues.nr_queues) return NULL; =20 @@ -2160,6 +2157,7 @@ static void cs_etm__flush_all_stack(struct cs_etm_que= ue *etmq) */ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) { + struct cs_etm_auxtrace *etm =3D etmq->etm; int ret; =20 /* The current block is not finished */ @@ -2188,6 +2186,27 @@ static int cs_etm__get_data_block(struct cs_etm_queu= e *etmq) */ cs_etm__flush_all_stack(etmq); =20 + /* + * Per-thread mode still uses a queue for each CPU, but that CPU can run + * different threads. When the TID from the AUX record on a CPU changes, + * re-initialize the thread using the AUX record/buffer fragment TID so + * we can start decoding even if the context ID packet was cropped or + * they're disabled. + */ + if (etm->per_thread_decoding) { + struct cs_etm_traceid_queue *tidq =3D cs_etm__etmq_get_traceid_queue(etm= q, + CS_ETM_PER_THREAD_TRACEID); + + if (thread__tid(tidq->decode_thread) !=3D etmq->buffer->tid) { + thread__zput(tidq->frontend_thread); + thread__zput(tidq->decode_thread); + tidq->frontend_thread =3D machine__findnew_thread(&etm->session->machin= es.host, + -1, etmq->buffer->tid); + tidq->decode_thread =3D machine__findnew_thread(&etm->session->machines= .host, + -1, etmq->buffer->tid); + } + } + return 1; } =20 @@ -3245,7 +3264,7 @@ static int cs_etm__queue_aux_fragment(struct perf_ses= sion *session, off_t file_o =20 if (aux_offset >=3D auxtrace_event->offset && aux_offset + aux_size <=3D auxtrace_event->offset + auxtrace_event->s= ize) { - struct cs_etm_queue *etmq =3D cs_etm__get_queue(etm, auxtrace_event->cpu= ); + struct cs_etm_queue *etmq =3D cs_etm__get_queue(etm, sample->cpu); =20 if (!etmq) return -EINVAL; --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84583BED06 for ; Tue, 11 Aug 2026 15:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462257; cv=none; b=aiT9437igkHeFHhS/vpinfJlWHA818X/vMbplsGOl/0lsJH3jbOkLRhMxAh62W6sLshm5uN7WTWv1Yh3/K9MfCaFaTv70iaBXX5VCjygIiPPJICUauEWpFyM7GdThJJiSStbKi5GD59vwGKP0JI7L+elx75imkUS5hVR+IUhw2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462257; c=relaxed/simple; bh=RecoXOCNMxrMx0zkiKfC1PDkmODYasriw0nUGDxsh8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X3iF2wrjdNvShhcgFHADGx6/XEqFjP44wH/6qZj8ZkT5eVXQ7WV7zgDhhkqiTp43xCBzRSssM3MFzBN6j5EXOegTf6lElXEa8jbh5ZyHeRi57K1NbPnSDO/Ry+2hw+nExWA8wdM8OSu8ahnElvy/x75UIsCBARcgh7wrD+Pr5Gg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ZMP7qi/M; arc=none smtp.client-ip=209.85.128.46 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) header.d=linaro.org header.i=@linaro.org header.b="ZMP7qi/M" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so26616515e9.1 for ; Tue, 11 Aug 2026 08:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462254; x=1787067054; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bcFhjwes9A89zvUuGgSpPmP9VQvVv75EU6Q8BfuMsS4=; b=ZMP7qi/Ml4GGGsBS7z3LLDHfKN+et54F6229HiDUdRPP+B5uniM5URGlOx6IOTbXf2 sU5mJaOFh2Hgnq3otUI/Q+rBwABMHTPA7rS42v3x2HK8QEpGI8Lb1lSbc89uhrmJjX/J 2QsQKHhqIoR+GOCvL8lrutwVetj0cvK6RGD7mBGXOj+J/W0MFylgviomZx5/IyLr2YH4 UIgSnFngWmLdBm5aZSXuOQf8i8buBJfDvzLyvDqCe6BPSAq9TuXW2Kp8cUN8n6UWygrb ELmfS26FlAQANTU6DBKzBTJqLZ+3KkjVOX0Km0sAkNgTPJEFeaB43NXv0dFuBVK/tujQ tudw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462254; x=1787067054; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bcFhjwes9A89zvUuGgSpPmP9VQvVv75EU6Q8BfuMsS4=; b=SkLOtdIiyWfrFPKP87gufxICLGCUwrPUCGpqD8inzEcqpX3aFAS8ZMCHthWG0VKhDs gAzEAhAM9DE0Ab3i6hZPrTNvNetolkc9s1BIhzCDl3tEaeYTaIzWPn4X4gyWasi5F3Ln kyTP5FUJLSwJU1CTM3roWpNthtTGfXr/+JNdD/7wjc/ZVLVIanFWhpQ1aoWsc7WgByID 0XMoTOIlw4vJl1eod3yvtvY0nXapQwFxPJ+59v/ioyL0SI0cl/UtdtHkkCG/WUIhiB8+ 5HSq2bIQfI63wlA+aBCLsbzRDLiaLDqXxvw4mvNrGTUc++/zW6nvsEivEq6me/1NllLe pvfw== X-Forwarded-Encrypted: i=1; AHgh+RpMfyWFRBkz0s9u4FHExrcLm2Iua+IUlwOmZ7/l5eECy7weZiexfJHgZxpzQhe8OYt+FepTxbcWBq+SiUc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4OyU/HkbJW2kCPkF1fne7TUxQA1mPEpqGo5Qa6GPj4Kq9/8Sy PSWvSjOCGkb9HvbGeEBUmrjYUh/lnZ4eMSwLAQ/ZqpmPqiFC+clRQTVNfC6albtRvSA= X-Gm-Gg: AR+sD11veCpo/Z8Eg8CuiXpIUjSmPRO59HE2rFLprGhiXZx1sauSKCNpjaQuY3JIWHo xy2d9muNHju92JUD0LRa7+ZsJwLMuLXnRUsj/llLQsOhg22N+0nfax4CPaOoumGoNi8zNsq8WBh yGLxfsGb1tQnQGOnMSomGRnxV0S4X5/g9wEBOW9BaBd59s+AYobMgZ8HVwwqmjfnAxk5InyvHUJ +Yhzw36QxYpyU+/6fmLSSF1yC03CFL6zyyiPs11LyLW1zPyBJbiHIlotPDAJZtwbGoP2q5XdH5t crwDR/aEF0CVg1YxVCA5dmbuSgklxuIDsgDTnwWHOZMN7LY5p2cZH/yeDPk8opT51y01mD2H135 73XOO2XVCdOJT2/aaP1/HstDRgNNo2nySftF0/OWp2kkN/kOeIciGl0KyUtAZQxl0J+VbpaCvFa 3uVLm3SAVffAltD6ZSOVNoNqc+yL7S2AAL1E4hXt5fMtwerBsu7eNQb2tXU8ySVs82piCYyA== X-Received: by 2002:a05:600c:8219:b0:493:bacb:1341 with SMTP id 5b1f17b1804b1-4997842db6cmr72514755e9.4.1786462253990; Tue, 11 Aug 2026 08:30:53 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:52 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:08 +0100 Subject: [PATCH 05/14] perf cs-etm: Increase default timestamp generation period Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-5-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 The original purpose of timestamps in per-CPU mode was to roughly emit samples in the order they occurred across multiple CPUs, rather than emit all the trace from CPU 1 followed by all from CPU 2 etc. Previously there was no way to change the interval from the minimum of 1 cycle, but custom intervals are now supported by the driver. Drastically reduce the number of timestamps emitted by increasing the interval, which is more than enough to interleave sample generation. This reduces the size of the trace generated. Signed-off-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index d0486a164a70..d36b7e41399b 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -70,6 +70,9 @@ static const char * const metadata_ete_ro[] =3D { =20 enum cs_etm_version { CS_NOT_PRESENT, CS_ETMV3, CS_ETMV4, CS_ETE }; =20 +/* Default timestamp period of 256 cycles (2 ^ (9 - 1) =3D 256). */ +#define DEFAULT_TS 9 + static bool cs_etm_is_ete(struct perf_pmu *cs_etm_pmu, struct perf_cpu cpu= ); static int cs_etm_get_ro(struct perf_pmu *pmu, struct perf_cpu cpu, const = char *path, __u64 *val); static bool cs_etm_pmu_path_exists(struct perf_pmu *pmu, struct perf_cpu c= pu, const char *path); @@ -458,7 +461,7 @@ static int cs_etm_recording_options(struct auxtrace_rec= ord *itr, * Timestamps are required to interleave samples from different * CPUs. */ - evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1); + evsel__set_config_if_unset(cs_etm_evsel, "timestamp", DEFAULT_TS); /* Context IDs are required to associate trace to a process */ evsel__set_config_if_unset(cs_etm_evsel, "contextid", 1); } else { @@ -477,7 +480,7 @@ static int cs_etm_recording_options(struct auxtrace_rec= ord *itr, * timestamp tracing. */ if (opts->sample_time_set) - evsel__set_config_if_unset(cs_etm_evsel, "timestamp", 1); + evsel__set_config_if_unset(cs_etm_evsel, "timestamp", DEFAULT_TS); =20 /* Add dummy event to keep tracking */ err =3D parse_event(evlist, "dummy:u"); --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 395C53B7776 for ; Tue, 11 Aug 2026 15:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462261; cv=none; b=ateNBQ8ixVFt8FEPKZHeW60uKmYgwuMv30kfbr0E/mEl/p0p09+K2QJid2ltlw/7gQ2yUjf5XyzujTpsLrWfXMbJCV4xS9D+IP0LwOIWhW8qSqSG3mGcDL4KsddC3Mwd98V5JREk/fnkVZOpNrIbzoGyKfkvE06gek8M71vvLSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462261; c=relaxed/simple; bh=8nKlxlZ9rNdVq6/YuvGCZHeAcrIjZBPa7mfw49A5I68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rtbOEZdRR9KUJm9ph0G5HSr50E4Ld9cicdvZKDTnN3WJi8I62JNPb9tuotxZdnHXDplp5Z5i12FrDUzza1oHTDGqnrFxUFKGqFWOG4hKDSYOiiEc51j793cR3z4qLyQ0pcIiK/qJuMheGeJIX+lDzQliPUK0ibDFyu17w/a6Zc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=p3jMA4SM; arc=none smtp.client-ip=209.85.128.41 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) header.d=linaro.org header.i=@linaro.org header.b="p3jMA4SM" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-496b7622a83so30172185e9.2 for ; Tue, 11 Aug 2026 08:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462256; x=1787067056; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+YA8YrDL1uH8EMoAnO7TYw3jh/MqqDQQTE9sn5mADtM=; b=p3jMA4SMCEj3LA5twDB/vyRC9v9004PW1f6qTKOswNYYc/2mJ+1el61qbDJmIr1lg+ k5l7KtH8gKuMeac0xscfEaSy6S1G8U4E2Ik0479gVmobZXNVPzvDXmB7Jj8YRz1G3xSt vmaZtazBMvsdlbVjehJYByhUqxD+HeIOl6C8gmHVLT9xln6lr/cGn0yE3S119dIZVFKD ePEXRjnIrf2AGBDuw8VwVv34tUnQqHn/qtIUR52KQNXC+UWQ1CpAmFGK9z/hZzltiAuO a70vZ+8emqjDqoDTmXqP+OG5SSM4t6DAx26BgW0rGyUCb8duN+xlVGoZF63hSGd6iv9O GE3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462256; x=1787067056; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+YA8YrDL1uH8EMoAnO7TYw3jh/MqqDQQTE9sn5mADtM=; b=AkW7WT7iYba1AJ8jxuXu/5H6XJE2Mp96NtmAWn64A6tmpKkNd8flupER1k29KfWIoC 3gDBMuT1iO7QldBaozykCQGv8r+qODp0pqdYmRS6xqsVTSmeUKXGZ98pTQPME7+8132T ObvSgsTEmPCCzHSSzKrE4D8u3yLWxVo/6jIx5wFZLG5f00FtxsEqIMFehNMuQ1Itn29d b/Xu54X++uJNo2RYze6MxBCLN7wqXIiiasIdQH/v+Ybnx+qH8O+y3IWHX8pyTrY5h9rN TXa1ZPLEjKeSzD5lGLzfyr5CoNJSgYLE8ykcszzntVGs9bFm61T7GvO8MFMm3BPnXJNP n4qA== X-Forwarded-Encrypted: i=1; AHgh+Rrco4Z6cgAWgi61cEyZgEa4UM3G7aoT8AlSiJjTmoD/x4mKwkjfRmoTv1JOKtRAPcvEm7tRrJTYUrOdQHY=@vger.kernel.org X-Gm-Message-State: AOJu0YxfVjvclT8cw8/mkGpZUzMX/V2K0Sqt/n1uYMoXPdigPJiNjn+j 20G9VLAGEwAgIuQsILCdGiSIgRmdWmwcX/YUQoHG2xdIq0yaqEE0ZsLkL4Ayat9i90TQss8/z5j ouoAcdJE= X-Gm-Gg: AR+sD12GPO3OWqF1Iy4z4J3X+lO0tJ5efXFn+x/8tf3nl2JVhlNz9mibKqOdgH1brdc M2I72bvPEv7AxmSy5u79+WM4xV9suhR4SA5A7Xmi3SD/yYAzMLbW61c/IqB+3cLkFdWjSy+CC2T Y4znT7aCHPwVl41DMUG1Q9BaHYKq2K+37Vm34ZY5VLjhuP05Jmox+IJNi1qPWebOj6UJAU9azVl pBNte/ShFwb4PEu3DIxX5fjb63/+N0tQFLppwjCIfZLHJN2RCHY3SNJfazmWtejD2fiqrmF57BX OoO9EhX5Gm8mrySdHMtTocgFwON9T7uWOeDgHI/BV8fxcYwrv9w93w95vxwDmrajSoKVoZbRYpI JR6l6avrJOECEty12yroOdokV6UVSeI9ie5lZyxccBieuC+flK3VDTNb8Hkc3d3lyT9B8+jLyiF yx0uYp6gOjy1lY5spJUlNngUar1Y6KaJ0qLp6LjWKvEcbYCvl4nkU83j887VIYZpJ1 X-Received: by 2002:a05:600c:34d3:b0:499:6eac:36d2 with SMTP id 5b1f17b1804b1-4997846d9c5mr72022945e9.17.1786462256298; Tue, 11 Aug 2026 08:30:56 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:55 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:09 +0100 Subject: [PATCH 06/14] perf auxtrace: Turn Intel BTS snapshot search into a generic one Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-6-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 Currently each auxtrace user has to implement both the snapshot search and the logic to fixup the 'head' and 'old' values after finding a wrap. IntelPT and BTS have the same fixup logic but different wrap searches. BTS and Arm SPE have the same search but SPE modifies head differently (although it probably shouldn=E2=80=99t), and Arm Coresight doesn't have a search at all, but later it will want its own search and same fixup logic. Start moving towards a system where the pointers are always fixed up in the same way by auxtrace.c, and users only have to provide a search function or can use the generic one without reimplementing it. The new auxtrace_find_snapshot() calls the search callback if it's implemented, handles pointer fixup in a consistent way and is based on intel_bts_find_snapshot(). auxtrace_record__has_wrapped() is the generic search function based on intel_bts_has_wrapped() and includes the caching from intel_bts_find_snapshot(). The old find_snapshot callback will eventually be removed. No functional changes intended apart from changing the pr_debug3()s to print hex to match __auxtrace_mmap__read() and no longer leaking snapshot_refs when expanding the array length. Signed-off-by: James Clark --- Documentation/userspace-api/perf_ring_buffer.rst | 6 +- tools/perf/arch/x86/util/intel-bts.c | 115 +------------------- tools/perf/util/auxtrace.c | 128 +++++++++++++++++++= ++-- tools/perf/util/auxtrace.h | 11 ++ 4 files changed, 133 insertions(+), 127 deletions(-) diff --git a/Documentation/userspace-api/perf_ring_buffer.rst b/Documentati= on/userspace-api/perf_ring_buffer.rst index dc71544532ce..687c95a738f7 100644 --- a/Documentation/userspace-api/perf_ring_buffer.rst +++ b/Documentation/userspace-api/perf_ring_buffer.rst @@ -796,9 +796,9 @@ The perf only accesses the head pointer ``perf_event_mm= ap_page::aux_head`` in snapshot mode and doesn=E2=80=99t touch tail pointer ``aux_tail``, this= is because the AUX ring buffer can overflow in free run mode, the tail pointer is useless in this case. Alternatively, the callback -``auxtrace_record::find_snapshot()`` is introduced for making the decision -of whether the AUX ring buffer has been wrapped around or not, at the -end it fixes up the AUX buffer's head which are used to calculate the +``auxtrace_record::snapshot_has_wrapped()`` is introduced for making the +decision of whether the AUX ring buffer has been wrapped around or not, at= the +end Perf fixes up the AUX buffer's head which are used to calculate the trace data size. =20 As we know, the buffers' deployment can be per-thread mode, per-CPU diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/uti= l/intel-bts.c index d44d568a6d21..1b1df0003435 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -34,20 +34,12 @@ #define KiB_MASK(x) (KiB(x) - 1) #define MiB_MASK(x) (MiB(x) - 1) =20 -struct intel_bts_snapshot_ref { - void *ref_buf; - size_t ref_offset; - bool wrapped; -}; - struct intel_bts_recording { struct auxtrace_record itr; struct perf_pmu *intel_bts_pmu; struct evlist *evlist; bool snapshot_mode; size_t snapshot_size; - int snapshot_ref_cnt; - struct intel_bts_snapshot_ref *snapshot_refs; }; =20 struct branch { @@ -280,46 +272,11 @@ static u64 intel_bts_reference(struct auxtrace_record= *itr __maybe_unused) return rdtsc(); } =20 -static int intel_bts_alloc_snapshot_refs(struct intel_bts_recording *btsr, - int idx) -{ - const size_t sz =3D sizeof(struct intel_bts_snapshot_ref); - int cnt =3D btsr->snapshot_ref_cnt, new_cnt =3D cnt * 2; - struct intel_bts_snapshot_ref *refs; - - if (!new_cnt) - new_cnt =3D 16; - - while (new_cnt <=3D idx) - new_cnt *=3D 2; - - refs =3D calloc(new_cnt, sz); - if (!refs) - return -ENOMEM; - - memcpy(refs, btsr->snapshot_refs, cnt * sz); - - btsr->snapshot_refs =3D refs; - btsr->snapshot_ref_cnt =3D new_cnt; - - return 0; -} - -static void intel_bts_free_snapshot_refs(struct intel_bts_recording *btsr) -{ - int i; - - for (i =3D 0; i < btsr->snapshot_ref_cnt; i++) - zfree(&btsr->snapshot_refs[i].ref_buf); - zfree(&btsr->snapshot_refs); -} - static void intel_bts_recording_free(struct auxtrace_record *itr) { struct intel_bts_recording *btsr =3D container_of(itr, struct intel_bts_recording, itr); =20 - intel_bts_free_snapshot_refs(btsr); free(btsr); } =20 @@ -349,75 +306,6 @@ static int intel_bts_snapshot_finish(struct auxtrace_r= ecord *itr) return -EINVAL; } =20 -static bool intel_bts_first_wrap(u64 *data, size_t buf_size) -{ - int i, a, b; - - b =3D buf_size >> 3; - a =3D b - 512; - if (a < 0) - a =3D 0; - - for (i =3D a; i < b; i++) { - if (data[i]) - return true; - } - - return false; -} - -static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx, - struct auxtrace_mmap *mm, unsigned char *data, - u64 *head, u64 *old) -{ - struct intel_bts_recording *btsr =3D - container_of(itr, struct intel_bts_recording, itr); - bool wrapped; - int err; - - pr_debug3("%s: mmap index %d old head %zu new head %zu\n", - __func__, idx, (size_t)*old, (size_t)*head); - - if (idx >=3D btsr->snapshot_ref_cnt) { - err =3D intel_bts_alloc_snapshot_refs(btsr, idx); - if (err) - goto out_err; - } - - wrapped =3D btsr->snapshot_refs[idx].wrapped; - if (!wrapped && intel_bts_first_wrap((u64 *)data, mm->len)) { - btsr->snapshot_refs[idx].wrapped =3D true; - wrapped =3D true; - } - - /* - * In full trace mode 'head' continually increases. However in snapshot - * mode 'head' is an offset within the buffer. Here 'old' and 'head' - * are adjusted to match the full trace case which expects that 'old' is - * always less than 'head'. - */ - if (wrapped) { - *old =3D *head; - *head +=3D mm->len; - } else { - if (mm->mask) - *old &=3D mm->mask; - else - *old %=3D mm->len; - if (*old > *head) - *head +=3D mm->len; - } - - pr_debug3("%s: wrap-around %sdetected, adjusted old head %zu adjusted new= head %zu\n", - __func__, wrapped ? "" : "not ", (size_t)*old, (size_t)*head); - - return 0; - -out_err: - pr_err("%s: failed, error %d\n", __func__, err); - return err; -} - struct auxtrace_record *intel_bts_recording_init(int *err) { struct perf_pmu *intel_bts_pmu =3D perf_pmus__find(INTEL_BTS_PMU_NAME); @@ -444,7 +332,8 @@ struct auxtrace_record *intel_bts_recording_init(int *e= rr) btsr->itr.free =3D intel_bts_recording_free; btsr->itr.snapshot_start =3D intel_bts_snapshot_start; btsr->itr.snapshot_finish =3D intel_bts_snapshot_finish; - btsr->itr.find_snapshot =3D intel_bts_find_snapshot; + btsr->itr.snapshot_has_wrapped =3D auxtrace_record__has_wrapped; + btsr->itr.snapshot_search_bytes =3D 4096; btsr->itr.parse_snapshot_options =3D intel_bts_parse_snapshot_options; btsr->itr.reference =3D intel_bts_reference; btsr->itr.read_finish =3D auxtrace_record__read_finish; diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index aa749e1c3036..9586989e645e 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -603,8 +603,10 @@ int auxtrace_record__info_fill(struct auxtrace_record = *itr, =20 void auxtrace_record__free(struct auxtrace_record *itr) { - if (itr) + if (itr) { + zfree(&itr->snapshot_wrapped); itr->free(itr); + } } =20 int auxtrace_record__snapshot_start(struct auxtrace_record *itr) @@ -621,12 +623,109 @@ int auxtrace_record__snapshot_finish(struct auxtrace= _record *itr, bool on_exit) return 0; } =20 -int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx, - struct auxtrace_mmap *mm, - unsigned char *data, u64 *head, u64 *old) +static int auxtrace_alloc_wrap_bitmap(struct auxtrace_record *itr, int idx) +{ + int len =3D itr->snapshot_wrapped_len; + unsigned long *new_bitmap; + int new_len =3D len * 2; + + if (!new_len) + new_len =3D BITS_PER_LONG; + + while (new_len <=3D idx) + new_len *=3D 2; + + new_bitmap =3D realloc(itr->snapshot_wrapped, bitmap_size(new_len)); + if (!new_bitmap) + return -ENOMEM; + + itr->snapshot_wrapped =3D new_bitmap; + bitmap_clear(itr->snapshot_wrapped, len, new_len - len); + itr->snapshot_wrapped_len =3D new_len; + + return 0; +} + +/* + * Generic auxtrace_record::has_wrapped() implementation that returns 1 if= non + * zero data exists within auxtrace_record::snapshot_search_bytes of the e= nd of + * the buffer. The result is cached for each buffer idx so the search is n= ot + * repeated. + * + * Writes at the end mean a high chance that trace would have continued pa= st + * this search area and wrapped to the beginning. It's not a perfect heuri= stic, + * but it's only to avoid saving mostly empty buffers into the file. A fal= se + * positive results in saving up to snapshot_search_bytes zeros before the + * actual data, which a decoder should be able to skip over. + */ +int auxtrace_record__has_wrapped(struct auxtrace_record *itr, int idx, + unsigned char *data, size_t buf_size, + u64 head __maybe_unused) +{ + u64 *wide_data =3D (u64 *)data; + s64 i, a, b; + + if (idx >=3D itr->snapshot_wrapped_len) { + int err =3D auxtrace_alloc_wrap_bitmap(itr, idx); + + if (err) + return err; + } + + if (test_bit(idx, itr->snapshot_wrapped)) + return 1; + + b =3D buf_size / sizeof(u64); + a =3D b - (itr->snapshot_search_bytes / sizeof(u64)); + if (a < 0) + a =3D 0; + + for (i =3D a; i < b; i++) { + if (wide_data[i]) { + __set_bit(idx, itr->snapshot_wrapped); + return 1; + } + } + + return 0; +} + +static int auxtrace_find_snapshot(struct auxtrace_record *itr, int idx, + struct auxtrace_mmap *mm, unsigned char *data, + u64 *head, u64 *old) { - if (itr && itr->find_snapshot) - return itr->find_snapshot(itr, idx, mm, data, head, old); + int wrapped; + + pr_debug3("%s: mmap index %d old head 0x%"PRIx64" new head 0x%"PRIx64"\n", + __func__, idx, *old, *head); + + wrapped =3D itr->snapshot_has_wrapped(itr, idx, data, mm->len, *head); + if (wrapped < 0) { + pr_err("%s: failed, error %d\n", __func__, wrapped); + return wrapped; + } + + /* + * In full trace mode 'head' continually increases. However in snapshot + * mode 'head' is an offset within the buffer. Here 'old' and 'head' + * are adjusted to match the full trace case which expects that 'old' is + * always less than 'head'. + */ + if (wrapped) { + *old =3D *head; + *head +=3D mm->len; + } else { + if (mm->mask) + *old &=3D mm->mask; + else + *old %=3D mm->len; + if (*old > *head) + *head +=3D mm->len; + } + + pr_debug3("%s: wrap-around %sdetected, adjusted old head 0x%"PRIx64" adju= sted new head 0x%"PRIx64"\n", + __func__, wrapped ? "" : "not ", *old, *head); + return 0; } =20 @@ -1958,12 +2057,21 @@ static int __auxtrace_mmap__read(struct mmap *map, union perf_event ev; void *data1, *data2; int kernel_is_64_bit =3D perf_env__kernel_is_64_bit(env); + int err; =20 head =3D auxtrace_mmap__read_head(mm, kernel_is_64_bit); =20 - if (snapshot && - auxtrace_record__find_snapshot(itr, mm->idx, mm, data, &head, &old)) - return -1; + if (snapshot) { + if (itr->find_snapshot) { + err =3D itr->find_snapshot(itr, mm->idx, mm, data, &head, &old); + if (err) + return err; + } else if (itr->snapshot_has_wrapped) { + err =3D auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old); + if (err) + return err; + } + } =20 if (old =3D=3D head) return 0; @@ -2042,8 +2150,6 @@ static int __auxtrace_mmap__read(struct mmap *map, mm->prev =3D head; =20 if (!snapshot) { - int err; - err =3D auxtrace_mmap__write_tail(mm, head, kernel_is_64_bit); if (err < 0) return err; diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index 6947f3f284c0..c2342d0f4afb 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -376,6 +376,7 @@ struct auxtrace_mmap_params { * @snapshot_start: starting a snapshot * @snapshot_finish: finishing a snapshot * @find_snapshot: find data to snapshot within auxtrace mmap + * @snapshot_has_wrapped: callback to check if the buffer has wrapped in s= napshot mode * @parse_snapshot_options: parse snapshot options * @reference: provide a 64-bit reference number for auxtrace_event * @read_finish: called after reading from an auxtrace mmap @@ -383,6 +384,8 @@ struct auxtrace_mmap_params { * @default_aux_sample_size: default sample size for --aux sample option * @pmu: associated pmu * @evlist: selected events list + * @snapshot_wrapped_len: number of bits in @snapshot_wrapped + * @snapshot_wrapped: bitmap indicating if each aux buffer has wrapped */ struct auxtrace_record { int (*recording_options)(struct auxtrace_record *itr, @@ -400,6 +403,8 @@ struct auxtrace_record { int (*find_snapshot)(struct auxtrace_record *itr, int idx, struct auxtrace_mmap *mm, unsigned char *data, u64 *head, u64 *old); + int (*snapshot_has_wrapped)(struct auxtrace_record *itr, int idx, + unsigned char *data, size_t size, u64 head); int (*parse_snapshot_options)(struct auxtrace_record *itr, struct record_opts *opts, const char *str); @@ -408,6 +413,9 @@ struct auxtrace_record { unsigned int alignment; unsigned int default_aux_sample_size; struct evlist *evlist; + int snapshot_wrapped_len; + unsigned long *snapshot_wrapped; + int snapshot_search_bytes; }; =20 /** @@ -590,6 +598,9 @@ int auxtrace_record__snapshot_finish(struct auxtrace_re= cord *itr, bool on_exit); int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx, struct auxtrace_mmap *mm, unsigned char *data, u64 *head, u64 *old); +int auxtrace_record__has_wrapped(struct auxtrace_record *itr, int idx, + unsigned char *data, size_t buf_size, + u64 head __maybe_unused); u64 auxtrace_record__reference(struct auxtrace_record *itr); int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx); =20 --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB023B42E1 for ; Tue, 11 Aug 2026 15:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462262; cv=none; b=EZHWhR7DpXz7ECDkqxKX0PnWJH4Wc/sJMC0+onZNnRnh5LwKE7KmDzfrLtZ4IMml7PGogcaaey1oar/dXdla1WjC/ayW4jxxMW9NOLUhy++92qx3GT6nN0E6a/dRPA9nIO37Abc12uMiOD34rctW7HKty61QdJfiC6QWzvkDa2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462262; c=relaxed/simple; bh=kA5LbSGzSFt0yV/2KASUph8Bp02kP3gLVrrUuWxXR3I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sWJwIm+XQ/zcMG1V/0/MlMNHqvvVHqPPtJay6Hth7zsDG/JoSf6wBqagMrZDW5vm61vbBcJIxCzVqw+cADQt3Dm+hUEoVV8WzGYKirxCEw/6oOahJ69OgJn6o1KaYo1TdYtZFTEPaTjIH0T5J8yBlLXSN69XLabutcZPjng5VIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=doX/qdOG; arc=none smtp.client-ip=209.85.128.48 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) header.d=linaro.org header.i=@linaro.org header.b="doX/qdOG" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-496bb7cdf51so45419665e9.2 for ; Tue, 11 Aug 2026 08:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462258; x=1787067058; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CbdOfomTAI7oLSknzQNqLoWXfzHYXHRHempsJBX4UAA=; b=doX/qdOGaEXQazU+mOEus+PVWQ7TMIqJd8kDLmP2Y5c1pG0KFmprPqyJjprxGfOupw gKA/YETT+b602Qw8MONZanT06vCm0e/V9ualoV0sRnKOTm2YRuCKswCG+hrevZUM++Vf ENxFrH1a4gSceSx1JwH48LtR6H9TNgX4G4qfdHxkW2bE8YIjOLN6gkc9p5fesXltNDIc /sidPbUr2IoZDpz9CSVKslPyiI2YMRV+yHpaeENoI5xfLZQ/ZFAN5mEmJfUwA7yshUTN t4ugYyffRx39y8OLV7gE48yakNYRNa5nCtuoiY1T+aVZ8GP5oaiA8niZNlLmApBhC/bv ATFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462258; x=1787067058; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CbdOfomTAI7oLSknzQNqLoWXfzHYXHRHempsJBX4UAA=; b=nv0dkBQTR16KjilpBFeiUpC5LI7e6bIusFAy4mVQ/iA0xjPEu1LkgfCX4Lwifo9CjO f4d3EqResQMMedVSsYWiKyKGcLh034J8hF3pn/sosY87guQr43O1WPfMnHJI0VfSyW9+ CHBw31vi9UhSz/9vbzEf6WlUWnhdz18Tu8KnM6gKk332luwbBwgPP0tyLJcWY60KAIei NX0/9py173uXeG9IL9zpvuwX21OMqMylPSzVa6w7u3Py+dX43qP+eH4sl/B+kC0C4s5/ sOUZI98zvt+bwVcUJSSLcULk6hajQh5XsY1hRHLwK6Mq6iRHL12BWkbdw1H2i8FIKIJf dUTg== X-Forwarded-Encrypted: i=1; AHgh+RoY+ouPaFwKJg6g9vGfxm4zlQv2G1N5LeexQTuhoBT+aTgVCt5UgEv6vXiiNla4Ohe+4HJ87kza9FO+KBE=@vger.kernel.org X-Gm-Message-State: AOJu0YxN9aro2GXuNZRIVTDqu6IhM4BZHpmt8V3OjG4iLOqoL5lvqUIV /27lXs/Vw0SUFKwEcO0GLnMsQeUbxe9UjQrXnfNXm0uNrmj2ZErlDH6x0UbbqUblka0= X-Gm-Gg: AR+sD13DfNAaJK7armUGON6e4urkhg1JZqGr+eGfRBfIk30LomptUP0ekQ16w++HLYp wX68hNGQzVnq5BHDrIGmHgQekY1cnVmglTUVO/7tgFGMpn/YWVWti5QErytlQq9MjkgSksfs6rh VoFNncAsvIKvnfIo2pqdrWu8fLhkRTVcFe+5EPh3Ch72L/TBkkcTg8WIO7ZlbYREHFeO1+AYYzK eosGyooAVLv9lnLyxPKFvywY/JqVHzZktC0XCcQrW6x9xKWDKk46O7tvjugF0yXkuYXYCujYRUm pT5ZxIA6ddilbPqwfypeTs68/xZ4Zr6DPzDmpxJ0RSFmVIWMk57pHFRHV/iqwxqPxWp1LDLWYMV XHoasBvg94JplLjzYFVhqA01ptw3rtuITxmqPGQIkDcaFcF3Rqi3S4pM6AVjlJ+YevhXCthHjPq wMQjqAlF4YGCYqSME1xndXtDyNlTBIv1+rgGfb1Q+zVDjCn50Lv3/dtQyr19GHyt+jQDeP9SMUl 9g= X-Received: by 2002:a05:600c:4594:b0:499:7aa7:eaa7 with SMTP id 5b1f17b1804b1-4997aa7eaafmr2747295e9.15.1786462258292; Tue, 11 Aug 2026 08:30:58 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:57 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:10 +0100 Subject: [PATCH 07/14] perf arm-spe: Use generic snapshot search Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-7-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 The new generic snapshot search gives a similar result as the reimplemented version of it here. One slight difference is in the pointer fixup. SPE has: *head +=3D mm->len; *old =3D *head - mm->len; Which gives exactly the same result but written in reverse order to the generic one: *old =3D *head; *head +=3D mm->len; SPE also had a special fixup case for head pointers greater than the buffer length, which is not needed because the SPE driver always wraps them, and __auxtrace_mmap__read() handles that anyway. It also didn't have the special case for old > head for when the wrap heuristic fails but the pointers showed a wrap had happened. The other feature lost is that this search only looked from head to the end of the buffer, rather than always at the last 512 bytes. This was flawed because once head is close to the end, it's likely it could contain zero padding from actual SPE data and a wrap would be missed. It's better to err on the side of caution and mark as a wrap, rather than trying to optimize by limiting the search from head onwards. Signed-off-by: James Clark --- tools/perf/arch/arm64/util/arm-spe.c | 147 +------------------------------= ---- 1 file changed, 2 insertions(+), 145 deletions(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/u= til/arm-spe.c index 1ba803a8d9b4..d8c4a1d6c621 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -26,7 +26,6 @@ #include "../../../util/record.h" #include "../../../util/header.h" #include "../../../util/arm-spe.h" -#include // reallocarray =20 #define ARM_SPE_CPU_MAGIC 0x1010101010101010ULL =20 @@ -37,8 +36,6 @@ struct arm_spe_recording { struct auxtrace_record itr; struct perf_pmu *arm_spe_pmu; struct evlist *evlist; - int wrapped_cnt; - bool *wrapped; }; =20 /* Iterate config list to detect if the "freq" parameter is set */ @@ -497,146 +494,6 @@ static int arm_spe_snapshot_finish(struct auxtrace_re= cord *itr) return ret; } =20 -static int arm_spe_alloc_wrapped_array(struct arm_spe_recording *ptr, int = idx) -{ - bool *wrapped; - int cnt =3D ptr->wrapped_cnt, new_cnt, i; - - /* - * No need to allocate, so return early. - */ - if (idx < cnt) - return 0; - - /* - * Make ptr->wrapped as big as idx. - */ - new_cnt =3D idx + 1; - - /* - * Free'ed in arm_spe_recording_free(). - */ - wrapped =3D reallocarray(ptr->wrapped, new_cnt, sizeof(bool)); - if (!wrapped) - return -ENOMEM; - - /* - * init new allocated values. - */ - for (i =3D cnt; i < new_cnt; i++) - wrapped[i] =3D false; - - ptr->wrapped_cnt =3D new_cnt; - ptr->wrapped =3D wrapped; - - return 0; -} - -static bool arm_spe_buffer_has_wrapped(unsigned char *buffer, - size_t buffer_size, u64 head) -{ - u64 i, watermark; - u64 *buf =3D (u64 *)buffer; - size_t buf_size =3D buffer_size; - - /* - * Defensively handle the case where head might be continually increasing= - if its value is - * equal or greater than the size of the ring buffer, then we can safely = determine it has - * wrapped around. Otherwise, continue to detect if head might have wrapp= ed. - */ - if (head >=3D buffer_size) - return true; - - /* - * We want to look the very last 512 byte (chosen arbitrarily) in the rin= g buffer. - */ - watermark =3D buf_size - 512; - - /* - * The value of head is somewhere within the size of the ring buffer. Thi= s can be that there - * hasn't been enough data to fill the ring buffer yet or the trace time = was so long that - * head has numerically wrapped around. To find we need to check if we h= ave data at the - * very end of the ring buffer. We can reliably do this because mmap'ed = pages are zeroed - * out and there is a fresh mapping with every new session. - */ - - /* - * head is less than 512 byte from the end of the ring buffer. - */ - if (head > watermark) - watermark =3D head; - - /* - * Speed things up by using 64 bit transactions (see "u64 *buf" above) - */ - watermark /=3D sizeof(u64); - buf_size /=3D sizeof(u64); - - /* - * If we find trace data at the end of the ring buffer, head has been the= re and has - * numerically wrapped around at least once. - */ - for (i =3D watermark; i < buf_size; i++) - if (buf[i]) - return true; - - return false; -} - -static int arm_spe_find_snapshot(struct auxtrace_record *itr, int idx, - struct auxtrace_mmap *mm, unsigned char *data, - u64 *head, u64 *old) -{ - int err; - bool wrapped; - struct arm_spe_recording *ptr =3D - container_of(itr, struct arm_spe_recording, itr); - - /* - * Allocate memory to keep track of wrapping if this is the first - * time we deal with this *mm. - */ - if (idx >=3D ptr->wrapped_cnt) { - err =3D arm_spe_alloc_wrapped_array(ptr, idx); - if (err) - return err; - } - - /* - * Check to see if *head has wrapped around. If it hasn't only the - * amount of data between *head and *old is snapshot'ed to avoid - * bloating the perf.data file with zeros. But as soon as *head has - * wrapped around the entire size of the AUX ring buffer it taken. - */ - wrapped =3D ptr->wrapped[idx]; - if (!wrapped && arm_spe_buffer_has_wrapped(data, mm->len, *head)) { - wrapped =3D true; - ptr->wrapped[idx] =3D true; - } - - pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n", - __func__, idx, (size_t)*old, (size_t)*head, mm->len); - - /* - * No wrap has occurred, we can just use *head and *old. - */ - if (!wrapped) - return 0; - - /* - * *head has wrapped around - adjust *head and *old to pickup the - * entire content of the AUX buffer. - */ - if (*head >=3D mm->len) { - *old =3D *head - mm->len; - } else { - *head +=3D mm->len; - *old =3D *head - mm->len; - } - - return 0; -} - static u64 arm_spe_reference(struct auxtrace_record *itr __maybe_unused) { struct timespec ts; @@ -651,7 +508,6 @@ static void arm_spe_recording_free(struct auxtrace_reco= rd *itr) struct arm_spe_recording *sper =3D container_of(itr, struct arm_spe_recording, itr); =20 - zfree(&sper->wrapped); free(sper); } =20 @@ -674,7 +530,8 @@ struct auxtrace_record *arm_spe_recording_init(int *err, sper->arm_spe_pmu =3D arm_spe_pmu; sper->itr.snapshot_start =3D arm_spe_snapshot_start; sper->itr.snapshot_finish =3D arm_spe_snapshot_finish; - sper->itr.find_snapshot =3D arm_spe_find_snapshot; + sper->itr.snapshot_has_wrapped =3D auxtrace_record__has_wrapped; + sper->itr.snapshot_search_bytes =3D 512; sper->itr.parse_snapshot_options =3D arm_spe_parse_snapshot_options; sper->itr.recording_options =3D arm_spe_recording_options; sper->itr.info_priv_size =3D arm_spe_info_priv_size; --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FCD83D45F7 for ; Tue, 11 Aug 2026 15:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462264; cv=none; b=Pp4bJ8YYzrIxMK3j5yOCkiVhL+EKGgZMOM42Yus70b7KECiWcaV9F3Z0PN6waS0zkRtkkohfi7VhVVDernYV7RnJYNfIgkWqLH+WDANzMzhrd29vmGHdZCvbloJfCmnJiI2K/+vdJ5lJGiL5gyT9NzzA7oTNyvrYD2CYjLbObHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462264; c=relaxed/simple; bh=H5RbpglB3mwc0VATOCqHp3bXAY+cQ8dXfMWjveqvYHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G34wzoJ/8+T6yf8HVq274et5+FxUp+z1av0yYvDi2culACjlo+pxPU0G60egKP1My/Wpg4fPwG6nk9a9/V2BcWRIOSiNwqcEYGKstZcZoAFZPEDWYR2hhx2vMPH3Xq55aLASQiWfYHtCTqFQJkbHeerqQcpGP9ebX8AOyMSypcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=sjPcPonI; arc=none smtp.client-ip=209.85.128.46 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) header.d=linaro.org header.i=@linaro.org header.b="sjPcPonI" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-495590dde14so14245455e9.0 for ; Tue, 11 Aug 2026 08:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462260; x=1787067060; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BqfzZM8zBnaNvy70ESgvPXpjemsAbMaxUvbbfAWEGvA=; b=sjPcPonIccVXnDHLLtkXOq86O/g7+r+RE8Lo31rnhV6hZef4GzzcGVTDtiyyf1OJLB VVgwBz/2W8UHHe83tSej3tAqEVvALnL8hHzP/QeN1Th1+Nj5Z7VUbrzgHsNrDF+EfMv+ tcjIcDZNL6rH4JHfpsCQ0VNsNCjKy8+Mw7Crawdc6FPx54Zw+nGRiwSAvB/D0Iik+p1m 4xHIuLiLf5bhpheYeZoJp7DlZxXMxf+sp0NIwrrP+rXkMyr9J6TIcDSKGs81lw17BsEK HxITZiZv8W/6f57SA5WCvshwFTK90Q8iGsHUmecRY5efK2vZrBanVNyR2dJq7nFqbpG+ aMYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462260; x=1787067060; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BqfzZM8zBnaNvy70ESgvPXpjemsAbMaxUvbbfAWEGvA=; b=SBVnO7GKlqsQKcifIs2M9oznSJ0WVtmfeVy6WdRnu8b7jNqi9u/AGOCEfmEySTXrcR QyU9JaijGVa5lorhrlNl4MGKR56hAlcpLujklsds5kn1wCM3nSCDSlY0dgOH8mjAdhMg txxM5lAu2zs5viCTpyMbDhVJTZJazlXjDmmyjUPG/G5CgktQQ0SbgzptIExqhOh4Ohst vYAMf4V40wl2CFyb0MKjmq7MJPm7f07xWLTr36R4C482obxaFA+tKPaygwByZOkd3aGV lUt5NlULGWZPH+CQCtGL1psPzaszpSN01HE2LYtZDEABe1TxH1iC/7+ZQyNwGhxeSSWr /Wig== X-Forwarded-Encrypted: i=1; AHgh+RoIrtzsQJbW7LY5/mMRBzqbcCwIO2qaz0zy/nQw6vt6ztyjG9gmJVNMb+RkRXyVRe2m+Wo/e0+e/Cza4r4=@vger.kernel.org X-Gm-Message-State: AOJu0YwC/6egF7gKJ83KMcDn36XqX/vEizuBxUEyOYxZRrJguqdwycTJ 2Gw3WvzNcCsdzN9zj9adb6eII2u+orNPcMuHrWtjKeP+r9w3Ls5rtilTJPgHa7AvPD4= X-Gm-Gg: AR+sD10eBlM4FKwGfsYWEX/wM6qxYtGvmRwFD2Z5a9+YT6ctdN2HeIytoA3w8zMVrBV dVL6c9Rp+Rw3bgO/vE9drYxuWzqaFcCwuJRSYAftmdJryWu98N/RNDAcgBiBtJV0W067FH+2YSn in5aPaleWQdFafRBqAE+JP3UgnZ4Hagx74NVjVArJs0T87LU77DWV3io+U0ZG9+HIcWnJ2skHlu RmbMDcOFQ58Soq9xhDwL4sMesp5hkyfeXKUdaF/D2ttHuX5MB4AD+PnyYcp9li+oWJOE85kiwt2 B7l3DCvKTFk8ESJBV+QY6s47TVwkqiYShncT8C2894CCXaL/JfguMT6IMREuwMXMUgmxGyISPKj B285vV88vFNzMs58uo8HvRWExwDncg2D+fx2dDg7kGXNrdoKAA2oC5A0PGUWj/0Mz8sMLYnYJOw xCoAgLyC5MLyMGa8+cqa1lZvCiz/Vqqh7cHR4W+NKwLtxWrbExA/08pT1gHZYEvewD X-Received: by 2002:a05:600c:6305:b0:495:7a5a:d96c with SMTP id 5b1f17b1804b1-4997aadefb7mr1062005e9.18.1786462260473; Tue, 11 Aug 2026 08:31:00 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:30:59 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:11 +0100 Subject: [PATCH 08/14] perf auxtrace: intel-pt: Use new snapshot_has_wrapped callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-8-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 The new callback is only for the search, and auxtrace.c fixes up the pointers after a wrap is found. Update Intel PT to use the new callback and finish removal of the old one now that there are no more users. No functional changes intended. Signed-off-by: James Clark --- tools/perf/arch/x86/util/intel-pt.c | 58 ++++++++++-----------------------= ---- tools/perf/util/auxtrace.c | 14 +++------ tools/perf/util/auxtrace.h | 7 ----- 3 files changed, 19 insertions(+), 60 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index a533114c0048..b8de129a218e 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -1080,17 +1080,17 @@ static void intel_pt_copy_ref(void *ref_buf, size_t= ref_size, size_t buf_size, } =20 static bool intel_pt_wrapped(struct intel_pt_recording *ptr, int idx, - struct auxtrace_mmap *mm, unsigned char *data, + size_t size, unsigned char *data, u64 head) { struct intel_pt_snapshot_ref *ref =3D &ptr->snapshot_refs[idx]; bool wrapped; =20 wrapped =3D intel_pt_compare_ref(ref->ref_buf, ref->ref_offset, - ptr->snapshot_ref_buf_size, mm->len, + ptr->snapshot_ref_buf_size, size, data, head); =20 - intel_pt_copy_ref(ref->ref_buf, ptr->snapshot_ref_buf_size, mm->len, + intel_pt_copy_ref(ref->ref_buf, ptr->snapshot_ref_buf_size, size, data, head); =20 return wrapped; @@ -1113,69 +1113,41 @@ static bool intel_pt_first_wrap(u64 *data, size_t b= uf_size) return false; } =20 -static int intel_pt_find_snapshot(struct auxtrace_record *itr, int idx, - struct auxtrace_mmap *mm, unsigned char *data, - u64 *head, u64 *old) +static int intel_pt_snapshot_has_wrapped(struct auxtrace_record *itr, int = idx, + unsigned char *data, size_t size, + u64 head) { struct intel_pt_recording *ptr =3D container_of(itr, struct intel_pt_recording, itr); bool wrapped; int err; =20 - pr_debug3("%s: mmap index %d old head %zu new head %zu\n", - __func__, idx, (size_t)*old, (size_t)*head); - - err =3D intel_pt_snapshot_init(ptr, mm->len); + err =3D intel_pt_snapshot_init(ptr, size); if (err) - goto out_err; + return err; =20 if (idx >=3D ptr->snapshot_ref_cnt) { err =3D intel_pt_alloc_snapshot_refs(ptr, idx); if (err) - goto out_err; + return err; } =20 if (ptr->snapshot_ref_buf_size) { if (!ptr->snapshot_refs[idx].ref_buf) { - err =3D intel_pt_alloc_snapshot_ref(ptr, idx, mm->len); + err =3D intel_pt_alloc_snapshot_ref(ptr, idx, size); if (err) - goto out_err; + return err; } - wrapped =3D intel_pt_wrapped(ptr, idx, mm, data, *head); + wrapped =3D intel_pt_wrapped(ptr, idx, size, data, head); } else { wrapped =3D ptr->snapshot_refs[idx].wrapped; - if (!wrapped && intel_pt_first_wrap((u64 *)data, mm->len)) { + if (!wrapped && intel_pt_first_wrap((u64 *)data, size)) { ptr->snapshot_refs[idx].wrapped =3D true; wrapped =3D true; } } =20 - /* - * In full trace mode 'head' continually increases. However in snapshot - * mode 'head' is an offset within the buffer. Here 'old' and 'head' - * are adjusted to match the full trace case which expects that 'old' is - * always less than 'head'. - */ - if (wrapped) { - *old =3D *head; - *head +=3D mm->len; - } else { - if (mm->mask) - *old &=3D mm->mask; - else - *old %=3D mm->len; - if (*old > *head) - *head +=3D mm->len; - } - - pr_debug3("%s: wrap-around %sdetected, adjusted old head %zu adjusted new= head %zu\n", - __func__, wrapped ? "" : "not ", (size_t)*old, (size_t)*head); - - return 0; - -out_err: - pr_err("%s: failed, error %d\n", __func__, err); - return err; + return wrapped; } =20 static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused) @@ -1221,7 +1193,7 @@ struct auxtrace_record *intel_pt_recording_init(int *= err) ptr->itr.free =3D intel_pt_recording_free; ptr->itr.snapshot_start =3D intel_pt_snapshot_start; ptr->itr.snapshot_finish =3D intel_pt_snapshot_finish; - ptr->itr.find_snapshot =3D intel_pt_find_snapshot; + ptr->itr.snapshot_has_wrapped =3D intel_pt_snapshot_has_wrapped; ptr->itr.parse_snapshot_options =3D intel_pt_parse_snapshot_options; ptr->itr.reference =3D intel_pt_reference; ptr->itr.read_finish =3D auxtrace_record__read_finish; diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 9586989e645e..8ca872e6d465 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -2061,16 +2061,10 @@ static int __auxtrace_mmap__read(struct mmap *map, =20 head =3D auxtrace_mmap__read_head(mm, kernel_is_64_bit); =20 - if (snapshot) { - if (itr->find_snapshot) { - err =3D itr->find_snapshot(itr, mm->idx, mm, data, &head, &old); - if (err) - return err; - } else if (itr->snapshot_has_wrapped) { - err =3D auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old); - if (err) - return err; - } + if (snapshot && itr->snapshot_has_wrapped) { + err =3D auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old); + if (err) + return err; } =20 if (old =3D=3D head) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index c2342d0f4afb..a9d0c84184c5 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -375,7 +375,6 @@ struct auxtrace_mmap_params { * @free: free this auxtrace record structure * @snapshot_start: starting a snapshot * @snapshot_finish: finishing a snapshot - * @find_snapshot: find data to snapshot within auxtrace mmap * @snapshot_has_wrapped: callback to check if the buffer has wrapped in s= napshot mode * @parse_snapshot_options: parse snapshot options * @reference: provide a 64-bit reference number for auxtrace_event @@ -400,9 +399,6 @@ struct auxtrace_record { void (*free)(struct auxtrace_record *itr); int (*snapshot_start)(struct auxtrace_record *itr); int (*snapshot_finish)(struct auxtrace_record *itr); - int (*find_snapshot)(struct auxtrace_record *itr, int idx, - struct auxtrace_mmap *mm, unsigned char *data, - u64 *head, u64 *old); int (*snapshot_has_wrapped)(struct auxtrace_record *itr, int idx, unsigned char *data, size_t size, u64 head); int (*parse_snapshot_options)(struct auxtrace_record *itr, @@ -595,9 +591,6 @@ int auxtrace_record__info_fill(struct auxtrace_record *= itr, void auxtrace_record__free(struct auxtrace_record *itr); int auxtrace_record__snapshot_start(struct auxtrace_record *itr); int auxtrace_record__snapshot_finish(struct auxtrace_record *itr, bool on_= exit); -int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx, - struct auxtrace_mmap *mm, - unsigned char *data, u64 *head, u64 *old); int auxtrace_record__has_wrapped(struct auxtrace_record *itr, int idx, unsigned char *data, size_t buf_size, u64 head __maybe_unused); --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 503DB3F822B for ; Tue, 11 Aug 2026 15:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462266; cv=none; b=WHYGHAjM2OTPh6fC9Zb2yiKELwlJ58guNofLQrykoNE/8UcZIgn4azahM8GayjjPHmYwvgsewbG17x+2cTU8Kn1CFA2yJEXykqS8jDan+8T8yHirMzC644OrU+gNI/myM4NZMYeZq4zCdu8lDsAzKcG4KzBHb22Mct7hA9rMSA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462266; c=relaxed/simple; bh=74lpABqcB4r+lKhOt5ne94g0pmOsy67TRdqfjLvxrH8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=imPLAft/XhQF/bpx60rj33QqojQ3wPdzxTXvNG8yLtq6K+fbbXEGrAV1YpMbqLzx3UEI8+0Cj7dIVwqpOiza5tlx7Ao4kRAlVCVBBxK+wZNjOQLpAHVJQnikE5ltYp7FJbSKSFwbr/uiBBdyhws5wQb0S9mI1hGgGoOtmfK2iQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=vIEMTAaT; arc=none smtp.client-ip=209.85.128.42 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) header.d=linaro.org header.i=@linaro.org header.b="vIEMTAaT" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-498028b3d5eso36355735e9.1 for ; Tue, 11 Aug 2026 08:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462262; x=1787067062; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sLrtzOE6JfG2/1H41zLGULod6PxsqgJ0B9NXXbgCKQM=; b=vIEMTAaTlzqeru1HrdB/3bWUniBfj1toChH6DTnMX/3uexN3G+3/HcBCd6vsqbf36j eN4CWuEazzV4u2j9XN9Lxwmffk2b5YCmSHdjfhMlfPO/XHI6jURnk7abLtzdoDXCrPxJ 9uZAas7BCuuO5IdbABxCZbIMx7ASt8IDXt2e4XkPTrPAj/GGihsM0lDGQrp3Ws9UM+uh EsKq1KNbrdhBmodJ4G+SODYTLGSOeAoTD9mxRv4ogbI8P6pDDlA5M33ZiE1I4hsfJCPx werw2S7hjKBJMw4AjA+CilKnNLhNj6eV7qJIKCumDlt04PRaYrylb/vM+yn9+LvUh4As cD1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462262; x=1787067062; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=sLrtzOE6JfG2/1H41zLGULod6PxsqgJ0B9NXXbgCKQM=; b=VzF17C70Bg5dq4Q8hYjvP58CHmSLW+wnjGqPC6CJ7+udz+OnlFcjX4HiZeHSnuc1wZ GnSXnP5ZuwTkeE5rkvFT3+vfbL0rrR+EyccVxXLoqfDJ1AGn87TGo0wIvR8W19F1dLeP h7tFyP32/ZsymxTLYQCRHSJ9bz+lcVuNFszKlKM0nJbPD1PYlcojTkwRrG321RZuLZr2 yYWZwBhnZXMZBn8jUyg6DM15y0Yk9k0IHogTi0npnTq/kHT4f/NcR1c3bes/juM9xP0S mnH8lHGdRvXC7XANuSQyJdbsuNHd/rRQijXEPLMA95nQj7RLYUCkFR0cx1qmbtbAdicb G9Mg== X-Forwarded-Encrypted: i=1; AHgh+RqgY3xAnw4e9guFjsjgR6rlybeGEyfthkyytcGtYZPG7EyiI3CGrXvI8N8eJzXsTxq5thdtnGcv7dhFeHI=@vger.kernel.org X-Gm-Message-State: AOJu0Yye7Crt+9tcd1KcBx/Ilj5MwURWUZmqRawBv91ro6R/pO4MQkDC Mo1/6byNP/4TJ/yj65LgeZbG5t9Q55jesOs9Bq+MzxoV+UDBaPxOQTbjMQtfftMCLIjnyMuF4IT ukR5ZNRk= X-Gm-Gg: AR+sD13R7JFlrwEDO64nPdyF7Go3BBDBUv2dH02GiQE0zhd9W6JIoL9zrDAaqxXROvv 0QS3WhDHHuY6JXSbIJjxj69ymU+nWj7DXeZP6McqhBjZG3eiE5uvUhxNievCUYkFydxpaEJW54X dhbDOWxzpgXFyaoI4ryUmN2/jlKcKLUC5MimpCHHgz7TxIKs0BvjEHeSMcE3RwJSIOwl1GWee3B iypANpg7DDBwp2rndMUnPKL4u4fRsEc9bYoapSZVURoyBcMVZHHzOnfd/rDUc4iC+6iT6lNxSSb /IacPEql9w1W9XwbOw4giRfF3yxGUXlbDPblJAcNv49plke6qnoWT1RTJxktUH5JuXwoyoXb8LK QCOoLuq27EieWqDhQXiVdT6wZ2D7gHC48EE0ywoVHNEEIo6tqyG4irpYDUdnTvuJSRZi2HgFH3a 8zfS6D+lGUjDHVmcRxcikpS9vjB8azuUv7Kwf8uGZ8wgG5B3e/R3+zRQFdAqnHpTm2 X-Received: by 2002:a05:600c:630e:b0:499:757f:a9ba with SMTP id 5b1f17b1804b1-49978463c2fmr54014135e9.9.1786462262497; Tue, 11 Aug 2026 08:31:02 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:31:01 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:12 +0100 Subject: [PATCH 09/14] perf cs-etm: Queue partial AUX records Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-9-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 In snapshot mode AUX records may straddle the boundary of multiple trace buffers. Currently we only queue AUX records whose range is contained wholly within a single buffer. Fix it by queuing any partial AUX range that overlaps any buffer. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 54 +++++++++++++++++++++++++++-----------------= ---- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 28f5ce63ba80..5bafee31cf4b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -3197,7 +3197,8 @@ static int cs_etm__queue_aux_fragment(struct perf_ses= sion *session, off_t file_o union perf_event *auxtrace_event_union; struct perf_record_auxtrace *auxtrace_event; union perf_event auxtrace_fragment; - __u64 aux_offset, aux_size; + __u64 aux_start, aux_end, auxtrace_start, auxtrace_end; + __u64 frag_start, frag_end, frag_size; enum cs_etm_format format; =20 struct cs_etm_auxtrace *etm =3D container_of(session->auxtrace, @@ -3245,42 +3246,41 @@ static int cs_etm__queue_aux_fragment(struct perf_s= ession *session, off_t file_o } =20 if (aux_event->flags & PERF_AUX_FLAG_OVERWRITE) { - /* - * Clamp size in snapshot mode. The buffer size is clamped in - * __auxtrace_mmap__read() for snapshots, so the aux record size doesn't= reflect - * the buffer size. - */ - aux_size =3D min(aux_event->aux_size, auxtrace_event->size); - /* * In this mode, the head also points to the end of the buffer so aux_of= fset * needs to have the size subtracted so it points to the beginning as in= normal mode */ - aux_offset =3D aux_event->aux_offset - aux_size; + aux_start =3D aux_event->aux_offset - aux_event->aux_size; + aux_end =3D aux_event->aux_offset; } else { - aux_size =3D aux_event->aux_size; - aux_offset =3D aux_event->aux_offset; + aux_start =3D aux_event->aux_offset; + aux_end =3D aux_event->aux_offset + aux_event->aux_size; } =20 - if (aux_offset >=3D auxtrace_event->offset && - aux_offset + aux_size <=3D auxtrace_event->offset + auxtrace_event->s= ize) { + auxtrace_start =3D auxtrace_event->offset; + auxtrace_end =3D auxtrace_start + auxtrace_event->size; + frag_start =3D max(aux_start, auxtrace_start); + frag_end =3D min(aux_end, auxtrace_end); + + if (frag_start < frag_end) { struct cs_etm_queue *etmq =3D cs_etm__get_queue(etm, sample->cpu); =20 if (!etmq) return -EINVAL; =20 /* - * If this AUX event was inside this buffer somewhere, create a new auxt= race event - * based on the sizes of the aux event, and queue that fragment. + * If this AUX event overlaps this buffer, create a new auxtrace event + * for the overlapping range and queue that fragment. */ + frag_size =3D frag_end - frag_start; auxtrace_fragment.auxtrace =3D *auxtrace_event; - auxtrace_fragment.auxtrace.size =3D aux_size; - auxtrace_fragment.auxtrace.offset =3D aux_offset; + auxtrace_fragment.auxtrace.size =3D frag_size; + auxtrace_fragment.auxtrace.offset =3D frag_start; auxtrace_fragment.auxtrace.idx =3D etmq->queue_nr; - file_offset +=3D aux_offset - auxtrace_event->offset + auxtrace_event->h= eader.size; + file_offset +=3D frag_start - auxtrace_start + auxtrace_event->header.si= ze; =20 pr_debug3("CS ETM: Queue buffer size: %#"PRI_lx64" offset: %#"PRI_lx64 - " tid: %d cpu: %d\n", aux_size, aux_offset, sample->tid, sample->cpu); + " tid: %d cpu: %d\n", frag_size, frag_start, sample->tid, sample->cpu= ); err =3D auxtrace_queues__add_event(&etm->queues, session, &auxtrace_frag= ment, file_offset, NULL); if (err) @@ -3320,6 +3320,7 @@ static int cs_etm__queue_aux_records_cb(struct perf_s= ession *session, union perf struct auxtrace_index *auxtrace_index; struct evsel *evsel; size_t i; + bool found =3D false; =20 /* Don't care about any other events, we're only queuing buffers for AUX = events */ if (event->header.type !=3D PERF_RECORD_AUX) @@ -3353,11 +3354,14 @@ static int cs_etm__queue_aux_records_cb(struct perf= _session *session, union perf ret =3D cs_etm__queue_aux_fragment(session, ent->file_offset, ent->sz, &event->aux, &sample); /* - * Stop search on error or successful values. Continue search on - * 1 ('not found') + * Stop search on error values. Continue search on + * 1 ('not found') or 0 ('queued') */ - if (ret !=3D 1) + if (ret < 0) goto out; + + if (!ret) + found =3D true; } } =20 @@ -3365,8 +3369,10 @@ static int cs_etm__queue_aux_records_cb(struct perf_= session *session, union perf * Couldn't find the buffer corresponding to this aux record, something w= ent wrong. Warn but * don't exit with an error because it will still be possible to decode o= ther aux records. */ - pr_err("CS ETM: Couldn't find auxtrace buffer for aux_offset: %#"PRI_lx64 - " tid: %d cpu: %d\n", event->aux.aux_offset, sample.tid, sample.cp= u); + if (!found) { + pr_err("CS ETM: Couldn't find auxtrace buffer for aux_offset: %#"PRI_lx64 + " tid: %d cpu: %d\n", event->aux.aux_offset, sample.tid, sample.c= pu); + } ret =3D 0; out: perf_sample__exit(&sample); --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FD524028F7 for ; Tue, 11 Aug 2026 15:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462268; cv=none; b=WWKKuYdF2XgiZAeYL/553nnajdyd7dnOgfTgYI2wsLUdmRA50FKCElaiRdQYN9oKyf0bdW9KhI34ln5/csybMb8RBUUiNLgV+5awOZ20BmIbv3g+Enq1awwoyxUBQaMcGHdG202Ot5sC3pogpmEctuw4XuV9+an+o9QBLHTdSl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462268; c=relaxed/simple; bh=CcziqDEFRnESq6aJPL8h/5XKaif1MSl+G2p58OltOUQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HIwCPN8xgIdfb0Mur+yNEuqfihxx+VznDdHVaB3COj48JdmmEy5ZrXqE7OuuICiaNjcZD5f+sVqUJMJ2+49WHsODUs626WHI4vgGrV5gGuap4nZLxqcLXs2YVIiPofXCPsx/A2i7pLKbZmxtpAh/4QqROVBb6tuqot9FzW9TVmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=PWm9Gb3Q; arc=none smtp.client-ip=209.85.128.49 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) header.d=linaro.org header.i=@linaro.org header.b="PWm9Gb3Q" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4980fe6b3beso9190055e9.0 for ; Tue, 11 Aug 2026 08:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462264; x=1787067064; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bA5/MBZwzPPdo+x/NUW/gcy1HnQst/utc/ghTFwGrIo=; b=PWm9Gb3QQzS+BGBfwnkf6erDZ5mo3mqTeBGS5LyhkS+mZm16fHlJh2Q/pswI0q/cXE KID8TXaluDarrMJfWt6Cnl8zxIw66Z3kzyWvz5+YuouhjnM8rKXR6VXkP/BpC4OWa2zv dcjK/5GVm1N/uSgw11hlOaZAax4btt76erwPq/L40N8xmymfjjeBBXA5j3uMFLiqokpa C8aD8JPRH2ulxqAbHkheyDJbH0CJvnP17U8wMAzPIwcVKWAeGW9y9SPC1RveIil3e5PB NYB4ezf7Vsms82VcVb4/gibaPbW2CFRWRkGPyUZknstdwsJ+59+FCB9DiJ4mLa4iNrix Safw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462264; x=1787067064; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bA5/MBZwzPPdo+x/NUW/gcy1HnQst/utc/ghTFwGrIo=; b=P91jclPzYoigebSsiszpRU1sDHmMHZ4knKpV7GP3h02qFWLMMoXuTwKAWpONXzqyTD sA/GtG/jQ22GNQUcbkzHd9VjTjvQvZbmccxvHWyV2O+DlN6oIFUFtFRzIBOMEi46WBYh ImciPwUAyu7BQJ4Ybm2cOGMQClQXgcSP0w7Yu8TA6rXyMgqr/zxIXfnsD4GjuTQD1gzN abNaTbfd+dw7Ib/olrpHnmO/zKBZO1UTd4ey7P9IUOwwCE7Mr70/hnbIIfdDh5SzEBvN pW3WghvhR6NVQT7M6fgvAHQJJz6+mpnd2J2xNcYNTkCp/g68pnQTksQjQZsdVS44zGw/ BLTQ== X-Forwarded-Encrypted: i=1; AHgh+RrkhNiqBnNjet0YEd50d35lNd1ku6xdABSVVP6G18VQeWQ+dTGoA0sGHSC81OxCFuKE5pToCBFMKnciO7s=@vger.kernel.org X-Gm-Message-State: AOJu0YwuiEa3VNA/XKOe70col6an9tybdKUX712XXvu7VFfMHU5v2MYw wGwkJf8fA6q0MQXD9/HbUzb88ZCkWNevBw6EYST3mQVFhpba870mSdP/EJXXWDnDPxg= X-Gm-Gg: AR+sD11LabwIHWio4wNRxJ4F2yyrd4kT2unmUrwiRdzLHyaHgpV+fE4yvhLmLNgEMkh 9LLglU5fvtJQnd3T16XaZBY4mqBNGqjtvdPY0EpIXPDHfzFqOAdvi7u/HUY64Jsu18JP2WrPczP zVXC6keU24DGBVL2/vBTUgw9MX1nVJQTqdwGtSWGy0SkIuCp0FmqpVNhdG4XYwr4AOwOC8EuZex 257/HCAAhT9KGSpvlR4dahSHOWTodGm/EI9HuM92Ui18plbvwZ5LOWaNjWXPmmA6RtwTMt8Lr24 JZKlxjWlx+loTo1mHrWl1PaCyzux0z0vEPk/sXR2FIic7zLj3QeHFOg2Qb94guTRn45r1B37N+d ktAZEdUgEAlGrD0nHJY4ckP6j2VBWOTliUmXm4OQvE70qroHwvyLA+rvgUQaTeGQBTMe2JbRaB0 s/5AsbIwzbWVMgpZHOdicmPxnDxCSEp1iE3h2630iLhF/WEY2pEybTx3vYiM9O8Qwn X-Received: by 2002:a05:600c:310e:b0:499:59fd:dbfc with SMTP id 5b1f17b1804b1-4997a6e5226mr11138885e9.1.1786462264095; Tue, 11 Aug 2026 08:31:04 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:31:03 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:13 +0100 Subject: [PATCH 10/14] perf cs-etm: Don't print missing buffers in snapshot mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-10-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 The driver produces lots of AUX records for trace data that was never captured in snapshot mode. Downgrade this to a pr_debug3 message as it's only an error in normal mode. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 5bafee31cf4b..a80f34530917 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -3317,6 +3317,9 @@ static int cs_etm__queue_aux_records_cb(struct perf_s= ession *session, union perf struct perf_sample sample; int ret; struct auxtrace_index_entry *ent; + struct cs_etm_auxtrace *etm =3D container_of(session->auxtrace, + struct cs_etm_auxtrace, + auxtrace); struct auxtrace_index *auxtrace_index; struct evsel *evsel; size_t i; @@ -3370,8 +3373,10 @@ static int cs_etm__queue_aux_records_cb(struct perf_= session *session, union perf * don't exit with an error because it will still be possible to decode o= ther aux records. */ if (!found) { - pr_err("CS ETM: Couldn't find auxtrace buffer for aux_offset: %#"PRI_lx64 - " tid: %d cpu: %d\n", event->aux.aux_offset, sample.tid, sample.c= pu); + int level =3D etm->snapshot_mode ? 3 : 0; + + pr_debugN(level, "CS ETM: Couldn't find auxtrace buffer for aux_offset: = %#"PRI_lx64 + " tid: %d cpu: %d\n", event->aux.aux_offset, sample.tid, sample.cpu); } ret =3D 0; out: --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5021E40DB4B for ; Tue, 11 Aug 2026 15:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462270; cv=none; b=CSIJclOi22LmBvImzlhkXy61T/wcnREBiLRxjWiCwRdb8hOeVMglyA4ZGb5zXhWFvR4GPsRlBvkrBmClmx0z8EfytOqhuGFFMRFJtusBVik2A8nCCI/4L9d20CKm0Fh5w1tvy49Os37yEaQqjuRm9RJ+BX5Wi0+IcAd3IlAYhaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462270; c=relaxed/simple; bh=fm7817PJXD9fz4lHXUyEY4UubPN/xPMUymDFvW6lWqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WjK8p1DZvQpnidEuZgEa3aP6sD9Jsr77al6spa5PczM7EB1fyqF1M+y85FroMmtK95WVjAFIG/DfrjWDUwmYEZTEJ4KUg3lcfYMAZOWCKuAgyaTyAa0VoJAtJWd/hmRhBqSHlDnwDxE9m16vthAmPal+WRFjU8JXpmHSQv0RrJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=oe3yG5Sk; arc=none smtp.client-ip=209.85.128.50 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) header.d=linaro.org header.i=@linaro.org header.b="oe3yG5Sk" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-495635a85d2so28136675e9.0 for ; Tue, 11 Aug 2026 08:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462266; x=1787067066; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iIEqHB2kupPj+LJwStZlpRLPHkBGU+WfDNFf0olHiVQ=; b=oe3yG5SkXDJbUeACkepPqbKesotJ9fOEgcTZVzKGGqCNRwrMa1OUtSTuNy2ftZS4nn Ie5cz9BLcuH3qUA6uW33Ejno0KzNse8N+4aBs3ayG6aq0CwY5WXeg4R0dPmcraxKJnDv Zcy1dwBpmUKqvNSTnBi34WmD6PTduw+/UB1LSmR54UoeXLYkbj/kRRjoabQU/U71npqd ObaZ3knULUyiEhAlTJdt/LlXfYpgJt6QUJ6Z+1rIdhbMAoMpujahUQQb83Fo+0hA0XpE aYjmpn2T8sKB/tDmHNnuAaEyfMkDlPZXRYJ1Xu3gEeqS5KlnwdCHYlCPF475wI4S5ESR D7tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462266; x=1787067066; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=iIEqHB2kupPj+LJwStZlpRLPHkBGU+WfDNFf0olHiVQ=; b=DvuiCDqFNQfZI8g3WaBSUqJ6GexeBXeKJc20Noi1qHNkyoIKXDi9UEDuWDgTKLydRd NgLZgNSRofcyyYE2p6yY9fRKHHUjcV+sUz2jRmhGrEaaS9RBZ5xC/jKLwy5S1uTWqGNj T5ugu7QEYEiPdVUt04XQZDZ2xYNYjrWOchhEZFbP3AYPNHT7GFOzs+1V0uj7z1fZTJlj DGB8KTGCDlCQvO6YqgRA9SXAYJvDzUuRpGv1j/+k2q5U7j4f5ZixHhukSPdgP2HKdr7F vEexP45iGudcpp/5iq2y3s5NVWunqYmwIE6t5484yFZ+jYm2d/UsN935kbdBM8/qgiaV m13Q== X-Forwarded-Encrypted: i=1; AHgh+Rr4oo0KlbbMK7Jzy6oers12PTAisQI8hybsLljm0wUz2c68w3PGjPmtdy95+DVLQA/nX39ZEUV4KEeJDCA=@vger.kernel.org X-Gm-Message-State: AOJu0YwyW+qahe0+JAKcs3X901VGl3PGVd0HUMUAzLHg4Do+U0eqw0Q4 hlLgEXKsJOb7Fy6BWFcEgBZ03/P3boOdrmuJbj6h7WI3bS1x3JZX36l6u5DhDK5PSRE= X-Gm-Gg: AR+sD12teSkYfFqNWPJpZBF2YlP+I7ndU/ap/+/gjnSsU/Kal3G1TgHZBU8T2vNNKXf P5AMwkzee3nd0uZNqABPifqB3ToD076GjDSed9HX3QbkdIjHS1Ca2L6B+4ckO65LHHxdHHI/Mxz Vp5fnM052a1WLRBzpYaGS3i6Em2r0Hv38aLo+vPf6tFuv30kC9hgrTLn0QAMXV7R9tJGQAhshbd G6i7aqbLbR5xIDQ1xYUTP9MLC8SqG3R8HDCKFPTNIwc9jFyAWNOJrl0KmUsb28bgc6mnUMxO9FJ i59o3POnShgBD7Iej17hU0sjrl52bENXlGOogITK2UIR5qIbUgKYBFgveSLA35r5dda6uJ0gpKZ C9rDyuNopiWoiAc/sicCHAYFccgODuwNl8w4x3L+uT/Oe7x56Ri7gMUzHz/mAdcdriaESNhCAgT /RVzQ7SjmFYutvzJyoJPoHP02W7eeLgRUhgOKnQk/m6PWoCb7Kf0bxkvFpufxg7tuH X-Received: by 2002:a05:600c:4709:b0:499:5220:db3d with SMTP id 5b1f17b1804b1-4997a65ef59mr12003705e9.16.1786462266487; Tue, 11 Aug 2026 08:31:06 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:31:05 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:14 +0100 Subject: [PATCH 11/14] perf auxtrace: cs-etm: Capture wrapped snapshots Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-11-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 snapshot_has_wrapped() isn't implemented for Coresight, so when a wrap occurs we only save from offset 0 to current head, modulo buffer size, rather than capturing the whole buffer. Coresight drivers currently use a monotonic head pointer even in snapshot mode, which gives a lot more information for taking snapshots than a wrapped pointer. It means we don't need to search for data at the end of the buffer to guess if a wrap has occurred, and we can go back to saving partial buffers after a wrap by checking if the next size to take is less than the buffer size. The drivers will always be able to generate a monotonic head because TRBE has a bytes written counter, so even if we stop generating an AUX record on every overflow, we can check if the counter indicated an overwrite and offset head by a whole buffer size if it wrapped. This forces userspace to read the whole buffer rather than between last and current head. ETR and other sinks use software double buffering, so can continue as they are. Add a much simpler 'monotonic_snapshot_head' path for tracers to use, and use it for Coresight. Signed-off-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 1 + .../perf/tests/shell/coresight/raw_dump_stress.sh | 5 ----- tools/perf/util/auxtrace.c | 22 ++++++++++++++++--= ---- tools/perf/util/auxtrace.h | 2 ++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index d36b7e41399b..dbf76dd3349e 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -918,6 +918,7 @@ struct auxtrace_record *cs_etm_record_init(int *err) ptr->itr.info_fill =3D cs_etm_info_fill; ptr->itr.snapshot_start =3D cs_etm_snapshot_start; ptr->itr.snapshot_finish =3D cs_etm_snapshot_finish; + ptr->itr.monotonic_snapshot_head =3D true; ptr->itr.reference =3D cs_etm_reference; ptr->itr.free =3D cs_etm_recording_free; ptr->itr.read_finish =3D auxtrace_record__read_finish; diff --git a/tools/perf/tests/shell/coresight/raw_dump_stress.sh b/tools/pe= rf/tests/shell/coresight/raw_dump_stress.sh index bea70d825596..c9459ded4cbe 100755 --- a/tools/perf/tests/shell/coresight/raw_dump_stress.sh +++ b/tools/perf/tests/shell/coresight/raw_dump_stress.sh @@ -48,11 +48,6 @@ read -r size offset last_idx <<< "$(awk ' # everything was dumped. Allow 48 bytes difference to cover 3 frames: curr= ent # frame length, a partial frame and a final empty one, all of which aren't # dumped. -# -# TODO: for a single snapshot, offset should always be zero. However, we -# currently output AUX records in snapshot mode when we shouldn't, which -# increments the offset. Allow for that until it's fixed so we can test raw -# dumping. decode_size=3D$((1 + last_idx - offset)) if [ "$decode_size" -gt "$((size - 48))" ] && [ "$decode_size" -le "$((siz= e))" ]; then echo "PASS: AUXTRACE buffer length matches dumped packet index" diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 8ca872e6d465..e3c770b46e94 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -2051,9 +2051,9 @@ static int __auxtrace_mmap__read(struct mmap *map, bool snapshot, size_t snapshot_size) { struct auxtrace_mmap *mm =3D &map->auxtrace_mmap; - u64 head, old =3D mm->prev, offset, ref; + u64 head, old =3D mm->prev, offset, ref, size; unsigned char *data =3D mm->base; - size_t size, head_off, old_off, len1, len2, padding; + size_t head_off, old_off, len1, len2, padding; union perf_event ev; void *data1, *data2; int kernel_is_64_bit =3D perf_env__kernel_is_64_bit(env); @@ -2061,10 +2061,20 @@ static int __auxtrace_mmap__read(struct mmap *map, =20 head =3D auxtrace_mmap__read_head(mm, kernel_is_64_bit); =20 - if (snapshot && itr->snapshot_has_wrapped) { - err =3D auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old); - if (err) - return err; + if (snapshot) { + if (itr->snapshot_has_wrapped) { + err =3D auxtrace_find_snapshot(itr, mm->idx, mm, data, &head, &old); + if (err) + return err; + } else if (itr->monotonic_snapshot_head) { + size =3D head - old; + /* Force a full buffer read if a wrap has occurred */ + if (size > mm->len) { + pr_debug3("%s: wrap detected, adjusting old from 0x%"PRIx64" to 0x%"PR= Ix64"\n", + __func__, old, head - mm->len); + old =3D head - mm->len; + } + } } =20 if (old =3D=3D head) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index a9d0c84184c5..971b817d3396 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -385,6 +385,7 @@ struct auxtrace_mmap_params { * @evlist: selected events list * @snapshot_wrapped_len: number of bits in @snapshot_wrapped * @snapshot_wrapped: bitmap indicating if each aux buffer has wrapped + * @monotonic_snapshot_head: driver doesn't wrap head pointer on overflow */ struct auxtrace_record { int (*recording_options)(struct auxtrace_record *itr, @@ -412,6 +413,7 @@ struct auxtrace_record { int snapshot_wrapped_len; unsigned long *snapshot_wrapped; int snapshot_search_bytes; + bool monotonic_snapshot_head; }; =20 /** --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C83B0442FB6 for ; Tue, 11 Aug 2026 15:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462272; cv=none; b=p8AlMQMAyx1V+rQ3VBY+5/IW0BTM2cUUZrawRGtpZhmp3+nnq9L0K5CejRSgBSAwBwnb085o0AioK7YIKpvvC9xHslj8gLVap1w7g/APayJsS7B/ISEXBzZKc7bO+GnLVi43uxnbWn3K9oDsWtNXEL8jRbMy7pCceaxeahnXtmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462272; c=relaxed/simple; bh=rTMPj/k3Q/u75BzRf3kKvE+NUom8emDrF383KCKzh/Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cpKb6dA7PpEFpwerJhGs3NfAweHQZRwDZhIunmA+BMT9LnjqUwiFKMi0Gopj8PyMUBK6wLQ/5QND+4DvLThKHxqJYJpRPFzxRgKJy+3rwlEpueFKSFNjyuPnzyEc1yMDI3+Vm8H2NVikJIbJdZ8CKI7DwnsWAhLyUrHKCob2CTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=OFqGozdW; arc=none smtp.client-ip=209.85.128.54 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) header.d=linaro.org header.i=@linaro.org header.b="OFqGozdW" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4954aff6088so28070865e9.3 for ; Tue, 11 Aug 2026 08:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462269; x=1787067069; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8Jf25htTTjahKWtoEfo2hIZORvEQKfVJc2fvPx9rUTY=; b=OFqGozdWLw7r2uGsqLBEHS0vupOiOUTSHCnqCJjqdsKwQCWkLwXS+eHDBJcgFSOcAf 3wIL8w3EQSvb3oehmrLk6V88cIHBt+lw/SsQVpVzecowSKVpNjSYgbcVidWVu2whAQ+z KGsiCWpeIUoGnzeGs0OGhTOKAI51V7um7qCZz7JxwJTycjbq8wovkdZ/dm4xhJKzhZ4e SnSbRM89BL2iwekIoytpuXYQFfM+YEJL3IrGDk4172d21er2PDLV8ezHrSbkTOOGK5BH hwJAoB5I/EUhnWgHhmQpd5ZPig6bSmNI5l4YelCv6e3hg0uoyV7b0JEv3W177jYDYVaW /OkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462269; x=1787067069; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8Jf25htTTjahKWtoEfo2hIZORvEQKfVJc2fvPx9rUTY=; b=KkGY1eYzBdXrzd88xqrSEi+73c6MG5YJNYGCsIZdWO8Cw6i9IDOuPkeXbxE85+KHdf oh2Ovv5wwDFQl456LRwVCjMfLquselcqpLjR53kp8vNg0tcKE1K21KgJ9FpsK3RW+Q5a wbf3bwrCx5oX+vHsW2XN3ZVXm1TVVELS9ZhiUwVCODqHdI8EWiZBWwJetCWD5jr8Y9ex HqpbdBnmSPB3lPtEhdOBLNi7hyujQzCDkaWIm4YVoZ6AC0BKEpcHutiAJednxIKY/VA7 DQFWbpjkX8rhjc4ZBdGt2XHBtKFE5sdGPOaYBdeIXbmHokSuXZSlJ/pYm2dZKU4rZWuf 5GTg== X-Forwarded-Encrypted: i=1; AHgh+Rp3xoDt8B6UPdzQqu810tmnG36XcwgQuNQ28N7NhEEls00XpVj93RB1o8leSHEOfQxzQ5Y0W7ZuKl2T8mc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9mxLo2ll9+Fa+CS7ieSJGrFUZryaVDEXGZrMaF01UhSZOXZvd rVEnv0Eb1M0SbTiSGjk+Y/K8lsnXwEXHxJ3wTFQ05baZz5mwhvS3f1eUEJoF81ZbAos= X-Gm-Gg: AR+sD11v4YwLOgPlUMLaYvG5x7VpA727CeVJhNcxvIRuECR+n6MeF9AS8J7ING1+F4y 0AoxegnK6QWs44ZXlVVpzO1fMwWwbDLxlFPcFGYLTvLX33lQ3v22wZygVOI7zREbRBdQ7s4YRNY tJpAAYBVa3sygTAADoAN1w//IJY/Y8zNQcj5O7yoDYAM2y6hsqXIBRPsBUdKJR5T85ru+7NGZDa LwfZiY0/tIMa8VGxyjdSkZuZcNHidGM8srIpBn4aZFq9F4++avRX+8DpeUXwPYbnmtqzCb2sajR eFg/Q01hRQAnTTvobTR2n5sq5g8kNTy0LKJjPYSJRKbZUJsBlns8djnQf1BqrnlZIF0uc6/0BW4 +NMcUdGJmreIa3ssLjM7KHDkgdjDkqnAIc6RAEoeSp22nM01OiGgphu/tYa6Zs4GI8N3LMzOTRw 3r3qRc/hyfSobg0OsfGALk/iYAbr77KRr+NR6nSO+HOFxy4YDq5hmsGB1hlaW4lPTU X-Received: by 2002:a05:600c:1550:b0:498:952:e276 with SMTP id 5b1f17b1804b1-499784358eamr51427345e9.8.1786462267978; Tue, 11 Aug 2026 08:31:07 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:31:07 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:15 +0100 Subject: [PATCH 12/14] perf test: Allow infinite named_thread loops Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-12-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 The following test will want this to run forever, so add support by treating 0 loops as infinite. Convert i and named_threads_work to be unsigned to avoid undefined signed overflow behavior in infinite loop mode. Signed-off-by: James Clark --- tools/perf/Documentation/perf-test.txt | 2 +- tools/perf/tests/workloads/named_threads.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentat= ion/perf-test.txt index 859df74e62ef..dca8972fec8d 100644 --- a/tools/perf/Documentation/perf-test.txt +++ b/tools/perf/Documentation/perf-test.txt @@ -68,7 +68,7 @@ OPTIONS nrloops: brstack, context_switch_loop =20 'named_threads' accepts the number of threads and the number of loops to - do in each thread. + do in each thread. Use 0 for an infinite loop. =20 The datasym, landlock, deterministic and callchain workloads don't accept any. diff --git a/tools/perf/tests/workloads/named_threads.c b/tools/perf/tests/= workloads/named_threads.c index d051d41a3cfe..6672c2f77684 100644 --- a/tools/perf/tests/workloads/named_threads.c +++ b/tools/perf/tests/workloads/named_threads.c @@ -11,7 +11,7 @@ #define MAX_THREADS 25 =20 static int iterations =3D 500; -int named_threads_work =3D 1234; +unsigned int named_threads_work =3D 1234; =20 typedef void *(*thread_fn_t)(void *); =20 @@ -19,7 +19,8 @@ typedef void *(*thread_fn_t)(void *); noinline void *named_threads_thread##n(void *arg __maybe_unused) \ { \ pthread_setname_np(pthread_self(), "thread" #n); \ - for (int i =3D 0; i < iterations; i++) \ + for (unsigned int i =3D 0; \ + i < (unsigned int) iterations || iterations =3D=3D 0; i++) \ named_threads_work +=3D 3; \ \ return NULL; \ @@ -65,7 +66,7 @@ static thread_fn_t thread_fns[MAX_THREADS] =3D { =20 /* * Creates argv[0] threads that run a unique function named "thread[x]" wh= ich performs - * a multiplication in a loop for argv[1] loops. + * a multiplication in a loop for argv[1] loops (use 0 for infinite loop). */ static int named_threads(int argc, const char **argv) { --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9966F446827 for ; Tue, 11 Aug 2026 15:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462273; cv=none; b=J9ju3+NigsdnRsy2QxtUpEEogwCPc4RUnP9RTH/9QziMhw2+5qtdHNZW2F7O2kMVNMD9weSYJHN+TQoSQaH8goEMuhb4Ofj2Ca9jK6JUdVZnB/8zFNmz2k/6NPEATZqiRuh79YbqYMkCMoXSbEEjL3Dln4TM7mmi2lQJZH4Jk0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462273; c=relaxed/simple; bh=oUg7RFIUnB5PZ229CdzPdEVvo+kzyf00RHPUIVcKnFA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T6Qo7GqAr/+M5difcTLJLrhu9IRdx/p4D443JpZIe3C4J/f1vtwA3I9RDgC0R+YFGjf3WPpnpeJl2uZ/YjO1Qde9ZmIOIU5gFI2ijD2SDunMjJDY7vtqAgw3VSo6/+MJpQI7Lza+YefqpzVNuhOkYiOaNGnRtk6xRGLpFI3yTVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Y7Lszj0H; arc=none smtp.client-ip=209.85.128.45 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) header.d=linaro.org header.i=@linaro.org header.b="Y7Lszj0H" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-49553515a8bso51318155e9.1 for ; Tue, 11 Aug 2026 08:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462270; x=1787067070; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=XCKgmnJbp7mmf0EumlB0lo4QQt9rPy5YuLxw+XknrhY=; b=Y7Lszj0H27SmfxlrUZIWt+HWf+SEXJE95/R33dWh5KuM7sI4JVHDzLCxoTyvTqzmF9 VGQcA+CP9T8J7fyOk9UxJxUQEE9Z3DtrBzSgD8XZiReyIJ6A3LrUcy81kLgyFDOXf1rl Iafvyrb2D2KJkip/MIlysM4XX3FcmP0V63Mb/0Av+AzGq5vIGWWABED5W0QmNQ1w+PB4 gMWU0vW88R7k+ZfZSPItzVoUYGoc22Y/2+I7tWjMxhCb36JAXTGtVk0VmKEYVROpX04D fm2tp2C2JuoRTaKmpkTZkJKtAmju8xr1IvJlpca4ROxZK5LiMtzId/L9IWB1WFvmi2o4 2Blw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462270; x=1787067070; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XCKgmnJbp7mmf0EumlB0lo4QQt9rPy5YuLxw+XknrhY=; b=cEs2BPgXbJobRQWiLe3rggtGk7ZnIM7nZFdWe9Nh+VFYoeTIHQBc+xc6slXfwQSwrd Ja0n1GDrLorKKZct48A0lVtsN+Sw0NLJfTc6ZoT+1oQzaXiCPUl/lUVdJ7/brLIVhdET C/uUqrXH8ZOuewwvvIyLMFGslHtS1i4TdcpmNx5b3GFjk8imf1QO49f6yUUmTnfp4agM h4pTDQesDNerYYU8yt9RKpodhL5edQztfEVZ7rCvXX+vBK8pXz7fJ/U9eO+FHtX59Fqp lPE8zgNvJORpXuazS29LYM2hhACG7AmcX0b2oE/36lLdz7+zivaw2dDtANGas/o+ZNcK +CTA== X-Forwarded-Encrypted: i=1; AHgh+Rpwvr/ep8gjQAWZ3OTJT6tIJy2Y4l7LLB/D9W8audNQ/Yige59UPmZhhZQOLcrAvMItZQaFMiBLOFCdPwQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1rUBgbZ98EYwh8zVR7qwS52TS8NlTvU8eNd58Ri2Nw4VQpJ5Z 3E6rQr99odMkH58x4K9JOnShZKzewM0jY8xkqbU3Y1N4rJQZOVgEGau2z+CNC7w6R4s= X-Gm-Gg: AR+sD10EZ6iiARs5bSDEf5oc0A6siLLUb/5RnC0c34IjZgEa41Or5ybxRghBVPBw1tQ L/V1vLIVk3O5R9SMvlL9YyRsNSFK0H/kuhLB9p7GkL9Lz/wbp+jVl78/VJO25ewZpUUgN0GcwoJ kTpBTHr0twwUZlhYNuzKLIARJCR2zuiJ84HYUkiLA2VrF4Fo0rJHhisqTK3X4vYuHR3SKO1klHt ejhOTW/NMy9plzty2PzHMhJyR9gHhB/EcjiFbUYI9uRhb6fyAjbr21nolZwBjRo03RbhoUQfAdx +xnuTKJVY4c0qq3gzd5sM3eg0GA2+BtJoEKkKjn6jHoXzyY5ZtsGysFHqKHD2U1IVxUUZQcxyTN tlZb0saCx3kyqrJWHZvOGWLl6tH+sxkbgLd1gLx+EL23a8milXYyIzQIvLQ0wp23GFoy4HucDXp h2233GPc7Nx5aEv37RGMp/0fnKje1OSdXqJeEl9nlfkzYBCr1T6tYSbPMD4yqm58sU X-Received: by 2002:a05:600c:c162:b0:499:484a:7644 with SMTP id 5b1f17b1804b1-4997845f3e7mr63045865e9.9.1786462269793; Tue, 11 Aug 2026 08:31:09 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:31:09 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:16 +0100 Subject: [PATCH 13/14] perf test: Add test for per-thread mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-13-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 Test that per-thread mode works when the process migrates across CPUs and that the decode happens in the correct order. A TODO is left in for when support for decoding in order with Perf records is added. Signed-off-by: James Clark --- tools/perf/tests/shell/coresight/per-thread.sh | 48 ++++++++++++++++++++++= ++++ 1 file changed, 48 insertions(+) diff --git a/tools/perf/tests/shell/coresight/per-thread.sh b/tools/perf/te= sts/shell/coresight/per-thread.sh new file mode 100755 index 000000000000..77d1ed3405a9 --- /dev/null +++ b/tools/perf/tests/shell/coresight/per-thread.sh @@ -0,0 +1,48 @@ +#!/bin/bash -e +# CoreSight per-thread CPU attribution (exclusive) + +# SPDX-License-Identifier: GPL-2.0 + +# If CoreSight is not available, skip the test +perf list pmu | grep -q cs_etm || exit 2 + +if ! tmpdir=3D$(mktemp -d /tmp/perf-cs-callchain-test.XXXXXX); then + echo "mktemp failed" + exit 1 +fi + +cleanup_files() +{ + rm -rf "$tmpdir" + trap - EXIT TERM INT +} + +trap cleanup_files EXIT +trap 'cleanup_files; exit 1' TERM INT + +echo "Recording..." +perf record -o "$tmpdir/data" -e cs_etm//u --per-thread -- \ + taskset --cpu-list 0 taskset --cpu-list 1 taskset --cpu-list 2 true > /de= v/null 2>&1 + +echo "Decoding..." +perf script -i "$tmpdir/data" --itrace=3Db -F comm,cpu 2> /dev/null | \ + grep -Eo '(taskset|true).*(\[[0-9]+\])' | \ + uniq | tail -n 3 > "$tmpdir/script" 2>/dev/null + +# Check that the decode says it ran on CPU 0, 1, 2, in that order. TODO: T= he +# correct result should be "taskset [0,1,2], true 2" but we don't decode t= race +# in order of the Perf events yet, so everything is associated with the la= st +# exec. +cat > "$tmpdir/expected" << EOF +true [000] +true [001] +true [002] +EOF + +if ! diff -q "$tmpdir/script" "$tmpdir/expected"; then + echo "FAIL: per-thread output doesn't match expected:" + cat "$tmpdir/script" + exit 1 +fi + +exit 0 --=20 2.43.0 From nobody Tue Sep 29 06:11:06 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3796C449B0E for ; Tue, 11 Aug 2026 15:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462275; cv=none; b=H71JxvyY/ksAvEHU8t4x7KO+Ub1KGwUAm/tr0l0V+hd7bb0HlVcIatdfj9IC8oKd+oy0bxNqpiTHuzbXqQU/iil1pukJpOmE57G0xK/BiUrnfEa0Dr+TFLUxd6l3Dk51OozjTmBredHaL5dxlddBDIYY/8Qi+5kbUQpV3XdPdzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786462275; c=relaxed/simple; bh=45ewM2dvFaY12LY151swUHBTvievnc3sust8Ep02uoY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KkDzUJMkuyp8ftQoZ6aCuJVN/6ALuDRHw2DeobVkqKonLGSZJWF4HzC06VLM4IyEJBMbJoGr1L+PFvz/C9GMWfFiq75UyR8EuUhE8HLQD1EQL3Bi1pZ8BvAtvfhNHGiD7lhaxGjpwiEyjZlcE1fbWOHofAwBC1KMjL1nxW4FT4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=XKhHoCze; arc=none smtp.client-ip=209.85.128.44 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) header.d=linaro.org header.i=@linaro.org header.b="XKhHoCze" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4954dff6536so25336485e9.0 for ; Tue, 11 Aug 2026 08:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786462271; x=1787067071; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ghssS34122+SF9JGQaRPjJsmiH0qvioNjK1NWp3olSk=; b=XKhHoCzeSiBQhbZ2h0qABiKAZFCt84kDfp3UQatAapL0fLX4CXM53CcuhBTL+lmDYH JntksQ1zn0P9dw/moBLZs+UzvO/o46NOc4NeXzE0NKNK12s3f05CzS5SKaBVtw1hf8pB a3uY0VLfVLCe7r23INbhZRBFTQ6JRDHdMxCHqKkorB0D6GU0DLbW0hrybiv3iXKufLsX ADzSlcYnlk07b7ref+v/qZrklxGf+/HAgq7dHwk1yzrea/sPSJFf1Z4rU8jSVcvazM3B wr9tqBws3K1cJdSjI7NAdSaTtnFue3W/jeaYDTrZgXBihtQhPnWtH6yAwvleVsUx6MNQ 42/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462271; x=1787067071; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ghssS34122+SF9JGQaRPjJsmiH0qvioNjK1NWp3olSk=; b=dYytEQyuxE+/cJb1t+wONKg1h0E4irPdT/iKkvI2zyTrXwl4qrfO2lb6Q0RESdRjJJ j5CXQyMVPHnQYXJEGZMOx2aN0SjvDRX1RPmSVlUgRXb8Y2dxD0j/KYpTj8OH7JA6L9+2 W0AYiXjnco+bRsu+jzB7VVRTTLnKpXWjGQbeiDtIgZmA7/d9A7Ql9fxKf5UB+QuP1Uoh 6nglrQhjrHy9RozyhrI2Q+87H1NYuCGDUIsBRr06Hq9D5RnwB960Jz7ATdiYSFVg3TT/ KM6GPVUmL/6Z7LKq6bKgOHvQKSjK0Rlpm7jsdgQpZN/0ku11ExAZE+s3Jycaycuu8Onl f82g== X-Forwarded-Encrypted: i=1; AHgh+RoHuTX54Vl4sFD12B4D6Ujx9z69M6TvMLGRgTlYcL/Gcao1HTqbjz18dtRD657bnQ7o4nq3aSqaRo9dncQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywc7LYcP4GxSs1aBHYPeKlyv/KGVg54Mvg9siQ4ivlBQOd6PSmR ZCNhDksOaRq2CoYCc6P4V1K115gUsXdKau2S8HMuZGN6sNU8Z3NaKYxyaMEPCdO1hwc= X-Gm-Gg: AR+sD12vm2vtn+zxfbJ9/ciTj5l0bYL8+Fz17vdwiCenAq2kAmmth7pmuwd7tsU2S9d P76ECku3WdstKwVqvSPqPWjD+Oe4ouWG+dgu5KtMt6I+LpQo8UtC6kh+W0B7F1ACpmHXzN0rP3/ gHAA+LCMg8eAJEShFGKe6krb81CSJQa9vvQ9u2PX7ABRQD2Na+QPYZc3wlZJB+vdLtDhM7++ylq O/oIovYct6LQWKxEDWODQ49+Y4NoiMY37zGKAvxntKBvjshGURMsWuMHAaAu1eNTY0mbRN5eNZq Ec2mAj33vPnnjzRoqyBC6Sd06tor3VFIW4TS+xkE08WaJXMB4pTwsz322suXcucxFR77oX5qatt qhVyId4DrfSOapiTf0fPGTsptPO2pbAq5ir8Ew2Eb3lbedoQGtYtNH71IsLg9bkUqWSPabcY0wt 80A0uG2B0wlv/nbXTzaDyIY253+3zlQJWDo+j7e4xWiU6F2ToW1a8AVc5i4+ugnXqG X-Received: by 2002:a05:600c:35c8:b0:498:28b:1025 with SMTP id 5b1f17b1804b1-49978433a49mr60012655e9.5.1786462271236; Tue, 11 Aug 2026 08:31:11 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49977dfacb6sm49865395e9.1.2026.08.11.08.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:31:10 -0700 (PDT) From: James Clark Date: Tue, 11 Aug 2026 16:30:17 +0100 Subject: [PATCH 14/14] perf cs-etm: Test multiple per-thread threads Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-james-cs-unformatted-per-thread-fix-v1-14-90565318f5f8@linaro.org> References: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> In-Reply-To: <20260811-james-cs-unformatted-per-thread-fix-v1-0-90565318f5f8@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Mathieu Poirier , Jonathan Corbet , Shuah Khan , Suyash Mahar Cc: Leo Yan , linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.15.2 Launch something that has multiple child threads, attach to it and make sure that all child threads are present in the samples Signed-off-by: James Clark --- .../perf/tests/shell/coresight/per-thread-multi.sh | 78 ++++++++++++++++++= ++++ 1 file changed, 78 insertions(+) diff --git a/tools/perf/tests/shell/coresight/per-thread-multi.sh b/tools/p= erf/tests/shell/coresight/per-thread-multi.sh new file mode 100755 index 000000000000..ea525ed5e18b --- /dev/null +++ b/tools/perf/tests/shell/coresight/per-thread-multi.sh @@ -0,0 +1,78 @@ +#!/bin/bash -e +# CoreSight per-thread multiple threads (exclusive) + +# SPDX-License-Identifier: GPL-2.0 + +# If CoreSight is not available, skip the test +perf list pmu | grep -q cs_etm || exit 2 + +if ! tmpdir=3D$(mktemp -d /tmp/perf-cs-callchain-test.XXXXXX); then + echo "mktemp failed" + exit 1 +fi + +cleanup_files() +{ + if [[ $parent ]]; then + kill -9 $parent + wait $parent || true + fi + if [[ $perf ]]; then + kill -9 $perf + wait $perf || true + fi + rm -rf "$tmpdir" + trap - EXIT TERM INT +} + +trap cleanup_files EXIT +trap 'cleanup_files; exit 1' TERM INT + +# Launch 2 threads to run indefinitely +nthreads=3D2 +perf test -w named_threads $nthreads 0 & +parent=3D$! + +# While parent still exists, wait for the 2 children to spawn +while kill -0 "$parent" 2>/dev/null; do + threads=3D(/proc/"$parent"/task/*) + + if (( ${#threads[@]} >=3D $(($nthreads + 1)))); then + break + fi + + sleep 0.1 +done + +echo "Recording..." +perf record -o "$tmpdir/data" -e cs_etm//u --per-thread -Se -m,64K --pid $= parent > /dev/null 2>&1 & +perf=3D$! + +sleep 1 + +kill $parent +wait $parent || true +unset parent +wait $perf +unset perf + +echo "Decoding..." +perf script -i "$tmpdir/data" > "$tmpdir/script" 2>/dev/null + +# Exit early unless there is a dedicated sink per core which only TRBE +# guarantees. This is because shared sinks will report BUSY if two threads= try +# to use them at the same time +if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then + echo "No TRBE sinks, skipping output validation" + exit 0 +fi + +# Check all threads were traced and they have the correct thread name and = symbol +for i in $(seq 1 $nthreads); do + if ! grep -q "thread${i} .* named_threads_thread${i}" "$tmpdir/script"; t= hen + echo "Error: thread${i} missing" >&2 + exit 1 + fi +done + +exit 0 --=20 2.43.0