From patchwork Thu Sep 12 15:11: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: 13802294 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 A563FEED613 for ; Thu, 12 Sep 2024 15:14:55 +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=FVBlRkBG8+Idy8ehQJVILHBn96DUefeGnB3enzkGPeQ=; b=a5sKaRfgyG4fSFpMZm+UnaTceQ 0ptNNy+q+4ANKhdUeTMpNmOsEeh978NGDS9q86FCOtS71VXa0Bx3jp14Lj1Cdg1zPjqdohBWdew8n fOt6CNW1RY0bRf6+IKNXlNsJInwlE4kPDByEKvTflkmlZ7E1MO+KV8svxoCKxSvMwStOM2eXz7pD7 rxerI7ak+2I6fNbKHzIGuH94gUk+fKgWH0KDW9ixqD19zN8kDuixNVN22Sm/PP0narxP5Pwy8D/BS 5Wycl2SqEqfB8xSkwyCnRImV6XON0ndMb78POwq/qSvcJvlcMLjUM1NB2GoSmfHodeYkF5e27w+dk 1bMIDSkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solWv-0000000DW27-1JMl; Thu, 12 Sep 2024 15:14:45 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1solUm-0000000DV4n-0UR1 for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:12:34 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso10187335e9.2 for ; Thu, 12 Sep 2024 08:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153950; x=1726758750; darn=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=FVBlRkBG8+Idy8ehQJVILHBn96DUefeGnB3enzkGPeQ=; b=QG5/Hcv6EWm8EXW3gMIFwuC2K02KczGwlDahOuor6Q9GJMrnlGrZMPInRrSiGyF8sb 3/BMPKdiX2UnUHlRjWU0xrExFnZVkTHBXvXWspHFwiUQKDqau8aNxs6JHS5s/5eHCYL+ mxQT35jrykvNHv88CoL/LrsbRHNsYRBg/r2gM6x1VXj2QRamG6FhdMgLuC7M89Gh1q7f cqen72pmXiQv7WNbrsEx08IcYsqIdCqU4OGjqmSLxpYlcOr5oUNgg/T/FuX2i2jBiV1O a7JCN8XF65nxzSfgOvADfY8JFnHhPh4V+i3TPBEHx4xLFtifqdHMfFBLkFlBpjNcfYIB 5+eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153950; x=1726758750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FVBlRkBG8+Idy8ehQJVILHBn96DUefeGnB3enzkGPeQ=; b=qN/5+ThcDOGnbMv/oWxcqlZaX2BcKroekM0pJ4PdHzCUpAcDYTgEXZlFe3D3o3SRis 3BHSpDC2OLWBAMknY5axZ7yC7/Iq2wHZ4kOugtHCtvqxg97S4gwo3pK999BfjwVlcqrd JtdvKO8BHrZ73ccRvVRc3pN84VISEWLVfzx7Z8GxK5wJNmWXOCVeaHGGWLKP334SpTgP tGC9VTgsYxjLdzbK6zaftFMAX0v1fVuUOHOeOqU4DyCRLLSV3kVgterWAwm955blLUTO NN6np4uNBrrcJpUQppqAMy2xtxBMWexDv+cDeoDhiBAQD5ycvrPd/OQnrADngNQYOWwk l9xQ== X-Forwarded-Encrypted: i=1; AJvYcCUfQfttePyoC+XNiuNjqv0S6cCOaWScd/U4czAT4DksCrWa9weetx2cC99Zn2H8PbqCq4885UjcGMZtXYAMl67F@lists.infradead.org X-Gm-Message-State: AOJu0Yw4vE6B23IJ0xtnmSPgkXhh80jPqvGwSBpqoJ5lpu7w8ycBgWNp OuEJm1WFPD4oyNYBMDP6ARKj4/21TT+YbIN3iKX58QhahjDc9hdWQjw4lJmIXSs= X-Google-Smtp-Source: AGHT+IF+9bah/yP5A17iSIWzhHNRw1ieQewYP5DtP+X3D3ShpKM5Hg1qUBA6sanEMQfeBKZpW/0C4g== X-Received: by 2002:a05:600c:1c91:b0:42b:af52:2525 with SMTP id 5b1f17b1804b1-42cdb54dd62mr28413645e9.16.1726153949096; Thu, 12 Sep 2024 08:12:29 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12:28 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/7] perf cs-etm: Don't flush when packet_queue fills up Date: Thu, 12 Sep 2024 16:11:32 +0100 Message-Id: <20240912151143.1264483-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912151143.1264483-1-james.clark@linaro.org> References: <20240912151143.1264483-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_081232_262932_2B9D98F2 X-CRM114-Status: GOOD ( 23.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org cs_etm__flush(), like cs_etm__sample() is an operation that generates a sample and then swaps the current with the previous packet. Calling flush after processing the queues results in two swaps which corrupts the next sample. Therefore it wasn't appropriate to call flush here so remove it. Flushing is still done on a discontinuity to explicitly clear the last branch buffer, but when the packet_queue fills up before reaching a timestamp, that's not a discontinuity and the call to cs_etm__process_traceid_queue() already generated samples and drained the buffers correctly. This is visible by looking for a branch that has the same target as the previous branch and the following source is before the address of the last target, which is impossible as execution would have had to have gone backwards: ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94 (packet_queue fills here before a timestamp, resulting in a flush and branch target ffff80008011cadc is duplicated.) ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff80008011cadc update_sg_lb_stats+0x94 ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34 After removing the flush the correct branch target is used for the second sample, and ffff8000801117c4 is no longer before the previous address: ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94 ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff8000801117a0 cpu_util+0x0 ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34 Make sure that a final branch stack is output at the end of the trace by calling cs_etm__end_block(). This is already done for both the timeless decode paths. Fixes: 21fe8dc1191a ("perf cs-etm: Add support for CPU-wide trace scenarios") Reported-by: Ganapatrao Kulkarni Closes: https://lore.kernel.org/all/20240719092619.274730-1-gankulkarni@os.amperecomputing.com/ Signed-off-by: James Clark Reviewed-by: Leo Yan --- tools/perf/util/cs-etm.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 90f32f327b9b..242788ac9625 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2490,12 +2490,6 @@ static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq) /* Ignore return value */ cs_etm__process_traceid_queue(etmq, tidq); - - /* - * Generate an instruction sample with the remaining - * branchstack entries. - */ - cs_etm__flush(etmq, tidq); } } @@ -2638,7 +2632,7 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm) while (1) { if (!etm->heap.heap_cnt) - goto out; + break; /* Take the entry at the top of the min heap */ cs_queue_nr = etm->heap.heap_array[0].queue_nr; @@ -2721,6 +2715,23 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm) ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); } + for (i = 0; i < etm->queues.nr_queues; i++) { + struct int_node *inode; + + etmq = etm->queues.queue_array[i].priv; + if (!etmq) + continue; + + intlist__for_each_entry(inode, etmq->traceid_queues_list) { + int idx = (int)(intptr_t)inode->priv; + + /* Flush any remaining branch stack entries */ + tidq = etmq->traceid_queues[idx]; + ret = cs_etm__end_block(etmq, tidq); + if (ret) + return ret; + } + } out: return ret; }