From patchwork Mon Sep 16 13:57: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: 13805533 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 7F85DC3ABA2 for ; Mon, 16 Sep 2024 14:07: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=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=xjJliRBTpqHpLUebovQMwDuwrA KoX6Eh7UiBMG+IUx1hUkGvPLGRugIycrX2kKi89ybH3qqq+NdQ2trJpNrtBd1g70N7Q70kPJDemmJ cAa4aawqqKv8BgaGbspxvlLXAW3RxBeFl6rhDzncVCt2jY0+8KmYfqbZzMFlYrJr/R3ZgJR5BE0V9 PrB5988/OxL5YspRmEo9P9J5ZLGQoaxPt9SY7RIMVW0xlyA5sNPn5KtPYdfAzhs+IACubH3dhSuO8 p8FFvYFgxNDaLhmt/I6j56+UbCEcICwcVqShyufvDwZt0+obEe0EDutY4OHJ7lCgr34PPkgpMEphW LTnEHjeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCNl-000000049js-1DUK; Mon, 16 Sep 2024 14:07:13 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFr-000000047ji-3QDM for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:59:06 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42cbbb1727eso37040315e9.2 for ; Mon, 16 Sep 2024 06:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495142; x=1727099942; 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=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=Dz8KFnSI/qge2ROGuIsaxjSfBXy0f0eS6RmMrW3qHDVLp8HooP4T9sr8rU74vGQAqh A3VAuY1JVAo70N06P61fAfzbtHpY5MoJmQ7E/7PD3bTWMdAnxsUE+LViWoDxzIzKL7jk 1tH/k/LagmTghefd6JoIbLnnH8bKIze7K5IrjlL4TDk/q+0ZBEVvE/2afTLG3dFCTAca 6xrILqdVCoJtTB/9Fks36emAATPVhZCTci8sLeU+cXF713ZVzADwL0IuzuH4AHPgvOz4 QgnRGFZgirV8Yrpx72XVpsdzPxF64KxWTa9qYzuzsiPuVHckb9in1IqaO9M/ROs1/6Lo K9SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495142; x=1727099942; 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=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=B8DFh8aRNqTogbHWkmNbLqtMQRCoG/E2xom34H0v6jBe3sRboqFDMIsf7uR9KMNKn/ htxKbeF/teFRD9RB6kp77VDOAejAoUB76Xb7K6oac/+vgX8cGbZsANwGEXQKJKIRxauD OndxyV5EgTsq87oW2Og0l7hFCaPeG+nTjPIGpYwz80hC0yXOkm1pHQbKu+ZKWrK7GDc3 78XRKFGflME+JHICCdwOShru+FlAsHs+JTK8OBRQwqtTDhxFTE9u3oYKU++JzGneIPhJ 0fhyuVcYRPDUHg44d8B+W6IGc027MM4QPpXYMv8dr2/NIA2fiNp+LGKxW68QCbKVDlJl bnvA== X-Forwarded-Encrypted: i=1; AJvYcCUCdLC8AJYogyCk4ndWsmSp/Rknx3lJUQh4oJna8xrfKyFdcftZimvO3jdVoy4sedBnQW0Rwgb1Wbi1cJwecJie@lists.infradead.org X-Gm-Message-State: AOJu0YxljinROw3jd9hBNjY3ii6cEV7aJsTqsY0z0LZCxjH9sZpME9Td /fFTOM/hFUZ3/45zwiTlosvxUmOKvLNTtigkZV1UNdrzBH780HN+8VcjnyvuRCk= X-Google-Smtp-Source: AGHT+IFfOYzBBBIIYNJK+kjCt+IJF25ig0AQEKRujrUPMLsjU/dSM9qgZ9BqDjeZ87bsAcUXX6zC2g== X-Received: by 2002:a05:600c:1d23:b0:428:eb6:2e73 with SMTP id 5b1f17b1804b1-42cdb58db62mr120870925e9.29.1726495141678; Mon, 16 Sep 2024 06:59:01 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:59:01 -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 v3 7/7] perf test: cs-etm: Test Coresight disassembly script Date: Mon, 16 Sep 2024 14:57:38 +0100 Message-Id: <20240916135743.1490403-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-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-20240916_065903_894726_BF8C1055 X-CRM114-Status: GOOD ( 17.25 ) 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 Reviewed-by: Leo Yan --- .../tests/shell/test_arm_coresight_disasm.sh | 65 +++++++++++++++++++ 1 file changed, 65 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..af63e3757cb0 --- /dev/null +++ b/tools/perf/tests/shell/test_arm_coresight_disasm.sh @@ -0,0 +1,65 @@ +#!/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) +# Relative path works whether it's installed or running from repo +script_path=$(dirname "$0")/../../scripts/python/arm-cs-trace-disasm.py + +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:${script_path} -- \ + -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:${script_path} -- \ + -d --stop-sample=30 2> /dev/null > ${file} +grep -q -e ${branch_search} ${file} +echo "Found userspace branches" + +glb_err=0