From patchwork Thu Sep 12 15:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13802297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13509EED615 for ; Thu, 12 Sep 2024 15:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MnGEReYZbV5wa8QJ65oYyeLT0QeGyCwvGtl5g2ahPgo=; b=K2NmJUOCXJHmQM5TCi1UbS72ry BxZwQJLtNLTNKNc2UrqLIMQzKt55Hs0KPED/81U+BIe/2DNbEoOrmtS68ekhQoFbbcV4Tj3FLvinM ysuQmIbYvBJjImB9nZD/6TK6qUitWW+uaQLaUeizl5Ml+yRn2MwA+On7R7x6bizjIRL/k+kRVj7nf vGKgbuSWRGq6ZCwd9jPCeSGSY4iNvUX28DzH3e0J822LKiE3oqf6H2JVdP4FKfkHYDnWqbnCvfyi4 58EJ9b+o67pvgZWmB/0mtJbyBRtn5FTbtAmwkXMB6dpkJWR17jhI2AyVpf7HzkwJEnLfE/7P7HoF2 b0ZuJBtA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg4-0000000DXqd-3OUf; Thu, 12 Sep 2024 15:24:12 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1solVN-0000000DVP5-1kgz for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:13:11 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42cb1e623d1so10474625e9.0 for ; Thu, 12 Sep 2024 08:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153988; x=1726758788; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MnGEReYZbV5wa8QJ65oYyeLT0QeGyCwvGtl5g2ahPgo=; b=meb050SwIZcnvv7n2bXhaUh/AzbS+5sSI5806JQTKcCpt2L+QZbsBygJkH1Phil9vg FrYMZqUs1xrTfVeoG+z7lZLDMM3bkwiY20pWTfvZNKpuxbmVqN6EIjx/eZI0FgvgeGdW IJM+/22hQJtxzZ1S3Kbrvkvn3SAOVOTupwW6A2eiSOR5KGDd7QUWE4DIh6V8ESPNqKzG XYKUGmVApvHhGxkM9EaYmACmpPP0+XlCAn3iAJ+Gom11crPyr/xh6k3r6vdtqxyVwqQa j8kdgAjA56F2Z9kGrzrvy9MD2BoYKC9Wgry/8SFiUjcUcA8nuoSZjXWBltysnlB1/Mnd KVsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153988; x=1726758788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MnGEReYZbV5wa8QJ65oYyeLT0QeGyCwvGtl5g2ahPgo=; b=KepMdSnM9FxLSV3udt4qdp5BrsFpr/53Hh5/yZA59H51vbHblpz35W2VDyxJV9S8+i +uv3GKaHfWtzxLA65j2hAGjb/3mcUUqnP5ZS/ZJ4gTkstyVee5lzZ8SmxlBkZxPhhT48 2IyHRWCVTdK5mve7DFLL3rzMVM+/RKcL/LplbRt0abu3PApKA/r1VI3R9sOYaGkjsj1L 11BbiWiT1wWRyoz94XEyjZh3AUkjXJ32ZjMPvZJcpysBK6Ry64RGqwybMXZ/zp3wxsto A33Wbq8xqKB/SndeXm3/ZNNnVWe4WLv6CUqaBJ3s2PNdDs6yQQQrPqkSi2ryGH1LOTLY 2UFg== X-Forwarded-Encrypted: i=1; AJvYcCX4CY5oncMRClKLemJHwpGtR9tSFFig2yM7oVCD9dvn2yycXBmGNUIAk30bWAsMjNhyo/ecPVIJzZQkGKL8BKC/@lists.infradead.org X-Gm-Message-State: AOJu0YwTPGpJVRDgy17DwENm0JedyT0btVy3g90+y4BTBiE7Zs6SK35s hU34Hmx6R3g7Hvuw41Hvjhjtq9BdM2gYyZ/4DmL0WG6v7b1guEmbY7vEpiSOn3Y= X-Google-Smtp-Source: AGHT+IGEre2u3si5izHKSVRnSaDHslzroiOmPSj+IMte3J2/T8vsKx8fqveYcxg7jVPpnaPL6vVMvQ== X-Received: by 2002:a05:600c:19c8:b0:42c:b187:bde9 with SMTP id 5b1f17b1804b1-42cdb579f3cmr26940435e9.30.1726153987871; Thu, 12 Sep 2024 08:13:07 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:13:07 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 7/7] perf test: cs-etm: Test Coresight disassembly script Date: Thu, 12 Sep 2024 16:11:38 +0100 Message-Id: <20240912151143.1264483-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912151143.1264483-1-james.clark@linaro.org> References: <20240912151143.1264483-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_081309_487868_73707290 X-CRM114-Status: GOOD ( 17.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Run a few samples through the disassembly script and check to see that at least one branch instruction is printed. Signed-off-by: James Clark --- .../tests/shell/test_arm_coresight_disasm.sh | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 tools/perf/tests/shell/test_arm_coresight_disasm.sh diff --git a/tools/perf/tests/shell/test_arm_coresight_disasm.sh b/tools/perf/tests/shell/test_arm_coresight_disasm.sh new file mode 100755 index 000000000000..6d004bf29f80 --- /dev/null +++ b/tools/perf/tests/shell/test_arm_coresight_disasm.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Check Arm CoreSight disassembly script completes without errors +# SPDX-License-Identifier: GPL-2.0 + +# The disassembly script reconstructs ranges of instructions and gives these to objdump to +# decode. objdump doesn't like ranges that go backwards, but these are a good indication +# that decoding has gone wrong either in OpenCSD, Perf or in the range reconstruction in +# the script. Test all 3 parts are working correctly by running the script. + +skip_if_no_cs_etm_event() { + perf list | grep -q 'cs_etm//' && return 0 + + # cs_etm event doesn't exist + return 2 +} + +skip_if_no_cs_etm_event || exit 2 + +# Assume an error unless we reach the very end +set -e +glb_err=1 + +perfdata_dir=$(mktemp -d /tmp/__perf_test.perf.data.XXXXX) +perfdata=${perfdata_dir}/perf.data +file=$(mktemp /tmp/temporary_file.XXXXX) + +cleanup_files() +{ + set +e + rm -rf ${perfdata_dir} + rm -f ${file} + trap - EXIT TERM INT + exit $glb_err +} + +trap cleanup_files EXIT TERM INT + +# Ranges start and end on branches, so check for some likely branch instructions +sep="\s\|\s" +branch_search="\sbl${sep}b${sep}b.ne${sep}b.eq${sep}cbz\s" + +## Test kernel ## +if [ -e /proc/kcore ]; then + echo "Testing kernel disassembly" + perf record -o ${perfdata} -e cs_etm//k --kcore -- touch $file > /dev/null 2>&1 + perf script -i ${perfdata} -s python:tools/perf/scripts/python/arm-cs-trace-disasm.py -- \ + -d --stop-sample=30 2> /dev/null > ${file} + grep -q -e ${branch_search} ${file} + echo "Found kernel branches" +else + # kcore is required for correct kernel decode due to runtime code patching + echo "No kcore, skipping kernel test" +fi + +## Test user ## +echo "Testing userspace disassembly" +perf record -o ${perfdata} -e cs_etm//u -- touch $file > /dev/null 2>&1 +perf script -i ${perfdata} -s python:tools/perf/scripts/python/arm-cs-trace-disasm.py -- \ + -d --stop-sample=30 2> /dev/null > ${file} +grep -q -e ${branch_search} ${file} +echo "Found userspace branches" + +glb_err=0