From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 126EB352000 for ; Tue, 9 Jun 2026 14:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781016033; cv=none; b=UJwIgLampwUB2fI8v3l5uhhNQcLjuVDoAzU9TBKQbhjJajPp24QX8dfsyDC2XwCa8QboLXxUGIwnL2clXdfZL2UfBd/wAwI4FW1ZyUspFL1uoTlfLwDl0LFpMmSSFlpsqxHtWQ0T8za3w03lEvzco4JnrXot9l6SiTP6u7szXwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781016033; c=relaxed/simple; bh=dIdyAuGP/OaUVcAMmgROZGX4ROjDm0H45x/4DXdzJEc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HUUxjAaG8ntSllsT+RUHBAtfAunSzsZMQNkjLQgOPQNqgvCKuh8mfIRS5O5mLINXtXD3DUP14XBcOgqSuencP7KXbJ1RNTT29/0nID0bajke5op9FTovQSd1utZZrzOa7QuOJ0DWrKPt/YMy7sh9/vDIv1EyZMLJHHNqEkyHiJM= 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=ukba1lLx; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ukba1lLx" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-490b64c8311so62873875e9.3 for ; Tue, 09 Jun 2026 07:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1781016029; x=1781620829; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PmgPHjWVH3cXsk2qRjnjPXugJJfk4bPfhv1qYZzCEfk=; b=ukba1lLxCvaQGy7Am1z2ze4BSX32hKePsH1WBv7K8XkHyX5RCClVKoZUoL30Icuhw9 iE1n0Uu5z7vpRJ8oyNSBEK/uS3xx1UoWIIZS+ntr7cnk5nyUsmFCeKXKAxxAkd18grNN 5pmOEyxyaw3lrWfgnCg1wn+qHLwxuXbd7eCH2vzbwe+VHwQ/50zbuzbXpM9IvZ/EvF01 AHmhBOHsTApJV1B7385N7XYEKKomaIoq0qwPUEblkEExrRF/4TAPG+wul8WNdoti+nJ4 BhjjydJ8YrjH3fmB7+eZM2XeX6aC0FrN8Lb7/KmMcHCow3sCV9naKuCulK9Tr5c9R4Rw T6FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781016029; x=1781620829; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=PmgPHjWVH3cXsk2qRjnjPXugJJfk4bPfhv1qYZzCEfk=; b=q7XraIdsOrq96HTLAxIJcTYnowIcbxApWVHu2U3CuAcniv5WvOz45GTyF8mXObV7aF vxoZcPHkDaIrvNdcybc79+LrgKPFEUdb9rl+omYGZ96OgSIoY0w1yzDuY+n3d6iHjR7H 98ChnbPwFgPswBSZIAn3AbOsc5I5wn4MVK27wgf2EpHQn3tAb8dK+ChvgB1xNusWPG38 17llyV6qkMyJwrQkz1OzlfjS1/rzQu5elbA1DmvY8CGBmmCCAuE8Hv/jk97ZjCjWztro GYCTCNvObuig0+ZRm06Up3NjExgF0Ibczh55Ip4BJ5+gHPXy80BW5rwnmsgQ8Uj0N7Yq /B/A== X-Forwarded-Encrypted: i=1; AFNElJ/zc6bnU1jTQ5rYxujDIyBTAaOmVP6Ktpq29eOtrXrqrV1KMLaNxbw0CU9wCfDZc8VIg0GJTz7DRwsZk2w=@vger.kernel.org X-Gm-Message-State: AOJu0YzVMzZXcxtLunqz5SRwKfH1aLH/cPknOImyihALAtJ14/4FqwrH imK2EnbijkI2aIwBGdS/339eLIiMa/ktxDxY8XSave0ldsPTEgZWFKlQh7tkG6vNxRE9K2+tdMQ Yv18jMqY= X-Gm-Gg: Acq92OGr1/hCepgZhb1vvFFZi2jgG648jCprErtykgfH35kE7Bmd2Ry7VCOUaWE8gvB BlNmEvmh+BYLmioK08Jg342jInSEEKOTgYdm/qqfAvA9LWxjDnvzzBxFaN+n6pPDn1xKhUnOlY8 3JWB6o5lNdYTwXwI16a1nV8pyUsSwTRgsLew2/uR/ZGbLfz4o3fgjLDF3TYdCmlSIWCcv6xtICv 9x/45nh0A71gtQelYP33pqlK6aRvQ4zlvKPaDOWICwqOL5OUemSo4KkDARJ8NTEh344PiDw7shN ChFlNX7ZQnxsCEZFKgoi2yCryQrs1vFoZFl/kpKfR6tvHrCsNa2WKpM535akzOn2b9VR9IsMsh5 e5AY2zORQMsXrGwkywGUZmCMdWlPmmHKYB+glo+4vLbu+C7J4BJlSorSpmIhV+awbykdiTpoEKG lPPfSkTiq2SFltiDLwQu+u1tuRcm9NsrixVyOp2FQhekw= X-Received: by 2002:a05:600c:5248:b0:490:cb90:3e00 with SMTP id 5b1f17b1804b1-490cb903f1emr190466575e9.14.1781016029071; Tue, 09 Jun 2026 07:40:29 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3c1149sm428411935e9.4.2026.06.09.07.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 07:40:28 -0700 (PDT) From: James Clark Date: Tue, 09 Jun 2026 15:40:09 +0100 Subject: [PATCH v5 04/19] perf test cs-etm: Test process attribution 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: 7bit Message-Id: <20260609-james-cs-context-tracking-fix-v5-4-d53a7d096a19@linaro.org> References: <20260609-james-cs-context-tracking-fix-v5-0-d53a7d096a19@linaro.org> In-Reply-To: <20260609-james-cs-context-tracking-fix-v5-0-d53a7d096a19@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Ian Rogers , Amir Ayupov , Jonathan Corbet , Shuah Khan , Paschalis Mpeis Cc: 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.14.0 Run the context switch workload on one CPU and trace it to test that symbols are attributed to the correct process and that the attribution changes at the exact point that the context switch happened. Reviewed-by: Leo Yan Signed-off-by: James Clark --- .../tests/shell/coresight/context_switch_thread.sh | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tools/perf/tests/shell/coresight/context_switch_thread.sh b/tools/perf/tests/shell/coresight/context_switch_thread.sh new file mode 100755 index 000000000000..2b9c44b86c59 --- /dev/null +++ b/tools/perf/tests/shell/coresight/context_switch_thread.sh @@ -0,0 +1,69 @@ +#!/bin/bash -e +# CoreSight context switch thread 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 [ "$(id -u)" != 0 ]; then + # Requires root for "-C 0" in record command + echo "[Skip] No root permission" + exit 2 +fi + +tmpdir=$(mktemp -d /tmp/__perf_test.coresight_context_switch.XXXXX) + +cleanup() { + rm -rf "${tmpdir}" + trap - EXIT TERM INT +} + +trap_cleanup() { + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +check_samples() { + owner_samples=$(grep -c "proc1.*context_switch_loop_proc1" "$tmpdir/script" || true) + next_samples=$(grep -c "proc2.*context_switch_loop_proc2" "$tmpdir/script" || true) + + if [ "$owner_samples" -eq 0 ] || [ "$next_samples" -eq 0 ]; then + echo "No samples found" + cleanup + exit 1 + fi + + if grep "proc2.*context_switch_loop_proc1" "$tmpdir/script"; then + echo "Thread1 symbol was attributed to proc2" + cleanup + exit 1 + fi + + if grep "proc1.*context_switch_loop_proc2" "$tmpdir/script"; then + echo "Thread2 symbol was attributed to proc1" + cleanup + exit 1 + fi +} + +cf="$tmpdir/ctl" +af="$tmpdir/ack" +mkfifo "$cf" "$af" + +# Pin to one CPU so the two threads alternate running but record into the same +# trace buffer. Start disabled and use the control FIFO to only record the +# workload and not startup. +perf record -o "$tmpdir/data" -e cs_etm/timestamp=0/u -C 0 -D -1 --control fifo:"$cf","$af" -- \ + taskset --cpu-list 0 perf test --record-ctl fifo:"$cf","$af" \ + -w context_switch_loop > /dev/null 2>&1 + +# Test both instruction and branch sample generation modes. +perf script -i "$tmpdir/data" --itrace=i4 -F comm,pid,tid,ip,sym > "$tmpdir/script" 2>/dev/null +check_samples +perf script -i "$tmpdir/data" --itrace=b -F comm,pid,tid,ip,sym > "$tmpdir/script" 2>/dev/null +check_samples + +cleanup +exit 0 -- 2.34.1