From patchwork Mon Sep 16 13:57: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: 13805523 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 73A6CC3ABA2 for ; Mon, 16 Sep 2024 14:00:54 +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=umuEtd6TXriWmaesvaUlkUkqPg9JblHlWbB3iYtKN0A=; b=moTnE2Do30hGvInRUIWNj/wsH0 dg6ZULaam/xPhxerL9mB16E1S0j62PRbq5PfEkRBCjxd/mFpbdw2RnB2Z/vQ4iEAD8WkU+tYbKE9T aVMa8Z0Og/qt/8SOfsoY2LJHJ6keM8IcmduMi9C9aZODGSSm3m+3wsilXDSX3Gvtodq/DhJ12bE/u oG6D42h+4ZXgK4SEY3TyFd9HXMECcUTAjeX9EeakDUCckbV0yhk2V/VmSJdoEoUp6W1tCsHXMi1IQ yDp4wmmoMh286TvVrCh+6EqDt9iSims2uHWinKRyXpriCjP6TBRv2E2PoBrsgmzRdrzRaTcUc1TYJ ta7xy7gA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCHM-0000000488j-0SEx; Mon, 16 Sep 2024 14:00:36 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFF-000000047Wt-1Jve for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:27 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3787e067230so3224439f8f.1 for ; Mon, 16 Sep 2024 06:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495104; x=1727099904; 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=umuEtd6TXriWmaesvaUlkUkqPg9JblHlWbB3iYtKN0A=; b=xQseGZ8zOPdMdGZOVYBXVlD8nK3SmfZ9kTdRCfJc8sDzZzDDBYMZEStcpPUtM/ZByp jCiUhcES3p0LPoNLlj0s3MedL/rQH2TqRnf82fB23M5s+UQNQiTJvLcTFS4Ruk4vvjRf 4GUKXUjxWePH7WBG2exZ01JusvIfidKO1Ecu6IB7fi/V9uyai/ucAfGu99SAdG7wamJC CJC9NLWPrMSxpJvn/V4d8eUvLE1OblYDSFX3JW+iUd6CWTpzaf2wyIiqxmfpqMcey2af 1+E0ttQJ5A0Nf0dBd0Z1HH2DlwPEEuiRSum4Iib+WnGHl75Lq021G5gS/Qlks7phAmLJ +CGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495104; x=1727099904; 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=umuEtd6TXriWmaesvaUlkUkqPg9JblHlWbB3iYtKN0A=; b=oLKs4bCFz3PhJaHdtcJXXirV66JA/jWQOMTWzectBt/KcpjhMO69xC8jqGVInbroAk 0KwNt4C5m/qarv28E1XxKpBbHkWV9jww2aCygMQITL4Zc68eMX3dc9VLHMaQVMN1U66h RHC18v6QnXc930iL++Ft4E3uHuLOxV/b2dc8hU7X2Nore2x9IxRVftEi8eBDwmC0Ar56 gDeYjs4LOEMdjfqRTwnATdwviXU5hm+UdiHKTb+5giUHSb9gS9vVfytZahpIEmLvHWqL eKtUJOKz80JQU4vDW8da+q2Nsk7muSL+qcyA3fwIHFq8M0tVkbeEdA3hHWra3sJEEIfw uSIA== X-Forwarded-Encrypted: i=1; AJvYcCWYCl9hrMo/Wp2XJMPIlagNfiAdsRHkKTNGXj1Y9CDMVYwU9yzJ7x3PPttcchYWvMfv3bsC1pjRLbqvYETQiPHe@lists.infradead.org X-Gm-Message-State: AOJu0YxneSMmr3vbWx7lEZLut9B3E3sG6b5fykPKf8p+eBbOtEyOIZ48 k4rHiVj9K0ADSILZJrsZ4lAYoeubsLNkBpwAAoxOOieTqx4wTbLDvj7IwZ4qYsI= X-Google-Smtp-Source: AGHT+IH+TmfCLdIaNzxJmSpEMr+pHlKHl21zQSiG9BRNBBOm0HusB70btlMPY4whjW+3iQfcuOBDCw== X-Received: by 2002:a5d:56d0:0:b0:374:ce9a:ff11 with SMTP id ffacd0b85a97d-378c2d7298fmr8875256f8f.50.1726495102704; Mon, 16 Sep 2024 06:58:22 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:58: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 v3 1/7] perf cs-etm: Don't flush when packet_queue fills up Date: Mon, 16 Sep 2024 14:57:32 +0100 Message-Id: <20240916135743.1490403-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065825_385959_DA89DD56 X-CRM114-Status: GOOD ( 23.36 ) 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/ Reviewed-by: Leo Yan Signed-off-by: James Clark --- 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 Mon Sep 16 13:57: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: 13805524 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 3FCFCC3ABA2 for ; Mon, 16 Sep 2024 14:02:03 +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=r6I1ojreNPMnAqnnyAmn/bcHu89TPQPwVi7gpVoP/po=; b=Gep9CwLwrT+tAjMlVVozPTtIRh uzaKGHin/VnkjmLzCPIdjBPm9URsiq7owhZrHUSS92LAeWNnAGDQi253xTtq3G9UmrMMRudlLUmQq flx8CdBhtagNYKP8uexDztj9tlpjMeW2NQXykQxXi+ZXnAdhfrZ3ZA+cpW1ak3tYvrskFbEXq2zay My6ZjGNi1Ep/KkSg9m827uZ9Ae4nGJiq4oRvbAD//dK4ht29YRaKXeLc3p8LijrCjvVKkiznEto47 KZhdVEmra8TJhkLSxObxXDUpkgC+z4FsrJEr14rRtgKuGbWpuBZpLGsNqtRH2QodJsGSVp7xDijfP l5aPPuSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCIR-000000048RF-1dOo; Mon, 16 Sep 2024 14:01:43 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFK-000000047Yf-48O7 for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:32 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-374c1e5fe79so3370326f8f.1 for ; Mon, 16 Sep 2024 06:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495109; x=1727099909; 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=r6I1ojreNPMnAqnnyAmn/bcHu89TPQPwVi7gpVoP/po=; b=yysB4NsllejBPrsrycxnQrDcsqVO/NKXUFmRPvop4Y4B/ev+IDXnUpThHOlzWvpSC/ tRgxMqQikWDJi9wVhdDtXHey6MicgfGP9z+4anwvQ4kkiW+qXi+MYjmnLigLXfL26eL1 KZwEdC0fkpvquQHUYRb1kOIiOZsNm2UNuUEVNXh3JCT64sI1fihr8kK+wPi2RM5ozmso MSBj0xF+kV3+gA2kZeh82GIkyTEa4gSQVvNXFBsQvyrFxK7xrEe7ikRE1qzeeEQ9ozQM PzcNlomWw4OC+M68cWHpOQyUtUS54eZg55Zrlrcc4s1Ec9cUMlw/ATJsCmenScSEZpG8 Pl7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495109; x=1727099909; 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=r6I1ojreNPMnAqnnyAmn/bcHu89TPQPwVi7gpVoP/po=; b=a/kqVJS6UqMRY8CDEuLYzAim15QTpRadTohkAvD3iLjzOD1tRZmBC3w35T+1J1SOWG Cnhvs3kqo8s5ZGrOAc/D5SQV2vECEKAwfTqc3ck0EqgauG52inPkOjGIbUOotOSEiLZo MWd0XOby54UoEfew8ehmDOKgKqPJ46/ibDV3u/CTW1yOgQsO1g9nkFnComQOQ0oUQQUe Riw0Eb9+lX2IvTHnUuqoIZh65ya5jbnHZddxbLHJlJrX0wrM2UdVQB83LXpP4spK9do3 S4D9VvHT6s9neR/0WxXwCPSoHMINNwAbVpR0dBESwQdb1ZGw4OjZRf1y7s4RtTZ07xra 4lSw== X-Forwarded-Encrypted: i=1; AJvYcCVwwXMcgDYAM2Fmn9wiocyILZ9HJLOQzJraPK3CU6UYtbHwPh+eHkwbMJDgfIPoUFhXFX5rPzsq98inpDvgf4nm@lists.infradead.org X-Gm-Message-State: AOJu0Yx8cl1tYMhrV/aqdH9tkursTF5tZyNT3Clo6davGASrYecraYup FAcZt5scjRXh0wmL6FYPSgzhGYZFuasMEW23N49YV+5z1BV7LqVQj41ybp/jCe0= X-Google-Smtp-Source: AGHT+IFsrj9c9D2EcipbKadvrs/i4J9td9eJ+dOatQVeHhmva8RKXjoSO6yE9qOqsI6nilv8hZ9Unw== X-Received: by 2002:adf:ae51:0:b0:374:d157:c019 with SMTP id ffacd0b85a97d-378c2cfeb36mr8698434f8f.12.1726495109000; Mon, 16 Sep 2024 06:58:29 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:58: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 v3 2/7] perf cs-etm: Use new OpenCSD consistency checks Date: Mon, 16 Sep 2024 14:57:33 +0100 Message-Id: <20240916135743.1490403-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065831_051580_63C2870C X-CRM114-Status: GOOD ( 13.64 ) 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/ Reviewed-by: Leo Yan 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 Mon Sep 16 13:57: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: 13805525 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 09F4AC3ABB2 for ; Mon, 16 Sep 2024 14:03:03 +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=J/Q4dm5nWNN2kHtmEV1dKoCfXKla/YrO0a8mdji6DIM=; b=vbtlMeo2OMkfLQozFaA36ZaDJD 36ZYG2RD3HDdI12Rx0joH4q5IPWwsvQ+LlCvu5lvw+RcjWLuasR8cgH3ZENVhuGIqnwjvtrmgujdE 78eBlr/Tpw5DBwydCwoEOCmBchBudDGEVpsb2dFAUrKfcB0eVst/PX0ecnjgmDw/cCrbINC12kJpM kSLDLT9sEYfE2+rpO0oAuP7ArtmmySMkqOVPa/vE0MZIQ3pLSykRk1hIqwIZm73ob56925mZ2oP9e O/RADYGbgjsHKMs0Y/s95KTdAQVo6Q4NS+6B36SNyPa92iX8PKko5udedL70T8I3HWup9tMs2Br+B e6WRSDvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCJV-000000048iD-0Ajb; Mon, 16 Sep 2024 14:02:49 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFR-000000047aq-2djt for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:39 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42bbffe38e6so34786955e9.0 for ; Mon, 16 Sep 2024 06:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495116; x=1727099916; 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=J/Q4dm5nWNN2kHtmEV1dKoCfXKla/YrO0a8mdji6DIM=; b=jyWwBjhv7QSMsQSRGXWs0y8C6hbVKknOnfb8rU8lMff5E+e3formb9KuMd88QHEx0z EYGYPpx5PK2QUsI/J6CPKGKMJ/+oxqu/s+baRBdNf+RFMWorndSwWrOmBj6osM/tFeZ4 AYslBSsafmVxDOkj7M0hA0s969kj4LWfA6d4F9wOwWyi8lCFyebJ0GlKmprOjrawZtRp O8e5sIf2FRAKh4qkmyAInDNRXgHrwqa9UMEC2M7zweBAG0vkOGdZdMbEuMjfECwgfsGl Kao0zX/w8sYjlucJ4+9cotJv2yxpqCYXyyc4sYV57Z7QBilMA7+Wi7vA49tb59tevHjq 3lyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495116; x=1727099916; 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=J/Q4dm5nWNN2kHtmEV1dKoCfXKla/YrO0a8mdji6DIM=; b=r4o3wClOXvghXPpLcxYvF8auranOzbvQN7hKZRfIMVTX0x13KqxgumsoEt8eUUK5l2 vyAwS33+Vo7YuJYSoFW3vLz3rIaHpBD7He4Batt1/UfY88TCi7Nqxg77YWE6P/xMmExm LAcQc7Vhq4hwom3EF3EF8K5ZNDCNf9s+HJnL7n0u3HnduDifCFHwlPHRJy8hFGDpkO+o po7Wtz1inc/l8yC2aDpf3SICO17HPCCDRVEFnVA9jfVPpAIgHIiIgJb0/C8CIRRHztK/ cy2xblzBrTO0NvJpfwQ/VAzptZ3HmnoxpcV5BFv/V7+jnU3OMqGGPJp+vFGay95Q6p+c STjQ== X-Forwarded-Encrypted: i=1; AJvYcCXid27o2cEj/3qcz/YpC0byXzNAOFcN1QhmHgEKWnB+RRjLDj91Pz4e1D6wGLF6hq8cNZo8Xw80kpdWEtBfJ/k5@lists.infradead.org X-Gm-Message-State: AOJu0Yyc1WSv0yj8u2OvSM/9WAosswV+jxya+8jHiOV6HhBysuZ/hlfJ DIv+MGFlNYLyZWcvpT7Oenl3/KUY6KJBsD3N+X1bVU4/wCFlrL0hQBn5FgyRk80= X-Google-Smtp-Source: AGHT+IFPjvdUr8a7pxtzlAcmP5XIdfDCWxcSeusMeAXrmeyVykL1AMAIIFJJfQRTYkSyTcytvjxS6w== X-Received: by 2002:a05:600c:474c:b0:42b:ac80:52ea with SMTP id 5b1f17b1804b1-42cdb5097fcmr124703765e9.6.1726495115549; Mon, 16 Sep 2024 06:58:35 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:58: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 v3 3/7] perf scripting python: Add function to get a config value Date: Mon, 16 Sep 2024 14:57:34 +0100 Message-Id: <20240916135743.1490403-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065837_694993_78CEF677 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. Reviewed-by: Leo Yan 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 Mon Sep 16 13:57: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: 13805530 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 4DE8BC3ABA2 for ; Mon, 16 Sep 2024 14:04:10 +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=lWq/62mWpUAFEk/gBjzNeVY0NoKYK+5WXUTV/6v1tA0=; b=wVGCJAbwHTcrxkkAlSuX2G1Uxk 96lHiSw2gRWbUI3v4mD7x31vIPeXrUgWHyMVN1F92E9rT4EDyy/4x2bdiPbhfmJksxFl1sjfV2I1M nINrSUtHVTNDaA/AApZ9H9CMYPV0d7J1SaUyOWtMwUDem1a/7kGbIqUy/WgedYIu+0rugN/zFHot7 LAA0arZGB6iwP8xskOq5+13a2rO5zqEpdFuH0D7K5ZZ7SDbJFEOBGaiSy8YqUPEOUlxmgClVJhrNm khDNwAxtx34Vt6WDSxmHHpq3CVnQAJC20xVkUjF7ymK6i+jFH+qT1xp5LORnjlvjAOT3lQswIOKqD qp5BBbKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCKZ-000000048yL-1ao1; Mon, 16 Sep 2024 14:03:55 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFX-000000047cr-1mnl for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:44 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-374c5bab490so3712703f8f.1 for ; Mon, 16 Sep 2024 06:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495122; x=1727099922; 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=lWq/62mWpUAFEk/gBjzNeVY0NoKYK+5WXUTV/6v1tA0=; b=N9rsL51MegDDi073VPWj3l6ARjx4zo5cTeJdv3B/FRJtqz8Xbj2057HhttyeSgQQ/f DWg8on1bUAo1j3m0YDOaRUlxW2PurMlsByNN3JKDMTXjK16wAsDdobtHp3INchYRtdKq +Ur2TlD4WxDzfvDK9/2V53SZn8nIzp1WGyMEYr4guJf93yLYXJcJMgranP7n4so+nzdt RzkImUwDK9R1H8kfNj2CuRaE0dsffJc/h1MKocWTpaXA6zjWVQOjMxJOrx67l1UnDgXa /WzEuTQAfWHH9GWb7qFExWPFrnpirNCEJob8eSpjxllIg2/lQXkrkzKRjpc77Wefval4 nNMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495122; x=1727099922; 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=lWq/62mWpUAFEk/gBjzNeVY0NoKYK+5WXUTV/6v1tA0=; b=MI8xoub/FEC5xgU4z3IV00MN01kOiZZ0iDUpPXR/cvCClYAqBK8DesRadrImBp8TME MqD5/J0IPKHY/4X+Bc4VEAJ1r82G32Yg0NOhrvuxRkf4tb7cIwrV00z2X+5gwG24M33Q f/xXjpJ+nU2r3PJYWgQ65wn5T4vHcK7Cl9WNiU4+qAE/uAtM3EDzYCd+V8t89Zld2fMs kR3PDHYxuRPMeb6zC0KWmsbBdR4lwYyV4xjlXZvU94WS+0YaH7KMqRGAF5gaUoK4Z5eI fUg5NEFmBXLBzRHIi0KVtcTcxuIFBi8XDxcUM1uwJIVqPPrMqv1Ce+M60fChrAuuD1lY aOfg== X-Forwarded-Encrypted: i=1; AJvYcCVMCJFjsh7i5BiozXp7kJrLD70O54fnMuejxkwxbHU3KTXWANXug+vdbtE/JpyavjO0a83JG8sh2Qr64WY4jqD3@lists.infradead.org X-Gm-Message-State: AOJu0Yzv0oj6eYV+sPfFavJJXTfBPqowCTz7a3Yb2QfRTPKmRa//+jdh mTx1dMRuDuSx2JDEYhfiCEEpIVdPw13EcQKjcn7f3R4ZwikqdSZzEFMI9rnZX+A= X-Google-Smtp-Source: AGHT+IGbvS6CYBCK4iQeg7G3Wj+J1fYZmYFe88jcm4ZQhuvkb+pN16rQGuWduTfP0xBqRl59dJ+Uyg== X-Received: by 2002:adf:b50a:0:b0:374:d130:a43b with SMTP id ffacd0b85a97d-378c27a12cdmr9347404f8f.4.1726495121954; Mon, 16 Sep 2024 06:58:41 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:58: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 v3 4/7] perf scripts python cs-etm: Update to use argparse Date: Mon, 16 Sep 2024 14:57:35 +0100 Message-Id: <20240916135743.1490403-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065843_492589_FE4C04C4 X-CRM114-Status: GOOD ( 15.15 ) 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. Reviewed-by: Leo Yan 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 Mon Sep 16 13:57: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: 13805531 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 5F194C3ABB2 for ; Mon, 16 Sep 2024 14:05:11 +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=wQSiMvQctmr2VbpvZ7u0ZKPRwr2TQbe0lgGJUjSaHZ0=; b=CBzf8OyOMThdiYE/XvB0W7rq2j Ft9VNytvwhauPt/jvI/o/JGUNYvRI/zkkTDYRi3kejRNl/CJbXDE+G5HvA0d/rcYgjw1Hm7Kx83sl 7nrj/9rzpu6wrN1hAeT505jjQ76HIaIW4QqArOVz4vHOgA0i6Hoqe/1pyXVoAYP9JVgSDQWz5fWj6 OuAB0sae0ATKDoPN30LBhU75i3gRqvhhxpsP4r0sqauR5DLl49PsSaPhsSc+yj5AIIMGarwpTDUZ8 X03kY5VQNSHmSXSldHVaYTLSm3io3sti/aU031tGcMHSFIT6vpHakChccJkZBb3dWxIDiV4UpTQmf rcufiuqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCLc-000000049Ev-32xr; Mon, 16 Sep 2024 14:05:00 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFg-000000047eF-06hc for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:53 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42cd46f3a26so26662435e9.2 for ; Mon, 16 Sep 2024 06:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495130; x=1727099930; 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=wQSiMvQctmr2VbpvZ7u0ZKPRwr2TQbe0lgGJUjSaHZ0=; b=PhNhsnhHZvV5syzyZaTdCroHkgOu3N1mGlUrwg6ESUPofjhG9EV9PcgAe6YcTpypm7 aJrOqdG8m44FBty01+QOjI2hb5yECANMQqK3ybJ09A35qc2Vc8gRgbOwS0duY1N5mhuU VEorSFwuUXkCzbuRKrRABPspiO09UVNQupv2J7GP+w+RBvfpAx0ghshLk3+6JSlFHoeE mwuJRykhEcmuLSIhl+lOJbx8gs3VIuMaJMjo+Dy83VklAxd+42KrUe23cGt3m12BHYvn CT9K0fD1r2NjRMhTpTs87I17Ea1mGf+Q9TuPDpot2AlrDjMNB9O8KihTgEzsRwuLJbHj kgmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495130; x=1727099930; 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=wQSiMvQctmr2VbpvZ7u0ZKPRwr2TQbe0lgGJUjSaHZ0=; b=nASjlJ9FJAvC3EJrNFHf91WmA3tGbovVAQ4uzVJKATNqEIniLnFeMXq34Y1EH1ddWc tK21z7mcqlpRUEHG8J9yeO6PWKNxMmj8f46bg+uVsd3OJWeYDthfrHFLqr2lWbUOvQAp mVrBIoosDkX9zu4E4QqoEM57AZ7Au6vfJCQKTQrAnGnaolbQAuFTWJA1sGHfh/usaVXf Y97lXec66jnBNAzRA7KxWpgocmiF0P1998lQUzVhq3mGUDxqZu3aIH25+Axzs7nRvGkS rdgOILVh8V0xzXRJbqJ1jrHTRiV3dWLcLE3Tl0beV2ryl/OJ2zwTzszn1Xsd/duVhUgo HlrA== X-Forwarded-Encrypted: i=1; AJvYcCU01/Ljyqm+Whukr1qLDE9xLR9r68cyTjPguA3xPf486Yhb4P1/a0zuI6oMNLs4IdhZewJ3SXBznBsdYDjESiSM@lists.infradead.org X-Gm-Message-State: AOJu0YyZG7VTulyJOuccfng0tcMc+oKF6vi68vclNtUwQWnCZdL6mOie UKTwxgVJWmg2rlG6sRURgjj5PjnN82YycV81U+B3uoYB2CB2kHWcvpxrzlMe8pw= X-Google-Smtp-Source: AGHT+IE63Rq5/cOxy2xm9RDFbt82etcAarWy5LN2E8qI6q5tX0ZkjrRI0pxkuOxkKIyNRSiiiK0lrw== X-Received: by 2002:a05:600c:1c29:b0:42c:ba0d:c766 with SMTP id 5b1f17b1804b1-42d9070a5e1mr83851605e9.6.1726495128349; Mon, 16 Sep 2024 06:58:48 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:58: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 v3 5/7] perf scripts python cs-etm: Improve arguments Date: Mon, 16 Sep 2024 14:57:36 +0100 Message-Id: <20240916135743.1490403-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065852_081507_2D605B50 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 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. Reviewed-by: Leo Yan 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 Mon Sep 16 13:57: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: 13805532 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 55A3CC3ABA2 for ; Mon, 16 Sep 2024 14:06:22 +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=8AtH/7E9TP7UM5eLIlL+QC7O7RdXR/ljZ9YaSiv2f5A=; b=lXGTdzlgM3MRpJkJBpK/YCsbH3 QDiI18ovPrBPBWkBHgcF5vYK4Dw+w3GV9Fh6YEejB0+v55GunaVsW0FN/2HuFoHjFrQZUT/A23hSX Rd4R2oTf/5BmLpC/jqELzVTB+s6wt8pTtqHTGED0XRXnfWfQIROtfqdnh9+Jl1MG41Ir6xMMVGv0R LuE6WVurO50G6OZQSPwSEjZOlCsvQEpaQmGRCX5qpWDZKTprE1GfAoMn+KNjrfR3iPckg7sD/noiM CvtwBZif1FreqHXpE3atqrIg3GPrBY4UNAoKyMwewvTKC9A+mPcqBYrA6tCxnet24GHnt850EkVKa GqNacl4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCMh-000000049XT-1TdU; Mon, 16 Sep 2024 14:06:07 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFl-000000047gS-0TCE for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:58 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-375e5c12042so2451600f8f.3 for ; Mon, 16 Sep 2024 06:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495135; x=1727099935; 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=8AtH/7E9TP7UM5eLIlL+QC7O7RdXR/ljZ9YaSiv2f5A=; b=m2aaVAztBNywuGFMnnKTqxMmN0eKPVOpTRnIakFddI9V/ZWNz8NB5Y6F1TuKDkS9Qu OepacO3lcvGdmRyO61fmNbHRamM20hEU8yJt2AUDd0tECUEgD01IvQ5Dwy1+iL1rXPuJ 4Ai/s3sFG4JhfeGXOt/KOtQXjGnsqxUzUbIHkOvQGuymUoK63nvog2zKRXxQkwAKShy1 chOEaea87qWKV14aZtg9CZNU/U98vrsl6hEoH2WSF3nR8UbvuA4njVNab4Z+BXYdZD9y LZojPhsmcG9hoBlIFRuhi3EFrAQBXojLOFKmT98Wsj2QOCvTwGkVXuh1ntziua/WoMWN 9E9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495135; x=1727099935; 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=8AtH/7E9TP7UM5eLIlL+QC7O7RdXR/ljZ9YaSiv2f5A=; b=eyWpkjNvTrYQwxLxZ6JBkRCrS7ydizoAHY/4A3f+VR5Mhr5ededPKSRD9PJPdlPjxX PU66CgsikTDjWPzq5NuZeE6zSWdGI4+uFegSV2f3uRpaECCd+l5IVBgLqcfZy0KMV6B3 WoDgwsIKqR/ecCHfOe7lSDmXP528V7Oqm0t+MB0PO/++b3XuhHOYziNFAq9mwVgEWNqx eC2tDmB4FqUzuZtvxNpBNpyqdm24lnSaWPckX6yrNcjj/lkEnEWza8y4HtiLMY7aRODK EOwYNzzTEG3qOtfm3ZXawpwvtLMODg9w9Mwm51T3gRNiIrxTJiY8zY7EeZNaByqiINpL 6ACw== X-Forwarded-Encrypted: i=1; AJvYcCWnXJtINIegxtBJ/nn8aF7nSdR11Gss8XyIwldHFFXGeG4WYOWjczbbcuiYlk/yOw5ETllXLTtycP9fcaBh4+4s@lists.infradead.org X-Gm-Message-State: AOJu0YzymR75WvUktqY08UMSuSgHKBS8NX3KoMyasOCU3HsvVehmRd3j 0wK8t3kwsiJptwYeNrZGuRBjacGHBia2FAed8W+4YTkeHqQuWSDimBpb4ReSy7U= X-Google-Smtp-Source: AGHT+IFAvOSLEn39dzXSrkked00cRci732/juuGdGaJTRnvElRy5+8Op6OR+biwvTP1c/MW380IWUw== X-Received: by 2002:adf:e7d1:0:b0:375:c4c7:c7ac with SMTP id ffacd0b85a97d-378c2d6165amr7924044f8f.49.1726495135275; Mon, 16 Sep 2024 06:58:55 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:58: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 v3 6/7] perf scripts python cs-etm: Add start and stop arguments Date: Mon, 16 Sep 2024 14:57:37 +0100 Message-Id: <20240916135743.1490403-7-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065857_180805_141FC034 X-CRM114-Status: GOOD ( 16.47 ) 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. Reviewed-by: Leo Yan Signed-off-by: James Clark --- .../scripts/python/arm-cs-trace-disasm.py | 40 ++++++++++++++++++- 1 file changed, 38 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..1128d259b4f4 100755 --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py @@ -49,13 +49,36 @@ def default_objdump(): return config if config else "objdump" # Command line parsing. +def int_arg(v): + v = int(v) + if v < 0: + raise argparse.ArgumentTypeError("Argument must be a positive integer") + return v + args = argparse.ArgumentParser() 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") +args.add_argument("--start-time", type=int_arg, help="Monotonic clock time of sample to start from. " + "See 'time' field on samples in -v mode.") +args.add_argument("--stop-time", type=int_arg, help="Monotonic clock time of sample to stop at. " + "See 'time' field on samples in -v mode.") +args.add_argument("--start-sample", type=int_arg, help="Index of sample to start from. " + "See 'index' field on samples in -v mode.") +args.add_argument("--stop-sample", type=int_arg, help="Index of sample to stop at. " + "See 'index' field on samples in -v mode.") + options = args.parse_args() +if (options.start_time and options.stop_time and + options.start_time >= options.stop_time): + print("--start-time must less than --stop-time") + exit(2) +if (options.start_sample and options.stop_sample and + options.start_sample >= options.stop_sample): + print("--start-sample must less than --stop-sample") + exit(2) # Initialize global dicts and regular expression disasm_cache = dict() @@ -63,6 +86,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 +175,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 +240,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 +256,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 Mon Sep 16 13:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13805533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F85DC3ABA2 for ; Mon, 16 Sep 2024 14:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=xjJliRBTpqHpLUebovQMwDuwrA KoX6Eh7UiBMG+IUx1hUkGvPLGRugIycrX2kKi89ybH3qqq+NdQ2trJpNrtBd1g70N7Q70kPJDemmJ cAa4aawqqKv8BgaGbspxvlLXAW3RxBeFl6rhDzncVCt2jY0+8KmYfqbZzMFlYrJr/R3ZgJR5BE0V9 PrB5988/OxL5YspRmEo9P9J5ZLGQoaxPt9SY7RIMVW0xlyA5sNPn5KtPYdfAzhs+IACubH3dhSuO8 p8FFvYFgxNDaLhmt/I6j56+UbCEcICwcVqShyufvDwZt0+obEe0EDutY4OHJ7lCgr34PPkgpMEphW LTnEHjeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCNl-000000049js-1DUK; Mon, 16 Sep 2024 14:07:13 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFr-000000047ji-3QDM for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:59:06 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42cbbb1727eso37040315e9.2 for ; Mon, 16 Sep 2024 06:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495142; x=1727099942; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=Dz8KFnSI/qge2ROGuIsaxjSfBXy0f0eS6RmMrW3qHDVLp8HooP4T9sr8rU74vGQAqh A3VAuY1JVAo70N06P61fAfzbtHpY5MoJmQ7E/7PD3bTWMdAnxsUE+LViWoDxzIzKL7jk 1tH/k/LagmTghefd6JoIbLnnH8bKIze7K5IrjlL4TDk/q+0ZBEVvE/2afTLG3dFCTAca 6xrILqdVCoJtTB/9Fks36emAATPVhZCTci8sLeU+cXF713ZVzADwL0IuzuH4AHPgvOz4 QgnRGFZgirV8Yrpx72XVpsdzPxF64KxWTa9qYzuzsiPuVHckb9in1IqaO9M/ROs1/6Lo K9SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726495142; x=1727099942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=B8DFh8aRNqTogbHWkmNbLqtMQRCoG/E2xom34H0v6jBe3sRboqFDMIsf7uR9KMNKn/ htxKbeF/teFRD9RB6kp77VDOAejAoUB76Xb7K6oac/+vgX8cGbZsANwGEXQKJKIRxauD OndxyV5EgTsq87oW2Og0l7hFCaPeG+nTjPIGpYwz80hC0yXOkm1pHQbKu+ZKWrK7GDc3 78XRKFGflME+JHICCdwOShru+FlAsHs+JTK8OBRQwqtTDhxFTE9u3oYKU++JzGneIPhJ 0fhyuVcYRPDUHg44d8B+W6IGc027MM4QPpXYMv8dr2/NIA2fiNp+LGKxW68QCbKVDlJl bnvA== X-Forwarded-Encrypted: i=1; AJvYcCUCdLC8AJYogyCk4ndWsmSp/Rknx3lJUQh4oJna8xrfKyFdcftZimvO3jdVoy4sedBnQW0Rwgb1Wbi1cJwecJie@lists.infradead.org X-Gm-Message-State: AOJu0YxljinROw3jd9hBNjY3ii6cEV7aJsTqsY0z0LZCxjH9sZpME9Td /fFTOM/hFUZ3/45zwiTlosvxUmOKvLNTtigkZV1UNdrzBH780HN+8VcjnyvuRCk= X-Google-Smtp-Source: AGHT+IFfOYzBBBIIYNJK+kjCt+IJF25ig0AQEKRujrUPMLsjU/dSM9qgZ9BqDjeZ87bsAcUXX6zC2g== X-Received: by 2002:a05:600c:1d23:b0:428:eb6:2e73 with SMTP id 5b1f17b1804b1-42cdb58db62mr120870925e9.29.1726495141678; Mon, 16 Sep 2024 06:59:01 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73f62dasm7285098f8f.49.2024.09.16.06.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 06:59:01 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 7/7] perf test: cs-etm: Test Coresight disassembly script Date: Mon, 16 Sep 2024 14:57:38 +0100 Message-Id: <20240916135743.1490403-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916135743.1490403-1-james.clark@linaro.org> References: <20240916135743.1490403-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065903_894726_BF8C1055 X-CRM114-Status: GOOD ( 17.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Run a few samples through the disassembly script and check to see that at least one branch instruction is printed. Signed-off-by: James Clark Reviewed-by: Leo Yan --- .../tests/shell/test_arm_coresight_disasm.sh | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 tools/perf/tests/shell/test_arm_coresight_disasm.sh diff --git a/tools/perf/tests/shell/test_arm_coresight_disasm.sh b/tools/perf/tests/shell/test_arm_coresight_disasm.sh new file mode 100755 index 000000000000..af63e3757cb0 --- /dev/null +++ b/tools/perf/tests/shell/test_arm_coresight_disasm.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# Check Arm CoreSight disassembly script completes without errors +# SPDX-License-Identifier: GPL-2.0 + +# The disassembly script reconstructs ranges of instructions and gives these to objdump to +# decode. objdump doesn't like ranges that go backwards, but these are a good indication +# that decoding has gone wrong either in OpenCSD, Perf or in the range reconstruction in +# the script. Test all 3 parts are working correctly by running the script. + +skip_if_no_cs_etm_event() { + perf list | grep -q 'cs_etm//' && return 0 + + # cs_etm event doesn't exist + return 2 +} + +skip_if_no_cs_etm_event || exit 2 + +# Assume an error unless we reach the very end +set -e +glb_err=1 + +perfdata_dir=$(mktemp -d /tmp/__perf_test.perf.data.XXXXX) +perfdata=${perfdata_dir}/perf.data +file=$(mktemp /tmp/temporary_file.XXXXX) +# Relative path works whether it's installed or running from repo +script_path=$(dirname "$0")/../../scripts/python/arm-cs-trace-disasm.py + +cleanup_files() +{ + set +e + rm -rf ${perfdata_dir} + rm -f ${file} + trap - EXIT TERM INT + exit $glb_err +} + +trap cleanup_files EXIT TERM INT + +# Ranges start and end on branches, so check for some likely branch instructions +sep="\s\|\s" +branch_search="\sbl${sep}b${sep}b.ne${sep}b.eq${sep}cbz\s" + +## Test kernel ## +if [ -e /proc/kcore ]; then + echo "Testing kernel disassembly" + perf record -o ${perfdata} -e cs_etm//k --kcore -- touch $file > /dev/null 2>&1 + perf script -i ${perfdata} -s python:${script_path} -- \ + -d --stop-sample=30 2> /dev/null > ${file} + grep -q -e ${branch_search} ${file} + echo "Found kernel branches" +else + # kcore is required for correct kernel decode due to runtime code patching + echo "No kcore, skipping kernel test" +fi + +## Test user ## +echo "Testing userspace disassembly" +perf record -o ${perfdata} -e cs_etm//u -- touch $file > /dev/null 2>&1 +perf script -i ${perfdata} -s python:${script_path} -- \ + -d --stop-sample=30 2> /dev/null > ${file} +grep -q -e ${branch_search} ${file} +echo "Found userspace branches" + +glb_err=0