From nobody Sun Feb 8 10:49:12 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 F041F198E89 for ; Thu, 5 Sep 2024 10:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533468; cv=none; b=VhYECEWOplcj69LDgRKYyISdoO+F9ZP08PEcaj6iQuH6Gd6Eli7PHkyZEUISuVViPupQ9v/GJ7ek4gmhrNKT7Y7yo929hp9LlaCrJaMkELqBK4rv5e617pM4UJUgXNDoi4+yDtrgFVBQHwnbddx3lsbdEoqKhj0SgFYXly4YmRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533468; c=relaxed/simple; bh=TQjF7jPPLYqbnWfFtn0ZeCefM3gftDDsQw5DBnhz4Lk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n/+Ml0Gcp0ltdwkGEAOEK4VCTfM7DfPfn89ejLqIabGvvPqAhNY7nQzPcpgZemllCYwPxt4aTOqXph2cf7gHv8J8A7pR24juCD6PJRZntsf1M5tYP0r7GQcI7mAw2io5pwMyvlAKyNhnEAa9kab3Kdmb13gLWL6gruWuzx0Ctyk= 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=StlV5EhQ; arc=none smtp.client-ip=209.85.128.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="StlV5EhQ" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42bb7298bdeso6160495e9.1 for ; Thu, 05 Sep 2024 03:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533465; x=1726138265; darn=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=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=StlV5EhQimy+NGpAsUm6ToloBCen8AHv6WYuaFXIR//tRkCYfDcCsRFw+WiD72z269 Tx1deb25fPOhHTONwDpsujvsf630YhxxEopmnC4apUFcB/vewugCrbtg6k+zky6azloM 94EXjjmOPzDlSztJX1GLOWd7SLfqAB32yIoLeECgPX9PiDcK+WW0uFbn+P3AtUEEuMkO JedoVPA5sSdatGu0iXMLFq8Lyg/xkqKvta8pVHPpXzsb1eSIfgf29KqAbPF7bTZBvukV znNtEKPaWbT1DwMAD79euIpg7UoROfuxCc/jKwqxts/zuHgJisAb9X/ilUOVqts5QV60 fmDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533465; x=1726138265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=SQBWVA+H7Li0P6BdTiG/OQIh0DgybPttdHmayfJgK/APSMfq7Q4QH6L5MdDTAC35KZ DuzczoapjcjCysiIMSdI6VAKpKk1A2NLKaZxHYOu63y119KXqGwZlwCG5M6/m8KeXF+c 4AJ+NdZztKDzKJwAabppAFRyRUrYkhr6xS6kEMIVsUc+3QSyg7Zdqe2P6fCNQMTYrl8Q FCGdgtoHJtyQYTtjMUCfBv7BcA97EMWtPCclb/WYJg4s2KEM2kQgvFEgmzXZbZfSTOuN iY+tNQArbIOVpmJZL6eZnoJKkSZ1A7Lk02kevovRffGfMy6uWugX/zQsdsqWqMxOSfEL if/Q== X-Forwarded-Encrypted: i=1; AJvYcCWv55uPaKNgDutpjPSnEdzFgpYfvMPyLzhm/0MDN7DJxnd7sh05eNuOI+NStchBvFEjox5jSB5+xPwRj2E=@vger.kernel.org X-Gm-Message-State: AOJu0YyrCb1qgY/Yu1m74AWobdb4Vgi9LatxV9TXZoDB36vJymB/F/Ss YdW+bSNEqGXcnQRMFcUuYPRg0104tFkwMo6XksJZWdfh0YhCR5imJDgbyvCs3/c= X-Google-Smtp-Source: AGHT+IEvKTt/6e8xWeLQPHZ+Y88gea0Wee1acuIi7mFkLMpU6DekcEkaro14JQNPOmXmgU7w0uaIgg== X-Received: by 2002:a05:600c:1c8a:b0:426:59d3:8cae with SMTP id 5b1f17b1804b1-42c9a365902mr18084165e9.13.1725533464564; Thu, 05 Sep 2024 03:51:04 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:04 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/8] perf cs-etm: Don't flush when packet_queue fills up Date: Thu, 5 Sep 2024 11:50:32 +0100 Message-Id: <20240905105043.160225-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 Fixes: 21fe8dc1191a ("perf cs-etm: Add support for CPU-wide trace scenarios= ") Reported-by: Ganapatrao Kulkarni Closes: https://lore.kernel.org/all/20240719092619.274730-1-gankulkarni@os.= amperecomputing.com/ Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 90f32f327b9b..602e791ff5ba 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2490,12 +2490,6 @@ static void cs_etm__clear_all_traceid_queues(struct = cs_etm_queue *etmq) =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 --=20 2.34.1 From nobody Sun Feb 8 10:49:12 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 97427198E89 for ; Thu, 5 Sep 2024 10:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533474; cv=none; b=r90/DMK8wzwe+Lz4C6Tn+gOxnLX+WkTSf3fC/mXbug+wVEtVSpwg8o8a36iLl39lBonz3BSlss27vM7z42ernxvoWFQeRWsjNStt1Z+yR6oJSbJUofiUtf7azMW4dz03+idpkK9c2ZY3lFAaqoTGIChCs1FSfq9H8oRwiddZ52Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533474; c=relaxed/simple; bh=PxZK1UYoQiEz/5XZdh+TkbpX8o1b6IrqnscJH918Tbw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EE72oLCmHFRUpXYDq1d2nrssDazWOVY9bioOw1i/4HCDn8mClE7xHnztEGncsc9yyHGFegWsb47DlZh8mB8MgV2OMEmf42s5Tp1WTqW44DyIW+okX84uGb+S4QhLWNxYOdyAqKE9ZTDLiFOxiHs2uabcsik0UbL2MMLUeq1ypZY= 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=gemYYS5H; arc=none smtp.client-ip=209.85.128.41 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="gemYYS5H" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-428e0d18666so4674925e9.3 for ; Thu, 05 Sep 2024 03:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533471; x=1726138271; darn=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=gemYYS5HX/jIdB8RFQ/VlJfB6jAMM6GDNoUoJn0MTVm+WpH72ltkwcLCGVK5Y1T7r0 o+pRJSdp+SdgMnH5PUueO7ng+CmDHp0gOz140vkVM1jLIeH6aEpGob27hzfFPBSuWYl7 AYNqCkLeEnxjalx/DuKfboV2fFOgtiYrhp0/GagTTtV2KKTcC27fajFLp/Dw0pMriVv3 9p3UUlkmGL4z+xVBE4XkFF8JbTLFGYeOfGGa5oBkHA/wV3Sm4idk4Xbt0nLzOGXaI6lV cz6QFKIxpW9vqOa/C+DRo0tXQr4z7/IwzzMvNEyMry7p+lqGzh24vii8VvhzpBOD1k/q E3Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533471; x=1726138271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pve9lnNvOpeZGUhzPh1pcaBloPgbua89KV6dx7HbhcI=; b=s+xazfWY8ONpsHLQoVkvuJ55F87934lDsXPZ39kbIMwiZCFitWO8JbW7PavPX4T0bv CMocpEL0J06K/EYs5ZWR3NMR+SGJ5hYhskRnMmPYxIlSg32/ofclkaLz0nolXTg5EBX3 lPaBYyCN4vPo1JT4SCENskTbUtoQoHpTQFb/rBWt8rexvqClBYNvlMExkXGnhi2Damoy 9ZvXtSmdjMUPXU8GXDRLy8jfX5HvLCkaantEL7b9EMYyypKG/IpNrmMNcVW7zhRL4GdL xwto6GfTk5qxutYqoVR3TOXAHetakcNa1872nPnVlqHT+Oj25yzRe+hA+2DXAcHFSLVb +mMg== X-Forwarded-Encrypted: i=1; AJvYcCWxQhuFnPm95dvkmSP4RMbh3UBY90NBc93TAX+bSzxfMmRz9uyTSJMadwFlHywsP0QRpUwUJKDNDQFdEek=@vger.kernel.org X-Gm-Message-State: AOJu0YzCMSEuI0OCnuEBCCeMlZRQTk7AAzSl8mAv87BBC1BVnZAJ8z9X U1hJBxGTBUBYxVlBDDGgesO8ZgYoSdDN0+uThWiRLO7pcJzZ7e3shaSHHSbw+3U= X-Google-Smtp-Source: AGHT+IGNR6IhhEwS/jgcksvn9DO/af4hIbBkDS8ADbe7BTQ8BnykRnU/aKDonHdKsUgmQWK1V7Lc5w== X-Received: by 2002:a05:600c:34c3:b0:426:5fe1:ec7a with SMTP id 5b1f17b1804b1-42bbb440201mr138466235e9.31.1725533470807; Thu, 05 Sep 2024 03:51:10 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:10 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/8] perf cs-etm: Use new OpenCSD consistency checks Date: Thu, 5 Sep 2024 11:50:33 +0100 Message-Id: <20240905105043.160225-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 --- 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 Sun Feb 8 10:49:12 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 EBB5C198E89 for ; Thu, 5 Sep 2024 10:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533480; cv=none; b=f5SDnW/95UcniljKk7NHyb3q0mzXC8F4o4kRN5ECTVlGwfPH5jEzUABqVGT3hjLSLPStG/OrAqF5Q8EJ/iPlcTlc+llGsHCsWSYAcv/JTFirAaUTaDbHS/avTBja4XiitmbcuZSa7OZbAmadAG5QWYPZeqQuTrqLqNSvoSEzZmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533480; c=relaxed/simple; bh=wzk9SyvQfKoXUMQnerIZ1e1CQ5nCLvLIdMZfnrTV2M4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GtIs+JbafgmfBxCbtjvFiuvSyarZRNjOdyMNuEs1xZVSHYnauQT9Y9ks//aKmOFxOh/PzMG3GlEwwLngucwcbMQDLozcxmEP5lrNdIeAScHmw7P+BxhJmvHmYsMAxmWvQSpvaDgehtHhApkfOZ5rTJ10EaXAU7xUWoExlep0rAI= 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=Pc6TCSp+; arc=none smtp.client-ip=209.85.128.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="Pc6TCSp+" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42c7a384b18so5096175e9.0 for ; Thu, 05 Sep 2024 03:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533477; x=1726138277; darn=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=LVd4bq0YTjw4v+0IMoc3Cm2fVjGVCOS4YTrWYkTu6OE=; b=Pc6TCSp+cTes7yo7UyKK3TevcHf8sJSDNfpAsOdR9e4qZfGoZE5DXQH0ET2KGR8L7E INXVbVF17E7U1u1/OrzU60XPxHaNb15crUe4AM7NcbG5YcWDYNSv4+i4x55JfkilsjnQ 7YjbSFJGny392eUMct6wtAl6lUCa5Cb9DNC7+HSP85I6jc4D70nXTqLUhweXBKsjSHNT lyLheFtrLrumKS9NnSURNrprKERngMf6nGMoJLkbd0uMreLXXBPuh8iUWnSkt3bhW3IB MBB30eJtRyUtorbdzBXE04diK9q4/nIIQcbX8kqxgH38ovRlqWXRukqLSNmmzHtaS8fN 44lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533477; x=1726138277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LVd4bq0YTjw4v+0IMoc3Cm2fVjGVCOS4YTrWYkTu6OE=; b=vjvFsaPnCUASmk7C5n2OQnQ6c+MfsFohXD2RbfgPvjMWjavcpQmv4hcyzLZfMLdsvg pHG6akKMiQKQtF/tpYcYfQaR3QWGESlj7cGym1WzwztGRyEMgWsnPX7AK3mzXqRA3fW4 t4AdMvPFrLgXdGHLDG8zpKFYagVXsT4CCfIi6rB92zOFBO8tEFbJDowTlgtT3yJq7XoZ /xyTRt32LXqPKHqeatFqzsteMMZVLi98VZGtNUawYzLpAcrLfAc4gp9ZRGidKSuFhvV/ jKA0TFopWCjxHhyOk4EW9frla8CwblRJNjyr9vzLdFRx1ya3aW604D0d3rTQ66bf6h3U asbA== X-Forwarded-Encrypted: i=1; AJvYcCXZZU1Q+bzzbkmQ0Hk8pd31M3vJ5M1Ub1PcmoY2ltayCdY9oL64S8qkROLz82xExN/RL1Lv3sZf9uQDqBs=@vger.kernel.org X-Gm-Message-State: AOJu0YzZIy3WurvRgToXPKO0tJODSbQEWXiJX7Eb1wOm/ZhE4KpHkp/L xl7yAgbdIFHAQq0PCXeXDXhRispYV3S1IAdPWLx2sLNArWz1DodqcBpvnwHPMww= X-Google-Smtp-Source: AGHT+IHLKD1lksVjuCFdRAy71VLeSYs/LO7EW6oQprwBpHDtYZTrW3t9QhBgsgUf6sAqeRl0YMfHGA== X-Received: by 2002:a05:600c:3584:b0:42b:afd8:7568 with SMTP id 5b1f17b1804b1-42bdc64e498mr125056915e9.23.1725533477165; Thu, 05 Sep 2024 03:51:17 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:16 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/8] perf cs-etm: Remove cs_etm__flush() Date: Thu, 5 Sep 2024 11:50:34 +0100 Message-Id: <20240905105043.160225-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 is only called on a discontinuity, and it generates a normal sample and then clears the branch buffer. I'm not convinced that any of the subtle differences between cs_etm__flush() and cs_etm__sample() weren't actual bugs or potential sources of them. Replace it with a call to the existing sample function and then a clear of the branch buffer. One obvious difference is that it now generates a range of instructions based on instructions_sample_period, rather than only a single instruction sample. I think this is actually the correct thing to do. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 62 ++++------------------------------------ 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 602e791ff5ba..cdda8403af2b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1908,60 +1908,6 @@ static int cs_etm__exception(struct cs_etm_traceid_q= ueue *tidq) return 0; } =20 -static int cs_etm__flush(struct cs_etm_queue *etmq, - struct cs_etm_traceid_queue *tidq) -{ - int err =3D 0; - struct cs_etm_auxtrace *etm =3D etmq->etm; - - /* Handle start tracing packet */ - if (tidq->prev_packet->sample_type =3D=3D CS_ETM_EMPTY) - goto swap_packet; - - if (etmq->etm->synth_opts.last_branch && - etmq->etm->synth_opts.instructions && - tidq->prev_packet->sample_type =3D=3D CS_ETM_RANGE) { - u64 addr; - - /* Prepare last branches for instruction sample */ - cs_etm__copy_last_branch_rb(etmq, tidq); - - /* - * Generate a last branch event for the branches left in the - * circular buffer at the end of the trace. - * - * Use the address of the end of the last reported execution - * range - */ - addr =3D cs_etm__last_executed_instr(tidq->prev_packet); - - err =3D cs_etm__synth_instruction_sample( - etmq, tidq, addr, - tidq->period_instructions); - if (err) - return err; - - tidq->period_instructions =3D 0; - - } - - if (etm->synth_opts.branches && - tidq->prev_packet->sample_type =3D=3D CS_ETM_RANGE) { - err =3D cs_etm__synth_branch_sample(etmq, tidq); - if (err) - return err; - } - -swap_packet: - cs_etm__packet_swap(etm, tidq); - - /* Reset last branches after flush the trace */ - if (etm->synth_opts.last_branch) - cs_etm__reset_last_branch_rb(tidq); - - return err; -} - static int cs_etm__end_block(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq) { @@ -2457,10 +2403,12 @@ static int cs_etm__process_traceid_queue(struct cs_= etm_queue *etmq, break; case CS_ETM_DISCONTINUITY: /* - * Discontinuity in trace, flush - * previous branch stack + * Discontinuity in trace, generate a sample then + * clear the branch stack. */ - cs_etm__flush(etmq, tidq); + cs_etm__sample(etmq, tidq); + if (etmq->etm->synth_opts.last_branch) + cs_etm__reset_last_branch_rb(tidq); break; case CS_ETM_EMPTY: /* --=20 2.34.1 From nobody Sun Feb 8 10:49:12 2026 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 17187198E89 for ; Thu, 5 Sep 2024 10:51:24 +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=1725533486; cv=none; b=AretDcPbwnpb0WYi5EjzMASNVMnMhdfPsRKBc1p3wzjbzeyBGpCkL2DaiuSNumOR8NMyePQmshPI3i9H4iho839EndjtvW6xsNzRmg6Jaw8iangOWXAJrXuOWTxYqgN94DFJH22LI2Wpy+fUd6k845TM/EspHI7HhskCC1kIqQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533486; c=relaxed/simple; bh=HzVLxxNDCC58aJIsJSeqkv1E21FxH0Gn8OwOLut/Kr4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h01OYDzXEAq4I36Q4OGOY7r4lB2tsqlEMSZSAuxYGmJknQj7l3CQ1NWZUzSHRtHfu5XBScecPAi2zM8CBu32jy9jR0pJukYihuxDbWNhZlGU9RTWH1R2zjYOIxquwSl+tXEOxAWT7UbpVuKUB9xVeHI140vVQ0t2nzMKfk3Fcfk= 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=Gh9h0dtP; 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="Gh9h0dtP" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42bb8cf8abeso4680325e9.2 for ; Thu, 05 Sep 2024 03:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533483; x=1726138283; darn=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=Gh9h0dtPpqjKb8Ch+M8Ae9q62yIuoqDKVeQPPQ5S1DH/EvvIcHv1Nmb+kV4sBDcajb /y9anpK1fCrxIDaJfz9JQ4lcCK7XLIqHMJtKyj/nljNE1LsNYbpha0mw7BySeV1yN3/R L2sHPPOoS3kZoh7kurg2+tmsO0Vgy47MfU2GFNBQPiKxY0F0Ppt9bzM9vtTyCzM4vVDs Y4eIEXSht1I6ckMhYsKfFpVZkb3Z+adlSYh2bsUvmbl+4I6niLg6v/9hBOHdR+3Co/Jj zww7jgNj2VVYL65PKhrOJ+/b4pjyen1oids+qiXkXBC1zjoXNfzN0fiUL4OKEAXian11 ndTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533483; x=1726138283; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=tEmysQulpCK6SWrnCBfP1g5tCdt09EQ6NHVxeQKFcTS5Sp8kOQWNIAMCSKfo57IvtV CtOyGo849uFEqgAX/3GMdCt8XSoIyn5euo4Gk6H43YDUMgG3otdLMVVxOj/fmY8vSZZ7 5oBk34g2/0uk3FX3RpeLjCXVsNuq3u3mJwteIxUj8/PqM9zR1T0dCofZhgjWrGJvp09x xMv9lvTglt0aAKho8O6zsDxsMpbJRB0N6BGncPgObt71ZmX3ESpe5lmaMd9pQsxhGDT+ iW5p9M8FFW7Ml0F9dxDKdNNL3u7eDjML/m1c8biOJt8/PS5Bbqe1wnC5//f/tceLLE0w dlQA== X-Forwarded-Encrypted: i=1; AJvYcCVgPJQSWrOD7T79MtFfch+UwdLLH8/hWKHsJvztWsU03kroU6os4uJ9FLiUmOaQJj/y8M9pHaCCjth8Rms=@vger.kernel.org X-Gm-Message-State: AOJu0YxKBqFagXqU8NLSgoBfm1KrhifJo8e5XdORkKqUWLy/Pod+hjj9 3HjU8Vo+GO7jp1o4WWKDVr9H8E4tbrY8jfqknmCx3BvTaAjMW+0qjB5J1VNRl9Y= X-Google-Smtp-Source: AGHT+IEL1yvO9/AmK9ifjqYg7iMQs4H/ox7GyqpcdtMyB1K5iTwls0MsnKmwOXtbuu/kXAMOTl2r5Q== X-Received: by 2002:a05:600c:241:b0:427:9a8f:9717 with SMTP id 5b1f17b1804b1-42c8e41bef0mr47718195e9.0.1725533483317; Thu, 05 Sep 2024 03:51:23 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:22 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/8] perf scripting python: Add function to get a config value Date: Thu, 5 Sep 2024 11:50:35 +0100 Message-Id: <20240905105043.160225-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 --- .../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 Sun Feb 8 10:49:12 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 4A86B199248 for ; Thu, 5 Sep 2024 10:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533493; cv=none; b=h0431bpH8Khd5PZZ2Ir6op/2FQkJxrd578ylZ4wreSQxpUwVdauk7wnjB0E8XSv9jfzMcBLJ2hNbisfmi1//7+UMc8cAelXuEzUNQbAI/i3AxoQ0NW+TAZis6+DqvzU1U9A9JbIFlh4Zf+WMbcv8apH3sqKd/aZQ6V13WKjWCRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533493; c=relaxed/simple; bh=Ent3NPYjQTNnHv+iKIcd7ubFUpZT8IyAhhOTjZikImk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wzlp4WMsmS3mORlCWnBVj71qWaX+pDM67xHm8WAgu1nVoA8g+0VzrzGlWP7lEwYqnhCk32EM20BJQfAXZKhplzZWII8GQn7X3TxOmpB7eh6lLup9vzD0FCE9t4y5nvxJokE7acIz7mOs873uS7W4Y73KTjqaJAJ5oeI23uaf9JI= 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=Z9beb/pt; arc=none smtp.client-ip=209.85.128.53 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="Z9beb/pt" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-428e0d184b4so4662275e9.2 for ; Thu, 05 Sep 2024 03:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533490; x=1726138290; darn=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=Z9beb/ptpvgmM/HWB6IjBKc5lFMYGZRjJCLlvO6oh1UCy3cfyOEnOdaikBe4VdOiob dAM9VAW5RLiVGEL8hNsYWpjKOTXIzXQZtuX5/nMXKxasdfk8Mv5TGNYnJseutpgMULQr ok/dFRbQeeOjQHBTmuzrJCbuDJMkNsGXBvGX6TopadxjcqiHj0rwN8VjAkMPQtUcwV2C 0Sx8l1WDSVhblXJouheFvd6a9agEiWLhfiJfnwej/6TSWZE4K3PV99QpWgI+UTFjcLrF ZNOaNECsgWJ445SlG7LS9BAJaIwm56zSDRbPk0y0VJxR6U0nNatCkvERZyF342gLY3oq y9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533490; x=1726138290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tvd47gfary40B5CZwKU25bQw1FRFKdvBGhXDTC0MpmU=; b=vkN8QsUJe27krstyCnkrzB4DsqUB+zKlByil7UKuUBV4XbtaO+/LFR3ltgsVe4IzYM c1OJVqTYf4drE0AaB3jL2v//swuq23DMzCu/vfwaWYL93JeoVoO+mxzuNJdPmS6/ATD8 Nv2ceXhkxqOBWqMA6Ok8eScBK/DypVTvYbeYnwuKMJBuFyzR3WqmWB05Nmos/VsQfEv9 bhSXb8s+UA1HaIJybu8loigiN7I7l/Muyn3KyYJPRBVI8jmBN7LQNwBxFeNdVhB5CPrN J8Bt1WPouc4aCbi9SPNSnts2rNCUSHIlbB6q2u78SVabOcRC0MWsDq+MxXd3WDiUlYn/ zNtQ== X-Forwarded-Encrypted: i=1; AJvYcCU/xzMMZR7Qk/IE0FtZAruOe5PXRhKXwcQT2Dq8CBMwonRUSlRdXKie6TgUovmjl9tNnhGUA/CKy3y0QLU=@vger.kernel.org X-Gm-Message-State: AOJu0YwPPywMkgHUCPmhR7vgvkiMnPwUMhyptgwlU/+mWCRCttc7IXi2 IoNdW7GDtxqCjcmFwNmPvaIr8SAmIVasBMRsPq6/fF+TeDn3rSM+KvvoPKNg9+E= X-Google-Smtp-Source: AGHT+IH/+XS62yXBkrtQXdlyQqjo3Bxww5IdiYqj0rBOSr4rHkxQrx9C9Aypty2rFMzvzq+ymudjxA== X-Received: by 2002:a05:600c:4f4f:b0:426:6000:565a with SMTP id 5b1f17b1804b1-42c7b5a8ee2mr111733575e9.16.1725533489532; Thu, 05 Sep 2024 03:51:29 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:29 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/8] perf scripts python cs-etm: Update to use argparse Date: Thu, 5 Sep 2024 11:50:36 +0100 Message-Id: <20240905105043.160225-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 --- .../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 Sun Feb 8 10:49:12 2026 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 8A4FE199248 for ; Thu, 5 Sep 2024 10:51:37 +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=1725533499; cv=none; b=UbOGCvawKTLzLxF7BV9BZdEgPEmrY5uAvZFCglNJ0QjzbdLK2EeB7xIAh3mPgnxC4A5m1eCbgfd4ZfrHUFTtLMhvV6wH8ywu47tprZrdUgVcbySuxIiIMv8JASJHzDBeo+P7lzb6259HPLRnoxKvLa7nugs9K/fktb2Lw8d9mBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533499; c=relaxed/simple; bh=bR690mMXw1GA2mO1jEEJOauZ9J/eD8W1OUd3Hv1VNaI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hQDxhmhCUX8mxpkXkQJ7pnli7YWr7Rayxbh865pX0ltIKTuTOLl5n5+PnCjKWexLz6ooVf/CthzL+CMfFHJ1O1Rq/03n3j+2f9WXFsWAwAgXNEgvxnpHx8ELZMEJQfKLI6FFO6IJuG4j+uOAsB8IsVXRJXXwBujflcK9gmHkoo0= 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=LeVvEAkf; 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="LeVvEAkf" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42bbd0a40faso5434915e9.1 for ; Thu, 05 Sep 2024 03:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533496; x=1726138296; darn=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=LeVvEAkfvO41ofNgejm4iJEtD2v8xlURx8FEfwZ3kKghjyinQ5dGgAcEa9UijO8yQN pUc2LKVZZ9PEek2WYc9ypv6vnNb75LqsYHhZhw50kSl7dTzYWXamessDbk9dVG1PN7bs nWRwM2olGrlMrQQZeWA6bgTChrzTRoyjis6hOK9UVcR44PfejP8cR1/qlR06+aRghI3b mOTYU30Gok2fax0zhui1GQzmpf69i3qzXIIwB9h85oM7GoRReKh/P/uPGdCv4D/BTWLc YkcULgxvEeGQS4H43WL3vrmiFPdQB4tYQtiGGni9xWBjcIjfMvWzsWY9V0Oe7W+qpT/g Li2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533496; x=1726138296; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1UQpIycFZTbpTomhD0ThkQ/OGwgElG8NTd5wS8H1d7Y=; b=BiKdN55PJZcWGhh8noEPlY+sw6vhJQSzq1NsdGRkNht92ZUONREtMoLtztuD/e3WXb zK65PXoOZ+zfVlOzOGy220W2TBlpSXYB9jAlQeFX0rqJ+obxc/kuEEiTckkhnjB1RR91 +10UBxXM2ctELIdQ6kN4oMHZfDZ1B0cp+yuFtt/zxvBMkxdp9/EtcJK2QAhDPD81VMUB UCm1o3TGcmG2TBeO8UjAMdMI5WrFHKUFDr+cb9lgWolCx9Gr5ZWfBxtDCvPDsrd0mo4w sy+XLUwa5GBcsnFB0Zo8dIZ9Hve0eThgYPmr2wjGobtyXJBEs7CZbjcDH7g4KTF6sbT/ 5grQ== X-Forwarded-Encrypted: i=1; AJvYcCUj+v5A8wJaiazYNteT+fZVSMXfLm4/835CxFR0feSvI05fTknsKIzf1Nn6Wk1NlsGw0BSH/tDK+4WSYww=@vger.kernel.org X-Gm-Message-State: AOJu0YzguxjWRIB/wqFq7+vM81sX+LLbg5PwH8onn391RR1W4IzaElSh C6jIs3mH6cWT6oRiTW5qpIYjJKKoCy45jDdpiB6ZM8x0pfpCgHGHlP+/DvuVZQ0= X-Google-Smtp-Source: AGHT+IEpfxBxgTLRhNXbNPhyw43kJddfslQaOh/lWQNdxGiZ7XJq9Wynx2djlTu5N/y0tXW9TP/TcQ== X-Received: by 2002:a5d:6b8d:0:b0:374:bf62:bc91 with SMTP id ffacd0b85a97d-374ecc8f283mr6307799f8f.25.1725533495732; Thu, 05 Sep 2024 03:51:35 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:35 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 6/8] perf scripts python cs-etm: Improve arguments Date: Thu, 5 Sep 2024 11:50:37 +0100 Message-Id: <20240905105043.160225-7-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 --- .../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 Sun Feb 8 10:49:12 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 CA105199248 for ; Thu, 5 Sep 2024 10:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533505; cv=none; b=KYjKYVDg+MRCdeus8NHtx+8bjs+wkW9fqzBrnDETx4SHqVWSep8bvkz3Yy6ZRyu+EkxGJ9kPsMyfyy8ZZxf785JgUudDxhkRa0sFIkDhj9LkMMV9bzW03lNGL/K39hwrKHWVUg91dSFdgpoxuYywKJV+uqs/mm6S9yBEpBIQNVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533505; c=relaxed/simple; bh=M/SxxS1EV5YiH2L2D9PMSuM/xyixk2ltobd2ktIOQbA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uSrWd69XvzkFqkbB78O0KbY/+waZnlmpbL+QZ98gHw7cYtdrHAgCCLQ5vNbtliGeS92XuW1p3piEX5scwJ7bhoTZ4IR3NrsqmWksxSZPTGPrNRQHrx1eXZReXnDG15JT2ZX7dmI4e+9+cWO5jSnD5h9//eqv59bpRYDsugx9Bgc= 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=mQRK0RMK; arc=none smtp.client-ip=209.85.128.44 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="mQRK0RMK" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-428e0d18666so4679605e9.3 for ; Thu, 05 Sep 2024 03:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533502; x=1726138302; darn=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=mQRK0RMKOxy2TQWQVPVccrs7/rIWe0HYrHOUTjDC0ZR4sm8sHREFys4xLtElvwrDfv YgBk5mq7s8UaiUvWEnF8BbL62LRAJFhD9Tx64u4vairLnup6TsjqeNK3k5HLQln7zgby qod5v6eF3QEBGUpJCJeGiRaxwZGQdh6HOAEfsPnpDyWzIAOjapfiswYlLNgUPKkrd/p9 fynitVzMGJIJiHlw3SeE/cyfmIugwUDIdoPWFYSjwofNf8n2cblltTpAYTwKEm4zs5XV 1Zq+t6cEUSOYZ//VviV9NK0grfd6izIWxNibzCKZV2T+vwRGv2AkR5ue5g4O+60ilb3j c5sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533502; x=1726138302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lyScag8p5nZQgcpgovS0Br7oaCoB8CMogAdxSo53VSM=; b=FJnCvuXwrUAAN+ixi0jALOUO98Ysq/LpDT43h0ElAx2oT8kzbL8Vs7G4pazXqgDSXM oC7yDfeSA/YFNevCL/CFJP02G47QqhMbVP6y0nFNOvtGSOWYWIZwhpMpShHQ97X5YviM 4qi6igrI/XlSsiB4j5RgUxqLznAQQo1eZzB9Hc3wRoRtanN1gPo7JekvegC3HJblvSO/ p2y03Mbi+E5aHPqUF04bHyq8VKIIyzd/QJS1pwwJL3zngOtQe2Xc9SwH0HFlo3b8C3TV 099TfCE1tkarn9w0gTsWSZPq7c87N7Pvhpbdg1d2AH03DctbbsroMMZp+ugXph/DFawm 5/Rw== X-Forwarded-Encrypted: i=1; AJvYcCUMu3S7K0jxMk68yqjU4AbA8ZuDESOx8D2wSEBuNue8Opn8G2p5FbXiWOJ3pLw0CYLOxJAqzKpFhc9n7Yc=@vger.kernel.org X-Gm-Message-State: AOJu0YynkXV1nosb7eNAqoNRKZGJZSHer/suKipcHItYBg6gMS6dnHCy aovKlPEs34vGvQ6T27LrXjI/Gu7uDHf8oxWAA+V0o4HrNLbxcw2IA0rzoOHTi/s= X-Google-Smtp-Source: AGHT+IGfFJqAayaXo8MfaP4LB16SCu3PZkqeamC6wY0GLppIU48zgj0W6/Wqg+hZrLLyTod8T3h8wA== X-Received: by 2002:a05:600c:4fd6:b0:426:60d7:d299 with SMTP id 5b1f17b1804b1-42bbb10d27dmr151939485e9.7.1725533501983; Thu, 05 Sep 2024 03:51:41 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:41 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 7/8] perf scripts python cs-etm: Add start and stop arguments Date: Thu, 5 Sep 2024 11:50:38 +0100 Message-Id: <20240905105043.160225-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 --- .../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 Sun Feb 8 10:49:12 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 D9930199248 for ; Thu, 5 Sep 2024 10:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533511; cv=none; b=fEk9SQDHi8GVdb30GmaKBzhvICELhnJEjuiPZqM3Hgjb3ruj9m/lprnTr3BreOZJ9IvhIzaiyN3rXIuF8Tn/zc2B6Kt8L/Z36pMox9ZTKhWOt15Wu685xz2r0w97zjTNOarqeNmYB0qmdvkgcD7/fq7wJt0Gjmj45Iq2lrsGuT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725533511; c=relaxed/simple; bh=x8bv8lif16GzTLpb0Qa7Ebuoe1yqdxh/JFp2faINf78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ROZ/iI6U/w/07rTETwSEdwgtVY93TP0bWc8WLcohvLTfzazcrEBcgHr5mC2OSwqWpz+KT0LAp2IgHUI2mFw3CqkVVjfRoVs1PvJ3IcLRR+Rnyp1eH9gUSgrfpwiaJl6r2lwcbkCnVyj9gtqsaR9Jp5YLHbWscEVbphuLeWT4yHA= 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=R8cOHbRB; arc=none smtp.client-ip=209.85.128.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="R8cOHbRB" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42bc19e94bdso4676975e9.3 for ; Thu, 05 Sep 2024 03:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533508; x=1726138308; darn=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=R8cOHbRBI+ktZkgHiUCX/xKeLQnit8awp1pzVUQgP5jjp5bLxxnA0h3fu6e3LZsBRG OjmeCWEFNF8AOEz1wftkuyIVbFdPZ3pyUneNlseKC0ec9IUa2mN6kb6Di8G+3GyjqN2J PBVtG3vbU4ySClIPJF11ldLeAWAvZMgk1e+MbvMu5693VnLLkuf1QpWdgnXkB0KhecPo u2LOxj8C48y609f/uF1sPN/x7OHQvcYHs4gYZmuOCbEGG9Y/2FB/SkqqKKtSOSocVKCD I6OQ1LF75w+plwEwNWhUiFKLR6SGHYRG650MMPeKpVIvOjDxFcmo2Gjct0ZjwR+pGeOy B0oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533508; x=1726138308; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MnGEReYZbV5wa8QJ65oYyeLT0QeGyCwvGtl5g2ahPgo=; b=cZSUeTQynfJh0ZqcKTXERQ48xZ28jS9VYzkxiq4VCVBvn2qGydbjPID5pjcVn9WpdE QznsZYT/NtsBSSlFp+yQuDFMuLUTHYygr0AATWTw2N/XEPOtjg2L3NCXnlixKdSvnjG5 /7gay8vW6ksU+kUepgKsSBYw0+yteCrLfV1AQJhw1TJTNzacdhweqmVuM0oPtupBl3G8 oW79M/Ru4Aez3jcT8u+O8c+goOxP4lKKZg8fol6/ScM5zDZ/ZK9171jmbMFYq6vg0q5m og3LpAEgK3giS3fY9PhNzGJ9URJe71KoK6FN8U3D7f1dpMilv9OvneoV9K8Qikiq3lOz 6woA== X-Forwarded-Encrypted: i=1; AJvYcCV79G7RzNC4EEnvEJiKiaW0lTWQ4GgiNuTEF+r5Gep3vUTV5fixg9oxE6xsagK98B+8th8dx7RWmKwgYk8=@vger.kernel.org X-Gm-Message-State: AOJu0YzdEDeyyEPP2eIm5UPmX+okc2U9L/7A3PBjwLbRRF3uXhcIK412 A9z7fANSzthCUrJdjv6PvfJKsMjB7LCdG3K0mgIi40A87tAo1Zg/7qF/iE8t4DI= X-Google-Smtp-Source: AGHT+IFLXh3uz6cqXjbXRFB+ADKQOX2EZTgrK+sgT0hn+8Lnw3zLZAPRZF6rIycBh6dNiFzAE5OxVA== X-Received: by 2002:a05:600c:b4b:b0:42c:9999:4fb3 with SMTP id 5b1f17b1804b1-42c999952dcmr18219615e9.34.1725533508196; Thu, 05 Sep 2024 03:51:48 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:47 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 8/8] perf test: cs-etm: Test Coresight disassembly script Date: Thu, 5 Sep 2024 11:50:39 +0100 Message-Id: <20240905105043.160225-9-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> 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 --- .../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