From nobody Sat Oct 4 19:15:11 2025 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 F393A2EACE7 for ; Wed, 13 Aug 2025 13:39:15 +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=1755092359; cv=none; b=dn+AXMsoBp6Or6FHdbVhCymnvLjugF8B9t4N26Zh1brBr1pnindfJQaPuPO+KPKI0bGgmDBXFa22NKcVyL7T/3sCphBodEKVS+8saxrS//gupqOdUb8kAHZPfqyWqJ609qsPSDuOkpOl4o/ceM36aYcUN09Sc981aDbveIOSeo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755092359; c=relaxed/simple; bh=eMGWrGU1Pq3EgL3IsVL861cKyUJJW8JuQmi9Pj8xfdE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=THjDJL7CuqYEq8QbtVBmmM4hHgWHJ/akgFoJiuZ1uXaLMle6d9MATG2qELK9G7ylpUOvD7vZ780fsdrUjH1QyQNbEh43YKb9EBwgB+VTWvBQb33J5xLu7lN9obQ8JWgT0cup/nKM+K86h2RXCc/1VycAAjVh66AD3ruF29eGN2Y= 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=jVhG9ttr; 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="jVhG9ttr" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-459e20ec1d9so63991385e9.3 for ; Wed, 13 Aug 2025 06:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1755092354; x=1755697154; 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=JsrMomRatGKoksxv3BcDep0KoaZwE6tn7JLahTJYPlc=; b=jVhG9ttrNOaerJo1gcfZkxy6iWNVmEWW1XjJIAVY3C6Fd8z0YF++boZtlalneAslIC LzrNEkQ9R8vgVlfRdhadlNz+/UwHzeRgGv/RQICjS6oxa4aiSjTb4Kyy2hZ2cCWbzATw K2IKDTTaRoSb672nD/QbNPmpbSgVT09mKECd6xbp8ZuvM3qBhmWP1Fh6Mqe2lQuQieqP H7qYc0dJoglyFuAfVFbexUbmPwGoxElmYcWm5S5L/iL7zvORHR2MwrvMyAXGQVwi/AWC IseY1mQSrXT5gbzVx5LchhW5DLV08sDrDX2LFvYz+ZHd6IiMZ05FudUtKZ0FYumnZZT1 AzCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755092354; x=1755697154; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JsrMomRatGKoksxv3BcDep0KoaZwE6tn7JLahTJYPlc=; b=wqeqWS+TQTnHepU0+cOx7BF4n1z5gb9g7oW55XWnXbyssE/Nm8YwMjuXUdFe/VVkSi qPoUFa/pUh7Kj4UwRP9QXwN/fNCK/fgOuyc2Mp/AtQnm2EI13LIpWLMywH8x+NoUfso3 mS1xmrK8flm3J6AhKsZaEjCF6bXoPM3Vij59poHohd+xUNUOysUzMP76N7MO4QTkZyUA oAw0T2bT07IINQmLgaHkdNzjbrpzdVY8QsafpF1TW3WkyE/vy2aVBJ/v4vItpNSsqdeZ B/jld1BYU5Q3PzEWcap5hWlt032sNOwC8EHMPGKfighKphrDFj8oICv09+Nny3FwJJxU JMhA== X-Forwarded-Encrypted: i=1; AJvYcCUL1P1/CBcUcs2Ss4R5e8INHTRduWi8TYqxdVMIMGPH5FCTGdk2KnpytyMsz3xs3jqjdSitDLO19nhDrFI=@vger.kernel.org X-Gm-Message-State: AOJu0YyGHsOda3+wQGLTuQxgvaEZvlwwfT9ifJddC40iU0RO4rldwf1a 3Gyb8RfxrCJpLxpyEB/r3sWRC49ktpiXyL2EoyBgFE07a+P59y1M57wrnP3qiaM/e64= X-Gm-Gg: ASbGnctYgGP1KNEuskx7YfeKI75STNHSU+XzYlYWvYl46gc2wv8xLaRJr7tLzxS65ky N+uOeeaiK6K0guPgvrDYibB+8/fnT9Lk4SVjkrscuDPPqn4lKYe9xUHwZWl+9CaQxldr1Z+dKyP 133I+/Ov+RexuiD6aHP7eyVbOic5WJDwqR0QBvfaFrEwazSSJWsG3BtwW3IeG3jbRAEX5eOvMza la1RidwvVR9r6Wj13aCZF2k43FUUVSc0qRCYzrSUAix0MGl3Ix0dIZ8sDapGBenA/ajV4hs+pn1 prSv9IBt7pxUWlK3dPNXQoOnST/UkAHdLaYoRr0opgYPeEvQoV7QADnrMmG2c2vcjyuKpiEy8JP Zeobj1KGjY5abX78fdZcpws5AY/5H4VA= X-Google-Smtp-Source: AGHT+IHVIhli+aqqVXI0G6Xjd/ZZnNQlJsxxmc5F7uroaQCRzsfsyiSwoF8oJK58CA523uRNRDvk7w== X-Received: by 2002:a05:600c:314c:b0:43c:f44c:72a6 with SMTP id 5b1f17b1804b1-45a17258921mr16333275e9.2.1755092354124; Wed, 13 Aug 2025 06:39:14 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1a596280sm2559145e9.28.2025.08.13.06.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 06:39:13 -0700 (PDT) From: James Clark Date: Wed, 13 Aug 2025 14:38:49 +0100 Subject: [PATCH 1/3] perf test: Refactor brstack test 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: <20250813-james-brbe-test-v1-1-76a0144b73fb@linaro.org> References: <20250813-james-brbe-test-v1-0-76a0144b73fb@linaro.org> In-Reply-To: <20250813-james-brbe-test-v1-0-76a0144b73fb@linaro.org> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Anshuman Khandual , Mark Rutland , "Rob Herring (Arm)" , Adam Young , Will Deacon , German Gomez Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 check_branches() will be used by other tests in a later commit so make it a function. And the any_call filters are duplicated and will also be extended in a later commit, so move them to a variable. No functional changes intended. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/tests/shell/test_brstack.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shel= l/test_brstack.sh index 9138fa83bf36..46e5aa9ce8ee 100755 --- a/tools/perf/tests/shell/test_brstack.sh +++ b/tools/perf/tests/shell/test_brstack.sh @@ -34,6 +34,13 @@ trap_cleanup() { } trap trap_cleanup EXIT TERM INT =20 +check_branches() { + if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$1"; then + echo "Branches missing $1" + err=3D1 + fi +} + test_user_branches() { echo "Testing user branch stack sampling" =20 @@ -55,11 +62,7 @@ test_user_branches() { ) for x in "${expected[@]}" do - if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$x" - then - echo "Branches missing $x" - err=3D1 - fi + check_branches "$x" done # some branch types are still not being tested: # IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX @@ -101,14 +104,16 @@ set -e =20 test_user_branches =20 -test_filter "any_call" "CALL|IND_CALL|COND_CALL|SYSCALL|IRQ" +any_call=3D"CALL|IND_CALL|COND_CALL|SYSCALL|IRQ" + +test_filter "any_call" "$any_call" test_filter "call" "CALL|SYSCALL" test_filter "cond" "COND" test_filter "any_ret" "RET|COND_RET|SYSRET|ERET" =20 test_filter "call,cond" "CALL|SYSCALL|COND" -test_filter "any_call,cond" "CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND" -test_filter "cond,any_call,any_ret" "COND|CALL|IND_CALL|COND_CALL|SYSCALL|= IRQ|RET|COND_RET|SYSRET|ERET" +test_filter "any_call,cond" "$any_call|COND" +test_filter "any_call,cond,any_ret" "$any_call|COND|RET|COND_RET" =20 cleanup exit $err --=20 2.34.1 From nobody Sat Oct 4 19:15:11 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 199932EACF8 for ; Wed, 13 Aug 2025 13:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755092358; cv=none; b=eP72P4xKpFjBKFj/uquyLaeG6oXK0AxVom1qbEbKOqG8WAX17GwyCOxmoJLHBkPDVNz0AE3JzsmYDEiB4zy+xM92A812Wmz8aPjYwzcR1C3C6KcYNSOJriOoGmeEATDu7LABrg2oqndnN0O3VC85MU3J0mg5nxV1HiJEoiLO0bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755092358; c=relaxed/simple; bh=8IXJ4w8szgydeEsRIezTVodOHdHqDxt5F6vslQDwrEk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ub4TA1wfQGEt+qlDhc7IdxhmwJdbUfskscgBTksoHIWMb4eF4nPeWUTvpHeRGtAvhJCINNYgi+fQiCBh/KaSUQ7I0XwB3YIFn32FoDVOEe3DwWkBNgGwvn47atOMm1kUILsPlLXMPBkGTkL4ls8y+Cwx9vHEiOXiCxhTRoS2Ur8= 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=iq2gnyUl; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iq2gnyUl" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-459d40d16bdso42303085e9.0 for ; Wed, 13 Aug 2025 06:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1755092355; x=1755697155; 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=KeStqnXaxy3QngS5Ia1n5mO+f7KQZ/BhVH2TpqaUklY=; b=iq2gnyUl7mkM8N3tauhLn3H9TxWZkUvQqwVokbMrY6m1U4y9QK0tj3zsYuQUpVTr2e xjwg/ff8rET2OAeCpu56SPzCmv3rLTl2Kk8oaNQRVcXmC3iGvay2XzebnR/lm4niBZTS B9ZHR5UKvxhTBwVf8TqG+xmCDe501++IzzQebMG8OP9FMcSd++Uw5N+531ZC2Itmv3Al Jd8jV5FzuTwh7xygFYfQ/rHdhpkoYzC+e34T2+DtipIzzyDVNwCGXfgRlDSVGOfL0ZKQ 8ip9+q1cslA4CUq4o9flnh7f0Uc97tTmAGoq5LMQuIDwxSt1Kv5O73dSnbdWfi8tFuiz juTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755092355; x=1755697155; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KeStqnXaxy3QngS5Ia1n5mO+f7KQZ/BhVH2TpqaUklY=; b=k7/aTNZIsDOfFDgk/0IEGKu+5h7obPXh4vr1z63dbeUzieaN3YWdsmlMIzY84/K8sC lICyFdrUYJmL0KuDdeAOex/bZ5psIcbjr884f93vQH0nxN1GA/AFnZCwAZZaWF7JxeeE +WoXQFTbYfW1C5pQ3mLWftjoTH0iWjYjqJYq57T554GSXj2/73G8v3noS8zPJ7ZpDNDQ 9AdFtGaKJs2IMAQBdNZrrmuIA31XogxRyXmhwltsZPUVIv9OYaFHd96VSnZ/nKqSY1QA +rH1cKx9pqQf49tHfbx+Xe0qJZeXJZnT/rUX1gh1QQ+do3SS+In1/dOkxch4BU5rrL7f haQA== X-Forwarded-Encrypted: i=1; AJvYcCU6V/ao4KIKjSB3j0ry50IKtUhpcxDTwMigXCyepeDUqbbATTB+F7DL7mLhjX1Lbjt1nSol9xaOt9IJxwc=@vger.kernel.org X-Gm-Message-State: AOJu0YwT+70Ki8Coz2Uulz7LW8i+lyLkbDz5d8VZdI+x94Z/+c4cNfEU qQhysFfWhW3itv+diz+5Lr/WRWBEzpg33nx/WGhprcVROyPxwDpNXGOxt2LVGO0wsvI= X-Gm-Gg: ASbGnctr3Hazo4qxntbmxhw3NN9WQK5+ZUPpoD4jC2WYCFFTY+YTQXj048dupBE4uBo /NkA8GpqUzjk6fpD9DvewkblXrR1iU4Od8obblMm7sM2vxsdDcHKe4Qxt7hY23kJe1rLL5Y4++1 yystHMFlo1JrSWCGWcsa9oDlLpJSSG8g8gG2E7224EoCHtsFKH1n15EUH8g7GRmDWW5MYFlIqib YrtToXZo+k0uEzigO66PRSIYaV6iErz1oka6zqzHkoVdqUU0lGTSjMCnIhjdlMgt08GNkAEE8Fv 0ZQHJF7cgaPWdAGGUqAIBI4GIRoN8xEE3VpGob/OpY0xJWOw3DfeeCfDK/MZuBtILzSnJOldgHF KKVTqT2pmM6q8Lr5zWipBOZHJWmJmyLg= X-Google-Smtp-Source: AGHT+IGiXArFsCsvNs28Mu9JVgeBLPfa1rYnkKC5It8U74TbonupuIcmTSAjOYs57oxdgF9sCrSLQw== X-Received: by 2002:a05:600c:4750:b0:440:6a1a:d89f with SMTP id 5b1f17b1804b1-45a165b7b22mr32838755e9.4.1755092355313; Wed, 13 Aug 2025 06:39:15 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1a596280sm2559145e9.28.2025.08.13.06.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 06:39:14 -0700 (PDT) From: James Clark Date: Wed, 13 Aug 2025 14:38:50 +0100 Subject: [PATCH 2/3] perf test: Add syscall and address tests to brstack test 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: <20250813-james-brbe-test-v1-2-76a0144b73fb@linaro.org> References: <20250813-james-brbe-test-v1-0-76a0144b73fb@linaro.org> In-Reply-To: <20250813-james-brbe-test-v1-0-76a0144b73fb@linaro.org> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Anshuman Khandual , Mark Rutland , "Rob Herring (Arm)" , Adam Young , Will Deacon , German Gomez Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 Test that SYSCALL type branches are emitted from the expected 'getppid' symbol. Test that when only 'k' is used, sources addresses are all in the kernel. Test that no kernel addresses leak by checking for them in the 'u' test. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/tests/shell/test_brstack.sh | 61 ++++++++++++++++++++++++++++++= +++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shel= l/test_brstack.sh index 46e5aa9ce8ee..252d22d39c7b 100755 --- a/tools/perf/tests/shell/test_brstack.sh +++ b/tools/perf/tests/shell/test_brstack.sh @@ -64,8 +64,50 @@ test_user_branches() { do check_branches "$x" done + + # Dump addresses only this time + perf script -i "$TMPDIR/perf.data" --fields brstack | \ + tr ' ' '\n' > "$TMPDIR/perf.script" + + # There should be no kernel addresses with the u option, in either + # source or target addresses. + if grep -E -m1 "0x[89a-f][0-9a-f]{15}" $TMPDIR/perf.script; then + echo "ERROR: Kernel address found in user mode" + err=3D1 + fi # some branch types are still not being tested: - # IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX + # IND COND_CALL COND_RET SYSRET IRQ SERROR NO_TX +} + + +test_kernel_branches() { + echo "Testing that k option only includes kernel source addresses" + + if ! perf record --branch-filter any,k -o- -- true > /dev/null; then + echo "skip: not enough privileges" + else + perf record -o $TMPDIR/perf.data --branch-filter any,k -- \ + perf bench syscall basic --loop 1000 + perf script -i $TMPDIR/perf.data --fields brstack | \ + tr ' ' '\n' > $TMPDIR/perf.script + + # Example of branch entries: + # "0xffffffff93bda241/0xffffffff93bda20f/M/-/-/..." + # Source addresses come first and target address can be either + # userspace or kernel even with k option, as long as the source + # is in kernel. + + #Look for source addresses with top bit set + if ! grep -E -m1 "^0x[89a-f][0-9a-f]{15}" $TMPDIR/perf.script; then + echo "ERROR: Kernel branches missing" + err=3D1 + fi + # Look for no source addresses without top bit set + if grep -E -m1 "^0x[0-7][0-9a-f]{0,15}" $TMPDIR/perf.script; then + echo "ERROR: User branches found with kernel filter" + err=3D1 + fi + fi } =20 # first argument is the argument passed to "--branch-stack ,s= ave_type,u" @@ -100,9 +142,26 @@ test_filter() { fi } =20 +test_syscall() { + echo "Testing syscalls" + # skip if perf doesn't have enough privileges + if ! perf record --branch-filter any,k -o- -- true > /dev/null; then + echo "skip: not enough privileges" + else + perf record -o $TMPDIR/perf.data --branch-filter \ + any_call,save_type,u,k -c 10000 -- \ + perf bench syscall basic --loop 1000 + perf script -i $TMPDIR/perf.data --fields brstacksym | \ + tr ' ' '\n' > $TMPDIR/perf.script + + check_branches "getppid[^ ]*/SYSCALL/" + fi +} set -e =20 test_user_branches +test_syscall +test_kernel_branches =20 any_call=3D"CALL|IND_CALL|COND_CALL|SYSCALL|IRQ" =20 --=20 2.34.1 From nobody Sat Oct 4 19:15:11 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 5677F2EBB81 for ; Wed, 13 Aug 2025 13:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755092360; cv=none; b=dUtO9iqlHVhd+V4dJh+EC5UE6VGg8mtZact3JfdX36UFJwG/KR6W6HF53CC0Tx2SzhzhHBH7NjFmAEaWze4P4s15+PBp1oldTAQ7uh5gdTUKmnIxQy6kW9ePuV0jUS8p0MEo/oj5TVUlpprCyngDVbwaUb6zE4QZP4c1cDvA9mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755092360; c=relaxed/simple; bh=Cj09as8AhkwGyMZb6hqGsQUOrGvO1cZWnTecDA9y7WQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KUhyR1nzGTdphGQWWlV8ArQA3yIkRKLRNa6+4yK/wLJix98Oqmh45D9ngpbPuRbYkjhfEzxq3v+h3tnUGUF9AkZULNd9DQkH5B44OaWVCGV+c/+r7vPWCN63G8lDGEps/cZ+tDy2oRgIuzqQSQ5h8Zq2l3sG/hAfna+psNe5UQU= 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=OoUmWnmP; arc=none smtp.client-ip=209.85.128.52 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="OoUmWnmP" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-459e20ec1d9so63992045e9.3 for ; Wed, 13 Aug 2025 06:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1755092356; x=1755697156; 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=7YfMIUKfALfBR+AjJWVdhiJltI5m6xsjP1Rg9Wv99io=; b=OoUmWnmPt2OeiYtukJhE1JibUoZ40bp0uqkGHOM5zYyXsTBz8cv89JNbM3UIGHwAKh OaenMwXGYx337oq5AeEg/4BcUiXd//4q+WPGevOgD3mYwj+nCaObwOLP9jEwK18zw6LO IDrHu2hXgzcMuCaSPBuP0RVbrlJ/a4CFGpvWRSrANjm7ILRKcjfkQ1WOCY00AwiqbRQ8 Jk4By09NPde/UdCGurY0Wyuc4vohOYXdQSHxJu9ZvhC0PmWng/U9qCwL6/XVDclzkwaR dEes6lHOflt9GytDauonHmkdPE+e8iDXf1WWjqAqPAwE+qDpFkqkovO40RkZESlvtE0K gO+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755092356; x=1755697156; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7YfMIUKfALfBR+AjJWVdhiJltI5m6xsjP1Rg9Wv99io=; b=Ud1RP65tJpaAaf/awtQAIDyhvxGglHzc9UhWE7SHURO8TJUpCXqJskZ1StDm0uD+O3 XJGGiK47wE2zXRPgkKZs8zRfqgJhIyFJxG7WaNDPi16KD2FHfTWh/wDV52isCNizWrt6 3DUf7EYSbCr7eJWS7xmVrLUmKmvQXUZRp8t3417csyjwtHU9TMF9WbkxdDxO41bxw8qY +fi5h+rHvptqNiyevPH36tOSttdqHMrAp8K8pbUHcyQ4hnf5FpIZdsya/WSeYw/2i5bf hKqcR2Nxh/1MHhaRGhLLr7noI5Y+TzX//D0znMx5haowBW9KE6+B5HZXYGjkDkCJRtfQ uxFw== X-Forwarded-Encrypted: i=1; AJvYcCULyr7BfH4o1oCe21IyqjMMY6uMhoVnGfN/lvkf27j6L3usa2jzdPKvjmDDYPG23rr25UV5NT2ltTtZMtE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzx0+CFsSk1GC8dZltQj+qZNOeaGqNFTk1YGLQ+0CH6WyW/5ytD McGCArwwL3cpHnTAkY4n+SQ67v9fwZZRverFWsHb0l/D4lvceuQc7l8Pu4wKMRpEWiA= X-Gm-Gg: ASbGncvZqg9wv86RNqacjn8wslyJAesa9DJUjFGd5fuFfbFwkLJtEAt1CT7ACDbHVyK naPnaoQFs5SILY5Pf1XemjnvxIDE84BphRAz7UrS7l4Wv0YHeoCdH0/JNGCwHTWlmwvDshi37op KpM2Qf+Ly6YouGH1wHweW7okwSR91nDBl+Em+m30DrHNhk6YxOdPvneNTgsGpp+EfAJdVluQfWQ IZLvfYvAO2gRmG6+VFRvrB0PiZTUbTXgLbRaQoQdgg/4Fjv8Bq1eeyumFpLJj5PWQzQ9+ZplkNZ SyAcCMmnkP/91Rkx4FmYLgnMdrHPdpFUKPIRQ3hP8G6+PEdN+jHvKHOKxwTbUX5cEvneVpPuKGs JDpAG9mTU/C+KA/llEBM8uavTRYGZbmo= X-Google-Smtp-Source: AGHT+IFCJ2V2UElphjXDu+KrovoN3PMnal4w2lEqDYxhJn5SbJZNtsKOGhd80c4dDIQ4M/2sKAthzw== X-Received: by 2002:a05:600c:4750:b0:440:6a1a:d89f with SMTP id 5b1f17b1804b1-45a165b7b22mr32839765e9.4.1755092356447; Wed, 13 Aug 2025 06:39:16 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1a596280sm2559145e9.28.2025.08.13.06.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 06:39:16 -0700 (PDT) From: James Clark Date: Wed, 13 Aug 2025 14:38:51 +0100 Subject: [PATCH 3/3] perf test: Extend branch stack sampling test for Arm64 BRBE 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: <20250813-james-brbe-test-v1-3-76a0144b73fb@linaro.org> References: <20250813-james-brbe-test-v1-0-76a0144b73fb@linaro.org> In-Reply-To: <20250813-james-brbe-test-v1-0-76a0144b73fb@linaro.org> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Anshuman Khandual , Mark Rutland , "Rob Herring (Arm)" , Adam Young , Will Deacon , German Gomez Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 BRBE emits IRQ and ERET branches for branching and returning from trapped instructions. Add a test that loops on a trapped instruction (MRS - Read special register) for this. Extend the expected 'any_call' branches to include FAULT_DATA and FAULT_INST as these are emitted by BRBE. Co-developed-by: German Gomez Signed-off-by: German Gomez Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/test_brstack.sh | 26 +++++++++++++++++++++++++- tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 ++ tools/perf/tests/workloads/traploop.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 85142dfb3e01..8921846b3f36 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -152,6 +152,7 @@ static struct test_workload *workloads[] =3D { &workload__brstack, &workload__datasym, &workload__landlock, + &workload__traploop, }; =20 #define workloads__for_each(workload) \ diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shel= l/test_brstack.sh index 252d22d39c7b..85233d435be6 100755 --- a/tools/perf/tests/shell/test_brstack.sh +++ b/tools/perf/tests/shell/test_brstack.sh @@ -34,6 +34,10 @@ trap_cleanup() { } trap trap_cleanup EXIT TERM INT =20 +is_arm64() { + [ "$(uname -m)" =3D "aarch64" ]; +} + check_branches() { if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$1"; then echo "Branches missing $1" @@ -76,9 +80,24 @@ test_user_branches() { err=3D1 fi # some branch types are still not being tested: - # IND COND_CALL COND_RET SYSRET IRQ SERROR NO_TX + # IND COND_CALL COND_RET SYSRET SERROR NO_TX } =20 +test_trap_eret_branches() { + echo "Testing trap & eret branches" + if ! is_arm64; then + echo "skip: not arm64" + else + perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u,k -- \ + perf test -w traploop 1000 + perf script -i $TMPDIR/perf.data --fields brstacksym | \ + tr ' ' '\n' > $TMPDIR/perf.script + + # BRBINF.TYPE =3D=3D TRAP are mapped to PERF_BR_IRQ by the BRBE driver + check_branches "^trap_bench\+[^ ]+/[^ ]/IRQ/" + check_branches "^[^ ]+/trap_bench\+[^ ]+/ERET/" + fi +} =20 test_kernel_branches() { echo "Testing that k option only includes kernel source addresses" @@ -162,9 +181,14 @@ set -e test_user_branches test_syscall test_kernel_branches +test_trap_eret_branches =20 any_call=3D"CALL|IND_CALL|COND_CALL|SYSCALL|IRQ" =20 +if is_arm64; then + any_call=3D"$any_call|FAULT_DATA|FAULT_INST" +fi + test_filter "any_call" "$any_call" test_filter "call" "CALL|SYSCALL" test_filter "cond" "COND" diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 97e62db8764a..cf3a14a95b67 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -239,6 +239,7 @@ DECLARE_WORKLOAD(sqrtloop); DECLARE_WORKLOAD(brstack); DECLARE_WORKLOAD(datasym); DECLARE_WORKLOAD(landlock); +DECLARE_WORKLOAD(traploop); =20 extern const char *dso_to_test; extern const char *test_objdump_path; diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/= Build index 5af17206f04d..fb1012cc4fc3 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -7,8 +7,10 @@ perf-test-y +=3D sqrtloop.o perf-test-y +=3D brstack.o perf-test-y +=3D datasym.o perf-test-y +=3D landlock.o +perf-test-y +=3D traploop.o =20 CFLAGS_sqrtloop.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_leafloop.o =3D -g -O0 -fno-inline -fno-omit-frame-pointer -= U_FORTIFY_SOURCE CFLAGS_brstack.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_datasym.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_traploop.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE diff --git a/tools/perf/tests/workloads/traploop.c b/tools/perf/tests/workl= oads/traploop.c new file mode 100644 index 000000000000..68dec399a735 --- /dev/null +++ b/tools/perf/tests/workloads/traploop.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include "../tests.h" + +#define BENCH_RUNS 999999 + +#ifdef __aarch64__ +static void trap_bench(void) +{ + unsigned long val; + + asm("mrs %0, ID_AA64ISAR0_EL1" : "=3Dr" (val)); /* TRAP + ERET */ +} +#else +static void trap_bench(void) { } +#endif + +static int traploop(int argc, const char **argv) +{ + int num_loops =3D BENCH_RUNS; + + if (argc > 0) + num_loops =3D atoi(argv[0]); + + for (int i =3D 0; i < num_loops; i++) + trap_bench(); + + return 0; +} + +DEFINE_WORKLOAD(traploop); --=20 2.34.1