From patchwork Fri May 7 09:58:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 12244263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5790C433ED for ; Fri, 7 May 2021 10:00:38 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13FE361451 for ; Fri, 7 May 2021 10:00:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13FE361451 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=pMqj7WZwxEzxX4P+5i8jkq7516C85DahRO5nTq9xm28=; b=mWNbCD4jZuLApcwOTvWhVVBzAI 5HEOgBlCVnq9EbmrvB+1xBYzbdjEcBl36xoXFR9Butnu4vbCntIDOkHKMZ0I/5Hshz4MbFDQoU5k6 yucpSBO2IbVXGKGRRovV5amXBiKEZs9Yhs+QvquN+px5pft3tcpEYF40oxLVCXWMu/tJEVY8zB2bV 0G3MJ06JHp/c8UB/GwqeYz0i3mpCP/WMOYZwxoYsePZ71sc827f/RqjzLx/ipUWt5EWyUkEYu7cOm 73syDY880qTtDm3rm3MsYoTWzvNf9rI4b4X54KM1cOWEyBhOCzevSRNMprBSUFKRQSdnQ0osgRShP FBiEecBg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lexFm-006kHz-Db; Fri, 07 May 2021 09:58:39 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lexFk-006kHo-QD for linux-arm-kernel@desiato.infradead.org; Fri, 07 May 2021 09:58:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=YHG5MzHUesy+7MwhPdTReKGZUYwqNnzJCZ1qBcyLoAY=; b=kqGyGeI7OSm39pzAoyfEyOA5mk 5liAarxYJWheOhZJwEpWCU0YXhfQChjjZqGa8L/XY4hhYEmMmBiAnZbJtN9csGAexRXq7TArE/Bav vdvBH7uxPsFWZo3l46Ef44fVbzw0nqjTVoyFQfGNq1yjoZSKidXj5eDlLXIxC7mOP+0RgEurveWbt Y4Rklia7KTMoBWYvbLpaPljQfOHIhTHJM58qDsnoq+Qj2yi8KEDVF0/c0eHOaHzhRHr9cQsWrVNyG Gly/tKAVpx1J08Ms+05NdDvo1J8vIABE8Lp7LFfsFQrcxKxMGIziIUypP7LIkPw2WbuulMTKs2riw 5tsBBxqA==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lexFi-006lHc-2b for linux-arm-kernel@lists.infradead.org; Fri, 07 May 2021 09:58:35 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 93F1C113E; Fri, 7 May 2021 02:58:29 -0700 (PDT) Received: from e121896.arm.com (unknown [10.57.84.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8F2C23F718; Fri, 7 May 2021 02:58:25 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, mathieu.poirier@linaro.org Cc: al.grant@arm.com, branislav.rankov@arm.com, denik@chromium.org, suzuki.poulose@arm.com, anshuman.khandual@arm.com, James Clark , Mike Leach , Leo Yan , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] perf cs-etm: Handle valid-but-zero timestamps Date: Fri, 7 May 2021 12:58:13 +0300 Message-Id: <20210507095814.17933-1-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210507_025834_234032_6DBEA564 X-CRM114-Status: GOOD ( 23.17 ) 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 There is an intermittent issue on Trogdor devices that results in all Coresight timestamps having a value of zero. Because zero is currently treated as "not found" rather than "found but zero", this breaks the decoding flow when it would otherwise work. This patch adds an out parameter and return code so the difference between zero and non-existent timestamps can be determined. There is also a change to fix an underflow. Although this is a workaround, the change is technically a valid way of writing the cs_etm__etmq_get_timestamp() function. It could have been written similarly to this without trying to work around this issue, so it's no less correct. But, because it's a workaround to a problem elsewhere, I will submit this as an RFC for feedback. This patch applies on top of the "[PATCH v2 0/2] perf cs-etm: Set time on synthesised samples to preserve ordering" patchset. Co-developed-by: Denis Nikitin Signed-off-by: Denis Nikitin Signed-off-by: James Clark --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 5 ++++- tools/perf/util/cs-etm.c | 22 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index b01d363b9301..947e44413c6e 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -320,7 +320,10 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq, * which instructions started by subtracting the number of instructions * executed to the timestamp. */ - packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count; + if (packet_queue->instr_count >= elem->timestamp) + packet_queue->cs_timestamp = 0; + else + packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count; packet_queue->next_cs_timestamp = elem->timestamp; packet_queue->instr_count = 0; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index e5c1a1b22a2a..1969921c406a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -210,13 +210,14 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, etmq->pending_timestamp_chan_id = trace_chan_id; } -static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq, +static int cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq, + u64 *timestamp, u8 *trace_chan_id) { struct cs_etm_packet_queue *packet_queue; if (!etmq->pending_timestamp_chan_id) - return 0; + return -ENODATA; if (trace_chan_id) *trace_chan_id = etmq->pending_timestamp_chan_id; @@ -224,13 +225,15 @@ static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq, packet_queue = cs_etm__etmq_get_packet_queue(etmq, etmq->pending_timestamp_chan_id); if (!packet_queue) - return 0; + return -ENODATA; /* Acknowledge pending status */ etmq->pending_timestamp_chan_id = 0; /* See function cs_etm_decoder__do_{hard|soft}_timestamp() */ - return packet_queue->cs_timestamp; + if (timestamp) + *timestamp = packet_queue->cs_timestamp; + return 0; } static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) @@ -864,11 +867,10 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all * the timestamp calculation for us. */ - cs_timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id); - - /* We found a timestamp, no need to continue. */ - if (cs_timestamp) + if (!cs_etm__etmq_get_timestamp(etmq, &cs_timestamp, &trace_chan_id)) { + /* We found a timestamp, no need to continue. */ break; + } /* * We didn't find a timestamp so empty all the traceid packet @@ -2286,9 +2288,7 @@ static int cs_etm__process_queues(struct cs_etm_auxtrace *etm) if (ret) goto out; - cs_timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id); - - if (!cs_timestamp) { + if (cs_etm__etmq_get_timestamp(etmq, &cs_timestamp, &trace_chan_id)) { /* * Function cs_etm__decode_data_block() returns when * there is no more traces to decode in the current