From patchwork Mon Sep 16 13:57: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: 13805523 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 73A6CC3ABA2 for ; Mon, 16 Sep 2024 14:00:54 +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=umuEtd6TXriWmaesvaUlkUkqPg9JblHlWbB3iYtKN0A=; b=moTnE2Do30hGvInRUIWNj/wsH0 dg6ZULaam/xPhxerL9mB16E1S0j62PRbq5PfEkRBCjxd/mFpbdw2RnB2Z/vQ4iEAD8WkU+tYbKE9T aVMa8Z0Og/qt/8SOfsoY2LJHJ6keM8IcmduMi9C9aZODGSSm3m+3wsilXDSX3Gvtodq/DhJ12bE/u oG6D42h+4ZXgK4SEY3TyFd9HXMECcUTAjeX9EeakDUCckbV0yhk2V/VmSJdoEoUp6W1tCsHXMi1IQ yDp4wmmoMh286TvVrCh+6EqDt9iSims2uHWinKRyXpriCjP6TBRv2E2PoBrsgmzRdrzRaTcUc1TYJ ta7xy7gA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sqCHM-0000000488j-0SEx; Mon, 16 Sep 2024 14:00:36 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sqCFF-000000047Wt-1Jve for linux-arm-kernel@lists.infradead.org; Mon, 16 Sep 2024 13:58:27 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3787e067230so3224439f8f.1 for ; Mon, 16 Sep 2024 06:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726495104; x=1727099904; 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=umuEtd6TXriWmaesvaUlkUkqPg9JblHlWbB3iYtKN0A=; b=xQseGZ8zOPdMdGZOVYBXVlD8nK3SmfZ9kTdRCfJc8sDzZzDDBYMZEStcpPUtM/ZByp jCiUhcES3p0LPoNLlj0s3MedL/rQH2TqRnf82fB23M5s+UQNQiTJvLcTFS4Ruk4vvjRf 4GUKXUjxWePH7WBG2exZ01JusvIfidKO1Ecu6IB7fi/V9uyai/ucAfGu99SAdG7wamJC CJC9NLWPrMSxpJvn/V4d8eUvLE1OblYDSFX3JW+iUd6CWTpzaf2wyIiqxmfpqMcey2af 1+E0ttQJ5A0Nf0dBd0Z1HH2DlwPEEuiRSum4Iib+WnGHl75Lq021G5gS/Qlks7phAmLJ +CGw== 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=oLKs4bCFz3PhJaHdtcJXXirV66JA/jWQOMTWzectBt/KcpjhMO69xC8jqGVInbroAk 0KwNt4C5m/qarv28E1XxKpBbHkWV9jww2aCygMQITL4Zc68eMX3dc9VLHMaQVMN1U66h RHC18v6QnXc930iL++Ft4E3uHuLOxV/b2dc8hU7X2Nore2x9IxRVftEi8eBDwmC0Ar56 gDeYjs4LOEMdjfqRTwnATdwviXU5hm+UdiHKTb+5giUHSb9gS9vVfytZahpIEmLvHWqL eKtUJOKz80JQU4vDW8da+q2Nsk7muSL+qcyA3fwIHFq8M0tVkbeEdA3hHWra3sJEEIfw uSIA== X-Forwarded-Encrypted: i=1; AJvYcCWYCl9hrMo/Wp2XJMPIlagNfiAdsRHkKTNGXj1Y9CDMVYwU9yzJ7x3PPttcchYWvMfv3bsC1pjRLbqvYETQiPHe@lists.infradead.org X-Gm-Message-State: AOJu0YxneSMmr3vbWx7lEZLut9B3E3sG6b5fykPKf8p+eBbOtEyOIZ48 k4rHiVj9K0ADSILZJrsZ4lAYoeubsLNkBpwAAoxOOieTqx4wTbLDvj7IwZ4qYsI= 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240916_065825_385959_DA89DD56 X-CRM114-Status: GOOD ( 23.36 ) 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/ Reviewed-by: Leo Yan Signed-off-by: James Clark --- 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; }