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>
This commit is contained in:
Adrian Hunter 2015-09-25 16:15:34 +03:00 committed by Arnaldo Carvalho de Melo
parent d062ac16f5
commit 9992c2d50a
1 changed files with 2 additions and 2 deletions

View File

@ -650,7 +650,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
if (data->from_mtc && timestamp < data->timestamp && if (data->from_mtc && timestamp < data->timestamp &&
data->timestamp - timestamp < decoder->tsc_slip) data->timestamp - timestamp < decoder->tsc_slip)
return 1; return 1;
while (timestamp < data->timestamp) if (timestamp < data->timestamp)
timestamp += (1ULL << 56); timestamp += (1ULL << 56);
if (pkt_info->last_packet_type != INTEL_PT_CYC) { if (pkt_info->last_packet_type != INTEL_PT_CYC) {
if (data->from_mtc) if (data->from_mtc)
@ -1191,7 +1191,7 @@ static void intel_pt_calc_tsc_timestamp(struct intel_pt_decoder *decoder)
timestamp); timestamp);
timestamp = decoder->timestamp; timestamp = decoder->timestamp;
} }
while (timestamp < decoder->timestamp) { if (timestamp < decoder->timestamp) {
intel_pt_log_to("Wraparound timestamp", timestamp); intel_pt_log_to("Wraparound timestamp", timestamp);
timestamp += (1ULL << 56); timestamp += (1ULL << 56);
decoder->tsc_timestamp = timestamp; decoder->tsc_timestamp = timestamp;