Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2154895ybm; Thu, 23 May 2019 12:15:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhaJPg5CWucDl0PNMjKT28Bmhr0K3fWco7s58gbVjtw6ijJcRyL2n6N9KJcbXco+sG0TQN X-Received: by 2002:a65:4349:: with SMTP id k9mr11881075pgq.243.1558638942393; Thu, 23 May 2019 12:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558638942; cv=none; d=google.com; s=arc-20160816; b=uRjpOhk2flVQHKZBlOxNUiqv+lIJKC89Fz8mOqHYi8hNNNm5gFGX39qxvdmiPXwzbf RD2ymolnbT5pNyxTNTs0Jpx8HG+4tg/Rr6205nrBfBgfm+OuDOyi90iKrbkPcel6PmjW VL6ba5eoWK1sTScWZOKboZuKuQP5VuTh6zVcms/3MzNLkrjBWLtJ+fapvM9/8Uv5rx0S qofife0jeoQSjhoE5taHZVMonS3onlHrLKSjhJ/ixeWm4tjwSp6dJ7u9SAD58nlH5vDR e8paCy1WMD4cCE73wZmKPaZ5kY0vtvWCjaln8lk/I+Sh8A4heLd185cBNcP0ELfsr64L dLlQ== 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=yK5I0B7rgDZapRkYeGJuxvFaJsJtInlKHjIeAQrlhuo=; b=QAFI0Hrg6vfGexFRuXCS84bwy77mqSuoBOOtFqVQG1b0LsTu1BQwaxMqTsT7p/UtQh SaeIblxuGINJxnVxkhRh7Xq2TPSqwcKdtDgsPdi43WhcUMFr+QDLlhYO8b6KJ+HJ7NIJ geQNMDl4V4b5zBcQohwiEO7QHYEOVaXK+mw7h42wm3ZrMXRacO1WQQZswxjOhsyUpLgA 2Hf2uz8GuTzCA6gthJ3EolBZJMoX+loBnB27MhFdKff6yDodYTTgBABLzWwjPXsSjOfo iWY/xMiPzVBH9TIMfygUwe5C0ZmD7ZTuZvUM+OBzpVE9KYtLY88erY2Yezbs05NthNQK I3yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zobJwNy0; 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 a33si543082plc.283.2019.05.23.12.15.27; Thu, 23 May 2019 12:15:42 -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=zobJwNy0; 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 S2387700AbfEWTMr (ORCPT + 99 others); Thu, 23 May 2019 15:12:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:46486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731768AbfEWTMm (ORCPT ); Thu, 23 May 2019 15:12:42 -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 4B48D21850; Thu, 23 May 2019 19:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638761; bh=uAgXl6jx6TsS2nw/MjIAyn/1+iFWziT62wRj3t4zXOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zobJwNy0DLxNu8CgJ2opVlEn6bTkl0QFunxfwX232AFbIDovsEmJxu7K0jBfaOsm2 1mGwj2O+mX5z5rFGsCHS0CC4MZapNR28QxHAgR5OHYQMZ1ipI0REu7Pn0F5kBd5Kc8 HgEz1p7k9fTL4+X1w/rpgzv0UKwd+ZNVWQoyVDVo= 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 4.14 38/77] perf intel-pt: Fix improved sample timestamp Date: Thu, 23 May 2019 21:05:56 +0200 Message-Id: <20190523181725.454806227@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@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: @@ -1256,7 +1258,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; @@ -1287,7 +1291,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; @@ -2356,6 +2362,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);