summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2016-10-07 09:42:25 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-24 09:31:32 -0400
commit32f98aab75dd385e326c975717f8b730c6c57508 (patch)
tree08f9357a1e5ee223e2c2e760ec2a397b1324b92e
parente9c848928abf4cb60601e9ae7d336f0333c98bca (diff)
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>
-rw-r--r--tools/perf/util/intel-bts.c8
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c13
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h6
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-log.c4
-rw-r--r--tools/perf/util/intel-pt.c8
5 files changed, 16 insertions, 23 deletions
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index f545ec1e758a..8bc7fec817d7 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -319,15 +319,12 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
319 struct machine *machine = btsq->bts->machine; 319 struct machine *machine = btsq->bts->machine;
320 struct thread *thread; 320 struct thread *thread;
321 struct addr_location al; 321 struct addr_location al;
322 unsigned char buf[1024]; 322 unsigned char buf[INTEL_PT_INSN_BUF_SZ];
323 size_t bufsz;
324 ssize_t len; 323 ssize_t len;
325 int x86_64; 324 int x86_64;
326 uint8_t cpumode; 325 uint8_t cpumode;
327 int err = -1; 326 int err = -1;
328 327
329 bufsz = intel_pt_insn_max_size();
330
331 if (machine__kernel_ip(machine, ip)) 328 if (machine__kernel_ip(machine, ip))
332 cpumode = PERF_RECORD_MISC_KERNEL; 329 cpumode = PERF_RECORD_MISC_KERNEL;
333 else 330 else
@@ -341,7 +338,8 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
341 if (!al.map || !al.map->dso) 338 if (!al.map || !al.map->dso)
342 goto out_put; 339 goto out_put;
343 340
344 len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf, bufsz); 341 len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf,
342 INTEL_PT_INSN_BUF_SZ);
345 if (len <= 0) 343 if (len <= 0)
346 goto out_put; 344 goto out_put;
347 345
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
index d23138c06665..5f95cd442075 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
@@ -27,6 +27,10 @@
27 27
28#include "intel-pt-insn-decoder.h" 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/* Based on branch_type() from perf_event_intel_lbr.c */ 34/* Based on branch_type() from perf_event_intel_lbr.c */
31static void intel_pt_insn_decoder(struct insn *insn, 35static void intel_pt_insn_decoder(struct insn *insn,
32 struct intel_pt_insn *intel_pt_insn) 36 struct intel_pt_insn *intel_pt_insn)
@@ -166,10 +170,10 @@ int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
166 if (!insn_complete(&insn) || insn.length > len) 170 if (!insn_complete(&insn) || insn.length > len)
167 return -1; 171 return -1;
168 intel_pt_insn_decoder(&insn, intel_pt_insn); 172 intel_pt_insn_decoder(&insn, intel_pt_insn);
169 if (insn.length < INTEL_PT_INSN_DBG_BUF_SZ) 173 if (insn.length < INTEL_PT_INSN_BUF_SZ)
170 memcpy(intel_pt_insn->buf, buf, insn.length); 174 memcpy(intel_pt_insn->buf, buf, insn.length);
171 else 175 else
172 memcpy(intel_pt_insn->buf, buf, INTEL_PT_INSN_DBG_BUF_SZ); 176 memcpy(intel_pt_insn->buf, buf, INTEL_PT_INSN_BUF_SZ);
173 return 0; 177 return 0;
174} 178}
175 179
@@ -211,11 +215,6 @@ int intel_pt_insn_desc(const struct intel_pt_insn *intel_pt_insn, char *buf,
211 return 0; 215 return 0;
212} 216}
213 217
214size_t intel_pt_insn_max_size(void)
215{
216 return MAX_INSN_SIZE;
217}
218
219int intel_pt_insn_type(enum intel_pt_insn_op op) 218int intel_pt_insn_type(enum intel_pt_insn_op op)
220{ 219{
221 switch (op) { 220 switch (op) {
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
index b0adbf37323e..37ec5627ae9b 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
@@ -20,7 +20,7 @@
20#include <stdint.h> 20#include <stdint.h>
21 21
22#define INTEL_PT_INSN_DESC_MAX 32 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
25enum intel_pt_insn_op { 25enum intel_pt_insn_op {
26 INTEL_PT_OP_OTHER, 26 INTEL_PT_OP_OTHER,
@@ -47,7 +47,7 @@ struct intel_pt_insn {
47 enum intel_pt_insn_branch branch; 47 enum intel_pt_insn_branch branch;
48 int length; 48 int length;
49 int32_t rel; 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
53int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64, 53int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
@@ -58,8 +58,6 @@ const char *intel_pt_insn_name(enum intel_pt_insn_op op);
58int intel_pt_insn_desc(const struct intel_pt_insn *intel_pt_insn, char *buf, 58int intel_pt_insn_desc(const struct intel_pt_insn *intel_pt_insn, char *buf,
59 size_t buf_len); 59 size_t buf_len);
60 60
61size_t intel_pt_insn_max_size(void);
62
63int intel_pt_insn_type(enum intel_pt_insn_op op); 61int intel_pt_insn_type(enum intel_pt_insn_op op);
64 62
65#endif 63#endif
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-log.c b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
index 319bef33a64b..e02bc7b166a0 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-log.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
@@ -119,8 +119,8 @@ void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip)
119 if (intel_pt_log_open()) 119 if (intel_pt_log_open())
120 return; 120 return;
121 121
122 if (len > INTEL_PT_INSN_DBG_BUF_SZ) 122 if (len > INTEL_PT_INSN_BUF_SZ)
123 len = INTEL_PT_INSN_DBG_BUF_SZ; 123 len = INTEL_PT_INSN_BUF_SZ;
124 intel_pt_print_data(intel_pt_insn->buf, len, ip, 8); 124 intel_pt_print_data(intel_pt_insn->buf, len, ip, 8);
125 if (intel_pt_insn_desc(intel_pt_insn, desc, INTEL_PT_INSN_DESC_MAX) > 0) 125 if (intel_pt_insn_desc(intel_pt_insn, desc, INTEL_PT_INSN_DESC_MAX) > 0)
126 fprintf(f, "%s\n", desc); 126 fprintf(f, "%s\n", desc);
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index dc041d4368c8..815a14d8904b 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -428,8 +428,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
428 struct machine *machine = ptq->pt->machine; 428 struct machine *machine = ptq->pt->machine;
429 struct thread *thread; 429 struct thread *thread;
430 struct addr_location al; 430 struct addr_location al;
431 unsigned char buf[1024]; 431 unsigned char buf[INTEL_PT_INSN_BUF_SZ];
432 size_t bufsz;
433 ssize_t len; 432 ssize_t len;
434 int x86_64; 433 int x86_64;
435 u8 cpumode; 434 u8 cpumode;
@@ -440,8 +439,6 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
440 if (to_ip && *ip == to_ip) 439 if (to_ip && *ip == to_ip)
441 goto out_no_cache; 440 goto out_no_cache;
442 441
443 bufsz = intel_pt_insn_max_size();
444
445 if (*ip >= ptq->pt->kernel_start) 442 if (*ip >= ptq->pt->kernel_start)
446 cpumode = PERF_RECORD_MISC_KERNEL; 443 cpumode = PERF_RECORD_MISC_KERNEL;
447 else 444 else
@@ -493,7 +490,8 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
493 490
494 while (1) { 491 while (1) {
495 len = dso__data_read_offset(al.map->dso, machine, 492 len = dso__data_read_offset(al.map->dso, machine,
496 offset, buf, bufsz); 493 offset, buf,
494 INTEL_PT_INSN_BUF_SZ);
497 if (len <= 0) 495 if (len <= 0)
498 return -EINVAL; 496 return -EINVAL;
499 497