diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2019-02-06 05:39:44 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-06 08:27:00 -0500 |
commit | 5a99d99e3310a565b0cf63f785b347be9ee0da45 (patch) | |
tree | b0d397535688ca0b17a3a7ac6d58f2b68ce28b16 | |
parent | c3fcadf0bb765faf45d6d562246e1d08885466df (diff) |
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>
-rw-r--r-- | tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 36 |
1 files changed, 34 insertions, 2 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 4503f3ca45ab..ecd25cdc1d3e 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "../cache.h" | 27 | #include "../cache.h" |
28 | #include "../util.h" | 28 | #include "../util.h" |
29 | #include "../auxtrace.h" | ||
29 | 30 | ||
30 | #include "intel-pt-insn-decoder.h" | 31 | #include "intel-pt-insn-decoder.h" |
31 | #include "intel-pt-pkt-decoder.h" | 32 | #include "intel-pt-pkt-decoder.h" |
@@ -2575,6 +2576,34 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2) | |||
2575 | } | 2576 | } |
2576 | } | 2577 | } |
2577 | 2578 | ||
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 | |||
2578 | /** | 2607 | /** |
2579 | * intel_pt_find_overlap_tsc - determine start of non-overlapped trace data | 2608 | * intel_pt_find_overlap_tsc - determine start of non-overlapped trace data |
2580 | * using TSC. | 2609 | * using TSC. |
@@ -2625,8 +2654,11 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a, | |||
2625 | 2654 | ||
2626 | /* Same TSC, so buffers are consecutive */ | 2655 | /* Same TSC, so buffers are consecutive */ |
2627 | if (!cmp && rem_b >= rem_a) { | 2656 | if (!cmp && rem_b >= rem_a) { |
2657 | unsigned char *start; | ||
2658 | |||
2628 | *consecutive = true; | 2659 | *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); | ||
2630 | } | 2662 | } |
2631 | if (cmp < 0) | 2663 | if (cmp < 0) |
2632 | return buf_b; /* tsc_a < tsc_b => no overlap */ | 2664 | 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 | found = memmem(buf_a, len_a, buf_b, len_a); | 2721 | found = memmem(buf_a, len_a, buf_b, len_a); |
2690 | if (found) { | 2722 | if (found) { |
2691 | *consecutive = true; | 2723 | *consecutive = true; |
2692 | return buf_b + len_a; | 2724 | return adj_for_padding(buf_b + len_a, buf_a, len_a); |
2693 | } | 2725 | } |
2694 | 2726 | ||
2695 | /* Try again at next PSB in buffer 'a' */ | 2727 | /* Try again at next PSB in buffer 'a' */ |