All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Adrian Hunter <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, hpa@zytor.com, adrian.hunter@intel.com,
	jolsa@redhat.com, tglx@linutronix.de, mingo@kernel.org,
	yao.jin@linux.intel.com, linux-kernel@vger.kernel.org
Subject: [tip:perf/core] perf intel-pt: Add intel_pt_fast_forward()
Date: Mon, 17 Jun 2019 12:43:06 -0700	[thread overview]
Message-ID: <tip-a7fa19f5a255cc8970202d5c54092089a01fc042@git.kernel.org> (raw)
In-Reply-To: <20190604130017.31207-9-adrian.hunter@intel.com>

Commit-ID:  a7fa19f5a255cc8970202d5c54092089a01fc042
Gitweb:     https://git.kernel.org/tip/a7fa19f5a255cc8970202d5c54092089a01fc042
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 4 Jun 2019 16:00:06 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 10 Jun 2019 16:20:12 -0300

perf intel-pt: Add intel_pt_fast_forward()

Intel PT decoding is done in time order. In order to support efficient time
interval filtering, add a facility to "fast forward" towards a particular
timestamp. That involves finding the right buffer, stepping to that buffer,
and then stepping forward PSBs. Because decoding must begin at a PSB,
"fast forward" stops at the last PSB that has a timestamp before the target
timestamp.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190604130017.31207-9-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 130 +++++++++++++++++++++
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |   2 +
 2 files changed, 132 insertions(+)

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 dde6a7a97a7a..c374a856e73f 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -126,6 +126,7 @@ struct intel_pt_decoder {
 	uint64_t timestamp;
 	uint64_t tsc_timestamp;
 	uint64_t ref_timestamp;
+	uint64_t buf_timestamp;
 	uint64_t sample_timestamp;
 	uint64_t ret_addr;
 	uint64_t ctc_timestamp;
@@ -519,6 +520,7 @@ static int intel_pt_get_data(struct intel_pt_decoder *decoder, bool reposition)
 		intel_pt_log("No more data\n");
 		return -ENODATA;
 	}
+	decoder->buf_timestamp = buffer.ref_timestamp;
 	if (!buffer.consecutive || reposition) {
 		intel_pt_reposition(decoder);
 		decoder->ref_timestamp = buffer.ref_timestamp;
@@ -2854,3 +2856,131 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
 			return buf_b; /* No overlap */
 	}
 }
+
+/**
+ * struct fast_forward_data - data used by intel_pt_ff_cb().
+ * @timestamp: timestamp to fast forward towards
+ * @buf_timestamp: buffer timestamp of last buffer with trace data earlier than
+ *                 the fast forward timestamp.
+ */
+struct fast_forward_data {
+	uint64_t timestamp;
+	uint64_t buf_timestamp;
+};
+
+/**
+ * intel_pt_ff_cb - fast forward lookahead callback.
+ * @buffer: Intel PT trace buffer
+ * @data: opaque pointer to fast forward data (struct fast_forward_data)
+ *
+ * Determine if @buffer trace is past the fast forward timestamp.
+ *
+ * Return: 1 (stop lookahead) if @buffer trace is past the fast forward
+ *         timestamp, and 0 otherwise.
+ */
+static int intel_pt_ff_cb(struct intel_pt_buffer *buffer, void *data)
+{
+	struct fast_forward_data *d = data;
+	unsigned char *buf;
+	uint64_t tsc;
+	size_t rem;
+	size_t len;
+
+	buf = (unsigned char *)buffer->buf;
+	len = buffer->len;
+
+	if (!intel_pt_next_psb(&buf, &len) ||
+	    !intel_pt_next_tsc(buf, len, &tsc, &rem))
+		return 0;
+
+	tsc = intel_pt_8b_tsc(tsc, buffer->ref_timestamp);
+
+	intel_pt_log("Buffer 1st timestamp " x64_fmt " ref timestamp " x64_fmt "\n",
+		     tsc, buffer->ref_timestamp);
+
+	/*
+	 * If the buffer contains a timestamp earlier that the fast forward
+	 * timestamp, then record it, else stop.
+	 */
+	if (tsc < d->timestamp)
+		d->buf_timestamp = buffer->ref_timestamp;
+	else
+		return 1;
+
+	return 0;
+}
+
+/**
+ * intel_pt_fast_forward - reposition decoder forwards.
+ * @decoder: Intel PT decoder
+ * @timestamp: timestamp to fast forward towards
+ *
+ * Reposition decoder at the last PSB with a timestamp earlier than @timestamp.
+ *
+ * Return: 0 on success or negative error code on failure.
+ */
+int intel_pt_fast_forward(struct intel_pt_decoder *decoder, uint64_t timestamp)
+{
+	struct fast_forward_data d = { .timestamp = timestamp };
+	unsigned char *buf;
+	size_t len;
+	int err;
+
+	intel_pt_log("Fast forward towards timestamp " x64_fmt "\n", timestamp);
+
+	/* Find buffer timestamp of buffer to fast forward to */
+	err = decoder->lookahead(decoder->data, intel_pt_ff_cb, &d);
+	if (err < 0)
+		return err;
+
+	/* Walk to buffer with same buffer timestamp */
+	if (d.buf_timestamp) {
+		do {
+			decoder->pos += decoder->len;
+			decoder->len = 0;
+			err = intel_pt_get_next_data(decoder, true);
+			/* -ENOLINK means non-consecutive trace */
+			if (err && err != -ENOLINK)
+				return err;
+		} while (decoder->buf_timestamp != d.buf_timestamp);
+	}
+
+	if (!decoder->buf)
+		return 0;
+
+	buf = (unsigned char *)decoder->buf;
+	len = decoder->len;
+
+	if (!intel_pt_next_psb(&buf, &len))
+		return 0;
+
+	/*
+	 * Walk PSBs while the PSB timestamp is less than the fast forward
+	 * timestamp.
+	 */
+	do {
+		uint64_t tsc;
+		size_t rem;
+
+		if (!intel_pt_next_tsc(buf, len, &tsc, &rem))
+			break;
+		tsc = intel_pt_8b_tsc(tsc, decoder->buf_timestamp);
+		/*
+		 * A TSC packet can slip past MTC packets but, after fast
+		 * forward, decoding starts at the TSC timestamp. That means
+		 * the timestamps may not be exactly the same as the timestamps
+		 * that would have been decoded without fast forward.
+		 */
+		if (tsc < timestamp) {
+			intel_pt_log("Fast forward to next PSB timestamp " x64_fmt "\n", tsc);
+			decoder->pos += decoder->len - len;
+			decoder->buf = buf;
+			decoder->len = len;
+			intel_pt_reposition(decoder);
+		} else {
+			break;
+		}
+	} while (intel_pt_step_psb(&buf, &len));
+
+	return 0;
+}
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index de36254c6ac9..e633fad2fd5d 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -130,6 +130,8 @@ void intel_pt_decoder_free(struct intel_pt_decoder *decoder);
 
 const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);
 
+int intel_pt_fast_forward(struct intel_pt_decoder *decoder, uint64_t timestamp);
+
 unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
 				     unsigned char *buf_b, size_t len_b,
 				     bool have_tsc, bool *consecutive);

  reply	other threads:[~2019-06-17 19:43 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 12:59 [PATCH 00/19] perf intel-pt: Add support for efficient time interval filtering Adrian Hunter
2019-06-04 12:59 ` [PATCH 01/19] perf auxtrace: Add perf time interval to itrace_synth_ops Adrian Hunter
2019-06-17 19:38   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 02/19] perf script: Set perf time interval in itrace_synth_ops Adrian Hunter
2019-06-17 19:38   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 03/19] perf report: " Adrian Hunter
2019-06-17 19:39   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 04/19] perf intel-pt: Add lookahead callback Adrian Hunter
2019-06-17 19:40   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 05/19] perf intel-pt: Factor out intel_pt_8b_tsc() Adrian Hunter
2019-06-17 19:41   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 06/19] perf intel-pt: Factor out intel_pt_reposition() Adrian Hunter
2019-06-17 19:41   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 07/19] perf intel-pt: Add reposition parameter to intel_pt_get_data() Adrian Hunter
2019-06-17 19:42   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 08/19] perf intel-pt: Add intel_pt_fast_forward() Adrian Hunter
2019-06-17 19:43   ` tip-bot for Adrian Hunter [this message]
2019-06-04 13:00 ` [PATCH 09/19] perf intel-pt: Factor out intel_pt_get_buffer() Adrian Hunter
2019-06-17 19:43   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 10/19] perf intel-pt: Add support for lookahead Adrian Hunter
2019-06-17 19:44   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 11/19] perf intel-pt: Add support for efficient time interval filtering Adrian Hunter
2019-06-17 19:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 12/19] perf time-utils: Treat time ranges consistently Adrian Hunter
2019-06-17 19:45   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 13/19] perf time-utils: Factor out set_percent_time() Adrian Hunter
2019-06-17 19:46   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 14/19] perf time-utils: Prevent percentage time range overlap Adrian Hunter
2019-06-17 19:47   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 15/19] perf time-utils: Fix --time documentation Adrian Hunter
2019-06-17 19:47   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 16/19] perf time-utils: Simplify perf_time__parse_for_ranges() error paths slightly Adrian Hunter
2019-06-17 19:48   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 17/19] perf time-utils: Make perf_time__parse_for_ranges() more logical Adrian Hunter
2019-06-17 19:49   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 18/19] perf tests: Add a test for time-utils Adrian Hunter
2019-06-17 19:50   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-04 13:00 ` [PATCH 19/19] perf time-utils: Add support for multiple explicit time intervals Adrian Hunter
2019-06-17 19:50   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-06-07 19:49 ` [PATCH 00/19] perf intel-pt: Add support for efficient time interval filtering 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=tip-a7fa19f5a255cc8970202d5c54092089a01fc042@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=yao.jin@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.