From nobody Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 496D546D0A5 for ; Fri, 21 Aug 2026 09:49:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305788; cv=none; b=oDp9fSZxot+BYJzKoeDV0Rsqf0i2Z1SOWlTC25GkocdYpwfWLCMzgBXJqSks+fPR0fqaXTZ8mvFfJv+jg+5zZz0C64fiz8skeyVk3/swnGKqMIKfrCx9NwXeYniMiKUhdfoS5jIHSbsozBOSRJ26o50s05yhSxbHDTn3qMC1dn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305788; c=relaxed/simple; bh=Zl8zJhePqsl4XxqWo/nMyVaX7NU6Mei8MsQZ1ECwbYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mXwC8CfxV/uGPpc4D1SMoexz0DMYmZaL3znImVSgq0yQxHy9sdjWVpQngRmWcwdDGzgIsoOM0ZiILT5wMTBWu83MU9HnqV+qKKmiqdKIxiOMzeO93a+usLmzwEJocFrQpA6vLsee+ExnkvDWG5otTSJfzz9iiN6rquvaJhnY/ms= 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=Tty1qgR3; arc=none smtp.client-ip=209.85.221.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="Tty1qgR3" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-47f84023916so659167f8f.3 for ; Fri, 21 Aug 2026 02:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305766; x=1787910566; 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=Tty1qgR35pkmgsE8YoRqwfUBbbp3yjlXpd8IcF5RJWQ+zGOlG/dsOCBTPCCqG2ClPr RxQ1SzYDALOs0KadEnvJM320jcnlkK2wbHI/dEm6SsFQTmn5hjmhPOxNjrFoTiY+DnsY HHC/ZZdt3NnNTxXL69mseUzfOV4/ndWNAdjJ1i5Q5n9G07ASbCzx0bLADwU5viMf1XFL nRMefWvjDjiQlMWTzkVeJKmE5gtoUSGMzr7MJcc7xqfkR3Jwdvhx7EPOEMP4bU2vLxWu Fc9U4AUt4FbNoohRnQ9Zy2UFjbh1wyZ/unO2LjVQvEhh+2314ZIys2sJkxJMDITQvYU1 x8rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305766; x=1787910566; 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=gYLwyWmerLHMY80Nz8hrQejQxR0o8eabFUa+lFKjEclAAwDDF4WGeNWV1YC50fpZ3D XWcK8hLc4SEZRthy3qH7nMMeTsRk85R4e3OJRsNOdA9GYY5InRdOAT+4QiKjRPQ6VM6T 2elq1V8NM/PKtNRHZMW9AbsqGEK0JPx71Yz8aEiYOjI0DGC210WU9xwmOzqex0z+l7WY jcRFSPDYQPC0we4gz7cUEzY4lP0OhMx8WLLCL/r9X8uqkCk6gGtiI2Hu5BfabOqp+ieb VV7shJbO/dDpic+hzuo3JkzI05/uALK2UDgfnnCo3gpzxo1XE0HWhbITiof3JUzaFsrt Ex9g== X-Forwarded-Encrypted: i=1; AHgh+RqYx105Ir0SltybC32mwTjlRR3/mEmLq3IXwyhl6IN5g7ayZw+K6p6OtJ0Gcxj2ehTYplZEpTIN3XjLWPc=@vger.kernel.org X-Gm-Message-State: AFuF++nO4UiX9rN6bbMglWjT7z5qjvaOzkXNAhUMntuIkjpvkI/eM2RR 5Dg5WQFfRfznN8rLz6MG0rmat/GdoCMvqNURmNBD+Nh3/r73be890uEzoggJA+YpwoQ= X-Gm-Gg: AR+sD13BrKckYE4DQtQTmzXWbUTYyQpIHHNtsXf9Yoo6JMBKNvuEL7uI+jdKaqIquWs 3Rq9MXi6T4t625pDhuwLAkIdaFllIATDEkUYnrycTbWAiJk54IaVx7PBFCXf8ML8XWVLfpdZ9Di HDMzdZSe7WM+aP9YWIDQPw79385Mq0/b2MddgMDdDqbjgv5SGAfVzizsHfry3/+MFeC7h1NndNk YoIZkgRwtJUvdcvenFoGfYQWufe9QAbrnXDUd6NPVkIY5lFS7b3XZFvCWcBeTIGfn8+yRqCrI7/ Zny1W9iDMo00MKItlziVJkrQtIzzyrAwQc6r50e7/jKZqtXVZHxYqMVbHqIUkdold21ltPKqFRe TnYt+JagISXCYRSWFESc/ulKkrJWL22LXN6lkScHggdaY9ASe0c4KBiuJm2HWe/+GkwKQxW42Fv dc30IiZ0XVvWIw/Pjc/g8xRxb/sTgsBRHIMoVUdzNYwVc4/cz0pTPuTXwzXf6nT7JQ3hO5/mls3 SZj X-Received: by 2002:a05:6000:26c6:b0:482:a36c:a5e1 with SMTP id ffacd0b85a97d-482c0b44b1fmr7088817f8f.1.1787305766006; Fri, 21 Aug 2026 02:49:26 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:25 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:48:59 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-1-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Reviewed-by: Leo Yan --- 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 8917D47043E for ; Fri, 21 Aug 2026 09:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305787; cv=none; b=T4C1mKg9t54M9p9C8NtuOtiGiCUqH7QnnmDw2dkbczGIywd+fBQjo9mLNKviIeM/cK8bXWuJO55F069Jhl+RklEtoqVV0IlMPHakRyET+jCnXjs76bSsBkrVTkvfhZErWnTOdPtM3+z9xKjR5BrkXJuqqThPzpZHbPXuL8SncTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305787; c=relaxed/simple; bh=h2Q0M74fb6yudEF8zDu1K70Lt8wJfWd+FJHyFrYnfK0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oQctiI0Cw8aizQkdaS4bo1oNwjHpnohxK1QjplnuqWIi0S4pJS/sBW2JUysPCnEGJj36844yQPULe3Ki03JJO2HaOAUAQ5RaW0RIFWtzSYSTR0TyIVDnxH58AbUjv2oUbVhIuUcqGYS89oPLZ8LfbtMr68Imrzyz/YzQ5EOSZe4= 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=yRHObLfo; arc=none smtp.client-ip=209.85.221.47 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="yRHObLfo" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-47fde295992so574049f8f.0 for ; Fri, 21 Aug 2026 02:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305767; x=1787910567; 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=yRHObLfoToUFaETJVNEIsodYXUXhy4bnofOQMJGo5rGXvEpWgolomWuigdAIj/NDN+ zAB6Jz3OnxeEvCSAnJCPACSg2Ref5w2ulMHAbIkrKuq6Ga/3Uz6ss08VeW4QsDdxM59d /yGGSs7qx/ok2/CvTxXBSM3wGNxvtSKwxbYcIUIMMrhxhW99K60jvgfynp8LLFP409mm 5V89sjCr79CEQPWDnweYQupJx0z5IRW0VPSef20U81T8joKK6soWgbetUK1MdqeqkyUR PWsdMXOrZ6ua6HLGp8XQveK2qTMyHV4t1T5mGrpOO5jzDtpdi11TORBGJKoph53WPhoU wRaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305767; x=1787910567; 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=HhhUVDipzY819PWP++iE1bAy90ByvEG6xXsN1q49pd9tV8sRgjWeottuyZHgMEfIv1 PDB1Jb6SGDM5+X7qSOxoXcfY9O1FdTMwVXebiokYkm1/JP19yusAgsvRAadClHMyVIeG KF3Xux9PBC9GUVSHnevdZu29eizHvmZWg4NFlQ8fGW8U4baTjRGIHbjoMQfQvQJ+mCK/ gz2udcy1cyygr3aL0hTXWG5omZewAt8nVaoPqnFPZDu5/JohxVYv0THl2pub+gyVoII3 jHqS2cZd7+SpDc0jVT+51zhwzd8+rL61gtGHaGRi8IBqNjExFsReUrtJ/hqxMT0bmJMD QO7Q== X-Forwarded-Encrypted: i=1; AHgh+RpYwhuolzfZhLcf61JTXJnWeTFDxEJm8MRUoq0wM3W9NPMeYAVSCM6J2wVTsOMyFdsYiTo01vddMObBb2A=@vger.kernel.org X-Gm-Message-State: AFuF++kJPKLSQuYxYXTbA27H3fZHdhr9Uacr6nCe8v9k5dvi0GKlv1gn J4UmPRDTKDF9SGa/7ol6wGW3KFk5DApeMtzDWZbSxrSt4eu2ruTvhqF/gaAPkwaU8V0= X-Gm-Gg: AR+sD10F7Y7mCKsEXytFKpHWnkk90b+CuG4fYMPxDqv+wVQfSsedz7/ATWgHEjCTtTB cN20B+SuF1GtqW4QH/MBGdRXTMf7FassCT3A7aUcjqRAW+W8kBW8zp0SEci+KZaNXbhRCypQFnM 2OVnz0AkVAIK5lWEg3Zh9sJ9xlelnj/+2E6IvsLvOfFLv0lfY74CK+5LlI7RMKf+V+9s3lTSicN kYFNw4ksUERV8mKnXdt+TEUBCkyizBHQTACUTaKCdEZdPSuO5s+OyyQMiTU4sxC0ypGr422fI1g YxiwAcKb4/my54msqm1HSTLVtei7dbshCk3V5/upxY5h2j/s9FhTgsR7BvXZYy67j8jyqR1ny39 jjIyI68qE442frScZ67yyI5G1DCsWSLF8RQTs6MuWvxE5xkkoloL46pa7U+tb854laMjoccvher YIaWrVMvTdLTnvRcwxc03YyBVFB7w9C31qPwIclcTTahX5rptVC2aZZMwlenwfPrhpeN828lMMu CM= X-Received: by 2002:a05:6000:985:b0:47f:e746:dcab with SMTP id ffacd0b85a97d-482c1184819mr5551648f8f.10.1787305767292; Fri, 21 Aug 2026 02:49:27 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:26 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:00 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-2-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Reviewed-by: Leo Yan --- 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 DC6613DDAED for ; Fri, 21 Aug 2026 09:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305777; cv=none; b=SMgpBZllzgTgoV0PNQP47gzuYLWvehHCPO84E6HnP+PI7cjHwzH4VNgJ5577F9s3WSoAAhVhOZfYvt5I8UH48ZwltfjWDs0m4kFCKKSqSQGKzV+tEiW9iaMsty0kA2ggxrN7M+O3GP+rCAp+z0w8+6cGrSJXk85gYgA2+hiXoqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305777; c=relaxed/simple; bh=fP2IfPP/3FxAZdBFPU46BWk56GVJBXw30IVSIBNxU7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uSm/7L6l8z5xf8Q729zpeuuJjYHqsM53Yy+d4MPKRUduth3KptkpgpguhaH0vNT1nt9+U5C6QehSG3acHcsZL3DdlrbtDceAl3TzNHD1Ra/caHD4vumshw0CcBAoLlwLV0z3a3CAAU+2EF5C8JJmGfJOJYG4orY/06hth8XmZFA= 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=h/k48Rod; arc=none smtp.client-ip=209.85.221.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="h/k48Rod" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-47f703a9d05so493576f8f.0 for ; Fri, 21 Aug 2026 02:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305768; x=1787910568; 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=h/k48Rodqxb3mS2n5Ozt4WGa7c1lfMDtzjRWobiRl0l0MDYLC0OrGu+r1yVZT70ad0 9UhHiBGxBcQycjA/p7Ij24+e1ch9n66GHCuWX3CW5gPB4Xx+2kzV0Kah/StXUurroalM UVdQIUVBHj1FalGOgEt5lnVj/ou2/4/r+t+JJ2BQw6JHp+HWlOpv6YD3dvRyj33f2v8H +mkD7ey9aqaanyrTf1fffBLf0WR8FzwKmP3YIidPOzhCbIVRhdnfZC9r4EN0TS+tlFWY IA/6Dodk1EuNVVM34G9bX0+U8FUlt0ob8SHejSZaLyESAIISr8Ip2s+utvgtj9c9Dvvo Shkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305768; x=1787910568; 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=aOrOus1FEvzBhGIjzHuXGaRB3CDYl088lh+UXvIOcfAMH9953JowSnvw1NvmdD8j2O ++2vKyRkhH7DDixHVUhXi91AlTiNnNQdpFldDThRV1eGxylSADQ8xFDIaIvh24Qgikqt AWgc0uphfgIrx341HDisaehsFnRK0YRcVBFLE7wzdEZA43fi/UuhomwFPxnwM1fT9dHH cYUv6HC+ceUTDAh/ga6pchMXuqbUUrYU11BTUVHDFmLrfATAzbdYz30wd35LFWU349KC BtXs5zB8dJgTZ9fCUiqCb5tR+lejUsDk6YkP2rTQmPKlAaY75P9UBu2KBhhAT1PcmEkh XlOQ== X-Forwarded-Encrypted: i=1; AHgh+Rp+OnP8smO5MJ6y0JrxG05QCk5uUcOqsl9j1liiS657Azr0JBU+V3qBHwKXujfzNpQG+7ssUVlR3jaIIO8=@vger.kernel.org X-Gm-Message-State: AFuF++mG2xd5ETe6Sto0aJoOV1x0YOjUk2S8y6I80B8h+PcePT5tIXJx 5a27rulrR0phS4vRuhe1un3qyCA9VhRSGYBHmTxk6mxJCzQC7xWbS9PPD+er66Z8K6M= X-Gm-Gg: AR+sD10S9GWuNK84dm5IU/nRodef+QhHF2GHhJrZlOt3eCyPbFaQGsjLSJ9mlRXbleG UyoUucSK2hWvOkLsE/iI+1xAhdO5kiFP/CCE1gc4mEPVMokD6XI3zBNGvNmHIt5DXCiPPntl6A0 u/Cw9PxbeR5FtYAX0CUSrJuTQtjt3O96AYEWRrbiDsrrmRsY96Qf7WDE1sNjCypR3S+tSx1s87g tp5jGwwiMRYZ3W67qH1mw8ReZ6TrjfiJcLdJ5C6LicMDI7z7m0Y7Z1zhG1U3oERANlPkBB4wbYA 5ENhp8urKR0ecjRwH3rPaYz5TQa91nG7mYgrJnqcELyeoc45vvxfkkg9nQdC1AIvlCSEGnRschj TfjzTXuRWi2/MzxUwYaiHrwiGYRdBpLE0a29TIDT1DYV0q4QsqHX1/xkO+BViruMtNykvcNzWNe QRz2OCdNyY9SmOu/SedWYKPm/76q5AeQjSqPSADteRYLkZKD50D4/RVMxSbOM+WQJA X-Received: by 2002:a05:6000:1aca:b0:47f:86af:8fdd with SMTP id ffacd0b85a97d-482c0b588eemr5703982f8f.3.1787305768520; Fri, 21 Aug 2026 02:49:28 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:28 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:01 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-3-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Mon Sep 28 13:18:04 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 24E7744CF40 for ; Fri, 21 Aug 2026 09:49:35 +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=1787305784; cv=none; b=nnKAGEUVZepiIJk0Q+rEUakLxY2SUoqgKuULfAEz0/YGnSpzZkqVsY3crNtwI2qcBYBE/QNTM7PxrE9ezu8C2qN2IVZXgcnxoJsCfrT7gqLqCx5YpwAMgPXeg0MJqgVR2PqfOJ0KDsOeFdz8ULRt0RAwoNs/8+vhnHlRfUpKQww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305784; c=relaxed/simple; bh=GmFPf0hS6ejuPSWWrOe80fbWivZhcfucDIR0UYfgWe4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mMlYYqTcpt3wFEhl+K3zQijUhTE9KBfsML/d4k2WpKaXMUPqNXutY2i1aEkN3S+xgp7YhPdeJ9Hmc9ym1Vq839xVqNVTjOqJMEOk7WBKRg7yDo0q7fcagfTS+3J7QsORIP/XhDkAd/tQQfL10FQ3imQWrhPP3C+4JSp1usOMmAg= 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=JanPLl/h; 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="JanPLl/h" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-498028b3d5eso8828565e9.1 for ; Fri, 21 Aug 2026 02:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305770; x=1787910570; 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=tvr/xW0gPJp55FsCc7tSxN43AAHHoShgvkJBQUdWPcc=; b=JanPLl/h1RfBcg1aCSM8G6aHLcVTL9ArM5LbozpK0IssaXyhiDCETUff8+ZvvypPmN G+ip8Iyl6EPyLljVCBrU0VnTeouagxc5FwrFXDwEWatkotuue+xqLS1TlJuKQVdDVnB1 RgEi7nm6VyMEa1Y71tzLBW0CUFIqh0GZep7Tn2dfRK3NpBDW4BBuCcN8nhlNAc3m4cV8 2orbSG7rz0h1SnZtPWvsCbdJ0UUPZnXQ4C1eulciVyybzoYqR5Iy7PucolUm4b5yJOeV lWm7d6U4U/3l2zN4B61Ydg9L+2d5KzIJf+/dILsMTWgHm9fg0U1GXsHFtMKWGc/wI5on Hn8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305770; x=1787910570; 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=tvr/xW0gPJp55FsCc7tSxN43AAHHoShgvkJBQUdWPcc=; b=PS+LoYObQtrixzce11GbH/KffTWMxiVxIQWZ5yP+WemSRHTT1IRn4OSHU0QIHLex60 TZenSchBOmH0zpud6FrCRQyna2Y3PlhNviR8vj0fB1ZjYe7+wNVrtOMHyn35KjfyL0kZ 7mvflFXhil7kSZUCp36KmvkVT/9+2RWt4zq4ik+qL9xkJTtxvX+RNTO/PtWqPQBb0p+m iN+EvFKiE+pWFhpv6n+8IHq2BzTv/1Hik+Z6nTKL9e2emxwWrXB+tGWPFxM28wt+1gGy rpmG0wf5ZlSPcg+P3nNA7DXsxkglcFHFAAu6E90xWJNHLpce2fY1BdUzLL13lKlGgSS7 UxVQ== X-Forwarded-Encrypted: i=1; AHgh+RrmhEdcPpQCUtVJ6tKLPTLq1ccFZXqV/V824RVIECD9Pd3dXOjuDkBMWYFaxWHIkfPlcGgS3dcjWZq9XYs=@vger.kernel.org X-Gm-Message-State: AOJu0YxcDWA/qOmCHX0PORyZgfeiQuKCP8aoxTCgd+Q2u8qFes+x+24C b8z7d+oTee4TBf2gFgamKRYbgI7iBKn3Fy+kquNYBISPHmTVqrR9db9V8lSYkPMfmS8= X-Gm-Gg: AR+sD131kai4LxyQ+fr9hUCOrcIaW9F8X40mfY2OZvLFLJ96rcis1u9WLXenFUtkUa/ rN+5QY+YBo/dbm9stG7Ba43KmRTrNCqugdw82GoIjJ4NdTFYYtqksuC0dy1quokeD8EewA3Ueka vOQUSzZ45RHDogaoUYNg+UagL5StnRJkHLNCUV2IpLRGLUv2nALPK2iuDjYzFXTzkW4f9IeJ7dK ScstTKBc6vBMCV2QI3gpzFy8ZuLyaJFG5qI0UZ0qqPCMs9Qbvdg9AvPjIeQW9usRJCIqV6+OCtc LnApA644s9PKRW9JPMpn1YxxLjZG0DV2MI59eJIh5b5iVRKHonWHE6SSUzV9IGlY20kpRPtka9d NBrNCk6q/zT6GylM4APErrDL5bAmWgZdVKFSp/pjKOWxJhWhTO9YrPSIjN0Ng5gvQXRyxMGh2A7 La7YLT4a0rXZ2lmYd0N8FRUnv8bdj0Md48Q54QWnDrglE25WTEUsoJbyH5kojbppKf X-Received: by 2002:a05:600c:8b0f:b0:496:c379:b2a1 with SMTP id 5b1f17b1804b1-499b82e8e92mr80267695e9.2.1787305769809; Fri, 21 Aug 2026 02:49:29 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:29 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:02 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-4-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index d423f1cb408f..ccf886efff95 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 @@ -1268,7 +1265,7 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace= *etm, queue->priv =3D etmq; etmq->etm =3D etm; etmq->queue_nr =3D queue_nr; - queue->cpu =3D queue_nr; /* Placeholder, may be reset to -1 in per-thread= mode */ + queue->cpu =3D queue_nr; etmq->offset =3D 0; etmq->sink_id =3D SINK_UNSET; =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; @@ -3258,6 +3277,7 @@ static int cs_etm__queue_aux_fragment(struct perf_ses= sion *session, off_t file_o auxtrace_fragment.auxtrace.size =3D aux_size; auxtrace_fragment.auxtrace.offset =3D aux_offset; auxtrace_fragment.auxtrace.idx =3D etmq->queue_nr; + auxtrace_fragment.auxtrace.cpu =3D etmq->queue_nr; file_offset +=3D aux_offset - auxtrace_event->offset + auxtrace_event->h= eader.size; =20 pr_debug3("CS ETM: Queue buffer size: %#"PRI_lx64" offset: %#"PRI_lx64 --=20 2.43.0 From nobody Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 8885B470455 for ; Fri, 21 Aug 2026 09:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305784; cv=none; b=P4siB9R0ouSThsVFvOgqZKtJKK3goKsSEpn3CqIvKMnyBoTs2ja6kvvn7Ty6/wTNoVDhiSo/z5oOPLI4MbpM+Rk2tNVpgYgWMnkvwxLCez3Q89QJ/0QmsSliFDNcjVxbokEUIJuFHWKK7VM5wJVHa4W+mdTFif2S5tw1K/+fqhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305784; c=relaxed/simple; bh=RecoXOCNMxrMx0zkiKfC1PDkmODYasriw0nUGDxsh8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WrlRE8s7aZjIsqLUjrz0Q33AWXW33nDR87YZnkH/uIuCS9y9hl3KMH/3B2Rq2HLl9yfpts4YXz4nrAfRv16LucWgktauLlZ1sryYq3Ec46oTWpWkbCfO96Bdk1aMHAvKXrKxYs1kW08v6EOThGoH21Mn7LVyjiKOy4W8l/FZ6k4= 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=KsjdWvMe; arc=none smtp.client-ip=209.85.221.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="KsjdWvMe" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-47fe377a217so461258f8f.1 for ; Fri, 21 Aug 2026 02:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305771; x=1787910571; 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=KsjdWvMeIFX9sdU1ll+27diRGYXannmkx1oxidLQLoYhsgYdunjdNaxra7hwrjW1qj +YKlKQ35w3SCe9ArSPkhm6Hq1sAUXwSGyqerHyGmR/EC9v8zvpytCyXRtpDWnL5gAtcj i4YN0rjCRpFzc0//qYFdd+B0xjD06AS49SU+ZZzWpOOywKeBdqguGGRQ1cg2j9H9IDYe 587n6KTZofTlYW3oIfoWC/svyFe0jTNqX63YkGtwn2xHscRLlA9FairwTegYMtmN1YaX HtjtVshcrw+CTdKTxBQNzhuYA9idqwUZ6c+au4PxpUpeNrkrOioh5u8cmu6kNTHh6vhB AS/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305771; x=1787910571; 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=chOq3WzszKvXYwMVsNQYRoimm8hD/Qq8I8Crawld/toZdelZwVyz5CNT9QAWyRiSWW lxaJ/kRdKuzLyBgKXQTeHVkEBgQeDjh3vUBB+MrY6hkAWlEN136ZPNlfWsXVuyECbzko Ebt6XOnOW8Y46mGk7kLXyqh0rkwRD9GY9+Tlr992E2d8QgfHSpg/Yzn2LifrbHCmcxXI n+VXjV99zdkWnNwZQz+TEX4HAmqpJkwFGrEvqbaG6nbIxDX0xzItB5fDdxR/mZVsMXgO +fUyCfPaxA4XlNqM7J0ohxe5RaHzFgsDLlDGklKCj/aBSFdwKiHKNCrnn4Dbltj6IV0g oqvw== X-Forwarded-Encrypted: i=1; AHgh+RqvCFJwiiry05LzsR/N7xJqM7qrNI8YXE+DLLo8TSYjOuyZeDWJeGR86xcFBtB8AopZU7iK4b3l5MGfMO8=@vger.kernel.org X-Gm-Message-State: AFuF++nutsjqHhdkmJLnzh5IQ3Px6ZfHuf6j7hgpgTMnhbNgRJpTw7HT EJD7Xcbd9Xk9lNs1uS1EeiJhtYVgxb/j37Ta2h79b6KP8EtEamflf4j014UTvNBCF40= X-Gm-Gg: AR+sD1118ZLN49UKasjs2zBR9ZPfN/iBMEVXgbN7bjfEcDekS9pfiP3FScgOy39UsRn KTJHS9aj8bdJl31OCbrqohvH0FT+g9oTPuCjIaWKjjBdJ5VQRyTuoJ0xh0zg/cNcsLBCldoykX5 diw2DE7ENaTlCylbge2eAOpExSDykHVmZnsVablpvWnXvejyAWcc3KHO+gBXgHPG/XMfTQDL2ln tqNhU8wnPX228qUbJ+iOTny4jkbmPrwFcT+gGShbYGBXhbEZpPWbdgotvx4tY7Eu5JT3lQAVvrB CK+5WYGXzxHZdJJhZWv4HZbKZlIT1XY080/4k46GPM1zASUNz4urxoWXivhW4XF7s8K5qRn4KXn KRme+K0kYWWxZqW3dKj4Kt1p8e5gdJQch7O6COM4s05KXefHJAW6JdWvbsFwXP+mILvJBiC0gyz tTVY9+aM2B8CmJrz0HjX295PjPetUikaOrHi5xxfI2d/lO3+3rC/DycRKsPThLP3Om X-Received: by 2002:a05:6000:461c:b0:47f:86d5:d1d7 with SMTP id ffacd0b85a97d-482c0b63396mr7979910f8f.6.1787305771015; Fri, 21 Aug 2026 02:49:31 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:30 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:03 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-5-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Reviewed-by: Leo Yan --- 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 07ED0471258 for ; Fri, 21 Aug 2026 09:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305788; cv=none; b=HFfFhg0IF22XB0Ge+Yng03nktVecQxk2ZIGtwudUxaPgE8QaseC4gp1MXuZDqh5RmQtKL8qRGmd4JfhMuKeh5y8ZU9OWntsC+1NJRoKRg4VnqbF0T61Ex0zuCck2Y6QibpbksVpXRo9AmzHhMfIzaf+U0ydYVEyGcSxRw5uTUhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305788; c=relaxed/simple; bh=8nKlxlZ9rNdVq6/YuvGCZHeAcrIjZBPa7mfw49A5I68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LMKVvjqSLSRmwJhYy6nV+8cb70eGbH1D/V/xhuU4Gos+4plkO8kPrgap9Y7y54xHJfdhAppNNx0YHnAeRboR3qzkITQCLtyhs2VsGRfPul9TqYujiD1SCpEWc+g0s97iAPOzVeOxh1ZgkfpCG/PeXW+I0ahJ7S/X9x33j5/cBWg= 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=kllZsaNa; arc=none smtp.client-ip=209.85.221.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="kllZsaNa" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-47f633e6058so720094f8f.0 for ; Fri, 21 Aug 2026 02:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305772; x=1787910572; 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=kllZsaNapbfANlhJ1PQrDc6GxE8zpnsNilu8CnlOhejtJSZru7V5geeA/5R6KOalTH aefClnSf4e9pvx7wQvhcB3HvGKuRG6U0wiJyRxP0Pt9u20hZJsmG0Ipgbfn/WGW72UiN DLO0l6qJw5Vc4WxIgoWVSETfC8OZlTkWJ7gPb+LFqj0vl2ttHSuD/yMEYSYJ3eDOOg6K +nCfmUE7oxE0iPczDqMbsMpGsAB+UPlbKqvbIUTWVqTFGII9wt+Pu5O2BBMS7i+1x6zz w02zJbptyyE+wjuJihfk9YgUj0boxrZatL27MB7BVrrvee36l1vKTukiqZfAIqqLHbsp LObw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305772; x=1787910572; 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=arwOT4MiCE6oUZS7tAV00FLDDRF1RVgMIzIpNg174gEDtzP6tNGiF7xYcfWnUx8fhG T4Nz1dQptdjL7hEMwv67gtqa6Y54K6XaX/gABuwOp/3uIKjm5OP2LDw+Z8f/Lj+GoZJn ae9FbzpgFng8d9jH+/i9UVcp33MYD1z3Lf1k/eQM08KBW5SVg6O/kfvqs9W4M3VBZ6gL rFLBoW3tyBti0qd4eAG6jCsak8bnb/KT+YUbA9PcWkIH2li85rfp5AJsDaqcK15az3f9 cDRkhkInHkbF2jNpHvSO5TWiqJv95deqzUX/Pwgr72bv+WsKvbK9/2KuoHnNYG+aU08P gjkA== X-Forwarded-Encrypted: i=1; AHgh+Rr/Vsv2QEtdtuEzBwgJ5o6yAqWg46Hsq5IYhjQKUARcQA1S9DDHdfJLtnCxpvIfV2xEwT89pzjs7NegFD0=@vger.kernel.org X-Gm-Message-State: AFuF++nVrIVvYhwHwu2YOP7jyuTlUFV86fdZ2bUhF1DeAq7A9kkPVaXn XSeBGJGyqgoHNLCwqp7PKYB3tFBJtgcKExzvHPPfFr6pkh/pNWGFtDF+L00tHprdYhM= X-Gm-Gg: AR+sD11SkfeReLaJQuboQXtsm/KZRIG3X5dSz+yEAq+cQRICYxMqlXewTyP8PDCzjEX vSY8702MJX3SQegZx0D897gagnB/ikZtRu4TSlpkmPqWEGJXq92x2WZ8VF7uA1FmUqVlQYxEk6J ZdFGofYPc28o6GCWRX4yfi7bce4gmU+rc7ZwtvAZKKrgv1AK5gJHMV/ryiP1FM8hG86x4/Rjj4t c4nmHDLsMBAe8XQnp4KHmyW8+SfsXdCAsGCtmp+kENrae3f8tFn0PQJjoO7pNZLiI6CUjvq3k9g Dj9qPwEJp3MTjx0KSkpAOFU4pFWWkDaq97YX++QGkYndXswXgKc+FcIqcZmk4oKN+M5ez7ERO4S mThOU23c8X3pxI5xWACPVqQP15klEMOqKKYQI6SGQAG9oBWGGOTnU9U/Jzsx0z5TI9cby+4Ewiw Qr2KLxm9s5Vb2oYYMpJ3GZ6PvutacpAUrXNp61Sq57Mmk2Df0Uvmycwk71yTPbHymrnfyYOzOwK wk= X-Received: by 2002:a05:6000:22c6:b0:481:5021:33cd with SMTP id ffacd0b85a97d-482c0b5482cmr6699145f8f.3.1787305772510; Fri, 21 Aug 2026 02:49:32 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:31 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:04 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-6-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 8D8B3470E81 for ; Fri, 21 Aug 2026 09:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305792; cv=none; b=mRoX+JU4cPG1La7vZJnX31mJDQrhWblp6vy/ht6YHJcOjYDqMG2KqDrQVA039MLaqVrDejEqPJyvTeFO0PZDrCQc56MssrsOLZI/K7bpHpJgu+Pj7JwMaFMyLYv74YoQyfJ+0DJBvYJrTUfi8CD2Joplw2JQyiDltTgX5Q4x2qU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305792; c=relaxed/simple; bh=kA5LbSGzSFt0yV/2KASUph8Bp02kP3gLVrrUuWxXR3I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uN8dq4yTKVOzNls0za1+AgdRdxA7TnmC9KbUYwdDr+7aaAZPylYJ8yR2U2v5kajEnqlA3A1P+aV1XQ8gaSBetAT4fN/cyUpe/5Yr8fMdY/2LzYylodqaIyfFX4z6k58PD5LWsNe/PwVuoirIbvM1M1zhMvpca5arjdKT0kytfUY= 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=Xfahit8L; arc=none smtp.client-ip=209.85.221.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="Xfahit8L" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-47de0093c42so725222f8f.3 for ; Fri, 21 Aug 2026 02:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305775; x=1787910575; 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=Xfahit8Lf3i3U+ZaKl0gRkU7HGroGJSv/7iuto/dbzfrweQqE4TcS9VkLcG49knPiK D0Yi3bhThTEYqNdwl+Ld4zQC0s1QuZWaloAiGmoOKMQwH20fvaUQtQXsfk/J9Ax1yXk+ Q4q3jHwvyJjbBOBzCPvOplz0gGHsu+PqcsvBQgj3Ifi/IzEUOK40LwrtS7LvAiobDq72 cMZM/ZJOUL2VLhzLMnNbgbcwXGYZnjmJlTeIhLV4qmv52btIrDZTZlotZsM9+e3IoYQB Fyl2auc0gTCOM4GUcf/vrth0msDLeKS0XgqdA4KNwMEZq0+vjTPfP6xcfWxfU36kzd9c xhaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305775; x=1787910575; 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=TQyRWvAnokx1B0hr3q4aVdfeS/uhoi2LDqXQNrkqUqh/ECW7mU+ADqUkazjdMJ19HM wnu9b/Y/UzzS6JrVWtVN1uJ6Xi/VaTb3mg1+QpZ5orqQyQN78WJ/eLvI1ymYjQwvgZLN Xlr/RnLgwTFuvwuOk5axa55WX39+jdTWnn93VIwPxMc+1+wpkz5Qzz+UogrQviXRPO4X 9jg2IykPtSDaLq0ShQ1GFtni1LuqVwlxunNW9/QI+kNX2+R0Kh0GA1iaQkQ4zX6xM80i PFEsahtJTgTzVjZmEnj1WTsTcq0J33xcGNCXOr6mVFnv3yVg82QqmKMXL8zClUXteF7w +9ow== X-Forwarded-Encrypted: i=1; AHgh+RpDt91tC+Ed/oyjn5qc70l64U5OlQONpyvb1nUVTGvKQlZ5rGWIt2Pu4xeGlyE07FhZvxewyjNisOkSAJs=@vger.kernel.org X-Gm-Message-State: AFuF++mKmqTgHeKhMXtqV8tyh0QoBfr3tzBaTPGQL1kHRI88UOqngrZf LTJkPgMXifwpKvQRUKmFcODOvgtHNSYTszU7b1okN13Dv3b8v681i/Rkopi+bOLAvpE= X-Gm-Gg: AR+sD12N5iw62cECRzuwWMFmlMJ9lrmEUVq7zg+iN97DqfF5uBMk6K6QQaYvh1W1Zhx okI37cH8+YRzVp0cPkpQnlQlR5oc6F9sDMPn1M1Jn13vZzYu7DpLf/56XbMQ2Ppb9cvKhsXSrbZ ssF85ybetjCrnnFxy/SnDlYKPFummUbqPhG3DojsYddoY+o+uD5Jyv6xW1JskPaeN6YuA2n/0Yd gBOUiH93s5XoX7eZI3bTJHV/kGWSf8I226HtngW3R4M210Wl2uurgd94BTaw/7ofptX9ssWHUzD EA41KBhUTivXNS72VC/zPk6sThyJnHF5lqRXnAR4zn2oROhjK8/45QK6ao3jumjklLazZxB2Iku TVoUayepZCW2qjx6Lhci4bhpxQ2RYyMi6h2Yz6uyxv+1jEdj5kQCW8LWJEt1W0A4mG7PWkr0PwU +q2CPyzydHg1ZsJM4mKshq7xRKOSdVJJzirHf3yAZrN6ya7vb4uuSLdYQpHjdr5y1t X-Received: by 2002:a05:6000:2305:b0:481:573d:9d29 with SMTP id ffacd0b85a97d-482c0b96bf7mr7076525f8f.14.1787305774666; Fri, 21 Aug 2026 02:49:34 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:33 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:05 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-7-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Reviewed-by: Leo Yan --- 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.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 8F5CC471437 for ; Fri, 21 Aug 2026 09:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305792; cv=none; b=p742zFZX/0MCKMFVJ4aDY0uL6fn87xYhzf8lxt1u8KGlBH45rVJkzsm9mUp2mU6fFyC8syagBj6P+HZABXNlRuBIsQB7MjfMx601ZwlsvjMZzmp9I/Wm8JauIrLkLEXv2ENi03EjYK/2+POd8hUoqQns2KWL8IBdJy+w+A0TZR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305792; c=relaxed/simple; bh=H5RbpglB3mwc0VATOCqHp3bXAY+cQ8dXfMWjveqvYHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ab4yb/CxE9s2x5cnBEFO4NGhc9gKuBHj0U/RBi8rDMlI66hHn6D/D3tja9D7EiqrLV36m/+5ZkDbsgEKqZJEoITwwjjsqUEwhAbaxkrk/Nb/Gn2cNTiiQpyX4ONfqg3Cpa8hZYb7NuHLTfTrYWs/BUSfY3hiJ2jBmzaPmELabOY= 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=xMTTh+Vd; arc=none smtp.client-ip=209.85.221.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="xMTTh+Vd" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-47fd4531020so473051f8f.3 for ; Fri, 21 Aug 2026 02:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305776; x=1787910576; 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=xMTTh+Vd6MDy1VRjERTsDKjGJwve/5mlmm0WFutZSanEmObEyKjA2whplluN4IAcBZ ZiSr7be8AeTW4vECforFHzRs1dZ+977tY2mYNfU45UMnMbHTJJNtCsmqP0NVu/NIblrT Wa/q4mXgUtvPgG1GGyz5AYeKDNF+JFblRY1d1/XoHUKsbZO6usal3fAwmpYxDUei7K5/ Cp91flZy7IhvilH5MwIg+MCGhD1oYZL77UPlNXxaJubhPIy+Z++F6jdT3w+gnSKfQVOL EiCt+3kvGbhC7XovpprCpSlPFSzlwNIaWOVFCK3vCkvygjPoaz0MIER92sQnMrHchk89 sALA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305776; x=1787910576; 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=NZxOSChIgxHnt8sewi/yGyD1J71zAmcJkwsWvLKPqp/Znz3wPm1QiO1xE1bMmBRKwy azERM50MNYllT0KB51V83v4qaRgnpRySTH340Rk2J+z8uiyE+B57y2RRI0RuwN7pRyu9 DAqPGRfWo2A2t+WAZ4oh5zD3CvkA+1bRAWv3/XpTxDG3sWxXKm+YmAlq9hHd7fU3Dbhg tD2riPBthApP78XDc8YI62DZ41MuwWjMHqYrqKCvZMxm1Ba2flDq8Nbi5Je7vDChXzAD 53jcGniVY9lxcLoPOqSasgeoVRnrz933L3FNsHbAGtStbbO/c8XT0Gwz+DjFjhISdM0a J6Mw== X-Forwarded-Encrypted: i=1; AHgh+RpKmeEQ8fwYAlOAa2+AqALVaU2lTxY7S8cGHu6xx6wzndR9rUyBUYc/IFkFEsqT2vD/IpFw2sZWFpj+WPM=@vger.kernel.org X-Gm-Message-State: AFuF++kCbwLvYEoWbdprAyuSRdcYGNWngPH+uYEKhBP5f7owm5BlyAkE oltvyh9yxn6KJ93Adqz+CLPum1KRvgGCsLz5Tui+Kv+zztdrfNxF7KR67wLiST/f1is= X-Gm-Gg: AR+sD12OeS9mVJdFLJQnuIH7amVupdYpY5W+t1m6AHDUaED69aohSvCI9o59o8R09un 39XWh5zMDv0n7kQ+sdNxoGkVVb1kgb7G/XWSDljRKIzHvf8nh4GVj5yFfu4jTeIwZmtX2qUBXHA 7UuHOBylqlyzbUe92250MA6Y3O5yzXCirCpfZZ8l5GHdAvvbz5Eazm6OWCA0O8v+/2Qr5VYFvUI k8kd+vJi9yLGoD/s+U17gzhNR/aquR0hwp3fcbLitZUu6mAIYsD5mKhqMXYCYZ8G2RlBf6sSKJF 06S2WHGFR62yIvltLgdLd9S/ZwDaMk/SyXmOVZcNEM+kXVm53/5ZXbuGQD2mub5SZaGvH1a/e/Q rbwDBS02LSd0NLeMx6UMRsD5Zt8/gkpsGd2UUd3WRN4f8/Z3Jn0zNRThcF5khCuqCXkSY+iJuT8 +FdHzaVubZKV5Szir8Sky+GEof7gt7JJSjGp3V/ufNuSSZiA9dYqWkcif06QI6dsNG X-Received: by 2002:a05:6000:40d9:b0:47f:f43e:f0cd with SMTP id ffacd0b85a97d-482c0b4230fmr7267629f8f.4.1787305776005; Fri, 21 Aug 2026 02:49:36 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:35 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:06 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-8-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.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 63D8D470E8F for ; Fri, 21 Aug 2026 09:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305797; cv=none; b=m5s67PpShzkCVGEQvj5JdiV4PbrM5ElP8cX0I3qbcVaJS0OeaJooqMujjIgAhbxPFri1lOUkv/1vp1LUdon86731U1qjQg1+oNEAKkXpLBZblp9CwgoVZKxZKkvtPEGx4OqySr+jV/oNsVevnkh4/eZJWXdMSvr/2MmZMIg8u44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305797; c=relaxed/simple; bh=VHbTeSJfXkNdpa7GWemni8wgMespqnXWXrv3pQGnqWo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FAIucxkd6cWR7NRpQfW9H1cywRqJM9zrdifNURmL3fU/xbIAVne1NXLx/XxIaKpobAfIfCb2CdUFil95w8FnCgp/v8PFfwQ6+fBh44XEy0v3U/qJMN9KbkPUZoFPjmfSJ3xljc8LHRjLbjV0qsnl21+RPZkTakJSWo/Ykz7+FN0= 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=aTVRvQmc; arc=none smtp.client-ip=209.85.221.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="aTVRvQmc" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-47f7027ca11so488827f8f.3 for ; Fri, 21 Aug 2026 02:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305779; x=1787910579; 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=FLPGCt4Z2rnGiWCr3RwF/7TLVu4WTyiGBE7+q4fWYws=; b=aTVRvQmcDOKOQbm+FsJqrmVuxXxD5zOzPq2TM8Aiu9qyrY0ZooKc4gLhRp2r2dZVIk PcvbMS4tjLGy9uSuAsACkDg8GTJAiN9oA26bkaLp0Z8ejpQ/PDTffablPBDEdYdvqL9d qeq9vcOUXdFAo+627E73sjorEEQK8HDvnDXU9T0I4xuRgDbNh8erahalB5FgjWPM2HXn D11VS83QwU4JGbZe7gkcqqIizzyqpzqSTtipskvDcrHTqufleChdIGIvnOPq7QLD8v2u qUbwt4k3rTEMiZsn1rDGTuH82wVvHGANJnRm8Fo2m6x3klxclfD1K40ibhoWgTa52v4X WwtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305779; x=1787910579; 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=FLPGCt4Z2rnGiWCr3RwF/7TLVu4WTyiGBE7+q4fWYws=; b=LfejGCs74cgCgh2Lc3gTZBYND923UzTIuQDY/u7SVP2a/Do7UolcEniQXkBpF7os9X V2mAZTxFed3KXadHe+WEq4dUPWcwz0gVf7q6CAssSdpH3gBBCKmQTxFSz+suLOYU64My 5cTeRtLDTYY477iKChjxL2K4uVyJi8oQHmWFGfUr8ahLzEaRWPNKsPZajRsUKMKWG+fv lMB072UD1vT5PnWm9GaUAfKGVPpBT3vdd497nqmAvSixXOO2RGtKWntk7us6jG4ToTAs YOLMdHOTS4HV1Cxbd/4VtjuY9uSsN9MstEm423o6Oaenb2xPd4xqg39Sg6GoGiHY3AVN T0bg== X-Forwarded-Encrypted: i=1; AHgh+RqDymhzt3eFheKJZeI6r5zUQJbwNH9KrUOHlA0twhtxL1NnXiXYjNOnhZnSq4MfYUIzCTlb6o5hYNDlBA4=@vger.kernel.org X-Gm-Message-State: AFuF++kHNcWG5vHGZKtoHdWX33YU/5L/amokkrrdVsZRDLeveOfl2Dlo Y8CRy7tQV7c0sMvaZJFf0NjOMh7mkmyMaHYInUBxTsGvqkMVQ/Tmi0yKoW0pC8EqNls= X-Gm-Gg: AR+sD10C1CZdmolqfOb18njYXlsEnG5wmpn6chvQgZyUCqCNNjkWKjLzPlAleACPlRQ n4yX9u8W4BWLKJYavgDzz6BLCmc+0i2J6QLCY6V8sSuSP/WGnmUGc9a5nv+5RfyXDUzz1R/zrpR zjX0ojNDpeU5DbPAoLryeAn5QqzJJGlp4Vp3XzIenfHKZRO4VpWSIP23fKnmZ6ESpOpLEopqpfl FIjZ+Ukhy7COv868FGOIkk9DMtfs3syoGgv9kp8IFRl1EGQcSLzlCq0YulXf0/anRugM8KZNvp7 XH5tOwyPvLAg/f1qVVyXPo0FfC5NcwFvI7YAbkQfjj1yyljRs3lDzQy41pIUamgr2sBT3dnkMY0 7uMK+pQ/hnceGEFbVnyqsrk0qvPjIdrE8goG56Q2rmqrzbknTRpQ7TUszo2fJ5F5Wh7QgQuYT7K FuNqQscAfRe0uFxzUCRn52mI3CgyzdHODn1pPKQvxvFfcbP6++5T9gk3milUnXDJSc X-Received: by 2002:a05:6000:4b1b:b0:482:bb55:8bda with SMTP id ffacd0b85a97d-482c0b5bf64mr7702886f8f.5.1787305778190; Fri, 21 Aug 2026 02:49:38 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:37 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:07 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-9-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Reviewed-by: Leo Yan --- 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 ccf886efff95..d1eb4ec17bbd 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,43 +3246,42 @@ 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; auxtrace_fragment.auxtrace.cpu =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) @@ -3321,6 +3321,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) @@ -3354,11 +3355,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 @@ -3366,8 +3370,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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.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 B977B46983A for ; Fri, 21 Aug 2026 09:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305795; cv=none; b=f3ev7qXgDtKdnPiN47f6yOT11cE28yKLJTPHKo5xx3AQI+hVpo4yVpDyDJ/0yjM1nfFZA/Sb2BOZsUV6I84w88YO3553aKvOxcupm0pltSZ8UR+u28odUqvYfFdU0N4e2KxtA/8T76Lw6ZYiEiQYvLA8i2yWP6axrFILMQ97biM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305795; c=relaxed/simple; bh=X5HTnmIevEAgh65VlSf446/RisR1ZaaOWZenKgokv10=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RmYwy2fsA/L+NvdokE2P3lMfb9CPAvZa9BdEKrQ20CgtX6wSe/i2zYaE+J/x6yZXN5HsQJjLfQxGgv7yBrqjS6xoD2oK9+ZY5xapqwQuobsIAMXjTTqMCBN8NBxBaU3eRaP+jwfnqWOauIEqD8Rfnukdc/THbprHXVFScsWfl/8= 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=Zd2SGbiT; arc=none smtp.client-ip=209.85.221.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="Zd2SGbiT" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-47f96c5b722so405818f8f.0 for ; Fri, 21 Aug 2026 02:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305779; x=1787910579; 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=g282Hfq1E3bRiinvQDdFnK2jPyq4jjgh08sJOHY2A+s=; b=Zd2SGbiT/L/ZYqaljm8dE28XLrWdMSCZZuW9zBGHFxPtucjNYDEo0uZMhE2udnoTRr mwh9/tGdMMeXq7mjuzKbEGdmzIm63JdmnksEWrRAOHUsaeAt6HWg92PDHqam313cFqr0 +beVeLSw7w4vp9M1+yQMXIG8AB69rfN0qnsicrALwG8p1b97eFXKyljqGsp5ymbFBU/a ZIdxQaI1Q8lwZcMrbzRfzd86fRE1XLHIdp+RpZ9L8Dnzv74MVSE2gPk7Pl0xF3DjKTEI i5pGLQjUaN+/TkUWcqDJuUyKW+vNr7Hn/yJS3zRkonzhd/O+XAlFj+GrKUBBW6ef1H+o cBHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305779; x=1787910579; 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=g282Hfq1E3bRiinvQDdFnK2jPyq4jjgh08sJOHY2A+s=; b=BBtvhPBjhN91SirWwy/zTJNaU8cjT7JBNvqfp3r48eUc2aR1a9eTJ61DE6vKZgvTsQ +MjCLmLhjRcn7h+ne9ij9bEYSvZcH/40fmJVEKvZcpa/FZ5e8BECf9CWfy4xNMZdD7l8 tT9s92PLE9XNlgpTVP0INt9k6MRxz7yO8/ojSpjQtAOs7168aDE2ppgweLVq1fXNCOze ZxkVOHI2R1O7JtgaGEs8PH2zU3gfgaViI9M+OeJt6m8ZT4pxz8+5YdE/970vhggkOP70 9kAbx1vLjDxqVFrc0Iy/fHoPEWKCdSeP5GseXmott1ofT+bK/aaSxUInsfU7OJlPH+d/ QrPA== X-Forwarded-Encrypted: i=1; AHgh+Rq9c8XO/U4vJtSAp0knTesRuNxB4a8wPZ211GCHzIgFHhd4CrjcaHNVJNMaMvHPMlBNWGS+ivwHMpbGcaY=@vger.kernel.org X-Gm-Message-State: AFuF++mpkmkbUEUxWq2O29aUcU0USQq71644WnqDk245rLhI2+E8IJMK Rs8hnADn4ZI4x6BcVFk5gVrQ1+4+oOtLVf8OFAXVz0x7J8dVmu+9+TIqdrPuLBZh5Ks= X-Gm-Gg: AR+sD10AOiAGbObtq0usdXiv+Ud+a+flwnr3VEXsdQ/TDk7/K28Z4ATAAP9D0erJvKo 5JWogCscAdcY/4MWw+4wCfy1Cp2RvKa7oEtPUwjP68ngOqlF2d6QXYzBgq99cih+8xG1i/Qy0Je WZVEynOvjsSX9OUruK+gotwovuYP55AdBsp0llq3AxyvT6hNxc47sMGlAsZ179olEFq3EGLVMOK jRKp5hcaZj17Mkfo2yuMJtEMFXdtHl65+opNbb8Rto3tXX1I5Ti0BfQOAx0ywujztx+EutOhAJ9 aY2xahbTC8f04x11JrbW9sTboIZrY2vCdeOmqNxIKfTB6efX2DzZcMSTcvbf9CGclQEZfNsSTSm tI3IrneLB6VXVnGkXrq2NeSgVDbJB3gluOw0u60byVPzNSyO+TnAumrK+TPtGV3sJit8/FHm5X+ HEfEPU5/RbUHX7SwmfEnwPoarLfEI7CwUQnbAkfyMhEukqAdloKAcy68PT5qQXESlI X-Received: by 2002:a05:6000:4310:b0:46e:7f72:b6fe with SMTP id ffacd0b85a97d-482c0b9dbf7mr7147239f8f.19.1787305779425; Fri, 21 Aug 2026 02:49:39 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:39 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:08 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-10-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Reviewed-by: Leo Yan --- 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 d1eb4ec17bbd..6e04602ec204 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -3318,6 +3318,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; @@ -3371,8 +3374,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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.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 A86FF471250 for ; Fri, 21 Aug 2026 09:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305795; cv=none; b=opzpP4AUHwCb1T9P18v6a1fITo69p7AclibVtiHOBV3Ta+qEnHwZT96mZM/ZiRx3AbcLokJqDEHEQ37D868Vd/iAWZ2koV1Sg/JbiDWwX/jKVSPtDz1cMtqY/zvWhNuCerDh/GxW1KHjGd1mN8SuU1tP1yEEUu9svq8kegz/4hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305795; c=relaxed/simple; bh=fm7817PJXD9fz4lHXUyEY4UubPN/xPMUymDFvW6lWqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G6zI2RMoF/SzuuzzXAarS76q3m15+thSZSpj7BQTg9LNE1DPo6ARHnvIwCDv+KWv6DuGjc0oBplcwSsYosmT4OpQAxRlJzxFLci/GkHmi1nvwXFv0ZUv0ulCcOrzs0YlHcBFhyAufxXgDrJsmlbHMBd/UdTyg8YUMlva3zS94Fc= 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=JVhcc9pq; arc=none smtp.client-ip=209.85.221.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="JVhcc9pq" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-47de008b020so413675f8f.1 for ; Fri, 21 Aug 2026 02:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305781; x=1787910581; 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=JVhcc9pqaZ0WA2wp4EnI/h8w79w81W97i0uEjWPNB7PyJgFpg+kr2ao0eBB+S9A1dE r2S09lxllcMUoXC15kgeumusX4ZS4YsY8x16fxeDPa+rJXEULCj1vQS1NB8w7Crcagsw T/TOwEHVdA5G7gvTxqil/rNXJ05ZHBWgRYrGWvWekw8pXoocQgSXtRV2Y0YEou2uAvj8 GQ7mWQLHBkR8qjeaxswGsfJtlPtowH2sas1Um+An8EEX7JAewT9uJOIwsZb9k3Gnz8bG to1auudUx/skWt0mHQoJSWGaoZBZ0glaP8RSHXq15gkiB93FmzIb0snVgbK4iNqbxfGK 1wTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305781; x=1787910581; 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=cme87Q5TYBNc7NskSux44Ff1yUNMo6pb6MRWfVYUOABw0WXsskqFOmhGlGmBe5MMEw FtFhHgCwMR4/oWeBo3CJyZLkgUnc8SXeVMrB8Nu9dfSYj6NE9tlFG9EPFNLnBYkVslg2 8Crk4XrCsT/94Mx6O9RGh7dhvjAjcvcEuMcYfOQCvTdZFagRt8QO6D7AjuoiKsYQIdGK J3BWR6SD0BiZVUfw3yNRJLNs7iAxg1YuNsbtuem/qYtMnBLmXQrLehjgOeLTelLx13sQ rUKMqR3qULL92cFrSpocueBpk2Crw1HQtNEJNNT381ZD+AsMBM/nISQKYEBPHa4iOjrP 318g== X-Forwarded-Encrypted: i=1; AHgh+Rr5S4SaW85lfZRgEmP//EX7x0UD0tU+FNTZWSKayXONV+lhI/h6eI2mYhe2sQXQP8oBgjcsh/Nsq28Q8yM=@vger.kernel.org X-Gm-Message-State: AFuF++mgp/UT3hnjLDhnJpKAKC7w7R8a/PDAlXeUB005WjQ1NwgtH3OD 9SxAxEAoOSqc715uPUQY7wJ5b5wFpy3nM6UNP6WWq5w3flJXT3+Q/HcfIaP+BUkp9q4= X-Gm-Gg: AR+sD12kJqmyrOWzkin+DdG069XXybwddkL3UE1y/ow5qhSubPYbY6diZyVaq8t23vX 2yfAvtIbS31NfLKc8BaEkbw8TzfE9x2hgXCm6qph51sczT/4mx8F9zENSjusI3o0BFjJioD1Pxm bLJDl0NyrbmoYEGOgMzW5LHWGOuvU4OJR/Zlw8hJpVgb9RgutI9m2ejtRZU1KWUOpiFORd/Z0GE kJEXG8luywvz4lamiWf+BrNbYRfKW5aO+JuGzbiB4QqJ1Ek72vQrx/zjW8eZl8cgYaBsJB6VoMZ L3uXkK4LUenUT4colBifxuNZ3Iue4K77YOcPuYs+Yd/3TrxmLPplTRQD0xGM6rCue4mBPaEH55p Lzra9SDJXGr8RVjrSnZCl2tIIB6L9CaIYbJYmekpyeYbmEkbvAvflEI7AZg/5N0EAV5Yrb9dJFW 7Du/pYCW2eQGaZ+PCGVbZkrZTVkkbdn16yKonBbtRo/Ccv19YuieJZxZSG88xulaB8 X-Received: by 2002:a5d:6f06:0:b0:475:da0e:744d with SMTP id ffacd0b85a97d-482c117267emr5590675f8f.8.1787305780785; Fri, 21 Aug 2026 02:49:40 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:40 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:09 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-11-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 60971470126 for ; Fri, 21 Aug 2026 09:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305796; cv=none; b=By0iqXAu2jhQWqkCC/aGHpcJ6rsDZE4qKLNWrSUKsz4wW0PXBYddievzs7uwaBqMQupXhomHiRaGQ6Asyt4vnoxGTxiN9aXL+pJKWudQC14u5oh16Fvu2Zc/G5A5XDZyrWqqtzzVhvdF50AczHZdcqOhfbLp3vZClOXSUrH4zJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305796; 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=Vv2BIJz8wdgEsEdHHLTJPdXo4d1azNJMGKVuU8kpYy+tEEZIbZCGFEXAHC6HY7MQUesb6GV2YFfb/AjtsB0yvoDV1MRkWNRGJigPzjL4p/P1Y5cunTHszyKhZV2LyWMJwdUJO+pJPsB6aX9QL1vnF6T13P4FEV779Z4sJhWcCrw= 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=xPBBt1HV; arc=none smtp.client-ip=209.85.221.51 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="xPBBt1HV" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-47362928f65so742044f8f.2 for ; Fri, 21 Aug 2026 02:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305782; x=1787910582; 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=xPBBt1HVtSCicig+auSHVMXi1J8mXZZWwff8aEJ660lfuZBAPxM9RXgPA1dzd7PZTz ByE2Qo6pEGk1zMCio/8zEJfVpxG9WT+VPPbhIqXICcs2iWF+fz7vvORgymjkULYtMkpy r+J0r03K0f5sY8OHd2uZcQCWNbeBsV5vdIvXZWQ79OOZrew10CuvmoYlwYUjXVmdK1nz ocKl0pBglFrOTNZaIbS6tEKKdXMDRcKIrq7A/Lp+uH2Jykue/uJUlcv9YSwAewyuFUVj /UhOrZgn1zhoXejPoq9cf+6ZYRbaMQyxCNL8O+PV5zE1YY3398/GZcqhheqDCu+K82NX dyZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305782; x=1787910582; 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=kN9H4A3d9Bu8olIIvbOMzRlXVxlYfH7T3XiI6AoMmY+xkb/2OQQ9bfY7m/rCYxeePo hhm4phtZhcrYQrdXv7+T46KOWqIgKgHNBJ3WC43X5jL0dTxdTRmM2fUW6fe7xBbDo/CY 9FoQPe5Qigm8tTzGxwRoMwPK2Dj6wynDCKTxC2iIIy17biSAxCgbBDbJMr67Lw+P7fkB Q4LbfVx56XZlOw5hmXt8Q56rgiYM+D9mLVjqh582KTKuphsSgX4tqjUN3kw98Gv0amyK Z/8g107I1Nn6aJPFoiyBCbfW5f6DBYsYFD+2EtAlRQRtYM8Gq+ZpYgIL6uOk/BkUIAHq kC0Q== X-Forwarded-Encrypted: i=1; AHgh+Rq3fphcDBhz/LV9znyT43ImTmwqUTP4nBoWma4kgCzLYzry6UQNYTq6wi+xQ27zbHtSfqdwjQPqVTD0s6Q=@vger.kernel.org X-Gm-Message-State: AFuF++mCkfD/Gl7QAxwcqUpOrHTvY7JdsJF7UapmhTPJupDXAD3EvgfX KvTZMGkt9iz9VHtkOPYnwCyKQ/aFlAoO70MWv1loZelc17hW/QRuFSQLYcosB82/Cqo= X-Gm-Gg: AR+sD12PYkWRxiXF32ydcrv5stBQGtjLBLGtNXg6s8kbziOGMsot3ka1TtnTfrtdg9u XI6rw/hYnRIF0tKcvLrGThne/YhBBuT6h1kdVmZGPU86Bxo2YHmAoSUtivQ1GMZvpkokNQ19YLh MPqWoYi2OtmZC8eT+Lt83PnDdqMrh6p9PaLJ0oPxRcfw4OdXPMUKmVAva6rLacTv5tiUU6f+gGn 7tkeXvA79pcRbt+5xS5cTD1hfwvHtcmxqdUaICaWziTgYCyK9KYlzptl2s/eO8cKnoKCdLCIH9h hY3Fc8B0cQHQf34TMe1CqGJ2O/2WS6juJNnedKQ2gmaXnPTyK+oZDEJqLNBzzo+/m2UWUj5dW32 Du22zdViPQ//utjlw2rSZ+2uB3GM7K4lUXbW4G4GqQrrJyLLOJnaVJqciy37PTnbqj5jTuIx3WH osGS2JPfOsLZhvRGbBAFvALFCkPbVpRcGKoqTC6x8U4w4fllMdeghamjfne4BrdGTb X-Received: by 2002:a05:6000:2589:b0:482:bf17:e685 with SMTP id ffacd0b85a97d-482c0b88f19mr8390069f8f.11.1787305782104; Fri, 21 Aug 2026 02:49:42 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:41 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:10 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-12-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Mon Sep 28 13:18:04 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 E63E947255E for ; Fri, 21 Aug 2026 09:49:45 +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=1787305791; cv=none; b=sqgSOrfZXnBWk4C9eUkWR3f4OdfzpGsSCaIwl++B4LRqOsnRjieDtaiwTiLYlsarkzxxhcVj73ooNZ0kTuNQXGNaiigpoSmvL361IUzjNWk2UP2qbu8KvEKs2wjzkhErPki4n0m/uK+k7CTk1Q81A1MxnzH5GzpDwP7+STeRJ88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305791; c=relaxed/simple; bh=oUg7RFIUnB5PZ229CdzPdEVvo+kzyf00RHPUIVcKnFA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oT7uisK89TEF1d1ZUNW9yq06dhuByZ9GAqO69fO3hCXRSnNtp53Aw21+BeUi0vRDF/PVuPap+douOZw1l5qNXSjeWz1HeWUpYLi77pb1H1tPR+8weq90+ndkgeitcMS1Q1y5E+++zQHiR3f8TyGPSHKZGjLcFVNjlNPtZhiTVaI= 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=H6O8ntTq; 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="H6O8ntTq" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-499b0eefa61so4509125e9.2 for ; Fri, 21 Aug 2026 02:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305783; x=1787910583; 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=H6O8ntTqWyKgZiUTVm2EavFKcq4xkn/0S+NsTSyQgW7OVWJ+LkjTk9bqDwT0HywcOY jlc2tvwbNwHZ5vlEc3gpu6PYTO23prPrWJNQi/IejXJFLP2KTVFtmHbDhs692rrteWPh fi4rdrkPyNAXgfgTMxNmBL6sRAHiS3R0PIM2j5PZhb4KAUdGVys9fKecP1hkzOCKrRh4 BCBngSUc4RQk/nwfAkNHlmS+vWg3yUcaIoHYCLAungY+xKNIIDRDvEjcTTiRwRzeiVBk V9cTnQ055KsMhXFdXmlk+TOBmRI5Kpo4gqxdCzds0dfLpgu6AgJYEdzqamdt3K9p2Rwu G4nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305783; x=1787910583; 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=U7YTCpUgBsGodV+b30LIrek/NqBuDTk7ZNhxKUZB77MmPOPHF8/d5XPHTe+zU8Q9T/ TyXF2IQy0kU9N6dYZzZ0M7mVAfl7IBBeNlspOLPHF7GPGBM7HlGoUnBvpjckX1L5YrOT xVv/MgOvDSASmsysl28M7khFc2B1WzHP9fBx3wrRqzOcuxMOs27wBNXAJA+OecIVls+y N5+bp37rWHLrvQ8s3WEVnSuDTknU+LhpVxNNAw3D7lAm7ScbkCOuwz1zqZaV5wT+8Zr0 iVvbPY4+r8Wzb80GsQrAnnqLb2aV1cBlNCFqQO66VSOqb/7383Tq7Hu0GxudeR+JhE61 iwgg== X-Forwarded-Encrypted: i=1; AHgh+Ro7pafw+1WuS4DarmvDJEO+4xLu85o4WHPWUzCQXVvMrNlgiqvC9/YOl0389sjFadS+7TrX/aoSxc7e6Gc=@vger.kernel.org X-Gm-Message-State: AOJu0YxMRM8W7TgfIMoK6PvuM4oUTbrxsjzowxKzGayG36S1BieSLxUj 0yAXEl3EkxOOE3KASEOpCa3VcKtCq7/zqdGKxisycMKhiykTWOgNp32uTTOKJCliNxY= X-Gm-Gg: AR+sD10Cr+Hot1EF5Jm7Aet11zcLlIV4oE/+msScMrXFW88OfswQHO9wS03tOlWnSat Qsip+ooIRsqClv9Uhp2ztjFp4ScwDg0ieFmwVBKIyVw/UY4vuhAhpmoh4ijkhPKTz3rQrdDx3jA 5xXY5afEYhZCnAXvBViGs+VhamgF5ftr9mmCiivgq9RlOZ35eiE1c9cDZIcn9x3r8qZewV6bSZw dzq/kBb2zUJqGv2fdscx0jtI5TZ4LISHxJnjUzxaAQmi0meJKCNAKjriO8aoupkUuIBg1oWmyZM UWHAd9evUt5n4AjC24wj+PFSR9hkjnoSY/9cCDzzMlJfhWPomnQ6vnw1sdW/Rdkb8eaHyMoQZAv zWLfdz9gGXYTpYRSZF/0/2IXJLLFmHUUwte/l00bp/b9nvp2PitfYiD/Q15zCa5LjfDok/JEYNe 5hBF8xhL0nvnluDxY71wcynH2F59B+kKVg4Kmx2CBBxH5nkOFvLuNEfhTvxppNnJlQ X-Received: by 2002:a05:600c:a088:b0:499:7a19:408b with SMTP id 5b1f17b1804b1-499b83572bbmr76994215e9.11.1787305783413; Fri, 21 Aug 2026 02:49:43 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:42 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:11 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-13-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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 Mon Sep 28 13:18:04 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 766483D5652 for ; Fri, 21 Aug 2026 09:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305800; cv=none; b=MQgfqhhxtYxdjaYoVr9EorCc8/VufUCSEChF5hJY+bwzgdvLBKXFI9OaSLnPujgR68lreV51NKJR9oJNprIwLL/ZMiQQ8FjMkkgzbRw5LGxww1Z/5/hm9wd587YDYsGIq187SqF5lIYjdnoHqHPjLW0bltJ/roL6fORZ/DmOJwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305800; c=relaxed/simple; bh=45ewM2dvFaY12LY151swUHBTvievnc3sust8Ep02uoY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MfKN88RpWTIRtQzNYeUNL7QVexACHHQPaeEdCJ9PPQghry8N+uCN08q+ownzbJGc5Q5UTEkCbT8NabG0c5zpRa/SaJOGzZVCLpKX2gfqxYJYfZ61v372XwHFw18ND+saT9QLD0YvgXP6oGZ8o9asTrumFV7f+gK2VzWlFxv77lM= 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=RfttxknL; arc=none smtp.client-ip=209.85.221.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="RfttxknL" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-481412f1828so278336f8f.1 for ; Fri, 21 Aug 2026 02:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787305785; x=1787910585; 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=RfttxknLuTZt2Qr2BtWUT3atEqCHAqw/Kv7RKtHnY/+qIU84Zu5F5Dh80192T7cCVL 2pxI1RM+McHyqNi2AAJbuESxWxi8cO7LcyLZfqrjgDZ7j5/s5q0M/SW8vNJm23o0eSFd 0bM5WO76hYjOHcaeVznou36UFTGx9dxW5sNYPFpF8pLR/kPjzUJWB7PcBQTv6xVy1e/o oos/aItt3jG7nDxA+RPrMJSCt5Jg9IgFjsisZ7iUx78ZbLSVVeCRvu9Y+T/fr0ssYOoJ hM6hULoeJsruVz9ebMTSkfH6iyQm/9OuBDA2mLnAm/BfChtDIC6gCme69mNqh8K2X+jw UmwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787305785; x=1787910585; 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=tVazBLH5MZV8+XRIM4km8Or+Q172wIHU6lqmAjPxe05Md2aHDmL207jjqivHna03Tj urIOEf4f2O6/hhL/qwmctqYvLfEdcCCfrgOEeTVXyRGWYSpM1eUyR+dUUvtEPcnH8w/I nX1uXEqfL0/TKrxmdd21ncluXS8jAN8M1Ray//SReNk/HBQIoKb7gqVNTlcWg036Lfuw dm3cDxg98KYpqQ8ajomkofhrx67xyjQrNoRAfari24ycz43zsFAkIr45lYgqChqWG9cI 6+wLaRtvkwJwt9IS/h+RTY9UJqaK8bis6bM0abEU3AdNWhk02l5ZUTEh6UmdI5mXXbOY 0SLA== X-Forwarded-Encrypted: i=1; AHgh+RqQ0PT52KVJwJEoiJqJetKUkfSACqavz4n1HZTIItX8HTR+37KOF2PgSp2BcysPY3vDZ/Kz3W2trk0wQRM=@vger.kernel.org X-Gm-Message-State: AFuF++lxVPO7v2uayEXwymvu8nn+pzsYYhHSt5U4iFRZ7t/c+sO+dsXs H9IIWuVwXgShLu23Lfw7feUaQiapmaWme/V4mndFpFQFMOyFzDgHzSSDlNXhWmog2g0= X-Gm-Gg: AR+sD13aD27Jm3509W/1NxICndGosXCuli9ipEh3vvz716m276VznP/kDHHpqkOsGBD 8AoUQLYG0AquX6Y9VmLP3aeSf7g2jhTyDbErhkECjTvO1Mz1X4/Dh/PgdnMMlM4DlDfUaKVckZ3 dJpBgVbu+l+lCqslvKo43g7q9w9ErV0cGxXwP1+nYvb8nZxYkZqZE9dW1zOly6Fd5t+BbIWALLX raVRV3LPS/VL9CMJnui+e6WcUKqbsdNE8OtCw/PUZHjn96Wep7QgYgaX1ynSz7rB6eJNFGNO3ME ai6dNAwX6gAYpcWKRHdXsRIMwenpd4xPoIa+NQTuIhx8wHHCDUALUBvL8PYcFMppi9VBhNA9/di pZ+WReKXn/jUgCkv29b61SMeBlnu0Q0aiPaGvmTQBuv0orJZCT55SQysrRkgDk38CQXkPA6qKFw z6U1I7i/CY3khFEl/AT3gnj7t26334c7biJ5jPO3VyRRhiIcH/iT6YWGRx60UBvcKw+BgU4jHBV 68= X-Received: by 2002:a5d:5846:0:b0:481:3124:c71f with SMTP id ffacd0b85a97d-482c0b907camr6412779f8f.17.1787305784814; Fri, 21 Aug 2026 02:49:44 -0700 (PDT) Received: from pop-os.local ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14d05a6sm17683479f8f.35.2026.08.21.02.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 02:49:44 -0700 (PDT) From: James Clark Date: Fri, 21 Aug 2026 10:49:12 +0100 Subject: [PATCH v2 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: <20260821-james-cs-unformatted-per-thread-fix-v2-14-00c4fd0701b4@linaro.org> References: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@linaro.org> In-Reply-To: <20260821-james-cs-unformatted-per-thread-fix-v2-0-00c4fd0701b4@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 , Amir Ayupov 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