From patchwork Thu Sep 12 15:11: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: 13802294 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 A563FEED613 for ; Thu, 12 Sep 2024 15:14:55 +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=FVBlRkBG8+Idy8ehQJVILHBn96DUefeGnB3enzkGPeQ=; b=a5sKaRfgyG4fSFpMZm+UnaTceQ 0ptNNy+q+4ANKhdUeTMpNmOsEeh978NGDS9q86FCOtS71VXa0Bx3jp14Lj1Cdg1zPjqdohBWdew8n fOt6CNW1RY0bRf6+IKNXlNsJInwlE4kPDByEKvTflkmlZ7E1MO+KV8svxoCKxSvMwStOM2eXz7pD7 rxerI7ak+2I6fNbKHzIGuH94gUk+fKgWH0KDW9ixqD19zN8kDuixNVN22Sm/PP0narxP5Pwy8D/BS 5Wycl2SqEqfB8xSkwyCnRImV6XON0ndMb78POwq/qSvcJvlcMLjUM1NB2GoSmfHodeYkF5e27w+dk 1bMIDSkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solWv-0000000DW27-1JMl; Thu, 12 Sep 2024 15:14:45 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1solUm-0000000DV4n-0UR1 for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:12:34 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso10187335e9.2 for ; Thu, 12 Sep 2024 08:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153950; x=1726758750; 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=FVBlRkBG8+Idy8ehQJVILHBn96DUefeGnB3enzkGPeQ=; b=QG5/Hcv6EWm8EXW3gMIFwuC2K02KczGwlDahOuor6Q9GJMrnlGrZMPInRrSiGyF8sb 3/BMPKdiX2UnUHlRjWU0xrExFnZVkTHBXvXWspHFwiUQKDqau8aNxs6JHS5s/5eHCYL+ mxQT35jrykvNHv88CoL/LrsbRHNsYRBg/r2gM6x1VXj2QRamG6FhdMgLuC7M89Gh1q7f cqen72pmXiQv7WNbrsEx08IcYsqIdCqU4OGjqmSLxpYlcOr5oUNgg/T/FuX2i2jBiV1O a7JCN8XF65nxzSfgOvADfY8JFnHhPh4V+i3TPBEHx4xLFtifqdHMfFBLkFlBpjNcfYIB 5+eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153950; x=1726758750; 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=FVBlRkBG8+Idy8ehQJVILHBn96DUefeGnB3enzkGPeQ=; b=qN/5+ThcDOGnbMv/oWxcqlZaX2BcKroekM0pJ4PdHzCUpAcDYTgEXZlFe3D3o3SRis 3BHSpDC2OLWBAMknY5axZ7yC7/Iq2wHZ4kOugtHCtvqxg97S4gwo3pK999BfjwVlcqrd JtdvKO8BHrZ73ccRvVRc3pN84VISEWLVfzx7Z8GxK5wJNmWXOCVeaHGGWLKP334SpTgP tGC9VTgsYxjLdzbK6zaftFMAX0v1fVuUOHOeOqU4DyCRLLSV3kVgterWAwm955blLUTO NN6np4uNBrrcJpUQppqAMy2xtxBMWexDv+cDeoDhiBAQD5ycvrPd/OQnrADngNQYOWwk l9xQ== X-Forwarded-Encrypted: i=1; AJvYcCUfQfttePyoC+XNiuNjqv0S6cCOaWScd/U4czAT4DksCrWa9weetx2cC99Zn2H8PbqCq4885UjcGMZtXYAMl67F@lists.infradead.org X-Gm-Message-State: AOJu0Yw4vE6B23IJ0xtnmSPgkXhh80jPqvGwSBpqoJ5lpu7w8ycBgWNp OuEJm1WFPD4oyNYBMDP6ARKj4/21TT+YbIN3iKX58QhahjDc9hdWQjw4lJmIXSs= X-Google-Smtp-Source: AGHT+IF+9bah/yP5A17iSIWzhHNRw1ieQewYP5DtP+X3D3ShpKM5Hg1qUBA6sanEMQfeBKZpW/0C4g== X-Received: by 2002:a05:600c:1c91:b0:42b:af52:2525 with SMTP id 5b1f17b1804b1-42cdb54dd62mr28413645e9.16.1726153949096; Thu, 12 Sep 2024 08:12:29 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12:28 -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 1/7] perf cs-etm: Don't flush when packet_queue fills up Date: Thu, 12 Sep 2024 16:11:32 +0100 Message-Id: <20240912151143.1264483-2-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_081232_262932_2B9D98F2 X-CRM114-Status: GOOD ( 23.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 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 Make sure that a final branch stack is output at the end of the trace by calling cs_etm__end_block(). This is already done for both the timeless decode paths. 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 Reviewed-by: Leo Yan --- tools/perf/util/cs-etm.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 90f32f327b9b..242788ac9625 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); } } @@ -2638,7 +2632,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm) while (1) { if (!etm->heap.heap_cnt) - goto out; + break; /* Take the entry at the top of the min heap */ cs_queue_nr = etm->heap.heap_array[0].queue_nr; @@ -2721,6 +2715,23 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm) ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); } + for (i = 0; i < etm->queues.nr_queues; i++) { + struct int_node *inode; + + etmq = etm->queues.queue_array[i].priv; + if (!etmq) + continue; + + intlist__for_each_entry(inode, etmq->traceid_queues_list) { + int idx = (int)(intptr_t)inode->priv; + + /* Flush any remaining branch stack entries */ + tidq = etmq->traceid_queues[idx]; + ret = cs_etm__end_block(etmq, tidq); + if (ret) + return ret; + } + } out: return ret; } From patchwork Thu Sep 12 15:11: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: 13802301 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 CD5FCEED613 for ; Thu, 12 Sep 2024 15:24:33 +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=zcClkrQA6flIGdP+nLkotiIGtn Apz0b1rgO0Ks1X71zWUOZP7B0EgTORxVHh2ZM3KunCjYu6w+DlG3/or7casB3Fw2V8roXPNzpau1Q 0agZ7Od3utf+z5g4E4FgrI3a4Y6ZLhborRp23KjlMqg1+HTEKbh/EaNJx6DxmrxbMkNC7bkKYNdAz ls4mzMhzKs8zO3GSN4ZwxBkxzNXOfZCfNlx5WA7j/IJOEizouFHbxO/WmqFRatew1mhiOP1x/EfSZ dp4WDwkSj5yRjGt4VwcRbl4F7cMOMnE7KnRXjYnvKsEZu1P5MYAlAIXHmEE4bgjDMWBjt2ZYSumE2 u5puB4Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg1-0000000DXpB-2oaV; Thu, 12 Sep 2024 15:24:09 +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 1solUr-0000000DV7B-1TnQ for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:12:40 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42bb7298bdeso12282885e9.1 for ; Thu, 12 Sep 2024 08:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153955; x=1726758755; 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=oeNt+266JoNGXdEZh/m0C4jx3jQ1fBvgooI5ZckWJe53ciS5mxeLv+ioz3UgOpY0X0 jT2YrXni9SMfEounYzr8vHv4tA8I8yAKWjRv6wZ5w01OebyJEtNBvjrmbAJNJ39fyq7O /H8gECjd0UlWmnUWYKdHqagfg3h09CptiE/oByzmid2Kbmtx8SZtVxHntNAOUmGxTMrs 1UIJMYlLPDccnIb3K0cojY97bJogrvU+Qo+QaSeQ0SEl1lvAhiAb5a4IOGpqVrL8DFUb /Hqq01X6nUNk/AnPkqvj02bvRjx8Wbi7OMflDpuZqmUGn4hWpLq2Qm/pbzmHKRKITZxc Otyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153956; x=1726758756; 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=ReYtRTWMYBtCbbuLcf5Bja5cRgO9o19huI2gLgDPmzWEFpr1uzCc0y39OUoRY7w+tT zDPyzZvMjviAOAupg3GD5aXa/fZT7FSWqGY1PS/wy7gttP4DmHH0rGlunzfEZSgGQpv0 +4U67jlxVvtbZMYB4wxk7x1kNqt8gzjjg4wxmqbSy+LMss9fdrBzBZHnTdZSVTY9kHyj kUGQR4Rw57hCg3574acu1QcLApIqzGdb2Jb2Rdf0Eon2f+IaE1mpu/U3pmpwgoEiP7Nt xPFTUOnNYYBrw+990GpC4+zH9U5ZxGSVD3uWy4eG/7YffXcM5t/JdtmO/4niTsRnKN2J HaLg== X-Forwarded-Encrypted: i=1; AJvYcCXt8+Hrifxzgx5r7EuMKZ6NskMBz8Ys5h5mi8Jdhu1/n61E9VNemAbBc+A1V8aJVeWhYl5ELEI48/gotjZ+7Mxu@lists.infradead.org X-Gm-Message-State: AOJu0YyqwQJaQgeLKu/ZUUgO9lgV2N51axgJS1Lbnq4FzPrh5R8feT78 gHUjIoXPADTmqffy7WxujkUy9mC/uVlR7PbMdBC9fq0eQzXXrJC2H7J/4Kx+CKg= X-Google-Smtp-Source: AGHT+IGzxYKeWu7EffFMWELHmwkIdN54nPpsTv5NT6AtbeSZT+Q/+XaT8AVKFhJoMlm8Z9w+5+yKlg== X-Received: by 2002:a05:600c:1992:b0:42c:c401:6d6f with SMTP id 5b1f17b1804b1-42cdb548b0emr34832575e9.16.1726153955430; Thu, 12 Sep 2024 08:12:35 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12:34 -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 2/7] perf cs-etm: Use new OpenCSD consistency checks Date: Thu, 12 Sep 2024 16:11:33 +0100 Message-Id: <20240912151143.1264483-3-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_081237_740509_BA6ADECA X-CRM114-Status: GOOD ( 14.09 ) 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 Reviewed-by: Leo Yan --- 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 12 15:11: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: 13802298 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 A4502EED613 for ; Thu, 12 Sep 2024 15:24: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=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=ucTLjSrDPBW7itralIk9qlLv2Y 4+eYhavqWCsX4r2Nl+IzGJFwSH5IrJKtXr/kRT3M4V066H7k3j/oSedMM0paSafNtG/uTNbUbgbgi IKsqWaJ9ct8KkKI/EfUoMGjy4MZk32JuAhYprTR8jYt72DfLfV2MUTvrPES3p0ECRUhffBl4w0FnS T7FDcGB901O3B1zH6BAzJIeRsUaPLnfKqEBuxhw6xbzSqNH4+JcXLx4SrFNww9flLST08UEF6Pcvh RW8jrwDfTa2TakMyJvRSo7jb554swuhRrNzTdfXdO+UuTz2dFVCB4SRRUdxtKfMIjvpMhK6C3di/G dp/NAcPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg2-0000000DXpG-1BUb; Thu, 12 Sep 2024 15:24:10 +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 1solUx-0000000DV8n-38FC for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:12:45 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso10190475e9.2 for ; Thu, 12 Sep 2024 08:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153962; x=1726758762; 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=xBfafZ0qDvMnmNpmTFzW3++iPIrz0nA2T54JYAUS3UduaLKyzopk77T09z/w4I08EP JQgkm73Uh2hqPaV8S1DQSgW0kk1fws5CfUNWRdLl/v0G6Dwro+ne6vU5iIL3xAzDEo41 gK4VDTwGVu66AV+oIfM4DwCE3FLtqgpEWY7PTM371W1moiTAODDA6muH9lcrLVbk5irP BeCFb96A/gvBC5H0v0S9krHua80g/euy/uj7k9RBJWW3cH4bEKWgg77i74CwBJ2kHlhp F00Su3iD34YOOI6N7Z37YeWKztoDAEGk4xJw1+1UkT9yWQxu3Ps+WReGr/VWDT90dUhV vaRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153962; x=1726758762; 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=PDjS38J6+2ERowBtDehh9qJKpkdWwomIoipNbtyntcErlCbSQ//DtR3SfgnwhWae8J K9pKMWhzEZ2T113unF5GzKyEPwERJA/2luDGB/Jw+MFd4PPNHQxPadRf6LX1gATur1jL grH+3xOz0zFhseVKMI07/rmlyIt2yxoyH98xNdkUi+o3BAZTtKEj6Jdlvh15/bGn00fN KcUAZB2Sn5GPww/wYHqbb00Oxro0a/ThxLrLvwA23eJ49y3Bmy111FQURyantik4ZxY4 fODUFpY7lUaNcGf4rzROZ2r7hmUGbsFSQAsKkyckYwVuiC7fmnkEJDQ2kiOClpKESXfL HKVw== X-Forwarded-Encrypted: i=1; AJvYcCXPa10J+eM1nA9txXjtx5UYPNyhm/vDZKbiwt27uMFWrbpGkuTNPGCRMCi6LeEXa0JpzRkeut/25YaS5/QoviOG@lists.infradead.org X-Gm-Message-State: AOJu0Yx+K+mtd1Ys0WNBoD94ebIJsRWtv1jblBVyQjJShB2y7ggCJXCr pvY1zYy9PpHYBtpaxbdEFJyPzJwHQuAhJh7dssY2h+9Wa09pbBQeSC4LQnFswUU= X-Google-Smtp-Source: AGHT+IHHXQ3L4ph9W3/LKP4w6PXlKUgz1FmPRZxqdPxBCXFwutCTMRNnHYk9J1u/W+htrP1UYDcjqA== X-Received: by 2002:a05:600c:35c1:b0:42c:bfb1:766e with SMTP id 5b1f17b1804b1-42cdb55006fmr26068025e9.21.1726153962042; Thu, 12 Sep 2024 08:12:42 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12: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 v2 3/7] perf scripting python: Add function to get a config value Date: Thu, 12 Sep 2024 16:11:34 +0100 Message-Id: <20240912151143.1264483-4-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_081243_821610_350BE344 X-CRM114-Status: GOOD ( 19.70 ) 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 Reviewed-by: Leo Yan --- .../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 12 15:11: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: 13802302 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 73D7EEED615 for ; Thu, 12 Sep 2024 15:24:39 +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=h0WZ/aTLtgw4aAQUWtwQpp4fC3 CmbD21P8r123YP7BVLJmMibVzERXG9I2n+CnCLhC9AQYbsjMHbnqZXqUmMEUiGX90kuQbD2wYIG31 aNR+5Lq/hb0bUQz43XqQI8p2nIdXgenVprYTaL41As0B0xqcXr4+/LyiGlwCkIXXyRSEhH6oHdJib QEMpDStQz+VDQxakhn0ZTCxpORTCfWUr37gFQBfWzdET9f/kJeJh0pXuW8nJ5ZybIt4jsdNVLI3wd bL4b96rd9o0uW2/2NC7X5QyVb+c1kK+i+N7lWiSDw1xID5jmyrVjfdWnEol//Yg1c+p8SFCYE/QS3 cDI7jwmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg2-0000000DXpR-3gAH; Thu, 12 Sep 2024 15:24:10 +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 1solV4-0000000DVBe-3FeT for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:12:53 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42cba8340beso13713185e9.1 for ; Thu, 12 Sep 2024 08:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153969; x=1726758769; 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=cCjiLlcU1lUh7QYOavgGhblH5fQPteQK6BQbu+075KweHFtmHjcEsjZfnEDESDbR9D q7idBskb7/BbLfiU+39Wz8fA+iEi1rQr/x0Lsq1eXQ/h9JPGtyluz4SQ1Om2p0jOYrph r/6EP3JWx6krgP49wCxA0EZcgWpgdjONeScAJoelBCRTxh1Lycb3uU2m8jANJoip3rMf /wodfNjOPgYHkI0UMgwuyYS9pmgWoip8HwADrxd+jH81ogSGT9T3+QgUGVx5A8K7jpgz VjJRkR+oud8LvcCl/fqck31j2Qc3dskdlfeZMvZMfpHyVfigU3Swq4429D9Sd+M+zcah cRjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153969; x=1726758769; 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=Fg3+lRt7n4d9mwvY8G43vYgZnLVqMuDWlZ2TEvbv0ue72Fmn4ywgZzQ1melJMu34Q4 t8WxUKLLddqjNP6vF0lOep2VuHOVIL0iAC8kYoz4rmjnMwn8XFs3rcmdPrHkLG+aT+qu gZvod51BXT0OZ4Oh065qCn2HzlJy6x67/DHPt/j9kOUPq+Dx/s0iH050CeCWdnEYyEwR t9+nedrSf/Q9gATBXaPZMj+QPGPklex1lWAN8YOd2d80HP4p1grikv+lEHAxMZbwzLZp 463DKHEVEiTFAjZJ2wVFUw6u3jMyLIndtaGF9vkc0qupK0qvcl5ajPiGcmADVD5S+kGp mruw== X-Forwarded-Encrypted: i=1; AJvYcCWT34lIwsKeLAAr+8NTzkk01aUTm2sz5MTt5znXNUmp81qFZmvgIn2BDWm0r7rV7Z4MRtEguANdLQ4IuVk8tN/5@lists.infradead.org X-Gm-Message-State: AOJu0YwfrmkG63AmWR7WhxHEmEED/NDNjkeOAGr1dcr/Rh+Ht9lB7Ykt QM5dNK9g2VWLjZt6FEkwdWz+txCIN3eR/TFHA2DPxjVMYCyWw68dcpo5nvxF12s= X-Google-Smtp-Source: AGHT+IGXc5ywzLhmjTHKXlNIwnMTOMLrdQHiAdNlmIcNXtaF4leLAP0V2tpbvYPIKGpqX0pwKDC7nw== X-Received: by 2002:a05:600c:3516:b0:42c:b7ae:4c97 with SMTP id 5b1f17b1804b1-42cbde1a867mr66142135e9.11.1726153968510; Thu, 12 Sep 2024 08:12:48 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12:48 -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 4/7] perf scripts python cs-etm: Update to use argparse Date: Thu, 12 Sep 2024 16:11:35 +0100 Message-Id: <20240912151143.1264483-5-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_081250_925638_37D01CA9 X-CRM114-Status: GOOD ( 15.76 ) 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 Reviewed-by: Leo Yan --- .../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 12 15:11: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: 13802299 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 746A5EED615 for ; Thu, 12 Sep 2024 15:24:25 +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=vTuJyV1coUx6Mf1qz1kGa8ZDNR PUX/67qedIc/v2L5kbbXHpxLG59g6V9Gn6ZmK4djrbYnQFRGn3+i3DkOPHdUYvylPCZ5xGzq4lxLN e/DEgOXA1rwAoVbRXBSk0T2Dr5WXF1FD+dLPL/yoiJJovp5id40KHOPUI9CzNefbulee28Whhyvli LPA2XluAeVZW4jaWFSQTspeJy2FaIuqHuKdkMOC0FAAwdhkYnXPDmP7bnhBPOjTykQOixReo6JrB3 7oi2lldy9GRVIrbkIPxOEdw8jiLwKmbiK7su+fw0RqNQYSUeJzdS2SZzczuyQyZct/TOd52nudnum ApIbSdDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg3-0000000DXpy-1taL; Thu, 12 Sep 2024 15:24:11 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1solVC-0000000DVGC-1Vlm for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:13:00 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-53661a131b4so1495613e87.1 for ; Thu, 12 Sep 2024 08:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153976; x=1726758776; 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=hH9dhyPjClq8smbb2NFYgwe5pA4CpWDBgydmTAEdZAUrDgP+J1azPWwVW7+CFO9u8f bkHqaTJJ3rDWNmFvJmtGbB+qv63x0DNNVVE54jTR3x3fPROkEEPC1h9hyvloBVNpxAiW NZsotverv10QsyLkCDBP8iwUIyEdAMNNq1GP7Jc4SpMw0kdzR4r3IwOvATKc9CaVIGRO l3r8fNY1AddMyd7rTBBRnUPFjN9awsIrdCMfEg4fOyQTVwehwwvkK4lXZk5hMILFnqDC QDB8p9jqi/OZtoRj7OhGqxfeDULG9zGIWvpAaxqdgsdy1uKoDBCj6kGvQ/zcH5N/nrDt HNWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153976; x=1726758776; 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=t2r2fNM/Ix1V7yoI8fNPHnZXooxQGf3MYAIljokwq7EiXvxCvbvFAuwiQ2Oh7Jub/e yrdqk4VAlDwNrAFA8IXEfDHlh1eCq9Sh69GdaXkleisYPuZWAR7y+kcFdaqgNo5F4q79 S9QHJaPRk1daNCdfPZFPefHzHYStHFfEeT37bSCGj1mMTg2HzI8UyrsSzNi8QUus57LP bSr1PYIAAn649C7jAJ8VJ23aFIYbF7aIEWVsRz/SduIqf3lXzWomcKw1/MdpwWUoGnxI ALnUuAEtKYE+nB4l7/lOi9EB+/QZ4YCaOYxH75e7tZpt4FvBLAT9v2Avhbpx6XHQRzAS 2f8g== X-Forwarded-Encrypted: i=1; AJvYcCV+q9VNrjrECFHtYZ6RQroD8FvEcCn/5M/Lk7Ihlz1CpjvHYUZ7pNzBIH6c13+8w0Qy6+gzVUakdQRxGWrxBiil@lists.infradead.org X-Gm-Message-State: AOJu0YyWbsb2jytHToaAUCSfdkCu7nCZaSab4uCC+3COsj9S/aU47viZ T8j/8ooO30Vf9+O+Rb48qedkJrufwIrT6dXWf+8FMKd8HKDmcOd4gE5Boa68qoo= X-Google-Smtp-Source: AGHT+IFgAMjvK9UCvsSa2ENtMA8fugJX5vUx4oGnluWZ4OiPoY/eCDU/q7/1d1etbgQS9qcJkbcEyg== X-Received: by 2002:a05:6512:2256:b0:535:68ab:7fdd with SMTP id 2adb3069b0e04-53678fb7170mr2044442e87.19.1726153974955; Thu, 12 Sep 2024 08:12:54 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12:54 -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 5/7] perf scripts python cs-etm: Improve arguments Date: Thu, 12 Sep 2024 16:11:36 +0100 Message-Id: <20240912151143.1264483-6-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_081258_847409_141533F8 X-CRM114-Status: GOOD ( 18.11 ) 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 Reviewed-by: Leo Yan --- .../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 12 15:11: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: 13802300 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 92B06EED618 for ; Thu, 12 Sep 2024 15:24: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=lyScag8p5nZQgcpgovS0Br7oaCoB8CMogAdxSo53VSM=; b=0o2xDiXzxV7NvumOPqyI/v5B94 u2408WMlQS2mtK4iIvdaVty8AP5S9AygF11xJ8lLqB8uo+/K6m5d43u2q6hdGoKF1jH7EV23sNWoA YHPaAQs2TFhwwACL5A6UWTAnB3otW2PWnVaLy67CLU1mHYtlxgcgMeyHX8BEsVlLO80Wv4e66IObj E/vUC7yY/UCL9thmn+2QJ/azVUvvL40BuNdrhwF4+6ad5Zyqr43FQZPAjd7+pBQGoyypgfLzuva2R Sw/apFDgKmdAdU2T1Wv+zjriKJupQ+ixsZE89N3Ym6YyVzgpZB94Sbys6XMN1faewaf8+HOdOc/f0 7xUd9kgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg4-0000000DXqK-0KAb; Thu, 12 Sep 2024 15:24:12 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1solVI-0000000DVKZ-0PuJ for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:13:05 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5356ab89665so1241990e87.1 for ; Thu, 12 Sep 2024 08:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153982; x=1726758782; 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=TAV6yZ/JP7q6BxGujYmVqrZU94d2YFcDGvDdLNhmIaID/b3qpkuFIXpU8SFyQ5iHn/ RkgMEBNa0u9Iq/mujaXVS5C6L0c6DaKu1miQ8QMornozspuzZ7r95EQDkK7ZFYUnbtHX dsjUowy6V5vuxozye1ITNNEUmAXoyy+l9kuOBndDrQ7vflPqggkIOK2kNRgvhZI6yT8n DteUgcQ41i3fchVUJwE7rYJW0xBmwxgnnLJdx8svchmqjjhVL4l4uTW44bgbbJwUpkty +LpgUXxQo1AJHs0D/8nezXpu9uHwyWo3aSbPFCp63n6E5JLXxkDQQFxl+8YjXVGKRSzK 0uYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153982; x=1726758782; 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=YR8yLC3BsclcKYEGsEkqf8vKgxBLnbJmzxItWRXTdDJGCaVj4KA+CPFBSYh7zWKd12 +tRLdORK4J0NYrf6HZcTXQjh0kYyGBDPQvNe/ggmac7y6KF/ZAmDB2iI73kkciMsk50K w4orSCF1CuIXIhTjWTpx603Uxxmt9ujDfrGr53CMhsG6lnqd3+3uL7DOjfwuSIJGEoBl JGtgU/D7aHwiMnspt3l6PQkZBS/F1stojtayV5cDI4q2/MaaiHiEaEJTZnjkmFjnURIt yxHnCo6RNKBreDNjp7Fd7WmBQ5r25j54/ixr1+rnOR1zEB7KzwLXAQLPZOJ7CzaR16i7 3Amg== X-Forwarded-Encrypted: i=1; AJvYcCX5Bq1LtKAG3rbRVl6mEWGhRgsXypR8VDRK/6sDg+L6ehyDJ8INKgBad6RuQGig9MwwMRqWt8bGEb7vRU7oTaPM@lists.infradead.org X-Gm-Message-State: AOJu0Ywe41UDzfd0EHRIk0pMXgpf2UY3iv+YksjevDOWVbj4drx2swZt fW8FLKJayra2tGO+rMDNSc+rRvjw0pe5gx/HsffsRBpcGsFQeMPWkg4NQssMRM8= X-Google-Smtp-Source: AGHT+IEU6nXG+B4QFLcwDCDs/5zj2w0oRrKPhJUxJ9n5pG2+xKrqgQBx/Dpn46aYZQ7Zt78NIeVlOg== X-Received: by 2002:a05:6512:e94:b0:530:b871:eb9a with SMTP id 2adb3069b0e04-53678feb5ffmr1855771e87.47.1726153981495; Thu, 12 Sep 2024 08:13:01 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:13:00 -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 6/7] perf scripts python cs-etm: Add start and stop arguments Date: Thu, 12 Sep 2024 16:11:37 +0100 Message-Id: <20240912151143.1264483-7-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_081304_183178_B0520F3E X-CRM114-Status: GOOD ( 16.11 ) 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 Reviewed-by: Leo Yan --- .../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 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