aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/intel-pt-decoder
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2015-09-25 09:15:34 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-28 15:44:31 -0400
commit9992c2d50a73f442653968a98a9e5f3bf4e769e9 (patch)
treea0506fd29d4af79483eaec038847c2d675e70187 /tools/perf/util/intel-pt-decoder
parentd062ac16f53d1a24047bcc9eded5514a71c363b8 (diff)
perf intel-pt: Fix potential loop forever
TSC packets contain only 7 bytes of TSC. The 8th byte is assumed to change so infrequently that its value can be inferred. However the logic must cater for a 7 byte wraparound, which it does by adding 1 to the top byte. The existing code was doing that with a while loop even though the addition should only need to be done once. That logic won't work (will loop forever) if TSC wraps around at the 8th byte. Theoretically that would take at least 10 years, unless something else went wrong. And what else could go wrong. Well, if the chunks of trace data are processed out of order, it will make it look like the 7-byte TSC has gone backwards (i.e. wrapped). If that happens 256 times then stuck in the while loop it will be. Fix that by getting rid of the unnecessary while loop. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: http://lkml.kernel.org/r/1443186956-18718-4-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/intel-pt-decoder')
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-decoder.c4
1 files changed, 2 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 22ba50224319..9409d014b46c 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -650,7 +650,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
650 if (data->from_mtc && timestamp < data->timestamp && 650 if (data->from_mtc && timestamp < data->timestamp &&
651 data->timestamp - timestamp < decoder->tsc_slip) 651 data->timestamp - timestamp < decoder->tsc_slip)
652 return 1; 652 return 1;
653 while (timestamp < data->timestamp) 653 if (timestamp < data->timestamp)
654 timestamp += (1ULL << 56); 654 timestamp += (1ULL << 56);
655 if (pkt_info->last_packet_type != INTEL_PT_CYC) { 655 if (pkt_info->last_packet_type != INTEL_PT_CYC) {
656 if (data->from_mtc) 656 if (data->from_mtc)
@@ -1191,7 +1191,7 @@ static void intel_pt_calc_tsc_timestamp(struct intel_pt_decoder *decoder)
1191 timestamp); 1191 timestamp);
1192 timestamp = decoder->timestamp; 1192 timestamp = decoder->timestamp;
1193 } 1193 }
1194 while (timestamp < decoder->timestamp) { 1194 if (timestamp < decoder->timestamp) {
1195 intel_pt_log_to("Wraparound timestamp", timestamp); 1195 intel_pt_log_to("Wraparound timestamp", timestamp);
1196 timestamp += (1ULL << 56); 1196 timestamp += (1ULL << 56);
1197 decoder->tsc_timestamp = timestamp; 1197 decoder->tsc_timestamp = timestamp;