]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.8.5/perf-intel-pt-fix-mtc-timestamp-calculation-for-large-mtc-periods.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.8.5 / perf-intel-pt-fix-mtc-timestamp-calculation-for-large-mtc-periods.patch
1 From 3bccbe20f6d188ce7b00326e776b745cfd35b10a Mon Sep 17 00:00:00 2001
2 From: Adrian Hunter <adrian.hunter@intel.com>
3 Date: Wed, 28 Sep 2016 14:41:36 +0300
4 Subject: perf intel-pt: Fix MTC timestamp calculation for large MTC periods
5
6 From: Adrian Hunter <adrian.hunter@intel.com>
7
8 commit 3bccbe20f6d188ce7b00326e776b745cfd35b10a upstream.
9
10 The MTC packet provides a 8-bit slice of CTC which is related to TSC by
11 the TMA packet, however the TMA packet only provides the lower 16 bits
12 of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC
13 provided by the TMA packet. Fix-up the last_mtc calculated from the TMA
14 packet by copying the missing bits from the current MTC assuming the
15 least difference between the two, and that the current MTC comes after
16 last_mtc.
17
18 Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
19 Cc: Jiri Olsa <jolsa@redhat.com>
20 Link: http://lkml.kernel.org/r/1475062896-22274-2-git-send-email-adrian.hunter@intel.com
21 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24 ---
25 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 36 ++++++++++++++++++++
26 1 file changed, 36 insertions(+)
27
28 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
29 +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
30 @@ -89,6 +89,7 @@ struct intel_pt_decoder {
31 bool pge;
32 bool have_tma;
33 bool have_cyc;
34 + bool fixup_last_mtc;
35 uint64_t pos;
36 uint64_t last_ip;
37 uint64_t ip;
38 @@ -584,10 +585,31 @@ struct intel_pt_calc_cyc_to_tsc_info {
39 uint64_t tsc_timestamp;
40 uint64_t timestamp;
41 bool have_tma;
42 + bool fixup_last_mtc;
43 bool from_mtc;
44 double cbr_cyc_to_tsc;
45 };
46
47 +/*
48 + * MTC provides a 8-bit slice of CTC but the TMA packet only provides the lower
49 + * 16 bits of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC
50 + * provided by the TMA packet. Fix-up the last_mtc calculated from the TMA
51 + * packet by copying the missing bits from the current MTC assuming the least
52 + * difference between the two, and that the current MTC comes after last_mtc.
53 + */
54 +static void intel_pt_fixup_last_mtc(uint32_t mtc, int mtc_shift,
55 + uint32_t *last_mtc)
56 +{
57 + uint32_t first_missing_bit = 1U << (16 - mtc_shift);
58 + uint32_t mask = ~(first_missing_bit - 1);
59 +
60 + *last_mtc |= mtc & mask;
61 + if (*last_mtc >= mtc) {
62 + *last_mtc -= first_missing_bit;
63 + *last_mtc &= 0xff;
64 + }
65 +}
66 +
67 static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
68 {
69 struct intel_pt_decoder *decoder = pkt_info->decoder;
70 @@ -617,6 +639,11 @@ static int intel_pt_calc_cyc_cb(struct i
71 return 0;
72
73 mtc = pkt_info->packet.payload;
74 + if (decoder->mtc_shift > 8 && data->fixup_last_mtc) {
75 + data->fixup_last_mtc = false;
76 + intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift,
77 + &data->last_mtc);
78 + }
79 if (mtc > data->last_mtc)
80 mtc_delta = mtc - data->last_mtc;
81 else
82 @@ -685,6 +712,7 @@ static int intel_pt_calc_cyc_cb(struct i
83
84 data->ctc_delta = 0;
85 data->have_tma = true;
86 + data->fixup_last_mtc = true;
87
88 return 0;
89
90 @@ -751,6 +779,7 @@ static void intel_pt_calc_cyc_to_tsc(str
91 .tsc_timestamp = decoder->tsc_timestamp,
92 .timestamp = decoder->timestamp,
93 .have_tma = decoder->have_tma,
94 + .fixup_last_mtc = decoder->fixup_last_mtc,
95 .from_mtc = from_mtc,
96 .cbr_cyc_to_tsc = 0,
97 };
98 @@ -1241,6 +1270,7 @@ static void intel_pt_calc_tma(struct int
99 }
100 decoder->ctc_delta = 0;
101 decoder->have_tma = true;
102 + decoder->fixup_last_mtc = true;
103 intel_pt_log("CTC timestamp " x64_fmt " last MTC %#x CTC rem %#x\n",
104 decoder->ctc_timestamp, decoder->last_mtc, ctc_rem);
105 }
106 @@ -1255,6 +1285,12 @@ static void intel_pt_calc_mtc_timestamp(
107
108 mtc = decoder->packet.payload;
109
110 + if (decoder->mtc_shift > 8 && decoder->fixup_last_mtc) {
111 + decoder->fixup_last_mtc = false;
112 + intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift,
113 + &decoder->last_mtc);
114 + }
115 +
116 if (mtc > decoder->last_mtc)
117 mtc_delta = mtc - decoder->last_mtc;
118 else