Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf intel-pt/bts: Tidy instruction buffer size usage

Tidy instruction buffer size usage in preparation for copying the
instruction bytes onto samples.

The instruction buffer is presently used for debugging, so rename its
size macro from INTEL_PT_INSN_DBG_BUF_SZ to INTEL_PT_INSN_BUF_SZ, and
use it everywhere.

Note that the maximum instruction size is 15 which is a less efficient size
to copy than 16, which is why a separate buffer size is used.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1475847747-30994-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
32f98aab e9c84892

+16 -23
+3 -5
tools/perf/util/intel-bts.c
··· 319 319 struct machine *machine = btsq->bts->machine; 320 320 struct thread *thread; 321 321 struct addr_location al; 322 - unsigned char buf[1024]; 323 - size_t bufsz; 322 + unsigned char buf[INTEL_PT_INSN_BUF_SZ]; 324 323 ssize_t len; 325 324 int x86_64; 326 325 uint8_t cpumode; 327 326 int err = -1; 328 - 329 - bufsz = intel_pt_insn_max_size(); 330 327 331 328 if (machine__kernel_ip(machine, ip)) 332 329 cpumode = PERF_RECORD_MISC_KERNEL; ··· 338 341 if (!al.map || !al.map->dso) 339 342 goto out_put; 340 343 341 - len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf, bufsz); 344 + len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf, 345 + INTEL_PT_INSN_BUF_SZ); 342 346 if (len <= 0) 343 347 goto out_put; 344 348
+6 -7
tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
··· 27 27 28 28 #include "intel-pt-insn-decoder.h" 29 29 30 + #if INTEL_PT_INSN_BUF_SZ < MAX_INSN_SIZE 31 + #error Instruction buffer size too small 32 + #endif 33 + 30 34 /* Based on branch_type() from perf_event_intel_lbr.c */ 31 35 static void intel_pt_insn_decoder(struct insn *insn, 32 36 struct intel_pt_insn *intel_pt_insn) ··· 170 166 if (!insn_complete(&insn) || insn.length > len) 171 167 return -1; 172 168 intel_pt_insn_decoder(&insn, intel_pt_insn); 173 - if (insn.length < INTEL_PT_INSN_DBG_BUF_SZ) 169 + if (insn.length < INTEL_PT_INSN_BUF_SZ) 174 170 memcpy(intel_pt_insn->buf, buf, insn.length); 175 171 else 176 - memcpy(intel_pt_insn->buf, buf, INTEL_PT_INSN_DBG_BUF_SZ); 172 + memcpy(intel_pt_insn->buf, buf, INTEL_PT_INSN_BUF_SZ); 177 173 return 0; 178 174 } 179 175 ··· 213 209 break; 214 210 } 215 211 return 0; 216 - } 217 - 218 - size_t intel_pt_insn_max_size(void) 219 - { 220 - return MAX_INSN_SIZE; 221 212 } 222 213 223 214 int intel_pt_insn_type(enum intel_pt_insn_op op)
+2 -4
tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
··· 20 20 #include <stdint.h> 21 21 22 22 #define INTEL_PT_INSN_DESC_MAX 32 23 - #define INTEL_PT_INSN_DBG_BUF_SZ 16 23 + #define INTEL_PT_INSN_BUF_SZ 16 24 24 25 25 enum intel_pt_insn_op { 26 26 INTEL_PT_OP_OTHER, ··· 47 47 enum intel_pt_insn_branch branch; 48 48 int length; 49 49 int32_t rel; 50 - unsigned char buf[INTEL_PT_INSN_DBG_BUF_SZ]; 50 + unsigned char buf[INTEL_PT_INSN_BUF_SZ]; 51 51 }; 52 52 53 53 int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64, ··· 57 57 58 58 int intel_pt_insn_desc(const struct intel_pt_insn *intel_pt_insn, char *buf, 59 59 size_t buf_len); 60 - 61 - size_t intel_pt_insn_max_size(void); 62 60 63 61 int intel_pt_insn_type(enum intel_pt_insn_op op); 64 62
+2 -2
tools/perf/util/intel-pt-decoder/intel-pt-log.c
··· 119 119 if (intel_pt_log_open()) 120 120 return; 121 121 122 - if (len > INTEL_PT_INSN_DBG_BUF_SZ) 123 - len = INTEL_PT_INSN_DBG_BUF_SZ; 122 + if (len > INTEL_PT_INSN_BUF_SZ) 123 + len = INTEL_PT_INSN_BUF_SZ; 124 124 intel_pt_print_data(intel_pt_insn->buf, len, ip, 8); 125 125 if (intel_pt_insn_desc(intel_pt_insn, desc, INTEL_PT_INSN_DESC_MAX) > 0) 126 126 fprintf(f, "%s\n", desc);
+3 -5
tools/perf/util/intel-pt.c
··· 428 428 struct machine *machine = ptq->pt->machine; 429 429 struct thread *thread; 430 430 struct addr_location al; 431 - unsigned char buf[1024]; 432 - size_t bufsz; 431 + unsigned char buf[INTEL_PT_INSN_BUF_SZ]; 433 432 ssize_t len; 434 433 int x86_64; 435 434 u8 cpumode; ··· 438 439 439 440 if (to_ip && *ip == to_ip) 440 441 goto out_no_cache; 441 - 442 - bufsz = intel_pt_insn_max_size(); 443 442 444 443 if (*ip >= ptq->pt->kernel_start) 445 444 cpumode = PERF_RECORD_MISC_KERNEL; ··· 490 493 491 494 while (1) { 492 495 len = dso__data_read_offset(al.map->dso, machine, 493 - offset, buf, bufsz); 496 + offset, buf, 497 + INTEL_PT_INSN_BUF_SZ); 494 498 if (len <= 0) 495 499 return -EINVAL; 496 500