From nobody Sat Nov 30 02:29:53 2024 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 859BB1B9B46 for ; Thu, 12 Sep 2024 15:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153954; cv=none; b=ksW1YLTX5zBx3CxqXf75E58fKDUuw35Fsg8zwMi7lq2FERIeigtFwCVFv+ZfE/j9n3OCwrwcyqv1EFbNlLbofd+8BDDFT3Yi0F5Ophv/z022qSsP4fetaH5V9qUt/RSt1f+fP176D4iz67Fm1kEPr9JNv13sBCCHBxI5Oq1TU7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153954; c=relaxed/simple; bh=BLyYNeKHXpaVRY3LVG7/JvVL5e/xrnUw/rEHeYJPcz8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ceBbtI2nL3akJjst6dX/AvnSkU3av9gfE9Abm69UjJCW5TcRY/FbvPxgfXpuLnsswvPUZtC8SAPwRXYCEnhTV/hDlp8W15VobGhRjZZ4FQ+Yr8F0gh3Xw1trPMvJzAdGbtPt6R17O2oEVIxkBqgmJQenli/yUc79bTqWBJmdhdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=s1pQwTD1; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s1pQwTD1" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42cb60aff1eso10399735e9.0 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=vger.kernel.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=s1pQwTD1sSGKbewqLBV5WUzMQk2nuWFhI9+wOf2+XVsHKIAr3Ib7P8TfojIfvQM8W/ QA/hU16yHywCsMdJ9QwvqjXRgncJhi4nHxK2PaLjRRXfJqhmSwD8tA+qvaGWvjUBmp7k HTq1ru0V+YeCWeJ3CRyHh0MhpKaXxlgzwUe51mv3jxq3TB21ele0fsz+TWKbTaibQyzC t9F4HuBujLflXWhjjvuBFsdFihVwib37PbfasIgxfci1V/4S5Ti5X1+r1MMhHfN4+37d qJhr+6a0VJ43lXSQee1uWHSRgCiLQ6MlLhjMHQr1SQvWc6X5b6kNcok9ImsFjE1R2eiQ rdlA== 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=YsJSwLA9fR9OmXRly+6nVpDSzianwwcSLet2vWd/BaRIAOAHBD4Za2z4dCXTAv6U1g 4ze1EBNCTEM2beK1/YZUNr6wIfFMGJqNTfQmu/IpkeShGc4/InGbTiMS+5J2NfL/WDd0 f5E2koQ6jBG/K95bQwx0LySsGoDpLY2qdsHkJYDUVdHTDN0iAH/i1u1YfEFKXWPWvL96 sFS2RPmuB1IqrgbDMmNguCgixV3lutoBVik9YLqoI184cUZCkX+NhZYqKeiUOfQYmUjE ueEyLwj20wmfDNlCvQfCEnTIYRKGLsCOUGmKZKhJ7kRI6QD7xr+w/jIK1xPeaHNtr4vx AP8g== X-Forwarded-Encrypted: i=1; AJvYcCWTGh97FItafOBKDp+p55nWNJsSwPDGp206iTgnW7uts0vTvlYdvEAn5HH4V68kOGfk/u0TEdt21TuRqaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxL639r02KdHw67GHeByy6PndYGbDNO1my6Fk9zJ+pltdcrj3h4 27v6+VnHHaHGCbZZaTgSIjfVTha9QKJKTbAuR52t2LroREdjn0X2hbuOErrps+0= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D> 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 =3D> ffff80008011cadc update_sg_= lb_stats+0x94 ffff8000801117c4 cpu_util+0x24 =3D> 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 =3D> ffff80008011cadc update_sg_= lb_stats+0x94 ffff80008011cb1c update_sg_lb_stats+0xd4 =3D> ffff8000801117a0 cpu_util+0= x0 ffff8000801117c4 cpu_util+0x24 =3D> 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 Tested-by: from the reporters and probably from someone with access to --- 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) =20 /* Ignore return value */ cs_etm__process_traceid_queue(etmq, tidq); - - /* - * Generate an instruction sample with the remaining - * branchstack entries. - */ - cs_etm__flush(etmq, tidq); } } =20 @@ -2638,7 +2632,7 @@ static int cs_etm__process_timestamped_queues(struct = cs_etm_auxtrace *etm) =20 while (1) { if (!etm->heap.heap_cnt) - goto out; + break; =20 /* Take the entry at the top of the min heap */ cs_queue_nr =3D etm->heap.heap_array[0].queue_nr; @@ -2721,6 +2715,23 @@ static int cs_etm__process_timestamped_queues(struct= cs_etm_auxtrace *etm) ret =3D auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); } =20 + for (i =3D 0; i < etm->queues.nr_queues; i++) { + struct int_node *inode; + + etmq =3D etm->queues.queue_array[i].priv; + if (!etmq) + continue; + + intlist__for_each_entry(inode, etmq->traceid_queues_list) { + int idx =3D (int)(intptr_t)inode->priv; + + /* Flush any remaining branch stack entries */ + tidq =3D etmq->traceid_queues[idx]; + ret =3D cs_etm__end_block(etmq, tidq); + if (ret) + return ret; + } + } out: return ret; } --=20 2.34.1 From nobody Sat Nov 30 02:29:53 2024 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5306C1BFE15 for ; Thu, 12 Sep 2024 15:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153959; cv=none; b=Qq4yo9YhDPoo1/lRzQyYC4IPKxDwllhqZg8dRkYu+9BQc0/lcOXycP3cYK/Spb5aeYUFPskfzCh4gNs48zqjCPIZ4+1pxrP+D8wsh8yUBozfdGwFiY+wjkQgaWTUQk0J8V2XX9tgjv/T2AgBshkEysUERW/gerWQL7wlfa9/N8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153959; c=relaxed/simple; bh=PxZK1UYoQiEz/5XZdh+TkbpX8o1b6IrqnscJH918Tbw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bp5YEK13i8BQCENS+pK56sqBka56QfkNM5GvPN3EBjfnYffC0BOtEGdZDUkNLzLN+WhnY1wVWRR/Kg4wMvKWXUB+7QEWJXgVLGytSk5UPc7eVvXUKixy3Mevq114T/d5BWuyTGdz2y5t8eMD2jykD+DQ8946Gpm9wo9yWF6gbhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=haeZG2xR; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="haeZG2xR" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42cb57f8b41so12422275e9.0 for ; Thu, 12 Sep 2024 08:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153956; x=1726758756; darn=vger.kernel.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=haeZG2xRiPkrqPRqk1/pqTIXkoDuFc2yaDAfb+EHoJr8xlDCY7NGhZAtmuNq6rxlna xCqVrDPrmntSkw5Nhk5ZFJoL8l2vZSOiRot/Ndwvm2lIAJ1sCDbtyxF5llJr9lf2vPCp HeXdQd50UJII7b7ml8PKfvNW1ztlwoCmkpJrayQPbRwPt74O8+oZZqNeb6RwBq3nuDEW UO7r9ZE+3DhhJa93kbSzghxoJ5l+IOK605ut/UR2PomhMrsLjjermix8txkCnH2uvx+O QK9xmcfXSzbsimT/m5mSOmavZEjwKtzc2+dAsGT+wO4GUITlu3uWWgrqc9Y0J25mt2+p 1taw== 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=If2OsdcbJBnRo3PpACV3C/X2OsH5yn6fDfu7efhFsJOM1LRLdlIWbwRC3AwaJYnWm/ kFvooE+i9ilDCSrClr8H3fSlRdVb5MXNufE3vaW5yc5LBJQxrEoh8au8t9v+mjFwhcxS qY4GahIRtjLocNz6yoxnqifmlAkgfJT/5LKkVwiRQykpVBg6M74nSGd1o1VwDRwQQcfg rtL1TPhk9qgjuddwSAs6WHM9o9+CfMEhh0kQ9LvfMbSe9n73BH41q55a5ZLnPgGaRJXO H6syC7kBMQsOAUn3PvjrNxIKJsblr78zNAE2uZtIuk/QpDJ1yZQgtt9ulLQ3Ujv+ND6F HG0w== X-Forwarded-Encrypted: i=1; AJvYcCUkFGrFk0E9g8nGx/8S73+BL4AnX2RzkeZ1e+bxBanY8FGXhaJ6yJ2y7JFiGbd9iseozV1MJDROaX2y84w=@vger.kernel.org X-Gm-Message-State: AOJu0YwTmsRbfNv5h7Yc+Jz82g80E90qLnbL7pZ3iyaoscHgTPd0VPdX zxW6vjVjC7rffgKKKrUxnTKX5saF/4ziEwdekPN6O91UVMe1iRWwyq5U3mzX2GTsGir6LUymPqB jnu0ueg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: from the reporters and probably from someone with access to --- 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/u= til/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_decod= er_params *d_params, } =20 if (d_params->operation =3D=3D CS_ETM_OPERATION_DECODE) { + int decode_flags =3D OCSD_CREATE_FLG_FULL_DECODER; +#ifdef OCSD_OPFLG_N_UNCOND_DIR_BR_CHK + decode_flags |=3D 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; =20 --=20 2.34.1 From nobody Sat Nov 30 02:29:53 2024 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D741D1BDAB8 for ; Thu, 12 Sep 2024 15:12:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153965; cv=none; b=cVbpvJ0xy9e4M9sgMhmhXOGCTipJnU2NQpJyx373onibpvFi5mJUWNxqRkURCmaUVFBS+PB7wozQBoLcK3xTyQNIOvwfvfHcSOHtnEXWO2kM98UjgHhSXtPmOMRyRkY2YyeKV/lfvx4T6tkUlEOphT7DAPEHR7qpsM3HMX/0Kj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153965; c=relaxed/simple; bh=HzVLxxNDCC58aJIsJSeqkv1E21FxH0Gn8OwOLut/Kr4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IcwGOjPpAUhOk8Vd4gSWm9M/x+wvIXqIYlfWdYlnwzfWgm2Rh5LGPCScn0EL7YUmKCny0XwA4xM17/zL+ZN5MPfwc44Zj8gIDh8JixnycLlwn++IjP+Kd3Bu3S3NXuO0EjghaMv0Z1MeaiYP0r+PdAVqk69zy3O36A2CI8trWwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ltLCRag6; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ltLCRag6" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42cae6bb895so10289025e9.1 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=vger.kernel.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=ltLCRag65QQgrxT0EZksyH6zpTHcQSouOON6PbB2rm3gPI0eUGordxuJoLyzLadJSL /PnI3zbnNzZ7OGGb3AVSC13EPnSWJHcugXSg6wH96gunJZ05LBm7fBOdrdMDTm5oa9ED 34Z0GXK/WB1VQEJKaG5ESY9z+CMu6X2CjMTVBo48FLe2eKXdx96A0wYfHQ/UXyI4lVxf V78e5MrJKjCTe3YNzWVK/zhSku1Nv6FKfH48ytj00pg+yKwiwRTqx+FNKvAK5jLGCNvy 3ViQhxE2horxwnMNWMyAa+BK6znBILNlfuj4b2bSjEA5wpfZOs0Nj4Wz62i3hqKYQ5F0 1gWg== 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=whSqqiiEEQiYlu8uoM27m7lxtCENDq+9qZiIY6YYur2/N3E9rLTMejfyQs96pP+qR/ bCAMQQJA6tCoAt0Or+Sks1umTTmZC7FH8rJ99jB09m/qGVs3brAbAk4kz5/TZwwXHAOb Ubn8ikpv8127y0QMmUL5MtyHp+1csJt94D28kE5zz7EA9DQBn98Rn1SDs5vpGZBHSqlw YX619ZUgesTymJ8+od6mxB1Q5xQ3frdYlBzyfNFs+IbgHZ7fBYQk69LRGV9qODgYj7ru EyTweieli444ppp/3PrVzx3A5zqzn1rzqRRmFIiP1PUgrR7iA+kw+Zk92gwerlLjpLGF iXnw== X-Forwarded-Encrypted: i=1; AJvYcCV5qP+SnRJIwBoQCRzYgB5WPcX3F3/RIXsvpI4/07Da10Uoxx1PZqY/XM7kOxsneErDOzZaA7v7vn3zJx0=@vger.kernel.org X-Gm-Message-State: AOJu0YwuS/oDiQjkvS9qmtju/keYCDbZcPL5GEfay+WpufQhLNRtbkSv brBa7BWxaeFEgv/CmgkfEDNLi2h3cx9mA+S9+M1ZU6fJn7JaW7ObsZIsORhua94= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This can be used to get config values like which objdump Perf uses for disassembly. Signed-off-by: James Clark Reviewed-by: Leo Yan Tested-by: from the reporters and probably from someone with access to --- .../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/D= ocumentation/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 i= f 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, sou= rce_line - + perf_config_get(config_name) - returns the value of the named config item= , or None if unset =20 Util.py Module ~~~~~~~~~~~~~~ diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/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 =20 #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, Py= Object *args) return perf_sample_src(obj, args, true); } =20 +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[] =3D { #ifdef HAVE_LIBTRACEEVENT { "common_pc", perf_trace_context_common_pc, METH_VARARGS, @@ -199,6 +209,7 @@ static PyMethodDef ContextMethods[] =3D { 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 en= try"}, { NULL, NULL, 0, NULL} }; =20 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= , ...) =20 return d.ret; } + +static int perf_config_get_cb(const char *var, const char *value, void *da= ta) +{ + struct perf_config_scan_data *d =3D data; + + if (!strcmp(var, d->name)) + d->value =3D value; + + return 0; +} + +const char *perf_config_get(const char *name) +{ + struct perf_config_scan_data d =3D { + .name =3D name, + .value =3D 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 *, vo= id *); 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 *); --=20 2.34.1 From nobody Sat Nov 30 02:29:53 2024 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 776A51BE227 for ; Thu, 12 Sep 2024 15:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153972; cv=none; b=QLliniQnCiyDgDJq2wWhWByiZHx01dU6IJrLNwtefAPtUxcBcr7MHbGgLhD8rbbeSWRNulTq6BeNFfDGgdf0rrbD3uCUyp6ESqfGH6Me3sb94qllbDHnZQ4CeSAoGcbvLjDEpsILF3Ggq6xh2FILjDkozMhQ1MO74ggvnYPusEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153972; c=relaxed/simple; bh=Ent3NPYjQTNnHv+iKIcd7ubFUpZT8IyAhhOTjZikImk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y8er0h1+NmdBSx+U9Zju14yXHFUelcvhLJJ0Af/RUeHaVb7IsDfQHbyA1TQZoH7wU1jA6e5DYTLqgekTbWRPTzmsWjrb10DHHSHqdZ00rVPI8NdkiFoVbgD4sAEo+NzdEiWFQOJgwNt6MMF+CTc0YeRyqF8+FYiU3s5BJqfWwV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=PVx/dzlS; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PVx/dzlS" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42ca6ba750eso6905155e9.0 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=vger.kernel.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=PVx/dzlS6y6TEKgYPMrbB3c4pb5gnR9KN0ZVJc+S1kwwOmduIVRbLafck4XNSa8gMf jZWcSo+BHnnnVHjDyds25Ut6M6yIjCBDR2HuyK2idHZreJbeLoKLJtuxERriia7iPk75 ST86mER2a7v1QiR52zqbbXKPhggYbm4h4oF7zhOwbWBguC7cHqJmEEOmFinbIPHCrwyi iDr7xbTlFkgYwY3IMzv/rswYrHhGPi03HKlr4vFDr1nH2xFELCiqocacHvDkXNWCphr3 kvMXzeICpnkgB4c+jCCHmXCTE5nETTuKXoCgFt0rUGbBQTHe38ByaCEPuGCVSICaO5eU FeuA== 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=Q9xQxtMuCZPLHRqv2VDFUYbKEj54PU4ufaWmucucW51uGeVyxEvb4TSU3WeDlcG+FH +tea4PMtjEM90YJwUY01FWxHX0mxio99yfQ2b7l4bGtjUl22RF3Zz4LZegATOyw0s5bB 4SwY6lTa+ZtoZTONUEpOGw4KVjJmEawofy/Gug+Mqn6XypXzKctKDQLIfREbAMAq26Dh RmodpDrAHxxprQc6ypR2IcJobY36fe4cilpTUxDzj1rnjivjbzKiQyzpLfTtOkxIzIOG IBk+AYxxwzTd/bMhUmhvM+LXxNL65pHXK1wT+27dxPtANMRARcaS5f914dykh8np3wUF mIkg== X-Forwarded-Encrypted: i=1; AJvYcCXxbOZd3udKJSeDTSffEmvm73XxjJbu09U8pQ5E2qWrareRBbN+EyWTXlfr3Enq/tUbin7YNy14y4qFZMo=@vger.kernel.org X-Gm-Message-State: AOJu0YwF0fAVwYO27stu/Jq3CwsHKmxc6BIZIoGzoxl5dQbO7t40GRrC xweCZJMo8sAWknJdXuuzD/SmEt9eVCP9d8Y6Z7rJR1xgKAq2lcadf6QdVX910DQ= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" optparse is deprecated and less flexible than argparse so update it. Signed-off-by: James Clark Reviewed-by: Leo Yan Tested-by: from the reporters and probably from someone with access to --- .../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 =20 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 =20 # Command line parsing. -option_list =3D [ - # formatting options for the bottom entry of the stack - make_option("-k", "--vmlinux", dest=3D"vmlinux_name", - help=3D"Set path to vmlinux file"), - make_option("-d", "--objdump", dest=3D"objdump_name", - help=3D"Set path to objdump executable file"), - make_option("-v", "--verbose", dest=3D"verbose", - action=3D"store_true", default=3DFalse, - help=3D"Enable debugging log") -] - -parser =3D OptionParser(option_list=3Doption_list) -(options, args) =3D parser.parse_args() +args =3D argparse.ArgumentParser() +args.add_argument("-k", "--vmlinux", help=3D"Set path to vmlinux file") +args.add_argument("-d", "--objdump", help=3D"Set path to objdump executabl= e file"), +args.add_argument("-v", "--verbose", action=3D"store_true", help=3D"Enable= debugging log") +options =3D args.parse_args() =20 # Initialize global dicts and regular expression disasm_cache =3D dict() @@ -65,8 +57,8 @@ def get_offset(perf_dict, field): =20 def get_dso_file_path(dso_name, dso_build_id): if (dso_name =3D=3D "[kernel.kallsyms]" or dso_name =3D=3D "vmlinux"): - if (options.vmlinux_name): - return options.vmlinux_name; + if (options.vmlinux): + return options.vmlinux; else: return dso_name =20 @@ -92,7 +84,7 @@ def read_disam(dso_fname, dso_start, start_addr, stop_add= r): else: start_addr =3D start_addr - dso_start; stop_addr =3D stop_addr - dso_start; - disasm =3D [ options.objdump_name, "-d", "-z", + disasm =3D [ options.objdump, "-d", "-z", "--start-address=3D"+format(start_addr,"#x"), "--stop-address=3D"+format(stop_addr,"#x") ] disasm +=3D [ 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 =20 - if (options.objdump_name !=3D None): + if (options.objdump !=3D 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. --=20 2.34.1 From nobody Sat Nov 30 02:29:53 2024 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B201C1BD51C for ; Thu, 12 Sep 2024 15:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153979; cv=none; b=AvJgN3mypZ78FN2OL+UY1zNbGkJEyzRhq4y6StJVqp6AAa4Xi1HwwxR2wnRUR8pdz+gkUq3Vje/vtwfw3tPFes4/fiHjSBbnFvFMm3W8L9ZMc2YVP/y//k/jaGpHwUohYEXuyilvObGBXXsoWJgjF6F8niP0FL0TfKVx9s6WiuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153979; c=relaxed/simple; bh=bR690mMXw1GA2mO1jEEJOauZ9J/eD8W1OUd3Hv1VNaI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ROYpuqwE/AlQSq3YO9+/h/qaOtJ7qA30tLJJH005MlEZxLd1Rrmm9C5Obi0mFsiSzO4n+TXeIUgJOZQYeboaCG9q2rWDd6tsigOrwN3xLLBqteZ4g+msFAgezA0ke0qX8gJuUvGmNb16yOeJUdiN07K1t3VIh0mNq7Vpq13L+Qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=q91+z1+b; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="q91+z1+b" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5367ae52a01so1031453e87.3 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=vger.kernel.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=q91+z1+ba1auBukQsrVJ/V9Fjav32n6sVB4gWduRiJ4i6tGw8zUFOLAG+4EsvjGGrd YyZR3td5kqhiX+SrT3cCp6XurSuUrCUVHs99rAaUzcASxCzk0Qn1UMaCFxksHaarM+ph e/bvSMH0XiaLkxWVchGO2batFGVTCRbNzZEIJFCpcaeYqaRpUdW+2CAopzMe4+Bb1ZwQ bgrghFSON8kBg3c7CIv9K0fc62UI5q2vR/J0QTzcOxydOXKbTCB+7JvlnzFGbIat8Lrv oxz+4n6o0ljJiiIUHo7bwXK4cBZlEuEVutd7vis18hU+iCEyTvRhYHm+QwXlicZDNx3W EoTw== 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=htLfKYqTU5Iu/yST5GQ4PAZ+QCYuMu5OxaL0OsBc+ZVLw9Ia/Gc/UY+FRBRqhs3P4B zzTXT4bcDEtm8U32k057g8vVIE8ZMhL4Kyz37pmlLaVt1TIUK3rnJlyJ7hH7kcGBpvf9 mLnzThKxRGHGcu3Mab3ajpWh3CxJ6sS9cAElAX2s4UqvZPqMpyH7bkaEph0BYzvKLFeG L5a6sFqluGmxKLAXVrm0oZniMO0igTNwcxHtJ5ugPtUy9/oAbJ6bWwyWc+HGWJfB2A8s fRdM7A0VRSSmwCkr0WUinpBFdjJquM7MaT5MC/Au7zz97QUHuE1U3L9o7NuhUH/7W3OY FeNg== X-Forwarded-Encrypted: i=1; AJvYcCXk1OzsyBKK06PYhAiX8n30ESDhf8IBbEuEgQ41Cri2QN00YV0lPh94wA6mEFkqVKcaGCOG6gBwZwyB7uc=@vger.kernel.org X-Gm-Message-State: AOJu0YxIU5TbkCg1fj9vzTc6J0rwhQiMNagY8SeiDXo5HUYE839R8mff QPpfooNW78JM1ebbvcKD+TsJLUHKPZSloiPCUo8XjewqXXTBdWg4FfsPkT2KD4E= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: from the reporters and probably from someone with access to --- .../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 =20 -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 =20 # 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 =20 +def default_objdump(): + config =3D perf_config_get("annotate.objdump") + return config if config else "objdump" + # Command line parsing. args =3D argparse.ArgumentParser() -args.add_argument("-k", "--vmlinux", help=3D"Set path to vmlinux file") -args.add_argument("-d", "--objdump", help=3D"Set path to objdump executabl= e file"), +args.add_argument("-k", "--vmlinux", + help=3D"Set path to vmlinux file. Omit to autodetect if running on sam= e machine") +args.add_argument("-d", "--objdump", nargs=3D"?", const=3Ddefault_objdump(= ), + help=3D"Show disassembly. Can also be used to change the objdump path"= ), args.add_argument("-v", "--verbose", action=3D"store_true", help=3D"Enable= debugging log") options =3D args.parse_args() =20 @@ -45,6 +68,17 @@ glb_source_file_name =3D None glb_line_number =3D None glb_dso =3D None =20 +kver =3D platform.release() +vmlinux_paths =3D [ + 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 "" =20 +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 =3D v + break + else: + find_vmlinux.path =3D None + + return find_vmlinux.path + def get_dso_file_path(dso_name, dso_build_id): if (dso_name =3D=3D "[kernel.kallsyms]" or dso_name =3D=3D "vmlinux"): if (options.vmlinux): return options.vmlinux; else: - return dso_name + return find_vmlinux() if find_vmlinux() else dso_name =20 if (dso_name =3D=3D "[vdso]") : append =3D "/vdso" --=20 2.34.1 From nobody Sat Nov 30 02:29:53 2024 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77D6D1C172E for ; Thu, 12 Sep 2024 15:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153985; cv=none; b=ins6BeT6v1pZG5LskPCfFgxGlxLA7mQw694HgWN/4hZLnF0XWY2I9MlLLY1iVr4cW1zeSYyCoK4A6YRas3Pcj/gRjOhcu11n+YBLX97n25oQQAD0DqLz5sSx15GbP94ft1X1JjWgo00KBGxZ+oC/m1UmqaRgnBwAVkBQ1zWMNVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153985; c=relaxed/simple; bh=M/SxxS1EV5YiH2L2D9PMSuM/xyixk2ltobd2ktIOQbA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b+zsnilUMQxV0a7asaxzEc7ZpVBO/D+yhwolvgO3G2PtgTJAu6AaIvWrdtzR8i+Dx8w6KGenGC15YkOQXdnflbTBGV9msMAgPm0wYC/n0/G0mS9k1NNtV2lOfHwVLHYYXsA5bXNDBk6CGW9l0dIDXKPOh41vM6zBT0RPEpkWk6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=QXzbLTPc; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QXzbLTPc" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2f74e468aa8so12710361fa.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=vger.kernel.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=QXzbLTPcq2Erda9zCSq4kqzXSrQSzAYZGcWKuaAoHMcA1InmEavdfH7gnWFDZhEzGB KmmDoXgUFhF1NXNRMBiofKvg1JR4cyW4/5AmAHujHCkdB5vs79ED49SkFXKMpibnSxC8 7bJ0AELgOx5pVeyKBv4uuus0QmGUUmGKMJ18cLko3aXiTxiupNuX4gzA+D84Y6T3t4uF y/2rzMrkTtoqHdIFMeuOZbzc7u16JBnVZoQudB7o+IpjV4vUeTsa8lW2ew8562jCfjnZ HoZVmVuMiCx/cDq+rZHu6WIQRo7mys1dOS5dvdBPPsNQ77Tw7qjt6P/6nb85XgKDKJN6 V0gw== 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=CoPqF2UTmXd6drnOIx/qRBq72/qm043JPmfcaM5YYnGZFtDBPaZ1KRtV6ZE6cNuQLc Qo2CaY2f7/SUJKF9N2ucnLpbQK7FlLJKCjSYGSyCoKEC7YBarDlabxVKN8CBdBEaWi2E yyQntw2hnB9IBJb8IiK+BJwodkD0yu+l8ub/mNNlH813kA0kTzntpHNdSuXjpyhUrDJk Z4SNcx6I2TWjrkwJ/6yF4Ivk/6g8Rp0cu0MkXU0Mf2soYYXQxuaOBQO5dce3XDD16LQl shMCXcJk1YyjxkO2JRgCYJh7FTTf1IBa0EHuW6rng3f/DgZiEK3vHPR1wEMGh5bV60FA 410A== X-Forwarded-Encrypted: i=1; AJvYcCXU69hT/VJzdAcEN6FNziZmZIuk7PCJMo2jL5ZXyEd+DIIZx6M/Q4EksCiyuSLgepdWtUUS2An3o3UO2GY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/Bl4U1n3ILg6jxRdRMZerJLOF7j04Pkmg9PP+Y06e6VobgiHz mCqju7MdzSWFGmmX3u6efB48LQy3vO3+v2ABjSPFJqN5d6YEFtWY7VhU3Tlw5j0= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: from the reporters and probably from someone with access to --- .../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=3D"?", const=3Ddefault_objdump(= ), help=3D"Show disassembly. Can also be used to change the objdump path"= ), args.add_argument("-v", "--verbose", action=3D"store_true", help=3D"Enable= debugging log") +args.add_argument("--start-time", type=3Dint, help=3D"Time of sample to st= art from") +args.add_argument("--stop-time", type=3Dint, help=3D"Time of sample to sto= p at") +args.add_argument("--start-sample", type=3Dint, help=3D"Index of sample to= start from") +args.add_argument("--stop-sample", type=3Dint, help=3D"Index of sample to = stop at") + options =3D args.parse_args() =20 # Initialize global dicts and regular expression @@ -63,6 +68,7 @@ cpu_data =3D dict() disasm_re =3D re.compile(r"^\s*([0-9a-fA-F]+):") disasm_func_re =3D re.compile(r"^\s*([0-9a-fA-F]+)\s.*:") cache_size =3D 64*1024 +sample_idx =3D -1 =20 glb_source_file_name =3D None glb_line_number =3D None @@ -151,10 +157,10 @@ def print_disam(dso_fname, dso_start, start_addr, sto= p_addr): =20 def print_sample(sample): print("Sample =3D { cpu: %04d addr: 0x%016x phys_addr: 0x%016x ip: 0x%016= x " \ - "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)) =20 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 =20 sample =3D param_dict["sample"] comm =3D param_dict["comm"] @@ -231,6 +238,17 @@ def process_event(param_dict): ip =3D sample["ip"] addr =3D sample["addr"] =20 + sample_idx +=3D 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 =3D=3D True): print("Event type: %s" % name) print_sample(sample) --=20 2.34.1 From nobody Sat Nov 30 02:29:53 2024 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1EFC1BC9ED for ; Thu, 12 Sep 2024 15:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153993; cv=none; b=N39zeg5gwdGp4wkV5brtKwbCYfZSlXAmydbuVM7ylDzrS0ktjIiyb72CqvhhkuHw6Rmio+VdnDLw9pjVs6kCiM/oBYJqgtjNGv2cM/vd90Z7RL5IjG9fjotshKTEzvThTRrSY8EvL7eMzsHlUMC5vupzW0V0BZuCibZUZL0+FIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726153993; c=relaxed/simple; bh=x8bv8lif16GzTLpb0Qa7Ebuoe1yqdxh/JFp2faINf78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F7nF4AhY+RdDiBfmhQOb/cOYUl29LI1jOWAUlS7xNeDYlTgsr1lGxIfQzu7EjkBqncUjZNqVwFohbBYcYUd6tqKMBHkJ1CO7tl6arUZDFN+Uhy+ZulMcQkdkb/CjcocifO4xSYzWJxnZctLZWr0RyzYge8KbmTcDUpNcBaHen50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=psNuG9lt; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="psNuG9lt" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42cc8782869so10258715e9.2 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=vger.kernel.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=psNuG9lt/LcjzWW5r2j927onbXcIwEdTT8gYoPR3YpUPkc5z6MxWpR0hXNkJwgka1z Zhg3ZeEAXyUgnWZjax/vr2Ufz4UdUcv+T8fROmCj7VwIPrqKu5WD2q16wF0Cst2mB2kd 3V0LXBRnhsmVr4uvfl37UCbggZVRRXSm8nWgGJ648VNfV89RupaH1OOhhPZQ4beOVYBH N+wuuqt6r8AQLZW3e4gk7GGE07DEWI/OPifxdBRKPORCRPNS/+NOsP367BsNbH+i0KMy t1JwJw7aT3wYBIKqT95GzZ2C7IJ06s/5CVzOM/3T+YKgkxwjNce7yB1xHrBpnTGXkE4d 0n5A== 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=OE3AOphoiik61JNdfhFRZ8OIdYBsXFmcF3G+ptxMTaf8g/CJ3oyCK0q7VLDfktcBcm CDPsFYFHpLtllL2abHTP0aZyHs/wYdx5Ud3jxyoJQqf/k7yyXqV7SJkpk2cLdGC747nS 7kwvb/A4Eg5Q9dGhB0c7oFwXAV34HfbqGIickN+7o7cP9B9ezYcgV0rPzqrxDGfHVx4/ Uvbk5knITBpS9P5UDpVUHAirhwj5xxBhRXHYBSNXc53ZAlnemkAclGWxTGjHpOiKtRXe bSsTUnatKXQJGM8FN+Yy0jV9o8vjx+F59q1iTS45H+tp14yRROId6daJ7hQOwp80PW9M u6gg== X-Forwarded-Encrypted: i=1; AJvYcCV48VI1Psw5hoh/z5Of/8kOOGJOCxi0sj6r5k82PkSFxoddw65/H7LSVfIn6WkSKGewKWENSuvonOi1Neg=@vger.kernel.org X-Gm-Message-State: AOJu0YxwJgCiUaPkYEjGhxYQTWCWDDpRjbHrfuWFwwFiPjCl0paL+Bo9 +Fi2NW7XL4F83XubwIo9ZT+F3fVotAbAlKCwGpuS5SVbDI+9rknFiXOcLbs6bGo= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: from the reporters and probably from someone with access to --- .../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/pe= rf/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 the= se to objdump to +# decode. objdump doesn't like ranges that go backwards, but these are a g= ood indication +# that decoding has gone wrong either in OpenCSD, Perf or in the range rec= onstruction 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=3D1 + +perfdata_dir=3D$(mktemp -d /tmp/__perf_test.perf.data.XXXXX) +perfdata=3D${perfdata_dir}/perf.data +file=3D$(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 instru= ctions +sep=3D"\s\|\s" +branch_search=3D"\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/nul= l 2>&1 + perf script -i ${perfdata} -s python:tools/perf/scripts/python/arm-cs-tra= ce-disasm.py -- \ + -d --stop-sample=3D30 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-trac= e-disasm.py -- \ + -d --stop-sample=3D30 2> /dev/null > ${file} +grep -q -e ${branch_search} ${file} +echo "Found userspace branches" + +glb_err=3D0 --=20 2.34.1