Skip to content

Commit ce37bc5

Browse files
author
Daniel Shaulov
committed
perf inject --jit: Remove //anon mmap events
While a JIT is jitting code it will eventually need to commit more pages and change these pages to executable permissions. Typically the JIT will want these colocated to minimize branch displacements. The kernel will coalesce these anonymous mapping with identical permissions before sending an MMAP event for the new pages. This means the mmap event for the new pages will include the older pages. These anonymous mmap events will obscure the jitdump injected pseudo events. This means that the jitdump generated symbols, machine code, debugging info, and unwind info will no longer be used. Observations: When a process emits a jit dump marker and a jitdump file, the perf-xxx.map file represents inferior information which has been superceded by the jitdump jit-xxx.dump file. Further the '//anon*' mmap events are only required for the legacy perf-xxx.map mapping. When attaching to an existing process, the synthetic anon map events are given a time stamp of -1. These should not obscure the jitdump events which have an actual time. Summary: Use thread->priv to store whether a jitdump file has been processed During "perf inject --jit", discard "//anon*" mmap events for any pid which has sucessfully processed a jitdump file. Committer testing: // jitdump case perf record <app with jitdump> perf inject --jit --input perf.data --output perfjit.data // verify mmap "//anon" events present initially perf script --input perf.data --show-mmap-events | grep '//anon' // verify mmap "//anon" events removed perf script --input perfjit.data --show-mmap-events | grep '//anon' // no jitdump case perf record <app without jitdump> perf inject --jit --input perf.data --output perfjit.data // verify mmap "//anon" events present initially perf script --input perf.data --show-mmap-events | grep '//anon' // verify mmap "//anon" events not removed perf script --input perfjit.data --show-mmap-events | grep '//anon' Repro: This issue was discovered while testing the initial CoreCLR jitdump implementation. dotnet/coreclr#26897. Signed-off-by: Steve MacLean <[email protected]>
1 parent ba17920 commit ce37bc5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

tools/perf/builtin-inject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int perf_event__jit_repipe_mmap(struct perf_tool *tool,
292292
* if jit marker, then inject jit mmaps and generate ELF images
293293
*/
294294
ret = jit_process(inject->session, &inject->output, machine,
295-
event->mmap.filename, sample->pid, &n);
295+
event->mmap.filename, event->mmap.pid, &n);
296296
if (ret < 0)
297297
return ret;
298298
if (ret) {
@@ -330,7 +330,7 @@ static int perf_event__jit_repipe_mmap2(struct perf_tool *tool,
330330
* if jit marker, then inject jit mmaps and generate ELF images
331331
*/
332332
ret = jit_process(inject->session, &inject->output, machine,
333-
event->mmap2.filename, sample->pid, &n);
333+
event->mmap2.filename, event->mmap2.pid, &n);
334334
if (ret < 0)
335335
return ret;
336336
if (ret) {

tools/perf/util/jitdump.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "jit.h"
2727
#include "jitdump.h"
2828
#include "genelf.h"
29+
#include "thread.h"
2930

3031
#include <linux/ctype.h>
3132
#include <linux/zalloc.h>
@@ -749,6 +750,34 @@ jit_detect(char *mmap_name, pid_t pid)
749750
return 0;
750751
}
751752

753+
static void jit_add_pid(struct machine *machine, pid_t pid)
754+
{
755+
struct thread *thread = machine__findnew_thread(machine, pid, pid);
756+
757+
if (!thread)
758+
{
759+
pr_err("jit_add_pid() thread not found\n");
760+
761+
return;
762+
}
763+
764+
thread->priv = (void *) 1;
765+
}
766+
767+
static bool jit_has_pid(struct machine *machine, pid_t pid)
768+
{
769+
struct thread *thread = machine__findnew_thread(machine, pid, pid);
770+
771+
if (!thread)
772+
{
773+
pr_err("jit_has_pid() thread not found\n");
774+
775+
return 0;
776+
}
777+
778+
return (bool) thread->priv;
779+
}
780+
752781
int
753782
jit_process(struct perf_session *session,
754783
struct perf_data *output,
@@ -765,7 +794,15 @@ jit_process(struct perf_session *session,
765794
* first, detect marker mmap (i.e., the jitdump mmap)
766795
*/
767796
if (jit_detect(filename, pid))
797+
{
798+
/*
799+
* Strip //anon* mmaps if we processed a jitdump for this pid
800+
*/
801+
if (jit_has_pid(machine, pid) && (strncmp(filename, "//anon", 6) == 0))
802+
return 1;
803+
768804
return 0;
805+
}
769806

770807
memset(&jd, 0, sizeof(jd));
771808

@@ -784,6 +821,7 @@ jit_process(struct perf_session *session,
784821

785822
ret = jit_inject(&jd, filename);
786823
if (!ret) {
824+
jit_add_pid(machine, pid);
787825
*nbytes = jd.bytes_written;
788826
ret = 1;
789827
}

0 commit comments

Comments
 (0)