From patchwork Thu Sep 5 10:50:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792151 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 50944CD5BA8 for ; Thu, 5 Sep 2024 10:54: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=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=VeNpOayS9d6u7S3cfYsswbZnhR +xlyiuqcUTLRofOqwRWniv2aZoOxtriZ5u8rzq9SuI4qKIeGUspXRsreNaHs+BzFmK/ALXdeeHs8s AbuTQssv7RZcJcXUhPmd/yAjscLm4WwCcvvQb6ynNlQqu+iidAPAYL2RExD7vo3fI0ujIrsAnh1p9 V4Gef9/QiG75jjzujriIHe/b0fXJLzCe6WTm4viwjy2dXvesBB/jS3xPI8Pl1f/OEDWOSKNNvd6kj tx2YkidWLQP4MyzprRIUtYqXxwREo+ApqLD5s1pByA7RIoq2gQ9wR+lBRMwBwh8MC3Oj1a5lfHPyw aIVXz5ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA7w-0000000829c-2vCR; Thu, 05 Sep 2024 10:54:12 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA4w-000000081Kv-4AA3 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:10 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42c7b5b2d01so6113325e9.3 for ; Thu, 05 Sep 2024 03:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533465; x=1726138265; 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=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=kg5Wl7lSJOk1jkmf/wT47+rzRCzTCNqSzN2BGW5LoN2AuknDoJ23zQGZ4c3MEn5Jyl Wdm5v9DjTlMQAz7S76hORvxajRtaQ/qMJQFp+sxUZ98XDoAADs+jVB+HIhiLxahp/w4W 3E7aM+5pJYeBjeXtPLsMq3cpC+qi7yWxz9HMwaZrb12VOnJLYWXb2+Izsy3pyGPHUpdZ pyqx4afthK+Dwv2999ikKo9HprJO0ays6G++Gzlf6NKVhtKp/crGOSI9CT4jJ7mEzURx fCP4JZe/uuU46kZD1PlDDaxeOJqsIebbkE1iAbitRdJtrygVP7zMIOXRziSK0TNu5kH0 OtVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533465; x=1726138265; 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=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=i0AzECpzaQh4ctEuMZ6qhuxxG/h762k+/7jUlKmlqMZ0yqWRmMSTZ/gnULldcFVLvE yJvV3XzHsmgy+BalfqHCZYDhBbg1QiPVd5KlXpvRbOIvaIi3oUwH73cPPwpieBxWA0zR LM+UjQ/MYf3UhKTBwulOccgdZdi/vN8xBoNvfsmH2EPoiWdNse+Dh6DzpBVZWpMvjw+V p2Z3s42ArJ6QmREdpisLwjGQznk/UsI7EStC4h2cH0cEmGAR+7oXSE5dUNdIatx1Bt9X I3AFaKVaLupGrjc5Hrxk1tJJw18uToPn02bgLKCmYDQ/2Yh84VKMobwpDuc0OCachoy+ 29SQ== X-Forwarded-Encrypted: i=1; AJvYcCUVBZXpbScSSeckBotFBNl3pBd+5uawxQchgariHJofHsMFoAhJgqE7LM7aE3D+BuIV1Zb2dPVZ4XIfhmGzXgAe@lists.infradead.org X-Gm-Message-State: AOJu0Yz+y7ticcvm6RYfjNGVCdlXqe7TB6rcirfpND1jnQMTlQbXEJJv 2Pvrhys2z46CBl2J8Rk15xlUhjKfyy8/k7vTHtyEHZ3SMcysHAUqM2BAVOgv87M= X-Google-Smtp-Source: AGHT+IEvKTt/6e8xWeLQPHZ+Y88gea0Wee1acuIi7mFkLMpU6DekcEkaro14JQNPOmXmgU7w0uaIgg== X-Received: by 2002:a05:600c:1c8a:b0:426:59d3:8cae with SMTP id 5b1f17b1804b1-42c9a365902mr18084165e9.13.1725533464564; Thu, 05 Sep 2024 03:51:04 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:04 -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 1/8] perf cs-etm: Don't flush when packet_queue fills up Date: Thu, 5 Sep 2024 11:50:32 +0100 Message-Id: <20240905105043.160225-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035107_058468_758550CD X-CRM114-Status: GOOD ( 16.86 ) 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 cs_etm__flush(), like cs_etm__sample() is an operation that generates a sample and then swaps the current with the previous packet. Calling flush after processing the queues results in two swaps which corrupts the next sample. Therefore it wasn't appropriate to call flush here so remove it. Flushing is still done on a discontinuity to explicitly clear the last branch buffer, but when the packet_queue fills up before reaching a timestamp, that's not a discontinuity and the call to cs_etm__process_traceid_queue() already generated samples and drained the buffers correctly. This is visible by looking for a branch that has the same target as the previous branch and the following source is before the address of the last target, which is impossible as execution would have had to have gone backwards: ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94 (packet_queue fills here before a timestamp, resulting in a flush and branch target ffff80008011cadc is duplicated.) ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff80008011cadc update_sg_lb_stats+0x94 ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34 After removing the flush the correct branch target is used for the second sample, and ffff8000801117c4 is no longer before the previous address: ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94 ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff8000801117a0 cpu_util+0x0 ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34 Fixes: 21fe8dc1191a ("perf cs-etm: Add support for CPU-wide trace scenarios") Reported-by: Ganapatrao Kulkarni Closes: https://lore.kernel.org/all/20240719092619.274730-1-gankulkarni@os.amperecomputing.com/ Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 90f32f327b9b..602e791ff5ba 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2490,12 +2490,6 @@ static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq) /* Ignore return value */ cs_etm__process_traceid_queue(etmq, tidq); - - /* - * Generate an instruction sample with the remaining - * branchstack entries. - */ - cs_etm__flush(etmq, tidq); } } From patchwork Thu Sep 5 10:50:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792152 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 AA789CD5BA8 for ; Thu, 5 Sep 2024 10:55:19 +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=Pve9lnNvOpeZGUhzPh1pcaBloPgbua89KV6dx7HbhcI=; b=uO37RxN7wuDzGQMuC0MUSAvzjU lPJ4qCJvPudhoALcIftQY8fQklA9QQDHYjOnJeKYBXpmKobtPDQrD8aKJhw+YLpJFZ9BntyuTZgEe +iu/oeruzZ6oOHRYaCiBKhIwHdqPlRemRywp+dTp/LAmpyt7khXTP/exKD+nTpq3X/ed/PMBR7Zzz 0dVJ3xGcVoSGxQKnIFrNyOrK5WwvnZSgRQEcpizufcBRMbuf5MseHtgLvf+xVQbZ9xWpIBtccyVvg 61VPaa+c23EqpmOX+kKMWoVDy9Jnjw5bMzW8f6efoGOdiyjqxkrXFyKrzDm/iekU+g2MLxicWVQAU opXY6PSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA8s-000000082Gn-060s; Thu, 05 Sep 2024 10:55:10 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA52-000000081Mw-1Vxd for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:15 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-428e0d18666so4674955e9.3 for ; Thu, 05 Sep 2024 03:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533471; x=1726138271; 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=Pve9lnNvOpeZGUhzPh1pcaBloPgbua89KV6dx7HbhcI=; b=h1YnEIUZCSojEP/pUY3MJDE10xqoNUAXf6AL1pCQUwcNk+7RQtwn9EeoyC6fB8mJ/V oaaRFr7F5kebRWzf9rmQ5kOMCLyk2W968N0LRmUBhiT2QaKXS9HjqFLrhAnqdaDxkM6/ /PJ9tNn2tYBJ59lYNo+Ppbb+QBCx4hTzyunpH8EDEIlzPTPboblJi/BPlypfMyNH5x65 UPbnF3i0aNOR7K7fD+RDQdY199veS/RsV8NSFvGnbPOOA+TKGoSiflgizAi0ziYcBE4a J//wlB9j1PU1ItbDCGWHXOhoof02+z50stbVXKBXtsFZXvMHEZDdLp8PJLAXMyCe8vYn veJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533471; x=1726138271; 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=Pve9lnNvOpeZGUhzPh1pcaBloPgbua89KV6dx7HbhcI=; b=eoU1M64qm7BZMCSMA92OoXJ4zqLen123weEsZL3dLQI7EsHOWvsddQhbAXtxR29pJY OK3U3Q6FZTqbMxFRTlqQUC0T1/LW78c2w2OpUb9JgDMxMWuHiogroXmXzQdRdw/JXY4G lEOOBSOKsmhi/CljJIkFLT+siLATzlb/ZrrlWO0s6pH0v6T+812IGzNugyf5ppb51opM wjNz7rGYk/V9NHPe0/k32LVCxMAh7jLu8EhaR2N8DhKUgHScNu7X8cfHLkIkOTbG1f9Z s5dd/itMVKmQTZR31QdKz1QMUdJq0KjGVl5OC0FA2HF2xoCZqzXKp+JXUHfX3Af3KmZZ sMSA== X-Forwarded-Encrypted: i=1; AJvYcCU3PNgFvzc2Xusqsgx3gmgmDL/wNx0p7uslAqnEEFa5+T7XVsuvf8LUHTbmCuPV8EKMfalY5a3jDTQbwjDILePb@lists.infradead.org X-Gm-Message-State: AOJu0Yx85/3+YZII+zdJI+xUAPyGDGT33KuL7NcDigFQz1aj5fYsqd4j vW3w4GqW+2PQh0xuuXyP8k3GYXynSthEGQZAsO08sqnGG7/I035xnxM8yDswcFA= X-Google-Smtp-Source: AGHT+IGNR6IhhEwS/jgcksvn9DO/af4hIbBkDS8ADbe7BTQ8BnykRnU/aKDonHdKsUgmQWK1V7Lc5w== X-Received: by 2002:a05:600c:34c3:b0:426:5fe1:ec7a with SMTP id 5b1f17b1804b1-42bbb440201mr138466235e9.31.1725533470807; Thu, 05 Sep 2024 03:51:10 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:10 -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 2/8] perf cs-etm: Use new OpenCSD consistency checks Date: Thu, 5 Sep 2024 11:50:33 +0100 Message-Id: <20240905105043.160225-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035112_428422_1C1F585E X-CRM114-Status: GOOD ( 13.53 ) 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 Previously when the incorrect binary was used for decode, Perf would silently continue to generate incorrect samples. With OpenCSD 1.5.4 we can enable consistency checks that do a best effort to detect a mismatch in the image. When one is detected a warning is printed and sample generation stops until the trace resynchronizes with a good part of the image. Reported-by: Ganapatrao Kulkarni Closes: https://lore.kernel.org/all/20240719092619.274730-1-gankulkarni@os.amperecomputing.com/ Signed-off-by: James Clark --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index b78ef0262135..b85a8837bddc 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -685,9 +685,14 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, } if (d_params->operation == CS_ETM_OPERATION_DECODE) { + int decode_flags = OCSD_CREATE_FLG_FULL_DECODER; +#ifdef OCSD_OPFLG_N_UNCOND_DIR_BR_CHK + decode_flags |= OCSD_OPFLG_N_UNCOND_DIR_BR_CHK | OCSD_OPFLG_CHK_RANGE_CONTINUE | + ETM4_OPFLG_PKTDEC_AA64_OPCODE_CHK; +#endif if (ocsd_dt_create_decoder(decoder->dcd_tree, decoder->decoder_name, - OCSD_CREATE_FLG_FULL_DECODER, + decode_flags, trace_config, &csid)) return -1; From patchwork Thu Sep 5 10:50:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792153 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 15C78CD5BA8 for ; Thu, 5 Sep 2024 10:56:35 +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=LVd4bq0YTjw4v+0IMoc3Cm2fVjGVCOS4YTrWYkTu6OE=; b=vPtY8p1P1XQ/M1LCkynz0GHdES WwJRox6Ycl0/hgFptlDSFr5c7vahWh7vo92/dtpXcSNOYTKO1wPAIUZxwVcfmtWzGkzSL3oRv7e8X +2iQ1Nb8MkkBuGwH64u4GducFY9SggZUk/9KPCAmEvxJlfrysbBEnfJOnvE3TfyVnc+6rVK+XsvY6 Ag49n6bDe1KNkrEPmvCxsEyN6llnNm3bYbNu1/YXx7l9IuPAh4NFN979YsD7+rOC0uWVVHflotqv+ giRAunrG61+3qKvhJBHTCESxTKVcVAV+1TmgrsvSsdKHrALf6pC2FKjdalCfChzdR0wPXa6TkQBhK zrhUmoMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA9w-000000082aI-2sfZ; Thu, 05 Sep 2024 10:56:19 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA58-000000081Oc-3g7x for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:23 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42bbe908380so4960105e9.2 for ; Thu, 05 Sep 2024 03:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533477; x=1726138277; 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=LVd4bq0YTjw4v+0IMoc3Cm2fVjGVCOS4YTrWYkTu6OE=; b=yOKahyjLU7ca8HrAEoumGxtkp2ZZv4TeFnkW8bvv/Hmm/b1iUuyqygYUEeGsLIVzsE 2Fm3M6Cx5S/F6jON1kO5j4v/yUS2ummqdGglaj/YJUVcki1sQTl6NIK7ilVMJc6qTbgj 5AqJau54TOYgqmQNK/pjltWXbsDMrwOe60AlWt6he3sR9llINe3+sQP761mFbcrstWTy 1FXpBPI1/VYuPrOTjmazISgu7FP1LBk+Gs+y+6ELDQWLFPtEAehy4fGF5yWZkB1gfuq6 QeKo9ypN1D4+4XS1DA8DuQlH4zPsljLRi2qraW3soCG+CHVtRlehVsNWTeCzJW7k+qfd bVGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533477; x=1726138277; 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=LVd4bq0YTjw4v+0IMoc3Cm2fVjGVCOS4YTrWYkTu6OE=; b=ZnJOpzboFXgsxq7PJmoeT5ufrOOnENt4ixSFNtAysrIN1SB0y7bxLxvg39FJzPaFnU a5EzGRs6gn8Yg10QxYgNNYYhZ8Ej5JeN0rpwBH04ThclBLAYqWBPLj9mbvB1FaSH3LRk 0pU6VBG21wvRwwPmcmR5uI3ul60xqELE7PX9l9JWjd7yn6UsPseNGwaLi5y9MBV3g83C 5IKQJEPxIOPlP1QdtT8X/6ALEJCJAxhpBEIHEXra0WL4EYS7RkRN787itq07dz4NpkwE Yhkt8ydg18eNCsm9ocv8DINOxzgW22l2zHAuk3E0o2Qi9TqRGlfM+vSHLM10C39r1xCq v45w== X-Forwarded-Encrypted: i=1; AJvYcCWQnK2tC+WOf0Ql83EGjQttDAc4kAmIofBzf+5ItTNclmMEQJ8+Na+sb1eiTZxYF8M/eXS0hDjoYSa04BzNivS6@lists.infradead.org X-Gm-Message-State: AOJu0YwwtLWFD2DFwWgUwUR/TeWF6p/CM/cCu5NhtzMh8XFQli+WkdrC TxZU5Q+UANZ582gjpzxKRkGMFuPIbv1iy+aI3FdcphupU4ww/0O03oW9S07ntA4= X-Google-Smtp-Source: AGHT+IHLKD1lksVjuCFdRAy71VLeSYs/LO7EW6oQprwBpHDtYZTrW3t9QhBgsgUf6sAqeRl0YMfHGA== X-Received: by 2002:a05:600c:3584:b0:42b:afd8:7568 with SMTP id 5b1f17b1804b1-42bdc64e498mr125056915e9.23.1725533477165; Thu, 05 Sep 2024 03:51:17 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:16 -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 3/8] perf cs-etm: Remove cs_etm__flush() Date: Thu, 5 Sep 2024 11:50:34 +0100 Message-Id: <20240905105043.160225-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035118_923724_DFD3DBF2 X-CRM114-Status: GOOD ( 20.92 ) 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 This is only called on a discontinuity, and it generates a normal sample and then clears the branch buffer. I'm not convinced that any of the subtle differences between cs_etm__flush() and cs_etm__sample() weren't actual bugs or potential sources of them. Replace it with a call to the existing sample function and then a clear of the branch buffer. One obvious difference is that it now generates a range of instructions based on instructions_sample_period, rather than only a single instruction sample. I think this is actually the correct thing to do. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 62 ++++------------------------------------ 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 602e791ff5ba..cdda8403af2b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1908,60 +1908,6 @@ static int cs_etm__exception(struct cs_etm_traceid_queue *tidq) return 0; } -static int cs_etm__flush(struct cs_etm_queue *etmq, - struct cs_etm_traceid_queue *tidq) -{ - int err = 0; - struct cs_etm_auxtrace *etm = etmq->etm; - - /* Handle start tracing packet */ - if (tidq->prev_packet->sample_type == CS_ETM_EMPTY) - goto swap_packet; - - if (etmq->etm->synth_opts.last_branch && - etmq->etm->synth_opts.instructions && - tidq->prev_packet->sample_type == CS_ETM_RANGE) { - u64 addr; - - /* Prepare last branches for instruction sample */ - cs_etm__copy_last_branch_rb(etmq, tidq); - - /* - * Generate a last branch event for the branches left in the - * circular buffer at the end of the trace. - * - * Use the address of the end of the last reported execution - * range - */ - addr = cs_etm__last_executed_instr(tidq->prev_packet); - - err = cs_etm__synth_instruction_sample( - etmq, tidq, addr, - tidq->period_instructions); - if (err) - return err; - - tidq->period_instructions = 0; - - } - - if (etm->synth_opts.branches && - tidq->prev_packet->sample_type == CS_ETM_RANGE) { - err = cs_etm__synth_branch_sample(etmq, tidq); - if (err) - return err; - } - -swap_packet: - cs_etm__packet_swap(etm, tidq); - - /* Reset last branches after flush the trace */ - if (etm->synth_opts.last_branch) - cs_etm__reset_last_branch_rb(tidq); - - return err; -} - static int cs_etm__end_block(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq) { @@ -2457,10 +2403,12 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq, break; case CS_ETM_DISCONTINUITY: /* - * Discontinuity in trace, flush - * previous branch stack + * Discontinuity in trace, generate a sample then + * clear the branch stack. */ - cs_etm__flush(etmq, tidq); + cs_etm__sample(etmq, tidq); + if (etmq->etm->synth_opts.last_branch) + cs_etm__reset_last_branch_rb(tidq); break; case CS_ETM_EMPTY: /* From patchwork Thu Sep 5 10:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792154 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 129BCCD5BA9 for ; Thu, 5 Sep 2024 10:57:26 +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=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=lYfiCJsSv3gXTfpU8JIawVQNlE 2NRaOQR5fpZvsjK3jYQTbS8lsHLIj/HASPVHA9kp6WZ7cG/OR/M9ytM5Wu1PAHBMeEV+I+W2aiJEv tsKb1n8aeq0tjv8l7V5HyTNppYLG7SHzEfc+Az8GtZ6YorAfrvFNeQ/jtYHgUBm3D4grTWUxvzjBq Oa9PawtVpqc/HE0UN1yEJuF8isbb6hH9040S0pMS3n1oytEr2Ztr3ZIZMZ2g29VtUYh6l1LFrlZKY 5j2RhRcL+HVq/HjA+c1X7lDbsrGnMW99csG+YdJKCDxH7lkmQ1UWiEieaN+EvwZCF1ubOpz886879 jOZhKQmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smAAu-000000082qp-43J1; Thu, 05 Sep 2024 10:57:16 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA5F-000000081RE-13Jx for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:29 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42bc19e94bdso4673675e9.3 for ; Thu, 05 Sep 2024 03:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533483; x=1726138283; 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=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=cMPX2M/PkOQl2n0Ozp6EnzXdmNcBQdIdKcDCvD5ULBORJzlwmIaarUcjDLTI/nLcW5 PzAeRnAZ8XKdVCDaa4kvaaqvWbb54Ve3WhDsoJalsJGRKxHRLw3UxmRdRP8txqkZYvNH 4f7DkNzO/LdJc9flDtV6cCA2R93lXt+X/IARbA099DY1Vp0GtTITjejQzrbOOO358vwr +x55lGTyxt3/AZoyHpuFb0xfEXnKN7xTd5kr9z3QGuSS7gXYjYiUqH2a6rloe3hqcVSh jeBZSkxL0aZ6wFpUkqX0AFgXc3mlZLV0HTkA+f3qlbLK407esw0oI0jFIwruIU/fDWoV GmAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533483; x=1726138283; 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=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=EMBnqMNio5unMD31UCXPgsMcRU20xQkBWdYfYFDk2BWLfEqj+pQTC4VZ2MsZK3BLYf 5VWEoCR5Sx0lwizzkR5sF6MDoR7ttYkcbMmxZGKaLJUdri1RVTHeC0ZlLT7FRSX854j5 52H/u/TsdXsJrDExYyC+K1A8vTdTbvyERqiB6en2IeXBfPk/UFe0HIjVtqwYsni5KZe0 /vOnsOtrnqDmsWYhfn1N1BlNjAOIgSp8/w+NkHpwWoG5sFbKrO1jni9zhlnRQpcQyA5Q M6SSxn8EI9zmsqqHP9Zbjzj8TWVq85dbIyA8qUkvpid+EnvDBX56oT7IqnWhwxls0z/e EzCg== X-Forwarded-Encrypted: i=1; AJvYcCXmWRs/5u4QcnTvFb4U/0bYX2189q75Y0xKBzwVcPLUYlUV2sIpeCAckbnrxXOLS66rp2SrjeTuMqX2JNDRWtAL@lists.infradead.org X-Gm-Message-State: AOJu0YzFKTtMhdjQ1tOjN2Yc9fFjUAVTuVYENgYEX0ghkk4d8LPA4l9e w04vT1SLj8PmvPkEtuTRDjjdYO22X7Dqa0eCy2xx+RsOUPG/TRgk80KIcQqsSfo= X-Google-Smtp-Source: AGHT+IEL1yvO9/AmK9ifjqYg7iMQs4H/ox7GyqpcdtMyB1K5iTwls0MsnKmwOXtbuu/kXAMOTl2r5Q== X-Received: by 2002:a05:600c:241:b0:427:9a8f:9717 with SMTP id 5b1f17b1804b1-42c8e41bef0mr47718195e9.0.1725533483317; Thu, 05 Sep 2024 03:51:23 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:22 -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 4/8] perf scripting python: Add function to get a config value Date: Thu, 5 Sep 2024 11:50:35 +0100 Message-Id: <20240905105043.160225-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035125_296049_E3A68D0E X-CRM114-Status: GOOD ( 19.44 ) 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 This can be used to get config values like which objdump Perf uses for disassembly. Signed-off-by: James Clark --- .../perf/Documentation/perf-script-python.txt | 2 +- .../scripts/python/Perf-Trace-Util/Context.c | 11 ++++++++++ tools/perf/util/config.c | 22 +++++++++++++++++++ tools/perf/util/config.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt index 13e37e9385ee..27a1cac6fe76 100644 --- a/tools/perf/Documentation/perf-script-python.txt +++ b/tools/perf/Documentation/perf-script-python.txt @@ -624,7 +624,7 @@ as perf_trace_context.perf_script_context . perf_set_itrace_options(context, itrace_options) - set --itrace options if they have not been set already perf_sample_srcline(context) - returns source_file_name, line_number perf_sample_srccode(context) - returns source_file_name, line_number, source_line - + perf_config_get(config_name) - returns the value of the named config item, or None if unset Util.py Module ~~~~~~~~~~~~~~ diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c index 3954bd1587ce..01f54d6724a5 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -12,6 +12,7 @@ #define PY_SSIZE_T_CLEAN #include +#include "../../../util/config.h" #include "../../../util/trace-event.h" #include "../../../util/event.h" #include "../../../util/symbol.h" @@ -182,6 +183,15 @@ static PyObject *perf_sample_srccode(PyObject *obj, PyObject *args) return perf_sample_src(obj, args, true); } +static PyObject *__perf_config_get(PyObject *obj, PyObject *args) +{ + const char *config_name; + + if (!PyArg_ParseTuple(args, "s", &config_name)) + return NULL; + return Py_BuildValue("s", perf_config_get(config_name)); +} + static PyMethodDef ContextMethods[] = { #ifdef HAVE_LIBTRACEEVENT { "common_pc", perf_trace_context_common_pc, METH_VARARGS, @@ -199,6 +209,7 @@ static PyMethodDef ContextMethods[] = { METH_VARARGS, "Get source file name and line number."}, { "perf_sample_srccode", perf_sample_srccode, METH_VARARGS, "Get source file name, line number and line."}, + { "perf_config_get", __perf_config_get, METH_VARARGS, "Get perf config entry"}, { NULL, NULL, 0, NULL} }; diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 7a650de0db83..68f9407ca74b 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -912,6 +912,7 @@ void set_buildid_dir(const char *dir) struct perf_config_scan_data { const char *name; const char *fmt; + const char *value; va_list args; int ret; }; @@ -939,3 +940,24 @@ int perf_config_scan(const char *name, const char *fmt, ...) return d.ret; } + +static int perf_config_get_cb(const char *var, const char *value, void *data) +{ + struct perf_config_scan_data *d = data; + + if (!strcmp(var, d->name)) + d->value = value; + + return 0; +} + +const char *perf_config_get(const char *name) +{ + struct perf_config_scan_data d = { + .name = name, + .value = NULL, + }; + + perf_config(perf_config_get_cb, &d); + return d.value; +} diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h index 2e5e808928a5..9971313d61c1 100644 --- a/tools/perf/util/config.h +++ b/tools/perf/util/config.h @@ -30,6 +30,7 @@ typedef int (*config_fn_t)(const char *, const char *, void *); int perf_default_config(const char *, const char *, void *); int perf_config(config_fn_t fn, void *); int perf_config_scan(const char *name, const char *fmt, ...) __scanf(2, 3); +const char *perf_config_get(const char *name); int perf_config_set(struct perf_config_set *set, config_fn_t fn, void *data); int perf_config_int(int *dest, const char *, const char *); From patchwork Thu Sep 5 10:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792155 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 14409CD5BA9 for ; Thu, 5 Sep 2024 10:58:24 +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=tvd47gfary40B5CZwKU25bQw1FRFKdvBGhXDTC0MpmU=; b=CSznTAkiUYs+zo3z9diQDvfmUN IGJGfuVFq2DTPDd5RCZSSR5Xryw+XgSWi885lz26kgHPYEnQaUuDKPkiYCLBFkxTA8H98jbZHvM1p vZ/Bd218RBX0xmF7grBXjo7DKxsXFxN2Uye93yDxPyY8Hy4s8I6es5lpxIET47zXLuxInNQkWWRxD YKrB/Zsecnl3g7YeYb9FWTOLal82BwA5GFQHNmEGaFNuACK+nNwcOzkw+RxW7mHH48m2cRhztz6G3 PaieWPpOeaMT2qy1wbxBs/b6i3Wqghs/HpeI17Cm/ab+3hZyVZAWx2tNgoRTPVArir5lKzHmMNUwA 1N++46dw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smABp-00000008337-1S6A; Thu, 05 Sep 2024 10:58:13 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA5L-000000081Ty-1neq for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:35 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-428e0d184b4so4662265e9.2 for ; Thu, 05 Sep 2024 03:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533490; x=1726138290; 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=tvd47gfary40B5CZwKU25bQw1FRFKdvBGhXDTC0MpmU=; b=q6z+nkoDfmIat0QJuPJKwRUW9Pt5alELuOCh1Fu0SKYpd4zeJu751vsBhxEE64Klyu 0Tns4KAlCc7xCsHXEmxiMGBNfjJo4wuhBpeJGcLdtao1GNuIRaaOWYzzQZb09VrjYnA7 qsh8TUKrIkp/KbYc+NFYuykQKBUaeudlUiiNjnTqjECj3GER1jPoYUnUbNRuaYh51ix0 NmRDWH7ZIh9P1VxOsofbE3DQaDaYPKjPJth+V8pdlQwihHqzHq+VO9KXAJBNBWksgZix EouGu9f8Ys1RqPjCHc6StO/pWerhc6p1c6J06UoKjKJ2BOYytp1EoNPcFQ110nwY4urt MmwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533490; x=1726138290; 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=tvd47gfary40B5CZwKU25bQw1FRFKdvBGhXDTC0MpmU=; b=toWV3BMpDVaOtV+X7i5tgBU12R1mm3yoPVN+c5j7LIYhfX1tYU7T5QAFT2r52P45eE 380/VhiqUWaSqipDs1UmTHUX++i/l6xaldANrc37Y77xw5Uq4atys0EjVBvDw2DmUjV6 gh9rPVHLnC+Xc2I6D0w5mHRXDrZx9gEN+A27/i8wvw4I2JNficTiSd5p/w68EwrtnYo8 gmKL0xEcPF3piGtWu7HneGJCZPp0SY8vAhQnnbNRxMUraQXgZpI2JNjYtCUWE1lGVFO4 l2FI6yskd2+xKh2z2dr3V7RKjcUFyq7RCcOixjxA3Y/A3bIqUQ82iV0WEZOTJWc/2chD Upxw== X-Forwarded-Encrypted: i=1; AJvYcCXzXkSjQFZIj1FAGPE22LZzZursQL85SXwWGDDboLMuNK6BY49elvprd7NjJu8bG+JnrTWthPkusNelssTmuW88@lists.infradead.org X-Gm-Message-State: AOJu0Yy6xxH4L1obkghZoZBnkRLGsRr74NCapALJ9qqS+SykE4rQ1f2l faR+CgIkS+g+yCfp+ZZt34arNR4rjqEtKvAaiF1qKC247agLo+oKV7uBGSNu0HE= X-Google-Smtp-Source: AGHT+IH/+XS62yXBkrtQXdlyQqjo3Bxww5IdiYqj0rBOSr4rHkxQrx9C9Aypty2rFMzvzq+ymudjxA== X-Received: by 2002:a05:600c:4f4f:b0:426:6000:565a with SMTP id 5b1f17b1804b1-42c7b5a8ee2mr111733575e9.16.1725533489532; Thu, 05 Sep 2024 03:51:29 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:29 -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 5/8] perf scripts python cs-etm: Update to use argparse Date: Thu, 5 Sep 2024 11:50:36 +0100 Message-Id: <20240905105043.160225-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035131_568676_A0166C23 X-CRM114-Status: GOOD ( 15.01 ) 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 optparse is deprecated and less flexible than argparse so update it. Signed-off-by: James Clark --- .../scripts/python/arm-cs-trace-disasm.py | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py index 7aff02d84ffb..45f682a8b34d 100755 --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py @@ -11,7 +11,7 @@ import os from os import path import re from subprocess import * -from optparse import OptionParser, make_option +import argparse from perf_trace_context import perf_set_itrace_options, \ perf_sample_insn, perf_sample_srccode @@ -28,19 +28,11 @@ from perf_trace_context import perf_set_itrace_options, \ # perf script -s scripts/python/arm-cs-trace-disasm.py # Command line parsing. -option_list = [ - # formatting options for the bottom entry of the stack - make_option("-k", "--vmlinux", dest="vmlinux_name", - help="Set path to vmlinux file"), - make_option("-d", "--objdump", dest="objdump_name", - help="Set path to objdump executable file"), - make_option("-v", "--verbose", dest="verbose", - action="store_true", default=False, - help="Enable debugging log") -] - -parser = OptionParser(option_list=option_list) -(options, args) = parser.parse_args() +args = argparse.ArgumentParser() +args.add_argument("-k", "--vmlinux", help="Set path to vmlinux file") +args.add_argument("-d", "--objdump", help="Set path to objdump executable file"), +args.add_argument("-v", "--verbose", action="store_true", help="Enable debugging log") +options = args.parse_args() # Initialize global dicts and regular expression disasm_cache = dict() @@ -65,8 +57,8 @@ def get_offset(perf_dict, field): def get_dso_file_path(dso_name, dso_build_id): if (dso_name == "[kernel.kallsyms]" or dso_name == "vmlinux"): - if (options.vmlinux_name): - return options.vmlinux_name; + if (options.vmlinux): + return options.vmlinux; else: return dso_name @@ -92,7 +84,7 @@ def read_disam(dso_fname, dso_start, start_addr, stop_addr): else: start_addr = start_addr - dso_start; stop_addr = stop_addr - dso_start; - disasm = [ options.objdump_name, "-d", "-z", + disasm = [ options.objdump, "-d", "-z", "--start-address="+format(start_addr,"#x"), "--stop-address="+format(stop_addr,"#x") ] disasm += [ dso_fname ] @@ -256,7 +248,7 @@ def process_event(param_dict): print("Stop address 0x%x is out of range [ 0x%x .. 0x%x ] for dso %s" % (stop_addr, int(dso_start), int(dso_end), dso)) return - if (options.objdump_name != None): + if (options.objdump != None): # It doesn't need to decrease virtual memory offset for disassembly # for kernel dso and executable file dso, so in this case we set # vm_start to zero. From patchwork Thu Sep 5 10:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792156 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 E662ECD5BA9 for ; Thu, 5 Sep 2024 10:59:19 +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=1UQpIycFZTbpTomhD0ThkQ/OGwgElG8NTd5wS8H1d7Y=; b=maEBs9zm55zDoDCOOlTtkJjI0p 4Q5GF2GWI3GKelehfnoWNhteaReFduRXWuGepURRVI/2nLEO7VySvpIRAU8eW1CjlPV3tiR7AUeDm /uoX5LV84DWtSy7LnkeD3tgf6avsxoi7IWOsibU2+oErB8/FpocV3XI8XDGxVh4VOmysyvWCDlTFO TYMFLRwA3ZJA/UY+H6Y79YXrjnvYxHcaH5QDFhfawceK6C0co931xNANfNzZhQy0bgWa+5vYQdicr svKb+T6CrfWt5OxAVpohh3PrffDWz/l/BuVrx+LPj99njBbGVyEV+tsTHhr7qwkk8jCwUvHH8fhYo ARa/pJgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smACl-000000083Dn-1ccZ; Thu, 05 Sep 2024 10:59:11 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA5R-000000081VV-2Wkk for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:45 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42bbd0a40faso5434925e9.1 for ; Thu, 05 Sep 2024 03:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533496; x=1726138296; 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=1UQpIycFZTbpTomhD0ThkQ/OGwgElG8NTd5wS8H1d7Y=; b=pxQ9g31KlVm/GVciVwrx3juTZAchBIZXeQsFmBdJ/vKIRYVrUuGzEJk9gISptOzhyr KtTV61z586rzJw5WySftW5mXZgyhppQC0NbgKrbLerOctgaGRReVEbTSv1bCBWpP7fGn iL2XTbLszNfuDsH8UqzkeLHFhQjYGG/gYVWskFZQVgdnGy3yEIylEn4xLjuXjFK0mqkz NMA1E3MGrpyGLtk/sKvkb318rDUso7U2qkc//dOorGSqzMDv5Z88pMtBjmT15bDI/GHm NdBPgOhj+QYfZ/OhgsTGPjmq1sTVheyZ1XWlh8uIVgaJB0MhXtlbsbhUNyVvPHLuuyTl q0yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533496; x=1726138296; 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=1UQpIycFZTbpTomhD0ThkQ/OGwgElG8NTd5wS8H1d7Y=; b=EYaRIDILxAY2os1yJtC+n6Qht6NO0hSEYnZnOB5w37ZDJImgoev8CP65icQ6iiEcmK 0LZyJ25GOuXlrWz1Jz1Auc/3RjNLqpXbarm4yjDjtsNP1uUpbndfxL9Ap4x3kw+mrykp hak43M0IC4Ov+0I9Ya4/j5AK+3OV+PUGR8OWE54BRf83z+1MClnkAJR+ttkc/xfKdVwY jLRfMsAeDU7ex77bQ0hlzPY4SmGREO4MgPlLigYP+aGc2bTZqrHlBbd/A9fHXdWcgil+ bOWFtWliZtDRtweXJ0/C6a2HRnG5wzZqn8vAwnjCi6r6fXx8a2jyvLpaIXTcvnqVx56/ FY2g== X-Forwarded-Encrypted: i=1; AJvYcCV6pva36Xc5/lMZyswl4ovbBpJO1g9wTXGmRepy0JA7S8X2mkt2IFG5RpeZN/cJFd2NUxqJrlGH+CZBslGr2h+S@lists.infradead.org X-Gm-Message-State: AOJu0Yy+ao3PwhApUE+8+6UqWR4p69+3VcVGBhcNremLrgT1IwqU7MpO qVPvmE9AvE2Ohy1cUm/Vj+2BvqyzfDZibGtDCkThuupFhpAxQulj+xMYzaFAJ20= X-Google-Smtp-Source: AGHT+IEpfxBxgTLRhNXbNPhyw43kJddfslQaOh/lWQNdxGiZ7XJq9Wynx2djlTu5N/y0tXW9TP/TcQ== X-Received: by 2002:a5d:6b8d:0:b0:374:bf62:bc91 with SMTP id ffacd0b85a97d-374ecc8f283mr6307799f8f.25.1725533495732; Thu, 05 Sep 2024 03:51:35 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:35 -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 6/8] perf scripts python cs-etm: Improve arguments Date: Thu, 5 Sep 2024 11:50:37 +0100 Message-Id: <20240905105043.160225-7-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035137_651300_E5D6CC4B X-CRM114-Status: GOOD ( 17.46 ) 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 Make vmlinux detection automatic and use Perf's default objdump when -d is specified. This will make it easier for a test to use the script without having to provide arguments. And similarly for users. Signed-off-by: James Clark --- .../scripts/python/arm-cs-trace-disasm.py | 63 ++++++++++++++++--- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py index 45f682a8b34d..02e957d037ea 100755 --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py @@ -12,25 +12,48 @@ from os import path import re from subprocess import * import argparse +import platform -from perf_trace_context import perf_set_itrace_options, \ - perf_sample_insn, perf_sample_srccode +from perf_trace_context import perf_sample_srccode, perf_config_get # Below are some example commands for using this script. +# Note a --kcore recording is required for accurate decode +# due to the alternatives patching mechanism. However this +# script only supports reading vmlinux for disassembly dump, +# meaning that any patched instructions will appear +# as unpatched, but the instruction ranges themselves will +# be correct. In addition to this, source line info comes +# from Perf, and when using kcore there is no debug info. The +# following lists the supported features in each mode: +# +# +-----------+-----------------+------------------+------------------+ +# | Recording | Accurate decode | Source line dump | Disassembly dump | +# +-----------+-----------------+------------------+------------------+ +# | --kcore | yes | no | yes | +# | normal | no | yes | yes | +# +-----------+-----------------+------------------+------------------+ +# +# Output disassembly with objdump and auto detect vmlinux +# (when running on same machine.) +# perf script -s scripts/python/arm-cs-trace-disasm.py -d # -# Output disassembly with objdump: -# perf script -s scripts/python/arm-cs-trace-disasm.py \ -# -- -d objdump -k path/to/vmlinux # Output disassembly with llvm-objdump: # perf script -s scripts/python/arm-cs-trace-disasm.py \ # -- -d llvm-objdump-11 -k path/to/vmlinux +# # Output only source line and symbols: # perf script -s scripts/python/arm-cs-trace-disasm.py +def default_objdump(): + config = perf_config_get("annotate.objdump") + return config if config else "objdump" + # Command line parsing. args = argparse.ArgumentParser() -args.add_argument("-k", "--vmlinux", help="Set path to vmlinux file") -args.add_argument("-d", "--objdump", help="Set path to objdump executable file"), +args.add_argument("-k", "--vmlinux", + help="Set path to vmlinux file. Omit to autodetect if running on same machine") +args.add_argument("-d", "--objdump", nargs="?", const=default_objdump(), + help="Show disassembly. Can also be used to change the objdump path"), args.add_argument("-v", "--verbose", action="store_true", help="Enable debugging log") options = args.parse_args() @@ -45,6 +68,17 @@ glb_source_file_name = None glb_line_number = None glb_dso = None +kver = platform.release() +vmlinux_paths = [ + f"/usr/lib/debug/boot/vmlinux-{kver}.debug", + f"/usr/lib/debug/lib/modules/{kver}/vmlinux", + f"/lib/modules/{kver}/build/vmlinux", + f"/usr/lib/debug/boot/vmlinux-{kver}", + f"/boot/vmlinux-{kver}", + f"/boot/vmlinux", + f"vmlinux" +] + def get_optional(perf_dict, field): if field in perf_dict: return perf_dict[field] @@ -55,12 +89,25 @@ def get_offset(perf_dict, field): return "+%#x" % perf_dict[field] return "" +def find_vmlinux(): + if hasattr(find_vmlinux, "path"): + return find_vmlinux.path + + for v in vmlinux_paths: + if os.access(v, os.R_OK): + find_vmlinux.path = v + break + else: + find_vmlinux.path = None + + return find_vmlinux.path + def get_dso_file_path(dso_name, dso_build_id): if (dso_name == "[kernel.kallsyms]" or dso_name == "vmlinux"): if (options.vmlinux): return options.vmlinux; else: - return dso_name + return find_vmlinux() if find_vmlinux() else dso_name if (dso_name == "[vdso]") : append = "/vdso" From patchwork Thu Sep 5 10:50: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: 13792157 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 DCE89CD5BA9 for ; Thu, 5 Sep 2024 11:00:18 +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=lyScag8p5nZQgcpgovS0Br7oaCoB8CMogAdxSo53VSM=; b=5GQHcRgyK3UIumQ8Zryug5s4B7 LLXt0ZMIzSWfwRM+uCAUp6YqXpamRmPfKVVkiIYzEKR6t7v7ncVgxQE6RCgvYKUyl1efI2Ae4z0Dw icnrw5/bI8vqNAY3PS5UKJFM0S/uj/axRlDeWRE2si+qLqixVVprHwpQwmZCGvOxiI4V2PM14eAU9 aCm/d5OIjdNPgcJJPcHGF3KmFvfmtMQgLtsGUhTdxTNLY4xYRD8U2fzqRXYy1d02MeTa4yC4MgV/u eK4pGh0FxLNEnz1w0HzFwdk54OlMtsi2zLhKdgMQI3Y7/R/yjHhQ0bY9gMrR/81jn+tD7dAKjdTPd L+lhw2Tw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smADf-000000083MR-1OnV; Thu, 05 Sep 2024 11:00:07 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA5X-000000081WH-3d6u for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:46 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42bb81e795bso4713135e9.1 for ; Thu, 05 Sep 2024 03:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533502; x=1726138302; 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=lyScag8p5nZQgcpgovS0Br7oaCoB8CMogAdxSo53VSM=; b=hPbLLQF3Qt2eaZz6wABDq7e8ifGx9WM3fQRs5nKnRVGQ2C//Th18Mxgd2uHjuo0pqU uMCkxbQOVM/iCSwBeS5RwZO++Iddfs31B/GJfDkvKZWAqU/1PGJT0598yEf0bu03g/7o MAHskGIWNhisXAFjxAFXhf6OP/2Ln1SF2M79VlkyT9/sO24ooOpqN2CSypJlM/s4m8u5 Q+E6J3GJ/QNxzk6yqA8iyCUFbWicYIXkl9S4bq3dTsWcXkfQ8LMU8t3xyYyxLqLn1ZMh GJIK55rOMc5Ta0R5sLOO5iHGFvQJcs1RIbLFcq3sLLYoi+ut4YZOIoY9L/UiWrHCvjik DUyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533502; x=1726138302; 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=lyScag8p5nZQgcpgovS0Br7oaCoB8CMogAdxSo53VSM=; b=poVyqNWwsQYOJ7N7ugVovc53htQUoDxA5eeKQzOIaA7+LnN/ZKaerNtSOgF8l5V0UX Hfi7I/It+Yu7sz4z3VSoZjBMeAjRZWRKLBf/byoZzETaV7aBatO4j3r9vrxD6hq54LIU Qw6rW31hMzpOb7GmqagPSK382oQHOyv7PAjY9d5MfrMdVtKks3VbwRQFbStyt7TmjIT1 OzTC4hoxdqdwv/6HWBkV14Jr2euunrCA9Ed7YSeUmfYaeFVh6eDVQgCV8+TZeqaMRFoJ FHQQktPZr7uAr6lfmoloPNqBO0q/TI+l3jtqCMvbaW1qGLIe2L3W99FlnJfVTzuAjxh0 +uSQ== X-Forwarded-Encrypted: i=1; AJvYcCUhbuEDEjl3/+5PpHdWONXbZvE9Rr0+2boen0aQL+w8RhsyWnEIUjEWWNBKY0TqpvNKiZApw/f4k1x8k1pD/wsi@lists.infradead.org X-Gm-Message-State: AOJu0YwUaEu/7oH7lywrWerasWqkwN7u0+vZgIS1zIKuQZMh1jlUE44r vUQ+aHZP++XkGHTsvgectM6oidNJCF10jovfY1CA/8HCsls/un4DbueCqE6sKc4= X-Google-Smtp-Source: AGHT+IGfFJqAayaXo8MfaP4LB16SCu3PZkqeamC6wY0GLppIU48zgj0W6/Wqg+hZrLLyTod8T3h8wA== X-Received: by 2002:a05:600c:4fd6:b0:426:60d7:d299 with SMTP id 5b1f17b1804b1-42bbb10d27dmr151939485e9.7.1725533501983; Thu, 05 Sep 2024 03:51:41 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:41 -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 7/8] perf scripts python cs-etm: Add start and stop arguments Date: Thu, 5 Sep 2024 11:50:38 +0100 Message-Id: <20240905105043.160225-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035143_911315_2A349C61 X-CRM114-Status: GOOD ( 15.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 Make it possible to only disassemble a range of timestamps or sample indexes. This will be used by the test to limit the runtime, but it's also useful for users. Signed-off-by: James Clark --- .../scripts/python/arm-cs-trace-disasm.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py index 02e957d037ea..a097995d8e7b 100755 --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py @@ -55,6 +55,11 @@ args.add_argument("-k", "--vmlinux", args.add_argument("-d", "--objdump", nargs="?", const=default_objdump(), help="Show disassembly. Can also be used to change the objdump path"), args.add_argument("-v", "--verbose", action="store_true", help="Enable debugging log") +args.add_argument("--start-time", type=int, help="Time of sample to start from") +args.add_argument("--stop-time", type=int, help="Time of sample to stop at") +args.add_argument("--start-sample", type=int, help="Index of sample to start from") +args.add_argument("--stop-sample", type=int, help="Index of sample to stop at") + options = args.parse_args() # Initialize global dicts and regular expression @@ -63,6 +68,7 @@ cpu_data = dict() disasm_re = re.compile(r"^\s*([0-9a-fA-F]+):") disasm_func_re = re.compile(r"^\s*([0-9a-fA-F]+)\s.*:") cache_size = 64*1024 +sample_idx = -1 glb_source_file_name = None glb_line_number = None @@ -151,10 +157,10 @@ def print_disam(dso_fname, dso_start, start_addr, stop_addr): def print_sample(sample): print("Sample = { cpu: %04d addr: 0x%016x phys_addr: 0x%016x ip: 0x%016x " \ - "pid: %d tid: %d period: %d time: %d }" % \ + "pid: %d tid: %d period: %d time: %d index: %d}" % \ (sample['cpu'], sample['addr'], sample['phys_addr'], \ sample['ip'], sample['pid'], sample['tid'], \ - sample['period'], sample['time'])) + sample['period'], sample['time'], sample_idx)) def trace_begin(): print('ARM CoreSight Trace Data Assembler Dump') @@ -216,6 +222,7 @@ def print_srccode(comm, param_dict, sample, symbol, dso): def process_event(param_dict): global cache_size global options + global sample_idx sample = param_dict["sample"] comm = param_dict["comm"] @@ -231,6 +238,17 @@ def process_event(param_dict): ip = sample["ip"] addr = sample["addr"] + sample_idx += 1 + + if (options.start_time and sample["time"] < options.start_time): + return + if (options.stop_time and sample["time"] > options.stop_time): + exit(0) + if (options.start_sample and sample_idx < options.start_sample): + return + if (options.stop_sample and sample_idx > options.stop_sample): + exit(0) + if (options.verbose == True): print("Event type: %s" % name) print_sample(sample) From patchwork Thu Sep 5 10:50:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792158 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 D0212CD5BA9 for ; Thu, 5 Sep 2024 11:01:17 +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=zwpGOoWEbz96WcKkeDZQ+t61lH /8+/3ShUOdb+PtoDmEl14KlJott3LW/Sk/FXWp/jFJfglXGH7FbrIB2f4oX/qIL03It4e7MMRbVlF Hvv2jKkVrlkVFd+q3pHsGZi1rbPZld2rEDCmihlVTVLDpfkOok+w2KJ6UGF8pkZd0Pcq+pM43wEQX 47/pW6pGosDpfbiHX3eSYf8M9dpWzoU3s7nvv7tUcWnZiU/J8s59Ny7W3n7AlBypdTJe1me42m/Kd Ohzcvyup178foWsTol5dYbVnsnbTFrmlcUrCfHmHhM8uQ2FFSQiXrMWnLOUg78889aX8J+Ji1CtEN EwtSMFGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smAEb-000000083an-2O0V; Thu, 05 Sep 2024 11:01:05 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA5d-000000081ZR-49IJ for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:51 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42bbc70caa4so4764695e9.0 for ; Thu, 05 Sep 2024 03:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533508; x=1726138308; 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=fvW9hJ8P3l+sjXlMPNfe7S6tPcvUGccCv96bPb5EN/nciKMJE+eJ3IPHftW5xF+RNb 9FLHmU4XzDeLUCylO74NzZEcISDZVEzkagBe6ACC5GHtBAAnGymEzvdy2by/EWLEQWSz zxTbiEyx2fIBgixZhjzd9lGj3sfo/yv0Df7e18HRSeaF8SGdy6EzznVOP7RhuBK1s6LM Q7VgCTyoboxsF4HFpUhxsRlVWMRfPn1P+Uiw3qeGet0awsNXiU2yURKkEUbG3KLMPgjW ZT4rzlcEATX/mSkEbjaKEamLnCPiMAWmiuEIr3a0lMB3u4xgzdX/aNAUnw/tdFHJebx+ ogBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533508; x=1726138308; 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=Rf8VCEE/BrA/wSPqpqRBTp6fjCzrqGCJDeEToWvvZ3xeTbdO9oaK0frAEnn1zaJCPJ TYWJS0yB6515JF0LylacLx0dBWL+TBEdJNBZFynsGTpPTqGA9yHDTtVqCGC4poZjDVtB kFW/FIv9TRDb32fesUDBh09j/botMKlIk800ru/DSkGPiH+095Fdjt517Rb9iD0t299h kilEez+/mQsvI0yg0fD0Oc8FEu42ffrs9rM2D7p4WVp3NeuokS5Hl6pkzaZEoGXvJDBx KXpPxEdhfT0/D+xBM0Mo9zfkQNvkr4wQxI9XkZcKsSWg/YRoYHbFxsQn96gg0aWTWCqg EitQ== X-Forwarded-Encrypted: i=1; AJvYcCUiy/XUxPCfSZ2o0TfYJGCXs3Yazym7j70UW2pNAKv9h6EvvpGo0/nrh1DvGGyEVIV+QQT1QzynjqShwr7QylcC@lists.infradead.org X-Gm-Message-State: AOJu0Yyy2vn4xdLx4V6IyjcETQRLiYO2QjRbVVAdThv2owbl8AVXxz2V UOxMtRqAX4iIsD8eLver6RWdvmveWQHiviYwOcUL5Bl95bhcsSFPMbpzMNPVjEk= X-Google-Smtp-Source: AGHT+IFLXh3uz6cqXjbXRFB+ADKQOX2EZTgrK+sgT0hn+8Lnw3zLZAPRZF6rIycBh6dNiFzAE5OxVA== X-Received: by 2002:a05:600c:b4b:b0:42c:9999:4fb3 with SMTP id 5b1f17b1804b1-42c999952dcmr18219615e9.34.1725533508196; Thu, 05 Sep 2024 03:51:48 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:47 -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 8/8] perf test: cs-etm: Test Coresight disassembly script Date: Thu, 5 Sep 2024 11:50:39 +0100 Message-Id: <20240905105043.160225-9-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-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-20240905_035150_041223_3C671ECF X-CRM114-Status: GOOD ( 17.10 ) 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