aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorStefano Sanfilippo <ssanfilippo@chromium.org>2016-10-13 06:59:40 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-24 10:07:39 -0400
commit0284fecd13b6db3ecd4c2b1bf3e72b105edce24b (patch)
tree87b58d544456e254ac939215eb813b8fe07b1427 /tools/perf/util
parenteac05af2bf33aa9474482f1f19555adfd2cdf69d (diff)
perf jit: Add unwinding support
This record is intended to provide unwinding information in the eh_frame format. This is required to unwind JITed code which does not maintain the frame pointer register during function calls. The eh_frame unwinding information can be emitted by V8 / Chromium when the --perf_prof_unwinding_info is passed. A record of type jr_code_unwinding_info comes before the jr_code_load it referred to and contains both the .eh_frame and .eh_frame_hdr. The fields in the header have the following meaning: * unwinding_size: size of the eh_frame and eh_frame_hdr, necessary for distinguishing the content from the padding. * eh_frame_hdr_size: as the name says. * mapped_size: size of the payload that was in memory at runtime. typically unwinding_size if the .eh_frame_hdr and .eh_frame were mapped, or 0 if they weren't. It should always be the former case, since the .eh_frame is guaranteed to be mapped in memory. However, certain JITs might want to inject an .eh_frame_hdr with an empty LUT to trigger fp-based unwinding fallback in libunwind. The only part of the .eh_frame_hdr that libunwind reads from remote memory is the LUT, and since there is none, mapping the unwinding info in memory is not necessary, and 0 in this field signifies that it wasn't. This practical hack allows to save bytes in code memory for those JIT compilers that might or might not maintain a valid frame pointer. The payload that follows is assumed to contain first the .eh_frame and then the .eh_header_hdr, with no padding between the two. Signed-off-by: Stefano Sanfilippo <ssanfilippo@chromium.org> Signed-off-by: Ross McIlroy <rmcilroy@chromium.org> Reviewed-by: Stephane Eranian <eranian@google.com> Cc: Anton Blanchard <anton@ozlabs.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1476356383-30100-7-git-send-email-eranian@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/jitdump.c57
-rw-r--r--tools/perf/util/jitdump.h12
2 files changed, 66 insertions, 3 deletions
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 75b66bbf8429..9bae66cc78f2 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -37,6 +37,10 @@ struct jit_buf_desc {
37 bool needs_bswap; /* handles cross-endianess */ 37 bool needs_bswap; /* handles cross-endianess */
38 bool use_arch_timestamp; 38 bool use_arch_timestamp;
39 void *debug_data; 39 void *debug_data;
40 void *unwinding_data;
41 uint64_t unwinding_size;
42 uint64_t unwinding_mapped_size;
43 uint64_t eh_frame_hdr_size;
40 size_t nr_debug_entries; 44 size_t nr_debug_entries;
41 uint32_t code_load_count; 45 uint32_t code_load_count;
42 u64 bytes_written; 46 u64 bytes_written;
@@ -295,6 +299,13 @@ jit_get_next_entry(struct jit_buf_desc *jd)
295 } 299 }
296 } 300 }
297 break; 301 break;
302 case JIT_CODE_UNWINDING_INFO:
303 if (jd->needs_bswap) {
304 jr->unwinding.unwinding_size = bswap_64(jr->unwinding.unwinding_size);
305 jr->unwinding.eh_frame_hdr_size = bswap_64(jr->unwinding.eh_frame_hdr_size);
306 jr->unwinding.mapped_size = bswap_64(jr->unwinding.mapped_size);
307 }
308 break;
298 case JIT_CODE_CLOSE: 309 case JIT_CODE_CLOSE:
299 break; 310 break;
300 case JIT_CODE_LOAD: 311 case JIT_CODE_LOAD:
@@ -370,7 +381,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
370 u16 idr_size; 381 u16 idr_size;
371 const char *sym; 382 const char *sym;
372 uint32_t count; 383 uint32_t count;
373 int ret, csize; 384 int ret, csize, usize;
374 pid_t pid, tid; 385 pid_t pid, tid;
375 struct { 386 struct {
376 u32 pid, tid; 387 u32 pid, tid;
@@ -380,6 +391,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
380 pid = jr->load.pid; 391 pid = jr->load.pid;
381 tid = jr->load.tid; 392 tid = jr->load.tid;
382 csize = jr->load.code_size; 393 csize = jr->load.code_size;
394 usize = jd->unwinding_mapped_size;
383 addr = jr->load.code_addr; 395 addr = jr->load.code_addr;
384 sym = (void *)((unsigned long)jr + sizeof(jr->load)); 396 sym = (void *)((unsigned long)jr + sizeof(jr->load));
385 code = (unsigned long)jr + jr->load.p.total_size - csize; 397 code = (unsigned long)jr + jr->load.p.total_size - csize;
@@ -408,6 +420,14 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
408 jd->nr_debug_entries = 0; 420 jd->nr_debug_entries = 0;
409 } 421 }
410 422
423 if (jd->unwinding_data && jd->eh_frame_hdr_size) {
424 free(jd->unwinding_data);
425 jd->unwinding_data = NULL;
426 jd->eh_frame_hdr_size = 0;
427 jd->unwinding_mapped_size = 0;
428 jd->unwinding_size = 0;
429 }
430
411 if (ret) { 431 if (ret) {
412 free(event); 432 free(event);
413 return -1; 433 return -1;
@@ -422,7 +442,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
422 442
423 event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET; 443 event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
424 event->mmap2.start = addr; 444 event->mmap2.start = addr;
425 event->mmap2.len = csize; 445 event->mmap2.len = usize ? ALIGN_8(csize) + usize : csize;
426 event->mmap2.pid = pid; 446 event->mmap2.pid = pid;
427 event->mmap2.tid = tid; 447 event->mmap2.tid = tid;
428 event->mmap2.ino = st.st_ino; 448 event->mmap2.ino = st.st_ino;
@@ -473,6 +493,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
473 char *filename; 493 char *filename;
474 size_t size; 494 size_t size;
475 struct stat st; 495 struct stat st;
496 int usize;
476 u16 idr_size; 497 u16 idr_size;
477 int ret; 498 int ret;
478 pid_t pid, tid; 499 pid_t pid, tid;
@@ -483,6 +504,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
483 504
484 pid = jr->move.pid; 505 pid = jr->move.pid;
485 tid = jr->move.tid; 506 tid = jr->move.tid;
507 usize = jd->unwinding_mapped_size;
486 idr_size = jd->machine->id_hdr_size; 508 idr_size = jd->machine->id_hdr_size;
487 509
488 /* 510 /*
@@ -511,7 +533,8 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
511 (sizeof(event->mmap2.filename) - size) + idr_size); 533 (sizeof(event->mmap2.filename) - size) + idr_size);
512 event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET; 534 event->mmap2.pgoff = GEN_ELF_TEXT_OFFSET;
513 event->mmap2.start = jr->move.new_code_addr; 535 event->mmap2.start = jr->move.new_code_addr;
514 event->mmap2.len = jr->move.code_size; 536 event->mmap2.len = usize ? ALIGN_8(jr->move.code_size) + usize
537 : jr->move.code_size;
515 event->mmap2.pid = pid; 538 event->mmap2.pid = pid;
516 event->mmap2.tid = tid; 539 event->mmap2.tid = tid;
517 event->mmap2.ino = st.st_ino; 540 event->mmap2.ino = st.st_ino;
@@ -578,6 +601,31 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr)
578} 601}
579 602
580static int 603static int
604jit_repipe_unwinding_info(struct jit_buf_desc *jd, union jr_entry *jr)
605{
606 void *unwinding_data;
607 uint32_t unwinding_data_size;
608
609 if (!(jd && jr))
610 return -1;
611
612 unwinding_data_size = jr->prefix.total_size - sizeof(jr->unwinding);
613 unwinding_data = malloc(unwinding_data_size);
614 if (!unwinding_data)
615 return -1;
616
617 memcpy(unwinding_data, &jr->unwinding.unwinding_data,
618 unwinding_data_size);
619
620 jd->eh_frame_hdr_size = jr->unwinding.eh_frame_hdr_size;
621 jd->unwinding_size = jr->unwinding.unwinding_size;
622 jd->unwinding_mapped_size = jr->unwinding.mapped_size;
623 jd->unwinding_data = unwinding_data;
624
625 return 0;
626}
627
628static int
581jit_process_dump(struct jit_buf_desc *jd) 629jit_process_dump(struct jit_buf_desc *jd)
582{ 630{
583 union jr_entry *jr; 631 union jr_entry *jr;
@@ -594,6 +642,9 @@ jit_process_dump(struct jit_buf_desc *jd)
594 case JIT_CODE_DEBUG_INFO: 642 case JIT_CODE_DEBUG_INFO:
595 ret = jit_repipe_debug_info(jd, jr); 643 ret = jit_repipe_debug_info(jd, jr);
596 break; 644 break;
645 case JIT_CODE_UNWINDING_INFO:
646 ret = jit_repipe_unwinding_info(jd, jr);
647 break;
597 default: 648 default:
598 ret = 0; 649 ret = 0;
599 continue; 650 continue;
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index bcacd20d0c1c..c6b9b67f43bf 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -19,6 +19,7 @@
19#define JITHEADER_MAGIC_SW 0x4454694A 19#define JITHEADER_MAGIC_SW 0x4454694A
20 20
21#define PADDING_8ALIGNED(x) ((((x) + 7) & 7) ^ 7) 21#define PADDING_8ALIGNED(x) ((((x) + 7) & 7) ^ 7)
22#define ALIGN_8(x) (((x) + 7) & (~7))
22 23
23#define JITHEADER_VERSION 1 24#define JITHEADER_VERSION 1
24 25
@@ -48,6 +49,7 @@ enum jit_record_type {
48 JIT_CODE_MOVE = 1, 49 JIT_CODE_MOVE = 1,
49 JIT_CODE_DEBUG_INFO = 2, 50 JIT_CODE_DEBUG_INFO = 2,
50 JIT_CODE_CLOSE = 3, 51 JIT_CODE_CLOSE = 3,
52 JIT_CODE_UNWINDING_INFO = 4,
51 53
52 JIT_CODE_MAX, 54 JIT_CODE_MAX,
53}; 55};
@@ -101,12 +103,22 @@ struct jr_code_debug_info {
101 struct debug_entry entries[0]; 103 struct debug_entry entries[0];
102}; 104};
103 105
106struct jr_code_unwinding_info {
107 struct jr_prefix p;
108
109 uint64_t unwinding_size;
110 uint64_t eh_frame_hdr_size;
111 uint64_t mapped_size;
112 const char unwinding_data[0];
113};
114
104union jr_entry { 115union jr_entry {
105 struct jr_code_debug_info info; 116 struct jr_code_debug_info info;
106 struct jr_code_close close; 117 struct jr_code_close close;
107 struct jr_code_load load; 118 struct jr_code_load load;
108 struct jr_code_move move; 119 struct jr_code_move move;
109 struct jr_prefix prefix; 120 struct jr_prefix prefix;
121 struct jr_code_unwinding_info unwinding;
110}; 122};
111 123
112static inline struct debug_entry * 124static inline struct debug_entry *