From patchwork Thu Sep 5 10:50:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50944CD5BA8 for ; Thu, 5 Sep 2024 10:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=VeNpOayS9d6u7S3cfYsswbZnhR +xlyiuqcUTLRofOqwRWniv2aZoOxtriZ5u8rzq9SuI4qKIeGUspXRsreNaHs+BzFmK/ALXdeeHs8s AbuTQssv7RZcJcXUhPmd/yAjscLm4WwCcvvQb6ynNlQqu+iidAPAYL2RExD7vo3fI0ujIrsAnh1p9 V4Gef9/QiG75jjzujriIHe/b0fXJLzCe6WTm4viwjy2dXvesBB/jS3xPI8Pl1f/OEDWOSKNNvd6kj tx2YkidWLQP4MyzprRIUtYqXxwREo+ApqLD5s1pByA7RIoq2gQ9wR+lBRMwBwh8MC3Oj1a5lfHPyw aIVXz5ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA7w-0000000829c-2vCR; Thu, 05 Sep 2024 10:54:12 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA4w-000000081Kv-4AA3 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:10 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42c7b5b2d01so6113325e9.3 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=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wCSBDf6vejOduoC/+lNg91tRBdxB4ctW3PuO513YgaA=; b=kg5Wl7lSJOk1jkmf/wT47+rzRCzTCNqSzN2BGW5LoN2AuknDoJ23zQGZ4c3MEn5Jyl Wdm5v9DjTlMQAz7S76hORvxajRtaQ/qMJQFp+sxUZ98XDoAADs+jVB+HIhiLxahp/w4W 3E7aM+5pJYeBjeXtPLsMq3cpC+qi7yWxz9HMwaZrb12VOnJLYWXb2+Izsy3pyGPHUpdZ pyqx4afthK+Dwv2999ikKo9HprJO0ays6G++Gzlf6NKVhtKp/crGOSI9CT4jJ7mEzURx fCP4JZe/uuU46kZD1PlDDaxeOJqsIebbkE1iAbitRdJtrygVP7zMIOXRziSK0TNu5kH0 OtVA== 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=i0AzECpzaQh4ctEuMZ6qhuxxG/h762k+/7jUlKmlqMZ0yqWRmMSTZ/gnULldcFVLvE yJvV3XzHsmgy+BalfqHCZYDhBbg1QiPVd5KlXpvRbOIvaIi3oUwH73cPPwpieBxWA0zR LM+UjQ/MYf3UhKTBwulOccgdZdi/vN8xBoNvfsmH2EPoiWdNse+Dh6DzpBVZWpMvjw+V p2Z3s42ArJ6QmREdpisLwjGQznk/UsI7EStC4h2cH0cEmGAR+7oXSE5dUNdIatx1Bt9X I3AFaKVaLupGrjc5Hrxk1tJJw18uToPn02bgLKCmYDQ/2Yh84VKMobwpDuc0OCachoy+ 29SQ== X-Forwarded-Encrypted: i=1; AJvYcCUVBZXpbScSSeckBotFBNl3pBd+5uawxQchgariHJofHsMFoAhJgqE7LM7aE3D+BuIV1Zb2dPVZ4XIfhmGzXgAe@lists.infradead.org X-Gm-Message-State: AOJu0Yz+y7ticcvm6RYfjNGVCdlXqe7TB6rcirfpND1jnQMTlQbXEJJv 2Pvrhys2z46CBl2J8Rk15xlUhjKfyy8/k7vTHtyEHZ3SMcysHAUqM2BAVOgv87M= 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_035107_058468_758550CD X-CRM114-Status: GOOD ( 16.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org cs_etm__flush(), like cs_etm__sample() is an operation that generates a sample and then swaps the current with the previous packet. Calling flush after processing the queues results in two swaps which corrupts the next sample. Therefore it wasn't appropriate to call flush here so remove it. Flushing is still done on a discontinuity to explicitly clear the last branch buffer, but when the packet_queue fills up before reaching a timestamp, that's not a discontinuity and the call to cs_etm__process_traceid_queue() already generated samples and drained the buffers correctly. This is visible by looking for a branch that has the same target as the previous branch and the following source is before the address of the last target, which is impossible as execution would have had to have gone backwards: ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94 (packet_queue fills here before a timestamp, resulting in a flush and branch target ffff80008011cadc is duplicated.) ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff80008011cadc update_sg_lb_stats+0x94 ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34 After removing the flush the correct branch target is used for the second sample, and ffff8000801117c4 is no longer before the previous address: ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94 ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff8000801117a0 cpu_util+0x0 ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34 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) /* Ignore return value */ cs_etm__process_traceid_queue(etmq, tidq); - - /* - * Generate an instruction sample with the remaining - * branchstack entries. - */ - cs_etm__flush(etmq, tidq); } }