Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3544523pxj; Tue, 11 May 2021 06:55:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7WF7mZYaoGySC7MgFXctIq/Svk8C/7BiKbqyDp84uoEO04GTxXeKPp9m9mVYz1hUPkSm3 X-Received: by 2002:a05:6402:1bc9:: with SMTP id ch9mr37091265edb.136.1620741314437; Tue, 11 May 2021 06:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620741314; cv=none; d=google.com; s=arc-20160816; b=nU3Mi96HSnVDDR3fpEDuBkUkl+tL8zGMYktn7y+WmOdCSZHAws6ievI+B9kXu5Wb1a I1+Q5oiBdtohx7LsivEdFpaMY/yAyusfLcd760gsLhZxE7ZHQEYtzpleki3DQCa8UaH4 3faPQXQ/5NGp77QPDkJtYnST3P1cbjImPFP6H/P79kIkWD/WnIE9uIp99p57DC4Iycmb lUg90LEE0v7sP3HTo96utqOx0MhNQIwD+MCk8BYc5on9zfVVk67gqDh5zpk5BcYgVJUq a9y/2iVN+7gCdJgDXxcxt2jnoEvyPzItL6ES3lMNwMm4a0p83CTVjkG++ST5y94ZoT0d mThQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=jM96kkXZnQ+ucwMD8GSlPg8jyZ0CWFEViFExRPLokco=; b=bkO28j21J+zJBcTIaShv7HaV4nhaUdJ6unYLrxYDBg7tbw6Y3k+zh+8Ge8cv02v1r6 qRNAsynlnr6N75sntZo1KLJDezQPSm7USgi7fAED8W0mywA1IJDlrLatSGxWWZoVJw/D oqzI/JkwcMD9G8E1/W2nBxkLLPOx0K8Xa//6STNmVo3XIl3xGmMM5Q7/v/9Do0cYT2qC 7ALHlyIMa7mH0XtEAwhpqOkigwjWKVpENA7eJslYx6hH0RDck+HkRYMF5JveANJN/lJ/ PVr0c3TV36pvyxCHQvm7RXX3DsKmyxkrxJhW83xD1wFqyLJbTBr9pvpcrGvdWgsaSBQb N/vQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc18si18203161edb.321.2021.05.11.06.54.49; Tue, 11 May 2021 06:55:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbhEKNys (ORCPT + 99 others); Tue, 11 May 2021 09:54:48 -0400 Received: from foss.arm.com ([217.140.110.172]:48240 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231599AbhEKNyr (ORCPT ); Tue, 11 May 2021 09:54:47 -0400 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 C4AC7101E; Tue, 11 May 2021 06:53:40 -0700 (PDT) Received: from [10.57.81.122] (unknown [10.57.81.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 561543F718; Tue, 11 May 2021 06:53:37 -0700 (PDT) Subject: Re: [RFC PATCH] perf cs-etm: Handle valid-but-zero timestamps To: Leo Yan Cc: coresight@lists.linaro.org, mathieu.poirier@linaro.org, al.grant@arm.com, branislav.rankov@arm.com, denik@chromium.org, suzuki.poulose@arm.com, anshuman.khandual@arm.com, Mike Leach , 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 References: <20210507095814.17933-1-james.clark@arm.com> <3926c523-3fdb-66de-8b9c-b68290a5053e@arm.com> <20210510053904.GB4835@leoy-ThinkPad-X240s> From: James Clark Message-ID: Date: Tue, 11 May 2021 16:53:35 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210510053904.GB4835@leoy-ThinkPad-X240s> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/05/2021 08:39, Leo Yan wrote: > Hi James, > [...] > >>> 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; > > Actually here have two situations: one case is "elem->timestamp" is zero, > another case is the overflow for "elem->timestamp". > > So the change should be like: > > if (!elem->timestamp) > packet_queue->cs_timestamp = 0; > else if (packet_queue->instr_count >= elem->timestamp) > /* handle overflow? */ > else > packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count; > > It's better to think about how to handle the overflow in this case. Do you have any idea about what to do in the overflow case? I think I will submit a new patchset that makes the new 'Z' timeless --itrace option work, because that also fixes this issue, without having to do the original workaround change in this RFC. But I'd also like to fix this overflow because it masks the issue by making non-zero timestamps appear even though they aren't valid ones. I was thinking that printing a warning in the overflow case would work, but then I would also print a warning for the zero timestamps, and that would make just a single case, rather than two. Unless we just have slightly different warning text? Something like this? Without the zero timestamp issue, the underflow issue probably wouldn't be encountered. But at least there would be some visibility if it did: 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 059bcec3f651..5d8abccd34ab 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -17,6 +17,7 @@ #include "cs-etm.h" #include "cs-etm-decoder.h" +#include "debug.h" #include "intlist.h" /* use raw logging */ @@ -294,9 +295,11 @@ cs_etm_decoder__do_soft_timestamp(struct cs_etm_queue *etmq, static ocsd_datapath_resp_t cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq, const ocsd_generic_trace_elem *elem, - const uint8_t trace_chan_id) + const uint8_t trace_chan_id, + const ocsd_trc_index_t indx) { struct cs_etm_packet_queue *packet_queue; + static bool warned_timestamp_zero = false; /* First get the packet queue for this traceID */ packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id); @@ -320,7 +323,20 @@ 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->timestamp = elem->timestamp - packet_queue->instr_count; + if (!elem->timestamp) { + packet_queue->timestamp = 0; + if (!warned_timestamp_zero) { + pr_err("Zero Coresight timestamp found at Idx:%" OCSD_TRC_IDX_STR + ". Decoding may be improved with --itrace=Z...\n", indx); + warned_timestamp_zero = true; + } + } + else if (packet_queue->instr_count >= elem->timestamp) { + packet_queue->timestamp = 0; + pr_err("Timestamp calculation underflow at Idx:%" OCSD_TRC_IDX_STR "\n", indx); + } + else + packet_queue->timestamp = elem->timestamp - packet_queue->instr_count; packet_queue->next_timestamp = elem->timestamp; packet_queue->instr_count = 0; @@ -542,7 +558,7 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq, static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, - const ocsd_trc_index_t indx __maybe_unused, + const ocsd_trc_index_t indx, const u8 trace_chan_id __maybe_unused, const ocsd_generic_trace_elem *elem) { @@ -579,7 +595,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( break; case OCSD_GEN_TRC_ELEM_TIMESTAMP: resp = cs_etm_decoder__do_hard_timestamp(etmq, elem, - trace_chan_id); + trace_chan_id, + indx); break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: resp = cs_etm_decoder__set_tid(etmq, packet_queue, James > > Thanks, > Leo >