From mboxrd@z Thu Jan 1 00:00:00 1970 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=-14.0 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 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 EE964C433ED for ; Sun, 16 May 2021 08:54:31 +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 69D6D61006 for ; Sun, 16 May 2021 08:54:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69D6D61006 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hyQQywmDGZo6iCkl2MfX2kNfemlkiB8TiCFbqTmp85E=; b=Q67eLcNXCzWnX3UadSFpjnIR4 rNvnv0kh+P6IFwoPjYaRom74fsKtXbK2BHPuK0Ud+/HEvdbEp6yX0DgzUJ4ulvLRwOGwPzpBu3T3+ B2cK3d1aYcOQEjOKznG9R72eeyorG3lNLZFmmCtxqNe6ZTWNLSX3q4V4WmBdzWAyvgrwT6TqhadA+ hgTyndMG7Qiw+4TczirSOtgYdEWfxx8m5vG9aabg2U6NMp9T056bF3e5InxLfGASTsrW+MOGFcQ58 Em8C04kDqohmxyNLwC5dhslkfLGvSlB0xqla+1Zyn7RN3wpf0SoFAFz+Q12DR/aDEFTBP1JwBbELF +M2kMGt0w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liCVl-00Bv2z-Iq; Sun, 16 May 2021 08:52:33 +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 1liCVi-00Bv2p-5c for linux-arm-kernel@desiato.infradead.org; Sun, 16 May 2021 08:52:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=my1Uzq63smYlq0aZ5BNjTy0z1PVgGz1T+UWNunjYlIE=; b=pAAQyxhPglJq6O8DfnqblwVeO2 owxNP6ZjSiGPesECuJGAA+X51R6k+LA3gGXEtPISQE4moqkG8DM0UgpI/omANK4dyBbMYnRYo9Y8u b5RHHnloH/OPED3DvtKNOXnWd9kMHt9pRCqy//pAMU1L6wC88ZzAdw6LrkZ/BUNQW4NH4XfTKGzta GebyhMGJExkYDZCbUHw6Vr6IoJqieytXumcf548ns/6bFmidqO9PzJgBlaTrcx2DA9ejbeI12Rdsd MtVtU4tta63/i1iIFWIiG4Td1R2m2EhgLf+dA0i0CzN7QfZoNgZchufQlwFBYgANzJxZ/gOVmeP8F 2nle6zdA==; Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liCVe-00CpLG-FM for linux-arm-kernel@lists.infradead.org; Sun, 16 May 2021 08:52:28 +0000 Received: by mail-pf1-x432.google.com with SMTP id d78so2077436pfd.10 for ; Sun, 16 May 2021 01:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=my1Uzq63smYlq0aZ5BNjTy0z1PVgGz1T+UWNunjYlIE=; b=ywZY4TFxPyyEYUw8Wf3TDHpGejYR3Q1+B0teMp/m5zIX+Sugy5E/MSAgvfewp0mxyp bXlQeI2bVz+Qv240bm0vRAnAVIKRDbTU3MEfNiGBuUPjw/FJZUs/IsQ5f+wWiYHXK8j0 1B/nvGP56clQHGt/kRlGikLNfL7W85RStvquI3z3HoPS5GKrI7OyibHp02FT/s5XF9GX /nlAXWRt2G3d/ior7+YG6C/sMtcsJKF0ZeqmTh0SI9xhZbt9pybgX/Y1y59bB7G/fgTa TYTa1OFzH1RKeq2Cy/kUmpMS/6r+Skp+NuROf7W6liDFDnhElODVR6qRrwgPL0k0cPPQ 6Sow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=my1Uzq63smYlq0aZ5BNjTy0z1PVgGz1T+UWNunjYlIE=; b=nMGlz4CHQ9toU+r5W07O7dDPwZb/e/yi1oMLc/VRK3zztxby+3fHSwCIbYyr/Ko8d/ 4Ljii29R+CzgTbCxzUkBds6ad/ksTZPAfpBxD++PHv2MOLkt+jTxA4K9C3IMRMEMMoUh AY6nQZbQwHfH+RPJrMdx3lVR7cAmIVJ3St9vmnpq+Pmj37PA7rS+j/cRVzy0tBQ8QSN6 qvuEfQrdznUkWvHsH7NPOZqcrwiQbtQfW1y85CEpOg0khL53Ud0e0kFjAByeyA5MtZLE MQv5vkAJg4trudedlP8Y0XzRVbOHp9dR0l56dkF9eyj2P+7IC5QjzK+g6DleYwmsN/TH +eAw== X-Gm-Message-State: AOAM5338Hfj/e72DvpDJoVBSyHv1O8NnLCY6tKvaWSKEqEO/fCbK0G1B Vzppoklw8KO1YwvzSo7pUTbrAw== X-Google-Smtp-Source: ABdhPJyA+L+EygDbRxFYR7HmPlyf5t3xdo5Q7O0XJeOn23ry6h/2jqknueCzh/krFIRlQRo1HxIWGA== X-Received: by 2002:a63:4706:: with SMTP id u6mr55272506pga.152.1621155140537; Sun, 16 May 2021 01:52:20 -0700 (PDT) Received: from leoy-ThinkPad-X240s ([204.124.180.30]) by smtp.gmail.com with ESMTPSA id c71sm1007536pfc.148.2021.05.16.01.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 May 2021 01:52:19 -0700 (PDT) Date: Sun, 16 May 2021 16:52:12 +0800 From: Leo Yan To: James Clark Cc: coresight@lists.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 , Mathieu Poirier , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/3] perf cs-etm: Prevent and warn on underflows during timestamp calculation. Message-ID: <20210516085212.GA942578@leoy-ThinkPad-X240s> References: <20210513143520.22694-1-james.clark@arm.com> <20210513143520.22694-4-james.clark@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210513143520.22694-4-james.clark@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210516_015226_579330_7019D4AF X-CRM114-Status: GOOD ( 30.99 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, May 13, 2021 at 05:35:20PM +0300, James Clark wrote: > When a zero timestamp is encountered, warn once. This is to make > hardware or configuration issues visible. Also suggest that the issue > can be worked around with the --itrace=Z option. > > When an underflow with a non-zero timestamp occurrs, warn every time. s/occurrs/occurs > This is an unexpected scenario, and with increasing timestamps, it's > unlikely that it would occur more than once, therefore it should be > ok to warn every time. > > Only try to calculate the timestamp by subtracting the instruction > count if neither of the above cases are true. This makes attempting > to decode files with zero timestamps in non-timeless mode > more consistent. Currently it can half work if the timestamp wraps > around and becomes non-zero, although the behavior is undefined and > unpredictable. > > Signed-off-by: James Clark All three patches look good to me: Reviewed-by: Leo Yan > --- > .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 45 ++++++++++++++----- > 1 file changed, 34 insertions(+), 11 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..3e1a05bc82cc 100644 > --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > @@ -6,6 +6,7 @@ > * Author: Mathieu Poirier > */ > > +#include > #include > #include > #include > @@ -17,6 +18,7 @@ > > #include "cs-etm.h" > #include "cs-etm-decoder.h" > +#include "debug.h" > #include "intlist.h" > > /* use raw logging */ > @@ -294,7 +296,8 @@ 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; > > @@ -313,14 +316,33 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq, > return OCSD_RESP_CONT; > } > > - /* > - * This is the first timestamp we've seen since the beginning of traces > - * or a discontinuity. Since timestamps packets are generated *after* > - * range packets have been generated, we need to estimate the time at > - * which instructions started by subtracting the number of instructions > - * executed to the timestamp. > - */ > - packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count; > + > + if (!elem->timestamp) { > + /* > + * Zero timestamps can be seen due to misconfiguration or hardware bugs. > + * Warn once, and don't try to subtract instr_count as it would result in an > + * underflow. > + */ > + packet_queue->cs_timestamp = 0; > + WARN_ONCE(true, "Zero Coresight timestamp found at Idx:%" OCSD_TRC_IDX_STR > + ". Decoding may be improved with --itrace=Z...\n", indx); > + } else if (packet_queue->instr_count > elem->timestamp) { > + /* > + * Sanity check that the elem->timestamp - packet_queue->instr_count would not > + * result in an underflow. Warn and clamp at 0 if it would. > + */ > + packet_queue->cs_timestamp = 0; > + pr_err("Timestamp calculation underflow at Idx:%" OCSD_TRC_IDX_STR "\n", indx); > + } else { > + /* > + * This is the first timestamp we've seen since the beginning of traces > + * or a discontinuity. Since timestamps packets are generated *after* > + * range packets have been generated, we need to estimate the time at > + * which instructions started by subtracting the number of instructions > + * executed to the timestamp. > + */ > + packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count; > + } > packet_queue->next_cs_timestamp = elem->timestamp; > packet_queue->instr_count = 0; > > @@ -542,7 +564,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 +601,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, > -- > 2.28.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel