linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	stable@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 30/54] perf intel-pt: Fix overlap detection to identify consecutive buffers correctly
Date: Thu,  8 Mar 2018 16:50:05 -0300	[thread overview]
Message-ID: <20180308195029.14991-31-acme@kernel.org> (raw)
In-Reply-To: <20180308195029.14991-1-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

Overlap detection was not not updating the buffer's 'consecutive' flag.
Marking buffers consecutive has the advantage that decoding begins from
the start of the buffer instead of the first PSB. Fix overlap detection
to identify consecutive buffers correctly.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1520431349-30689-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 62 ++++++++++------------
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  2 +-
 tools/perf/util/intel-pt.c                         |  5 +-
 3 files changed, 34 insertions(+), 35 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 aa1593ce551d..00f25f4b5f48 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2390,14 +2390,6 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 	return &decoder->state;
 }
 
-static bool intel_pt_at_psb(unsigned char *buf, size_t len)
-{
-	if (len < INTEL_PT_PSB_LEN)
-		return false;
-	return memmem(buf, INTEL_PT_PSB_LEN, INTEL_PT_PSB_STR,
-		      INTEL_PT_PSB_LEN);
-}
-
 /**
  * intel_pt_next_psb - move buffer pointer to the start of the next PSB packet.
  * @buf: pointer to buffer pointer
@@ -2486,6 +2478,7 @@ static unsigned char *intel_pt_last_psb(unsigned char *buf, size_t len)
  * @buf: buffer
  * @len: size of buffer
  * @tsc: TSC value returned
+ * @rem: returns remaining size when TSC is found
  *
  * Find a TSC packet in @buf and return the TSC value.  This function assumes
  * that @buf starts at a PSB and that PSB+ will contain TSC and so stops if a
@@ -2493,7 +2486,8 @@ static unsigned char *intel_pt_last_psb(unsigned char *buf, size_t len)
  *
  * Return: %true if TSC is found, false otherwise.
  */
-static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc)
+static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc,
+			      size_t *rem)
 {
 	struct intel_pt_pkt packet;
 	int ret;
@@ -2504,6 +2498,7 @@ static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc)
 			return false;
 		if (packet.type == INTEL_PT_TSC) {
 			*tsc = packet.payload;
+			*rem = len;
 			return true;
 		}
 		if (packet.type == INTEL_PT_PSBEND)
@@ -2554,6 +2549,8 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)
  * @len_a: size of first buffer
  * @buf_b: second buffer
  * @len_b: size of second buffer
+ * @consecutive: returns true if there is data in buf_b that is consecutive
+ *               to buf_a
  *
  * If the trace contains TSC we can look at the last TSC of @buf_a and the
  * first TSC of @buf_b in order to determine if the buffers overlap, and then
@@ -2566,33 +2563,41 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)
 static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
 						size_t len_a,
 						unsigned char *buf_b,
-						size_t len_b)
+						size_t len_b, bool *consecutive)
 {
 	uint64_t tsc_a, tsc_b;
 	unsigned char *p;
-	size_t len;
+	size_t len, rem_a, rem_b;
 
 	p = intel_pt_last_psb(buf_a, len_a);
 	if (!p)
 		return buf_b; /* No PSB in buf_a => no overlap */
 
 	len = len_a - (p - buf_a);
-	if (!intel_pt_next_tsc(p, len, &tsc_a)) {
+	if (!intel_pt_next_tsc(p, len, &tsc_a, &rem_a)) {
 		/* The last PSB+ in buf_a is incomplete, so go back one more */
 		len_a -= len;
 		p = intel_pt_last_psb(buf_a, len_a);
 		if (!p)
 			return buf_b; /* No full PSB+ => assume no overlap */
 		len = len_a - (p - buf_a);
-		if (!intel_pt_next_tsc(p, len, &tsc_a))
+		if (!intel_pt_next_tsc(p, len, &tsc_a, &rem_a))
 			return buf_b; /* No TSC in buf_a => assume no overlap */
 	}
 
 	while (1) {
 		/* Ignore PSB+ with no TSC */
-		if (intel_pt_next_tsc(buf_b, len_b, &tsc_b) &&
-		    intel_pt_tsc_cmp(tsc_a, tsc_b) < 0)
-			return buf_b; /* tsc_a < tsc_b => no overlap */
+		if (intel_pt_next_tsc(buf_b, len_b, &tsc_b, &rem_b)) {
+			int cmp = intel_pt_tsc_cmp(tsc_a, tsc_b);
+
+			/* Same TSC, so buffers are consecutive */
+			if (!cmp && rem_b >= rem_a) {
+				*consecutive = true;
+				return buf_b + len_b - (rem_b - rem_a);
+			}
+			if (cmp < 0)
+				return buf_b; /* tsc_a < tsc_b => no overlap */
+		}
 
 		if (!intel_pt_step_psb(&buf_b, &len_b))
 			return buf_b + len_b; /* No PSB in buf_b => no data */
@@ -2606,6 +2611,8 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
  * @buf_b: second buffer
  * @len_b: size of second buffer
  * @have_tsc: can use TSC packets to detect overlap
+ * @consecutive: returns true if there is data in buf_b that is consecutive
+ *               to buf_a
  *
  * When trace samples or snapshots are recorded there is the possibility that
  * the data overlaps.  Note that, for the purposes of decoding, data is only
@@ -2616,7 +2623,7 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
  */
 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 have_tsc, bool *consecutive)
 {
 	unsigned char *found;
 
@@ -2628,7 +2635,8 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
 		return buf_b; /* No overlap */
 
 	if (have_tsc) {
-		found = intel_pt_find_overlap_tsc(buf_a, len_a, buf_b, len_b);
+		found = intel_pt_find_overlap_tsc(buf_a, len_a, buf_b, len_b,
+						  consecutive);
 		if (found)
 			return found;
 	}
@@ -2643,28 +2651,16 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
 	}
 
 	/* Now len_b >= len_a */
-	if (len_b > len_a) {
-		/* The leftover buffer 'b' must start at a PSB */
-		while (!intel_pt_at_psb(buf_b + len_a, len_b - len_a)) {
-			if (!intel_pt_step_psb(&buf_a, &len_a))
-				return buf_b; /* No overlap */
-		}
-	}
-
 	while (1) {
 		/* Potential overlap so check the bytes */
 		found = memmem(buf_a, len_a, buf_b, len_a);
-		if (found)
+		if (found) {
+			*consecutive = true;
 			return buf_b + len_a;
+		}
 
 		/* Try again at next PSB in buffer 'a' */
 		if (!intel_pt_step_psb(&buf_a, &len_a))
 			return buf_b; /* No overlap */
-
-		/* The leftover buffer 'b' must start at a PSB */
-		while (!intel_pt_at_psb(buf_b + len_a, len_b - len_a)) {
-			if (!intel_pt_step_psb(&buf_a, &len_a))
-				return buf_b; /* No overlap */
-		}
 	}
 }
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 921b22e8ca0e..fc1752d50019 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -117,7 +117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);
 
 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 have_tsc, bool *consecutive);
 
 int intel_pt__strerror(int code, char *buf, size_t buflen);
 
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 3773d9c54f45..4a7746249999 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -207,14 +207,17 @@ static void intel_pt_dump_event(struct intel_pt *pt, unsigned char *buf,
 static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *a,
 				   struct auxtrace_buffer *b)
 {
+	bool consecutive = false;
 	void *start;
 
 	start = intel_pt_find_overlap(a->data, a->size, b->data, b->size,
-				      pt->have_tsc);
+				      pt->have_tsc, &consecutive);
 	if (!start)
 		return -EINVAL;
 	b->use_size = b->data + b->size - start;
 	b->use_data = start;
+	if (b->use_size && consecutive)
+		b->consecutive = true;
 	return 0;
 }
 
-- 
2.14.3

  parent reply	other threads:[~2018-03-08 19:50 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08 19:49 [GIT PULL 00/54] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 01/54] perf cgroup: Remove misplaced __maybe_unused Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 02/54] perf cgroup: Rename 'struct cgroup_sel' to 'struct cgroup' Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 03/54] perf cgroup: Introduce cgroup__delete() Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 04/54] perf cgroup: Rename close_cgroup() to cgroup__put() Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 05/54] perf cgroup: Introduce cgroup__get() Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 06/54] perf cgroup: Introduce find_cgroup() method Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 07/54] perf cgroup: Introduce cgroup__new() out of open coded equivalent Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 08/54] perf sched: Move thread::shortname to thread_runtime Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 09/54] perf sched map: Re-annotate shortname if thread comm changed Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 10/54] perf record: Combine some auxtrace initialization into a single function Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 11/54] perf cgroup: Add evlist__findnew_cgroup() Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 12/54] perf cgroup: Add evlist__add_default_cgroup() Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 13/54] perf cgroup: Make the cgroup name be const char * Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 14/54] perf trace: Support setting cgroups as targets Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 15/54] perf auxtrace: Add missing parameters from kernel-doc comments Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 16/54] perf auxtrace: Rename some buffer-queuing functions Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 17/54] perf auxtrace: Make auxtrace_queues__add_buffer() return buffer_ptr Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 18/54] perf tools: Correct title markers for asciidoctor Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 19/54] perf pmu: Support wildcards on pmu name in dynamic pmu events Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 20/54] perf pmu: Display pmu name when printing unmerged events in stat Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 21/54] perf pmu: Auto-merge PMU events created by prefix or glob match Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 22/54] perf evlist: Store 'overwrite' in struct perf_mmap Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 23/54] perf mmap: Store mmap scope in struct perf_mmap() Arnaldo Carvalho de Melo
2018-03-08 19:49 ` [PATCH 24/54] perf mmap: Use the stored scope data in perf_mmap__push() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 25/54] perf mmap: Use the stored data in perf_mmap__read_event() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 26/54] perf mmap: Use stored 'overwrite' in perf_mmap__consume() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 27/54] perf mmap: Simplify perf_mmap__consume() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 28/54] perf mmap: Simplify perf_mmap__read_event() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 29/54] perf mmap: Simplify perf_mmap__read_init() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` Arnaldo Carvalho de Melo [this message]
2018-03-08 19:50 ` [PATCH 31/54] perf intel-pt: Fix sync_switch Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 32/54] perf intel-pt: Fix error recovery from missing TIP packet Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 33/54] perf intel-pt: Fix timestamp following overflow Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 34/54] perf intel-pt/bts: In auxtrace_record__init_intel() evlist is never NULL Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 35/54] perf intel-pt: Get rid of intel_pt_use_buffer_pid_tid() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 36/54] perf intel-pt: Tidy old_buffer handling in intel_pt_get_trace() Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 37/54] perf intel-pt: Remove a check for sampling mode Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 38/54] perf intel-pt: Adjust overlap-checking to support " Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 39/54] perf annotate: Fix s390 target function disassembly Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 40/54] perf report: Fix the output for stdio events list Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 41/54] perf report: Display perf.data header info Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 42/54] perf record: Move machine variable down the function Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 43/54] perf record: Remove progname from struct record Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 44/54] perf tools: Add refcnt into struct mem_info Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 45/54] perf c2c: Use mem_info refcnt logic Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 46/54] perf tools: Add MEM_TOPOLOGY feature to perf data file Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 47/54] perf tools: Update tags with .cpp files Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 48/54] perf build: Add llvm/clang/cxx make tests into FEATURE_TESTS_EXTRA Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 49/54] perf build: Add llvm/clang make targets to FILES Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 50/54] perf build: Force llvm/clang test compile output to .make.output Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 51/54] perf report: Provide libtraceevent with a kernel symbol resolver Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 52/54] perf annotate: Support to display the IPC/Cycle in TUI mode Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 53/54] perf annotate: Handle s390 PC relative load and store instruction Arnaldo Carvalho de Melo
2018-03-08 19:50 ` [PATCH 54/54] perf tools: Update quipper information Arnaldo Carvalho de Melo
2018-03-09  7:29 ` [GIT PULL 00/54] perf/core improvements and fixes Ingo Molnar

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=20180308195029.14991-31-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=stable@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;
as well as URLs for NNTP newsgroup(s).