Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2172152ybm; Thu, 23 May 2019 12:32:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJw/SUNBShTVQpcn3o9OPjlG6hcsrsDmUySRbDYc2tIkYtl8K3y5789nZ0phMp4gCpKXfK X-Received: by 2002:a17:90a:dd45:: with SMTP id u5mr3576213pjv.109.1558639961032; Thu, 23 May 2019 12:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558639961; cv=none; d=google.com; s=arc-20160816; b=jl5nkBtkmDGdPs8ixuuFnc2jdaW+t1hIVLwJdU9jrev0g2QF/uHcr+89q/41rDsbiB h2oZBwmUgO3grlvt6fk/UsRlspU0De03E1s24ySlFYpNdNkJMUD5laGz7vI1FSTD+t9U XsHdE7VGj0+Cyfj3uOnN/hFYxBjjLsNBdroFhCNpXFbKP3uvKrZ90qwn3+wXr6icbh9m rDaJZL8/O7vTIS5PUm4DSvQSFBSM4YgF0FT6FdF+L23j+oYgghBm5PsMqfv6aPR8YD9x dRUzwC4jDv1x8bt8G/u2ELfhM/NJTU0KSLguQUajbLXlwd4U3R6oLu2sBy6ggSAXRfiJ rR9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kuPfF6EL274F0UZyG6+evGd1ivMWf9Ehv/2x5yxv6dQ=; b=caywI5nTzlsfBHFCOcC7yUC6FBlV2tVOjhSEz7MWZ5yS3c+0OKJh9LowdWkM/c8L3Z Wh9LE4oJajAcIMr69GwYuNaKOOfzh0cx47XCty4alYorUcC7uUV/3d2NrFh9yfbL4Wqi 2kQLJwbli2p2cN/kD8QngYkrGIOYwb8hlnY37xjm3QTW39KO275lAo2Wq7SE5dVDYZ5x hVv//nLd5o5ory3ioJ5CkOTGx7ygjRQetgdkSfZks+MU1lES+PMoahhtIFJNdJ3YQVNz 0S8SOgPZ2dV5DTrbJFe330JqxLK4ZDzZ4LFQpJNSWZ+YQVTB8JKHuteeqE6zAnKX0Szt 7TVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gt5FhsLv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q195si538656pgq.119.2019.05.23.12.32.25; Thu, 23 May 2019 12:32:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gt5FhsLv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392033AbfEWTaC (ORCPT + 99 others); Thu, 23 May 2019 15:30:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:43216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392018AbfEWTaA (ORCPT ); Thu, 23 May 2019 15:30:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 91539217D7; Thu, 23 May 2019 19:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639799; bh=bKs5VgwY2UPSlE56fRRjQSE74HLtE6QYQqPNJaat+zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gt5FhsLvCxtQByiFGyNSdf1ifmkJZqPqSaz0+/tZYlvLzxGUttJ9p4SkczVF6sujo uVmC64+CPXMprHvFjKMPhZfla0dpzLQQ+eAbu5C/J2d0tLyuCmLLxYxbEZVdYUV/3U kVs+ul5aiI66OanCca6rL0h0dw8NNoOLRL/k4iAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Jiri Olsa , Arnaldo Carvalho de Melo Subject: [PATCH 5.1 080/122] perf intel-pt: Fix improved sample timestamp Date: Thu, 23 May 2019 21:06:42 +0200 Message-Id: <20190523181715.374011582@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adrian Hunter commit 61b6e08dc8e3ea80b7485c9b3f875ddd45c8466b upstream. The decoder uses its current timestamp in samples. Usually that is a timestamp that has already passed, but in some cases it is a timestamp for a branch that the decoder is walking towards, and consequently hasn't reached. The intel_pt_sample_time() function decides which is which, but was not handling TNT packets exactly correctly. In the case of TNT, the timestamp applies to the first branch, so the decoder must first walk to that branch. That means intel_pt_sample_time() should return true for TNT, and this patch makes that change. However, if the first branch is a non-taken branch (i.e. a 'N'), then intel_pt_sample_time() needs to return false for subsequent taken branches in the same TNT packet. To handle that, introduce a new state INTEL_PT_STATE_TNT_CONT to distinguish the cases. Note that commit 3f04d98e972b5 ("perf intel-pt: Improve sample timestamp") was also a stable fix and appears, for example, in v4.4 stable tree as commit a4ebb58fd124 ("perf intel-pt: Improve sample timestamp"). Signed-off-by: Adrian Hunter Cc: Jiri Olsa Cc: stable@vger.kernel.org # v4.4+ Fixes: 3f04d98e972b5 ("perf intel-pt: Improve sample timestamp") Link: http://lkml.kernel.org/r/20190510124143.27054-3-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -58,6 +58,7 @@ enum intel_pt_pkt_state { INTEL_PT_STATE_NO_IP, INTEL_PT_STATE_ERR_RESYNC, INTEL_PT_STATE_IN_SYNC, + INTEL_PT_STATE_TNT_CONT, INTEL_PT_STATE_TNT, INTEL_PT_STATE_TIP, INTEL_PT_STATE_TIP_PGD, @@ -72,8 +73,9 @@ static inline bool intel_pt_sample_time( case INTEL_PT_STATE_NO_IP: case INTEL_PT_STATE_ERR_RESYNC: case INTEL_PT_STATE_IN_SYNC: - case INTEL_PT_STATE_TNT: + case INTEL_PT_STATE_TNT_CONT: return true; + case INTEL_PT_STATE_TNT: case INTEL_PT_STATE_TIP: case INTEL_PT_STATE_TIP_PGD: case INTEL_PT_STATE_FUP: @@ -1261,7 +1263,9 @@ static int intel_pt_walk_tnt(struct inte return -ENOENT; } decoder->tnt.count -= 1; - if (!decoder->tnt.count) + if (decoder->tnt.count) + decoder->pkt_state = INTEL_PT_STATE_TNT_CONT; + else decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; decoder->tnt.payload <<= 1; decoder->state.from_ip = decoder->ip; @@ -1292,7 +1296,9 @@ static int intel_pt_walk_tnt(struct inte if (intel_pt_insn.branch == INTEL_PT_BR_CONDITIONAL) { decoder->tnt.count -= 1; - if (!decoder->tnt.count) + if (decoder->tnt.count) + decoder->pkt_state = INTEL_PT_STATE_TNT_CONT; + else decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; if (decoder->tnt.payload & BIT63) { decoder->tnt.payload <<= 1; @@ -2372,6 +2378,7 @@ const struct intel_pt_state *intel_pt_de err = intel_pt_walk_trace(decoder); break; case INTEL_PT_STATE_TNT: + case INTEL_PT_STATE_TNT_CONT: err = intel_pt_walk_tnt(decoder); if (err == -EAGAIN) err = intel_pt_walk_trace(decoder);