diff options
Diffstat (limited to 'tools/perf/util/intel-pt-decoder')
-rw-r--r-- | tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 44 | ||||
-rw-r--r-- | tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 24 |
2 files changed, 40 insertions, 28 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 9c8f15da86ce..8ff6c6a61291 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | |||
@@ -123,8 +123,6 @@ struct intel_pt_decoder { | |||
123 | bool have_calc_cyc_to_tsc; | 123 | bool have_calc_cyc_to_tsc; |
124 | int exec_mode; | 124 | int exec_mode; |
125 | unsigned int insn_bytes; | 125 | unsigned int insn_bytes; |
126 | uint64_t sign_bit; | ||
127 | uint64_t sign_bits; | ||
128 | uint64_t period; | 126 | uint64_t period; |
129 | enum intel_pt_period_type period_type; | 127 | enum intel_pt_period_type period_type; |
130 | uint64_t tot_insn_cnt; | 128 | uint64_t tot_insn_cnt; |
@@ -191,9 +189,6 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params) | |||
191 | decoder->data = params->data; | 189 | decoder->data = params->data; |
192 | decoder->return_compression = params->return_compression; | 190 | decoder->return_compression = params->return_compression; |
193 | 191 | ||
194 | decoder->sign_bit = (uint64_t)1 << 47; | ||
195 | decoder->sign_bits = ~(((uint64_t)1 << 48) - 1); | ||
196 | |||
197 | decoder->period = params->period; | 192 | decoder->period = params->period; |
198 | decoder->period_type = params->period_type; | 193 | decoder->period_type = params->period_type; |
199 | 194 | ||
@@ -362,21 +357,30 @@ int intel_pt__strerror(int code, char *buf, size_t buflen) | |||
362 | return 0; | 357 | return 0; |
363 | } | 358 | } |
364 | 359 | ||
365 | static uint64_t intel_pt_calc_ip(struct intel_pt_decoder *decoder, | 360 | static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet, |
366 | const struct intel_pt_pkt *packet, | ||
367 | uint64_t last_ip) | 361 | uint64_t last_ip) |
368 | { | 362 | { |
369 | uint64_t ip; | 363 | uint64_t ip; |
370 | 364 | ||
371 | switch (packet->count) { | 365 | switch (packet->count) { |
372 | case 2: | 366 | case 1: |
373 | ip = (last_ip & (uint64_t)0xffffffffffff0000ULL) | | 367 | ip = (last_ip & (uint64_t)0xffffffffffff0000ULL) | |
374 | packet->payload; | 368 | packet->payload; |
375 | break; | 369 | break; |
376 | case 4: | 370 | case 2: |
377 | ip = (last_ip & (uint64_t)0xffffffff00000000ULL) | | 371 | ip = (last_ip & (uint64_t)0xffffffff00000000ULL) | |
378 | packet->payload; | 372 | packet->payload; |
379 | break; | 373 | break; |
374 | case 3: | ||
375 | ip = packet->payload; | ||
376 | /* Sign-extend 6-byte ip */ | ||
377 | if (ip & (uint64_t)0x800000000000ULL) | ||
378 | ip |= (uint64_t)0xffff000000000000ULL; | ||
379 | break; | ||
380 | case 4: | ||
381 | ip = (last_ip & (uint64_t)0xffff000000000000ULL) | | ||
382 | packet->payload; | ||
383 | break; | ||
380 | case 6: | 384 | case 6: |
381 | ip = packet->payload; | 385 | ip = packet->payload; |
382 | break; | 386 | break; |
@@ -384,16 +388,12 @@ static uint64_t intel_pt_calc_ip(struct intel_pt_decoder *decoder, | |||
384 | return 0; | 388 | return 0; |
385 | } | 389 | } |
386 | 390 | ||
387 | if (ip & decoder->sign_bit) | ||
388 | return ip | decoder->sign_bits; | ||
389 | |||
390 | return ip; | 391 | return ip; |
391 | } | 392 | } |
392 | 393 | ||
393 | static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder) | 394 | static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder) |
394 | { | 395 | { |
395 | decoder->last_ip = intel_pt_calc_ip(decoder, &decoder->packet, | 396 | decoder->last_ip = intel_pt_calc_ip(&decoder->packet, decoder->last_ip); |
396 | decoder->last_ip); | ||
397 | } | 397 | } |
398 | 398 | ||
399 | static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder) | 399 | static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder) |
@@ -1657,6 +1657,12 @@ next: | |||
1657 | } | 1657 | } |
1658 | } | 1658 | } |
1659 | 1659 | ||
1660 | static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder) | ||
1661 | { | ||
1662 | return decoder->last_ip || decoder->packet.count == 0 || | ||
1663 | decoder->packet.count == 3 || decoder->packet.count == 6; | ||
1664 | } | ||
1665 | |||
1660 | /* Walk PSB+ packets to get in sync. */ | 1666 | /* Walk PSB+ packets to get in sync. */ |
1661 | static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) | 1667 | static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) |
1662 | { | 1668 | { |
@@ -1677,8 +1683,7 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder) | |||
1677 | 1683 | ||
1678 | case INTEL_PT_FUP: | 1684 | case INTEL_PT_FUP: |
1679 | decoder->pge = true; | 1685 | decoder->pge = true; |
1680 | if (decoder->last_ip || decoder->packet.count == 6 || | 1686 | if (intel_pt_have_ip(decoder)) { |
1681 | decoder->packet.count == 0) { | ||
1682 | uint64_t current_ip = decoder->ip; | 1687 | uint64_t current_ip = decoder->ip; |
1683 | 1688 | ||
1684 | intel_pt_set_ip(decoder); | 1689 | intel_pt_set_ip(decoder); |
@@ -1767,8 +1772,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder) | |||
1767 | case INTEL_PT_TIP_PGE: | 1772 | case INTEL_PT_TIP_PGE: |
1768 | case INTEL_PT_TIP: | 1773 | case INTEL_PT_TIP: |
1769 | decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD; | 1774 | decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD; |
1770 | if (decoder->last_ip || decoder->packet.count == 6 || | 1775 | if (intel_pt_have_ip(decoder)) |
1771 | decoder->packet.count == 0) | ||
1772 | intel_pt_set_ip(decoder); | 1776 | intel_pt_set_ip(decoder); |
1773 | if (decoder->ip) | 1777 | if (decoder->ip) |
1774 | return 0; | 1778 | return 0; |
@@ -1776,9 +1780,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder) | |||
1776 | 1780 | ||
1777 | case INTEL_PT_FUP: | 1781 | case INTEL_PT_FUP: |
1778 | if (decoder->overflow) { | 1782 | if (decoder->overflow) { |
1779 | if (decoder->last_ip || | 1783 | if (intel_pt_have_ip(decoder)) |
1780 | decoder->packet.count == 6 || | ||
1781 | decoder->packet.count == 0) | ||
1782 | intel_pt_set_ip(decoder); | 1784 | intel_pt_set_ip(decoder); |
1783 | if (decoder->ip) | 1785 | if (decoder->ip) |
1784 | return 0; | 1786 | return 0; |
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c index b1257c816310..4f7b32020487 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | |||
@@ -292,36 +292,46 @@ static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte, | |||
292 | const unsigned char *buf, size_t len, | 292 | const unsigned char *buf, size_t len, |
293 | struct intel_pt_pkt *packet) | 293 | struct intel_pt_pkt *packet) |
294 | { | 294 | { |
295 | switch (byte >> 5) { | 295 | int ip_len; |
296 | |||
297 | packet->count = byte >> 5; | ||
298 | |||
299 | switch (packet->count) { | ||
296 | case 0: | 300 | case 0: |
297 | packet->count = 0; | 301 | ip_len = 0; |
298 | break; | 302 | break; |
299 | case 1: | 303 | case 1: |
300 | if (len < 3) | 304 | if (len < 3) |
301 | return INTEL_PT_NEED_MORE_BYTES; | 305 | return INTEL_PT_NEED_MORE_BYTES; |
302 | packet->count = 2; | 306 | ip_len = 2; |
303 | packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); | 307 | packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); |
304 | break; | 308 | break; |
305 | case 2: | 309 | case 2: |
306 | if (len < 5) | 310 | if (len < 5) |
307 | return INTEL_PT_NEED_MORE_BYTES; | 311 | return INTEL_PT_NEED_MORE_BYTES; |
308 | packet->count = 4; | 312 | ip_len = 4; |
309 | packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1)); | 313 | packet->payload = le32_to_cpu(*(uint32_t *)(buf + 1)); |
310 | break; | 314 | break; |
311 | case 3: | 315 | case 3: |
312 | case 6: | 316 | case 4: |
313 | if (len < 7) | 317 | if (len < 7) |
314 | return INTEL_PT_NEED_MORE_BYTES; | 318 | return INTEL_PT_NEED_MORE_BYTES; |
315 | packet->count = 6; | 319 | ip_len = 6; |
316 | memcpy_le64(&packet->payload, buf + 1, 6); | 320 | memcpy_le64(&packet->payload, buf + 1, 6); |
317 | break; | 321 | break; |
322 | case 6: | ||
323 | if (len < 9) | ||
324 | return INTEL_PT_NEED_MORE_BYTES; | ||
325 | ip_len = 8; | ||
326 | packet->payload = le64_to_cpu(*(uint64_t *)(buf + 1)); | ||
327 | break; | ||
318 | default: | 328 | default: |
319 | return INTEL_PT_BAD_PACKET; | 329 | return INTEL_PT_BAD_PACKET; |
320 | } | 330 | } |
321 | 331 | ||
322 | packet->type = type; | 332 | packet->type = type; |
323 | 333 | ||
324 | return packet->count + 1; | 334 | return ip_len + 1; |
325 | } | 335 | } |
326 | 336 | ||
327 | static int intel_pt_get_mode(const unsigned char *buf, size_t len, | 337 | static int intel_pt_get_mode(const unsigned char *buf, size_t len, |