Skip to content

Commit 5a99d99

Browse files
ahunter6acmel
authored andcommitted
perf intel-pt: Fix overlap calculation for padding
Auxtrace records might have up to 7 bytes of padding appended. Adjust the overlap accordingly. 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/20190206103947.15750-3-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent c3fcadf commit 5a99d99

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

‎tools/perf/util/intel-pt-decoder/intel-pt-decoder.c‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "../cache.h"
2828
#include "../util.h"
29+
#include "../auxtrace.h"
2930

3031
#include "intel-pt-insn-decoder.h"
3132
#include "intel-pt-pkt-decoder.h"
@@ -2575,6 +2576,34 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)
25752576
}
25762577
}
25772578

2579+
#define MAX_PADDING (PERF_AUXTRACE_RECORD_ALIGNMENT - 1)
2580+
2581+
/**
2582+
* adj_for_padding - adjust overlap to account for padding.
2583+
* @buf_b: second buffer
2584+
* @buf_a: first buffer
2585+
* @len_a: size of first buffer
2586+
*
2587+
* @buf_a might have up to 7 bytes of padding appended. Adjust the overlap
2588+
* accordingly.
2589+
*
2590+
* Return: A pointer into @buf_b from where non-overlapped data starts
2591+
*/
2592+
static unsigned char *adj_for_padding(unsigned char *buf_b,
2593+
unsigned char *buf_a, size_t len_a)
2594+
{
2595+
unsigned char *p = buf_b - MAX_PADDING;
2596+
unsigned char *q = buf_a + len_a - MAX_PADDING;
2597+
int i;
2598+
2599+
for (i = MAX_PADDING; i; i--, p++, q++) {
2600+
if (*p != *q)
2601+
break;
2602+
}
2603+
2604+
return p;
2605+
}
2606+
25782607
/**
25792608
* intel_pt_find_overlap_tsc - determine start of non-overlapped trace data
25802609
* using TSC.
@@ -2625,8 +2654,11 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
26252654

26262655
/* Same TSC, so buffers are consecutive */
26272656
if (!cmp && rem_b >= rem_a) {
2657+
unsigned char *start;
2658+
26282659
*consecutive = true;
2629-
return buf_b + len_b - (rem_b - rem_a);
2660+
start = buf_b + len_b - (rem_b - rem_a);
2661+
return adj_for_padding(start, buf_a, len_a);
26302662
}
26312663
if (cmp < 0)
26322664
return buf_b; /* tsc_a < tsc_b => no overlap */
@@ -2689,7 +2721,7 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
26892721
found = memmem(buf_a, len_a, buf_b, len_a);
26902722
if (found) {
26912723
*consecutive = true;
2692-
return buf_b + len_a;
2724+
return adj_for_padding(buf_b + len_a, buf_a, len_a);
26932725
}
26942726

26952727
/* Try again at next PSB in buffer 'a' */

0 commit comments

Comments
 (0)