From nobody Fri Nov 29 18:41:23 2024 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 4145D1591F1 for ; Mon, 16 Sep 2024 13:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495107; cv=none; b=prUh+L3SvOLLaDCz5vn2HJ152TcTbuf4ypWql18ZkAbFZ1FSTxMgtBfnRRnxWPyWSFTfGq3XdC2lGOuBkcRxtr6AH/jrdLcfxqurKpr6yeELWCPIDQyuOizMvS4C8mr1J59EYVxhHVV5no9jHjnpTdewvpKuSyKYWeTApmRy3Ic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495107; c=relaxed/simple; bh=xqzKWqo2N+qrwkny8IWgiAeXyj7BCHbJKMyWllqHEio=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gjwE0cc9QuOcjE/Y/klmP7Yvff3Qy2uMWcsX4+OIxL19+qEDj+UkjgfGMWe98DbbZxfV/KCcE49ZWwTkkBYfVJMte8qPIagY3Z5wrNAUQPZEULI5fKrQXkOWrQhYpdZ9pWn3JrM8geSmmExMsx+4FTF+BdDDPG7K5cSZeNEHg8M= 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=g5C5ZQx0; arc=none smtp.client-ip=209.85.221.45 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="g5C5ZQx0" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3787e067230so3224434f8f.1 for ; Mon, 16 Sep 2024 06:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495104; x=1727099904; 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=umuEtd6TXriWmaesvaUlkUkqPg9JblHlWbB3iYtKN0A=; b=g5C5ZQx0M7PIZ6SlEBGVHMTTHJKcU62m7BbcgxnwSCglj+DPjZZV42A9m9projAnT3 c4dI//kdmAQYHB+iW5NlCsNVrUl63OUte48j8fi1KYUo9Hz6qbl5AwTued/YztOAxvEc /GHAuyBTdoRYwtrmKCLknLRL0uWeNUBFTQsQUCPfoNaGpNFmBhLHq4ZikkfhCEBtX1d2 yMhm0zMfVNmq5FpiPMmZL2I8gQh+1LbRxSAIT3lweSHEP9OaI3mJm5jdGWHWubSEsEfG 5QMn75jw0UQ6S4KmtBY6G+jh7cKrPQPeZ7FVbS3n9AMOmwvAXHzDkL6g6xRywu35QFpe 8i8w== 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=RxHogg+bAI9lLkrLu4xcN6vfJBuqLZmaolBoZKFgdWRZdOmZ4CFJphXUyDLrPkw9XH y+OQbqMTyBuqhOAWXSmwsPV9N3osLXcvkqIhKPfgbe6STCO1C4+G4FRmAV5P1ENax2Km WPfkg8fGj4CRGMgI19DT7lCFY/BnhetptajrEuFhW9e4DvQN37XfUOST1T+sjgJ1yeSd HyZYNsQngbPD2/fi4mD4jtkYfFsVeaxEeeZKT0cMEZSChgW50Y2hG9Yj0tLlHWyBF7pO Ll5UQEbCWmqnDEGBAiE1uD13T7n45x4/y8d/FjEy3Zpx3rAkcyfhiw7N6unSzVxstZMV JWpQ== X-Forwarded-Encrypted: i=1; AJvYcCX/DrZVV2A+Dc+nA6eQ4J62/L5sGIUcx4s468o3OEzbkkWYVbK1dVWhZy5fOwmNiTfFzMmusuro0FaGS38=@vger.kernel.org X-Gm-Message-State: AOJu0YxBkyTKLmFBCdCcdWHrLu/u1sm+ZJr4g/uBtlbqMUqiXd20SHnd rnynTFqRMiWqDJsYsyvEYNGWlUVimLjrUX/SxzLDe2UO6lWo61FXIDFN0Cq9gn4= 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> 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/ Reviewed-by: Leo Yan Signed-off-by: James Clark Tested-by: Ganapatrao Kulkarni --- 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 Fri Nov 29 18:41:23 2024 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.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 BC7E415A876 for ; Mon, 16 Sep 2024 13:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495113; cv=none; b=RyDtEijHPgUZYEegftGJ+bbxYAu3zOGRsrry0WpY1S9o8ZnpZrE5sCUGl86tdQwvym42FLswyk6Iz3auefqBj7zNPRH5EL6ln+Uya9gcezO9UNVh2Iqy7HUHyaxcUN+Wsfw2RBmRNRWxHMSvDe1pCeHnOH/KgjPZf8zjtDx/vzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495113; c=relaxed/simple; bh=3cu2k6gc2jH2QRlu3LXOLx+bvkQ+zgDEXORBnmpwwJc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MbbpxSgMyza8vkpygXa7ED49/v0IGSLpMiDhTPFpa1fs4/ftdshMrUrrxQKrBics4PINJk7wiMg7l4jMuLTMQyp+uzjSiWpS2+is3aBYzYPt6YhNTuv6u4UlvSNlVWByHXAE3LBncVnZFYnB2b8mBfIP50A6H/5+8ufqGYf+jCA= 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=DjAl9MKK; arc=none smtp.client-ip=209.85.221.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="DjAl9MKK" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-374c1e5fe79so3370323f8f.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=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=r6I1ojreNPMnAqnnyAmn/bcHu89TPQPwVi7gpVoP/po=; b=DjAl9MKKA7VI4fhjfFLwW6yztxM5O4IIYnm/UzZJ3is4T6kVz+9Xcgdncx7WvZzoeQ nRk3JaRmIZRO6D6XhiZektTzbF7dBsDWc0/ej4yrk0DiGHo6/ViPa4zR0xYf0L/atFMb 6M3R5+WP7RznOfH7U6yFAvvf+LvwWNFyQ/7MHHSvwH0V8l8Rs6zVcC8M1yE69LGBbN9k GU5Wq57Nn+NXUWD6wgBOMKBkNZQ5TWMQEbqPJJJV89ssIOZWMSKJPpSqmZG/y6neNzYd 1zUNwODc7dRTL3RQFRfRRQcrasvMieIFC6fMyZOHPMyjvfx/97XJP2BKkVxhjxh0BAQy AF5g== 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=pw++0SNEQwh6jYe4lrz6egQ7ltpdt4Dz4NuIibKQUlNnLZzvC7D7nLE7H9MCPA1Qv6 hRHSM925R1QcE3Q4bvvo3/U+fG4tkOQWIcS5pIoHJ5zSK/8gesV4ZOGKYFqABc+gE7vT b9DyLRu5LyHGfB1BIkj3oTvUnKm8tl1Wlf6tAXHX0mw+3lPrxF6g4qqqAU1qGI5shwhn kBMvt+LSebIPbu+1Cr1OodNaDOgIJaeDNXf7ChPrnbI0v2GLCe1EqV4b6penMJ5T3/n0 o6f46yTRQ+HYSvYxdmHnVMEupIQcdJa6Kqpu9LuXXWmE3MaGrD1RNDCfc1KZ+kQbVjKy Asqg== X-Forwarded-Encrypted: i=1; AJvYcCWYkABGYjjmkxB4C0lLkP1mrcwCLEfs1MMybxMZB5X46UofCA+dpgYXpkSD+fRCEZXWsnGvDhZtRv13vbA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0eqmkLvsyhg1r4As5o/031U301S1JfsC7y97dvMlmCsOwhI4o +WaB6nvF9BCzhZnUtXtmCRoRUlElgD1BA2AbeHJn88UNAwHMjOSu20UrGd+8ks8= 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> 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/ Reviewed-by: Leo Yan Signed-off-by: James Clark Tested-by: Ganapatrao Kulkarni --- 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 Fri Nov 29 18:41:23 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 93462193401 for ; Mon, 16 Sep 2024 13:58: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=1726495119; cv=none; b=XLCQtjz2oy9GZL3GBlwXRLOGmN3eaOWk3jJsx6EC4Xl+lwE3DZ3n8U5IcAmOfjUtejKLcvSSeWxkCgFupU+Ts5mcVZL311GZS2mU2HQl9REopNr6rPtc4hli0RxAy6ciJ4r5U4sWGlGaeaNB+Txw+VD/V4awGA1mRHeo8X7gdaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495119; c=relaxed/simple; bh=dTvkJQEBjfJBUyrVZVrGWbpyuBvUrffdGllEAiZzKVM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MBO/h0Zd0ps0BZzAeSAo8sFNS8il0Uz/VrUKMztecMlLbEcbdbtGsaVfPOsG9sSDq6aYRGJNe46LvDZ24DCa6XRdZh/sqb/fGdQ6Mg0jE7+X4560vB5FN3M7ugB68sUgKSP7gD9xQ36ZnNtRnyMW6vroQ5hT8YKlLgHC9spc4HQ= 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=FROTD1lj; 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="FROTD1lj" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42ca4e0299eso34592955e9.2 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=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=J/Q4dm5nWNN2kHtmEV1dKoCfXKla/YrO0a8mdji6DIM=; b=FROTD1ljg4dmaZKS39RnKpYRjH0Zem8GJlBm0U4mcI6woySF9xnX9/sad6nY4nVTad zi3zwfGUWkQvZsNUOim1h0rr+a7Wr7RXgcUeahxGBbOO2S5N6Hrl4OandsrxIG7WFabv skpPfwrb0EWym1D5a+t7PbGhpTjevu4iXLEh0RJtZ3poyb9bP1fYdqtwgho/nN0svrkE SEY7flvQ/wfn3v92PBwN58TgZiAqLZN5sRMA1RCERG3TBEHtUG2dznoyH5LCXV4yEGnA /PGtHZ/QT2c/tUdiUNiTflPsfiNy2y5ru5L9FJAy63IjCb6XXgOKHiZoqStzr+ga/NSV mb7Q== 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=qVtVb4jv1mBYVm52uWCpairO2SZl7RyAAJotTa13NCUCBgdFDMfvrX9HCoJEgM0wpE n37fpJEoPrYgfvKeRLknlSFYESD1ILKnAk7sCAX6zKQdjEUkXawWL4NqiqLWQjNUJLNc D5PXc65MzUzkUJhSJj/JClms/L4+IKvQkvTjNnbjhebo5CmqsWtyXBvX2uYZoDxt1SAf HDKz5d02Ql+H8EscYF8TPMXXe1jzXg4wDXXJeKlReR2ekEjA7ONBTtsFeoXNVDMcvk7P GaCNPfBFJNkr0wE1qU3PBubGZ076vniqjWrc52LoYMyZKm8xtyrPESmCqPiXLqPQiFVC JJfA== X-Forwarded-Encrypted: i=1; AJvYcCUCh2hpvRFUJnk7vKNPTapqar/evwour5bJld2xPW6CYWKEy7uhsyhivhNxKlq8BgGxeDQB8wydk+qtek0=@vger.kernel.org X-Gm-Message-State: AOJu0YwS4OBxufFrYrYWPyMftuNENCtNxS9/UGFZLlP3pNLDR4yCdFpa 4itNmxO+L4PlKPVF1OcaoYFrIl9YCIvSM027J1eLEWsnzm5RMkZ3uzGgzj6LZEs= 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> 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. Reviewed-by: Leo Yan Signed-off-by: James Clark Tested-by: Ganapatrao Kulkarni --- .../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 Fri Nov 29 18:41:23 2024 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 CF483193401 for ; Mon, 16 Sep 2024 13:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495125; cv=none; b=dDbP9WVzyKgSLmaF3/vaEAAdp1wOuKXLJfW+m2KgJuCZAAgUhWtnaOqYEFOjXsOF61bclgVfFW/qzVFKubBdJfU6HMVsvHpLZA/XaeNZn5X7i9mMRWupngIH424WBSrLnxDshAuuDynis+KZCwGvp7R73Fp+Vz98d14ib3nzvMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495125; c=relaxed/simple; bh=7C8D26xIfSeu12DrQ5Nvi9yW1AADGqbli210vQMd9w0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KIYmidZJuAkNdEjFwLLC55cUXGm1Nmq/PLlYSJgfTneRnMlyzB8pwZz0FSxR/ntWH4RZYiRbYHhfexgR+BRQlVaGccrFyFCff8cvEEZn3MOc5nu8rXvdBpKOiwwq4gqIMKgYoPfUiY1OIOYT/nZ2EJBQQh1BaKpLvh6cBJEYl8I= 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=DkZi46vq; arc=none smtp.client-ip=209.85.221.52 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="DkZi46vq" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-374c962e5adso2837817f8f.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=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=lWq/62mWpUAFEk/gBjzNeVY0NoKYK+5WXUTV/6v1tA0=; b=DkZi46vqpHBdHfOn/TWX9vowjdlwFxiEYlpZYoes3uFiLMXA2YoHK8EbE+4vbgopM4 1uPHxOL7hslKINTXrlaQfclPe5cqYjBVTq4JhAiBllsDq/fmOENZBFTJVpkCzad54f4/ zxEDc5ow1r2C/fiQxdTHIIeVQ+Aog6jP2xsqAvl716GRC/88NNKYQJvR7aZhSJ4ddFol 2iHSLmP2A3RSNaRA08wovge7nozXUuzG216LG8ZVxc7TZeBY/7eEgFcPb8otKWVsp+db AJMEIqqHitil7BY/vqJmVA+FDj9a+AtPk2pZWrDJdJx5mUXF3CBN3TBpDz6epg/Kzlsh gxHA== 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=r0H2OSRNa1abBBevGpl/YV0xbtBsq1xGdMfXRHZUD/lVXhoAFy+iekP6x109jxyjy3 Mk4UweA7FuM4dsQL1py6v701uTOaXixoTQngGjNW0MOEW0dyqY1QwErRkegZa7itPpqT EG4PPdNyfF1f2xI+vK1UV6qPMHLkgyEKyNu01CENLioE2waMfL6yYj+uMi6UuA+VtKUm hDI6rm3WyxM66ovuTDE6Gl47ofh3/MNGF8L5bV7KWQUBLJfdyn9VqzaCsirrP4ejEMu2 qxJFPgWeedKLlgCGol1P8NmuqmGG6mtx/GQHmfurDlQxCS51hGs5dVOhi1+g2HK9Oips DFTA== X-Forwarded-Encrypted: i=1; AJvYcCVe73hQKuReJ4t2Xf3E5dIlp/ovF6IFtyuklKRIsXrSFZFIAPWvqKLtzmPBb7OkfZhn2OgRhq/ErbrTVDs=@vger.kernel.org X-Gm-Message-State: AOJu0YwFahf+YP7XuqVrSHFoErkKbK+5P/MO3vdcEhOxDOgLuM6G7XXk FVb+1SKSLoQxo1DGES8Fq8Lgt1e/WYy5qpjoND6TJ5aam2aANv4L0be5naT1Tqc= 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> 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. Reviewed-by: Leo Yan Signed-off-by: James Clark Tested-by: Ganapatrao Kulkarni --- .../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 Fri Nov 29 18:41:23 2024 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 D59F415ADB8 for ; Mon, 16 Sep 2024 13:58:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495133; cv=none; b=FtKrIsEgwIRukk0bsnHvuxnKtN4/6D8ssJh/IfhL55eGj0gHdhncWmTq9DuVGsjpsdCUlH5bucgwEV3TI0YFc3pPDcRxLwqGsuysgn6ihaUyTrUT9RNtxwStIYGbZShZsAcWA4EG6zuQjx9SSprRgJphN6lk1HOKI9xUYjhFHYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495133; c=relaxed/simple; bh=bVkb9Wm6MnZrus/WrNLvL0MJT/HE5RVP/22d/aiAs40=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IuuNdPG2GhmzQom94aV2uWtBs0L8NfyGJTVLUB5xd6z4Q7haiFkwccNSofHA3q2a7RNf6x6f5dVoJBXkyJjBjXngRdZX4qjYkKpdw4fzHIMQR31TN1oc/7D1etuVYpe3g8BV0DnvEO2ECE/ZA7dE1wFNu6Be11zS58rqX+KcaQ0= 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=IAKisCmk; arc=none smtp.client-ip=209.85.128.47 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="IAKisCmk" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42cd46f3a26so26662495e9.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=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=wQSiMvQctmr2VbpvZ7u0ZKPRwr2TQbe0lgGJUjSaHZ0=; b=IAKisCmkI6ef90IbnPr006ECpc03SsIfM1cRWs/0vfQD52qYJVCfw04b4QQhx/A8n2 jv+tFQepRDok6+rP6adaXkVrOaNwT7aB7AR5YwvzQzDldUj2GZR/Iw8B6C5WBrgNP/aD +ocO3VhhBtK8IpkgKKajwEOZNufNpEtf/nZ40j7yILJ8P39vzPd5lvA0P+ui7V0OkoSl FQElDsrTEj7R9X9+s8XtgIX4VfLaWpO7uMTZkm8YFxWpwCaMOTDBvJu3C46Qvs7IucWo H6ha0h26QKRwpzIxAde/sgnSMPpBelwj8oW6dh8FidhmvZ/w6uNeZ73ELZmWWOLSJv9t K4iA== 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=APOhgNkLn3a+duiiOtHB2gpncAsxa9fEob/rT+OCxOkYL0fwOzycMn2LXeNzKKAzBu 76KvZaxWmVtPaqH1NbgVvgSvzDdApv5R4zl/EaRsE5zqAhNywLoOvW6Iq8f/0vRRmqIA kkLhAK80kVqmVbjcaa/BQ5IeKK12ENRyAGFM3yV5KIQ2Qg55GV+cnjiRHGsOu+ewfkX8 YsLUFxgd6VkLA9QP71UffMZdB2K+QULigCo06IvK+lPj01Xx4Zqaq2pntW5uVEGrcQD2 wFu1N9laL7wF8Jpg1ar7izkzzlYE13791w+0a18ggLvX9NfWkKxsKSu7BwTSHPybXwYU zm6A== X-Forwarded-Encrypted: i=1; AJvYcCVNVuTewkYZ6Xnk5J5j7eirj8ftKO69fdQIbs+Y6TQbwPYkiEgn7Jd24vg4wVRzrNAe1kx6QOiHjBa/8pk=@vger.kernel.org X-Gm-Message-State: AOJu0YxL7a1qqgVaCwdtkMJZ9KDFLphkD0yi/o33UuarxWTf+j1WyMuF eNyhywUEx7tf3P5NA9cotV+DQQp2WYfzqgfsw2NmP1iHwlScll5kLteG5zTX48Y= 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> 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. Reviewed-by: Leo Yan Signed-off-by: James Clark Tested-by: Ganapatrao Kulkarni --- .../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 Fri Nov 29 18:41:23 2024 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 3CE7B1940BE for ; Mon, 16 Sep 2024 13:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495140; cv=none; b=aFTuTWhm9Up6V+fSFASVU8qErkdheDc7Tw1J2HG8fX+SdkrRr75XsFlmW6Z2w279VWjhuAmmpmH0YtdRnDSHBEjK2WmaoKuR5I/dZGUy5B2/j/+jxTrcy9IlFfqc1fJHQKrime8KbKhCbsTDyvsnNwXleDMaHqWNHMhidJ4lRUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495140; c=relaxed/simple; bh=vdLgIo8GePp53xw04KnAQCJh5F4oiBViPbxwtI67iKQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e3WfdPUZHb03ePCLp2/u03cJXlVKEgFUWCiqtmcI7NhdFRYyHZzU9c+ef/WuiB234WRYeu1pGSBit5hiRowW1g5vSM5rDU1MdfLbcVXgNuSUuGZ+uDTgDgNJw5a5EVkU1tg6Tfska0IvfkWMlo2lfw41GZLcLzJXopyIZYW48ak= 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=EkoBby1/; arc=none smtp.client-ip=209.85.221.52 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="EkoBby1/" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-374c7e64b60so2685711f8f.2 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=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=8AtH/7E9TP7UM5eLIlL+QC7O7RdXR/ljZ9YaSiv2f5A=; b=EkoBby1/YraoUcAQyMtJSNzAqzq+a9n+Icc4U5LlfHmDHRyzquT15WBT16uD4nUwUw /bE/kwGv001Q0CbpiArwV9dsqWJKv+mzN7PcvFTLPhjp7srShEgpunlU9Scxy5xoMxuM 0UEw93nvowNhUdy4rsrJEbIjIzXgP6vDSLDIIefnbEwabgFp98Y7W1CyNQbRMnBwb1oM SxOlCi1nwNY93hYI4UcttC+B1oENgVC7KzDkNpRlQW5N1aMcta/aDrVw356xYnmy5eY7 JnundSiLAbSfOTzScGJh4jPWYAEIEe1oKWwerPkbZ54eIRlr099ZGF2HBTdJ2H9VF9s0 JFwA== 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=GzdhzJwAEnE0DZsjqld0SQXh0CZWNt9dYx+EEJLbJf8Y/gc47D7IAlkU5hDPpSMAme 98j1s7oCcFOvhZMi0amfaWC5TD+lSefNVwxWNya9lDFPwdo4Ad4Xah1VmIzKdQtdUhtd X8dPs8zhY6PK2AauG8J6EVojd5MP1JiFrd+CmonDiGgMvatMzTU5i2IP5ELX3n063aNW BLFt0oLbaXqPWmXSoe9HlwmfWQXy+CHbDUKY27L2t3eu0I2T2rvNIAG0HVl1JQfo185x ZHBqLax4lIaHy3xDSjclsq2Q5/6zPaEaSNLfcMW8m0957CcklSzFcweiYSFDQgdRsKZZ LEMw== X-Forwarded-Encrypted: i=1; AJvYcCVnaqcbry/Ggz9ovYABdt2GVny77TtKVsQMzPbDGV0Z2jyERHSUYeu906ZbhbTAuN0A4C2GW4NrckgZoT0=@vger.kernel.org X-Gm-Message-State: AOJu0YxT+oxrYbmLECvcIjVZ4arvpZZGVZfh0NwmtWfin1ULOzw4vnLk aBbNRAcvR2oTjAulCDrmbENVe4lw12dRalIcK1T/55tkN6TfiXy4rj00Fj8GgJw= 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> 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. Reviewed-by: Leo Yan Signed-off-by: James Clark Tested-by: Ganapatrao Kulkarni --- .../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" =20 # Command line parsing. +def int_arg(v): + v =3D int(v) + if v < 0: + raise argparse.ArgumentTypeError("Argument must be a positive integer") + return v + args =3D argparse.ArgumentParser() 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") +args.add_argument("--start-time", type=3Dint_arg, help=3D"Monotonic clock = time of sample to start from. " + "See 'time' field on samples in -v mode.") +args.add_argument("--stop-time", type=3Dint_arg, help=3D"Monotonic clock t= ime of sample to stop at. " + "See 'time' field on samples in -v mode.") +args.add_argument("--start-sample", type=3Dint_arg, help=3D"Index of sampl= e to start from. " + "See 'index' field on samples in -v mode.") +args.add_argument("--stop-sample", type=3Dint_arg, help=3D"Index of sample= to stop at. " + "See 'index' field on samples in -v mode.") + options =3D args.parse_args() +if (options.start_time and options.stop_time and + options.start_time >=3D 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 >=3D options.stop_sample): + print("--start-sample must less than --stop-sample") + exit(2) =20 # Initialize global dicts and regular expression disasm_cache =3D dict() @@ -63,6 +86,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 +175,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 +240,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 +256,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 Fri Nov 29 18:41:23 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 93C8815B104 for ; Mon, 16 Sep 2024 13:59:03 +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=1726495145; cv=none; b=RZFUqftN92DmwU85sLzWh4ITzjBu/GuI2XxrWut81nwZuZ2DHSxrz45iCseTpMMZ1TdJqCJKmymGiA+9lEVuMXY83mS5DPsgUlJRrLT2ZR3GfJQOQw5Ed9yPPYHjIOQtFTFiNcCG7YjJiuqom/7shVk1g/nStDBxKnzupNBGMgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726495145; c=relaxed/simple; bh=LpbrfoAMw8cIGP9OaIf+Z3dR5YKTR9A/lE/Ry4NDj4k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Vb0+TBTCDKou+tTLJ0v1xN9ac6z6iVWGUQvnZp2f3xPEdhReLHVpyJYLYVtyZNtpKpl4qP/CcN9PiDcApObYmWc0PcBinKmPTCgVHwaanUZHkB4p0dPl0YL+wDViNgLc+ic2WKOIvnKrRQgDaJHrnc0s2YtacJgrrNO2NndxwHw= 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=UKTYoE/B; 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="UKTYoE/B" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42cb7a2e4d6so37226825e9.0 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=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=yHXcyBY1OfnYqyQEUkR+bbmX4p4XqE9ZVvOmdb+dg98=; b=UKTYoE/BR0G71Jd8TivJs8j5a/4xfnH/0UVAj4JNRcx75XtxGRHN/lCNnISbnDTOuz 90+prIFL+NDH8G19mwMbJXWKHiXGddFzLhGVOGyDsQyhydY0ETsLppanCQX/9JUoKQXe uLBPCaVbDbrHv7/j/FX56SFUEyheHNVYZkDLnWUstGybZSRAJukGB5pGeVznmq2Vm+MN VMS2HPcwBtUbhKSn4X/86Ff+rpLejcndLcS11LmZsR3RUxyM+0QRzq6okOHlsFjgbI9e WqF5EztiZFQjaqLzDwZY/IhNPNkhio6sohUGLUH7h8VbjuZjPrSMFal2oDsmJKU5UN80 6IPA== 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=TYM2yUndjtnIKYYRQuDJkOmNOTVV8erxMbPa2W7g2tMBJk+AI6P2xewkcBsWPPXxGL C4EK8Sh8Lf8nJxbV5NHFjnB59pwqq/PELYfCrnn2/adA5ozjJrAIUIJFCMJ6p3R0TxER KAFAay8Iem/k0gYa2Or5soAspgQL4co45XMCPfEN/8wcxCDwFHDM1yaRjPumQYCBphqY LnyUoscDciaR2nvwzpFBMql+k0GNy0+gFqSiq8T2pW/2F/JyRQWQUUTgFhVtpBABZ/Qm KOXfgsF3xLGzI7SUtR+cAX9gbOZ9c3qZ83/73tzk/Sqs6Tu1DLK5PrmnlkmSGuYsfOLI MSAA== X-Forwarded-Encrypted: i=1; AJvYcCWgMqLV/gwbv1zqT9GzCR+P+rz3TWJYcLw2bbwr86lp0FjCj0VRgm2uPsgPlqZOd7HiFN0xAnHG4M+iibk=@vger.kernel.org X-Gm-Message-State: AOJu0YwMeJHLmuCIF6q35L8bSr0fV4Glk9V8sGDIgVcNHoIlzVaKMaD8 FJhgIlN0QRmfeWJhD+bASFZGuhpZZPzXQoZkI8dtKyMX5mt+QzlFpEBt/6J4/zk= 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> 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 Reviewed-by: Leo Yan Tested-by: Ganapatrao Kulkarni --- .../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/pe= rf/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 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) +# Relative path works whether it's installed or running from repo +script_path=3D$(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 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:${script_path} -- \ + -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:${script_path} -- \ + -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