Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1378512pxy; Thu, 29 Apr 2021 06:02:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0CyGYXgBukcPa/bE0b00IJdje+ASY/0fLM+1HqiqHWY2v0/Q3ugXwRAA9gr5SB04MYuqQ X-Received: by 2002:a17:906:7942:: with SMTP id l2mr33971432ejo.314.1619701329630; Thu, 29 Apr 2021 06:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619701329; cv=none; d=google.com; s=arc-20160816; b=RHd+wb2C4op7VpjTmfs7Pv2BJyZGi5i/6h9B7ZHp8L0SQ039xe40rXXJ6Ya1XboIJe pOp8kv0OIhm+s6O7xKiuiZ3sMmSPuTtF0zrERFru91hIUu5068QnvnBFUKcB9Dqzhd6j 5uwf9jMdgGeUUB0FcJ5bhe9Wdwha5NtYXakd0oe0ZgKKZTsK2Zgv+GaEkj5PN0r1B7l0 Hqe51SAzYNoMK/3wJVvZ2irjzOmeRbcYwsZZ8+R1zKUILaUeW1Oi3rcbHZW1ngHk7bxP ABM4j2PGB5vY0s+vPJpjLByej0XOntpk9xZWSKKFAtKNi8npwZ7dzD1XysZS6f00Lj8U 6fow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:references:in-reply-to:message-id :date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=gf9rdTuH54eWReETUjAuQt1eRi+hviSYfAsZyNgG1Vw=; b=OVhH6Y5NwxlapC9rQltrTvJRsZb9X5JerktXyDNs44hYxuq59FP/BsuXxKIi6G/FIe GhXlKUqgDtRctUs6NnZsJKO39pAen/cJJKxbZ3rMDriQfUDHHzruUJnAeWU9akwblbl7 BM4w/iuaskNMh90Vvosj4RyPi82Vs5f2+sPLuuKiyGELf70HYV1OK5YHI36L/eLtJ3/6 f11Y7XvCdWgrAUmv5c/jXIv3qKZ1hky+J5qupL0g4NdlUeEsJ6itWjqa9FXoMtkMNkGa wXP0fw17wSVtKq7eeYH34FrqMDFKTrtHKpOGRr0gxTiwSKLPw0j9ik/Fyz2YE9x2aV3s M2+w== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si2630761edv.309.2021.04.29.06.01.43; Thu, 29 Apr 2021 06:02:09 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239032AbhD2NAT (ORCPT + 99 others); Thu, 29 Apr 2021 09:00:19 -0400 Received: from mga17.intel.com ([192.55.52.151]:50859 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238780AbhD2NAJ (ORCPT ); Thu, 29 Apr 2021 09:00:09 -0400 IronPort-SDR: PDvHjcpJWnLHGbvHjo6OmsgngcgERTwIL27OJ9jmDeouOlu9NCNfYhG49GmXEZ0xYICl4eaHyN CreXNw82f+nA== X-IronPort-AV: E=McAfee;i="6200,9189,9969"; a="177107525" X-IronPort-AV: E=Sophos;i="5.82,259,1613462400"; d="scan'208";a="177107525" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2021 05:58:51 -0700 IronPort-SDR: 3/3b5QseZ4HsUftWd/EiooAuVWZlLihivT0V2hb/zuq8XC99+h8zs19K+v+wfnXZ88eAB1r9s0 mDWEbV1eN44Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,259,1613462400"; d="scan'208";a="537361675" Received: from ahunter-desktop.fi.intel.com ([10.237.72.174]) by orsmga004.jf.intel.com with ESMTP; 29 Apr 2021 05:58:50 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo , Jiri Olsa , Andi Kleen Cc: linux-kernel@vger.kernel.org Subject: [PATCH 10/12] perf intel-pt: Better 7-byte timestamp wraparound logic Date: Thu, 29 Apr 2021 15:58:52 +0300 Message-Id: <20210429125854.13905-11-adrian.hunter@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210429125854.13905-1-adrian.hunter@intel.com> References: <20210429125854.13905-1-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A timestamp should not go backwards. If it does it is assumed that the 7-byte TSC packet value has wrapped. Improve that logic so that it will not allow the timestamp to go past the buffer timestamp (which is recorded when the buffer is copied out) Signed-off-by: Adrian Hunter --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c index ba5b5782acc1..b95312ec3832 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -1499,9 +1499,15 @@ static void intel_pt_calc_tsc_timestamp(struct intel_pt_decoder *decoder) timestamp = decoder->timestamp; } if (timestamp < decoder->timestamp) { - intel_pt_log_to("Wraparound timestamp", timestamp); - timestamp += (1ULL << 56); - decoder->tsc_timestamp = timestamp; + if (!decoder->buf_timestamp || + (timestamp + (1ULL << 56) < decoder->buf_timestamp)) { + intel_pt_log_to("Wraparound timestamp", timestamp); + timestamp += (1ULL << 56); + decoder->tsc_timestamp = timestamp; + } else { + intel_pt_log_to("Suppressing bad timestamp", timestamp); + timestamp = decoder->timestamp; + } } decoder->timestamp = timestamp; decoder->timestamp_insn_cnt = 0; -- 2.17.1