public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] perf intel-pt: Fix improved sample timestamp
Date: Fri, 10 May 2019 15:41:42 +0300	[thread overview]
Message-ID: <20190510124143.27054-3-adrian.hunter@intel.com> (raw)
In-Reply-To: <20190510124143.27054-1-adrian.hunter@intel.com>

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 <adrian.hunter@intel.com>
Fixes: 3f04d98e972b5 ("perf intel-pt: Improve sample timestamp")
Cc: stable@vger.kernel.org # v4.4+
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 ++++++++++---
 1 file changed, 10 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 26dbf11e071a..9cbd587489bf 100644
--- 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(enum intel_pt_pkt_state pkt_state)
 	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 intel_pt_decoder *decoder)
 				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 intel_pt_decoder *decoder)
 
 		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_decode(struct intel_pt_decoder *decoder)
 			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);
-- 
2.17.1


  parent reply	other threads:[~2019-05-10 12:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-10 12:41 [PATCH 0/3] perf intel-pt: Intel PT fixes Adrian Hunter
2019-05-10 12:41 ` [PATCH 1/3] perf intel-pt: Fix instructions sampling rate Adrian Hunter
2019-05-18  9:32   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-10 12:41 ` Adrian Hunter [this message]
2019-05-18  9:33   ` [tip:perf/core] perf intel-pt: Fix improved sample timestamp tip-bot for Adrian Hunter
2019-05-10 12:41 ` [PATCH 3/3] perf intel-pt: Fix sample timestamp wrt non-taken branches Adrian Hunter
2019-05-18  9:34   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-15 19:30 ` [PATCH 0/3] perf intel-pt: Intel PT fixes Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190510124143.27054-3-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox