Commit 5a99d99e authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarAdrian 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c3fcadf0
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "../cache.h" #include "../cache.h"
#include "../util.h" #include "../util.h"
#include "../auxtrace.h"
#include "intel-pt-insn-decoder.h" #include "intel-pt-insn-decoder.h"
#include "intel-pt-pkt-decoder.h" #include "intel-pt-pkt-decoder.h"
...@@ -2575,6 +2576,34 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2) ...@@ -2575,6 +2576,34 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)
} }
} }
#define MAX_PADDING (PERF_AUXTRACE_RECORD_ALIGNMENT - 1)
/**
* adj_for_padding - adjust overlap to account for padding.
* @buf_b: second buffer
* @buf_a: first buffer
* @len_a: size of first buffer
*
* @buf_a might have up to 7 bytes of padding appended. Adjust the overlap
* accordingly.
*
* Return: A pointer into @buf_b from where non-overlapped data starts
*/
static unsigned char *adj_for_padding(unsigned char *buf_b,
unsigned char *buf_a, size_t len_a)
{
unsigned char *p = buf_b - MAX_PADDING;
unsigned char *q = buf_a + len_a - MAX_PADDING;
int i;
for (i = MAX_PADDING; i; i--, p++, q++) {
if (*p != *q)
break;
}
return p;
}
/** /**
* intel_pt_find_overlap_tsc - determine start of non-overlapped trace data * intel_pt_find_overlap_tsc - determine start of non-overlapped trace data
* using TSC. * using TSC.
...@@ -2625,8 +2654,11 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a, ...@@ -2625,8 +2654,11 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
/* Same TSC, so buffers are consecutive */ /* Same TSC, so buffers are consecutive */
if (!cmp && rem_b >= rem_a) { if (!cmp && rem_b >= rem_a) {
unsigned char *start;
*consecutive = true; *consecutive = true;
return buf_b + len_b - (rem_b - rem_a); start = buf_b + len_b - (rem_b - rem_a);
return adj_for_padding(start, buf_a, len_a);
} }
if (cmp < 0) if (cmp < 0)
return buf_b; /* tsc_a < tsc_b => no overlap */ 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, ...@@ -2689,7 +2721,7 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
found = memmem(buf_a, len_a, buf_b, len_a); found = memmem(buf_a, len_a, buf_b, len_a);
if (found) { if (found) {
*consecutive = true; *consecutive = true;
return buf_b + len_a; return adj_for_padding(buf_b + len_a, buf_a, len_a);
} }
/* Try again at next PSB in buffer 'a' */ /* Try again at next PSB in buffer 'a' */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment