Add support of user space symboles for guest.
v2 cover Add support of user space symboles for guest.
Hi Arnaldo:
Please help to review this patchset.
Changelog:
- v2:
* splite the first commit.
Dongsheng Yang (7):
perf tools: Add support for PERF_RECORD_MISC_GUEST_USER in
thread__find_addr_map().
perf tools: Find the proc info under machine->root_dir. perf tools: Set event->header.misc to PERF_RECORD_MISC_GUEST_USER if
machine is guest.
perf tools: Use machine->pid for tgid if mahicne is guest. perf tools: Do not synthesize the treads of default guest. perf tools: Add support of user space symbols for guest in perf kvm
top.
perf tools: Add support of user space symbols for guest in perf kvm
record.
tools/perf/builtin-record.c | 10 ++++++++++ tools/perf/builtin-top.c | 15 ++++++++++----- tools/perf/util/event.c | 44 ++++++++++++++++++++++++++++++-------------- 3 files changed, 50 insertions(+), 19 deletions(-)
Signature · 1 line
1.8.2.1
PATCH v2 1/7 perf tools: Add support for PERF_RECORD_MISC_GUEST_USER in thread__find_addr_map().
This patch remove a TODO in thread__find_addr_map() and add support of PERF_RECORD_MISC_GUEST_USER.
--- tools/perf/util/event.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
tools/perf/util/event.c +3 -8
@@ -658,15 +658,10 @@ void thread__find_addr_map(struct thread *thread, al->level ='g' ; mg = &machine->kmaps; load_map = true; + }else if (cpumode ==PERF_RECORD_MISC_GUEST_USER && perf_guest) { + al->level ='u' ; }else { -/* -* 'u' means guest os user space. -* TODO: We don't support guest user space. Might support late. -*/ -if (cpumode ==PERF_RECORD_MISC_GUEST_USER && perf_guest) - al->level ='u' ; -else - al->level ='H' ; + al->level ='H' ; al->map =NULL ; if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
Signature · 1 line
1.8.2.1
tip-bot for Dongsheng Yang
merge bot[tip:perf/core] perf tools: Add support for PERF_RECORD_MISC_GUEST_USER in thread__find_addr_map().
perf tools: Add support for PERF_RECORD_MISC_GUEST_USER in thread__find_addr_map().
Commit-ID: fb50bb43d051d12aad9e2337d0d5d14d0d3dd281 Gitweb: http://git.kernel.org/tip/fb50bb43d051d12aad9e2337d0d5d14d0d3dd281 Author: Dongsheng Yang <[email protected]> AuthorDate: Fri, 20 Dec 2013 15:52:56 -0500 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Dec 2013 16:49:49 -0300
perf tools: Add support for PERF_RECORD_MISC_GUEST_USER in thread__find_addr_map().
This patch remove a TODO in thread__find_addr_map() and add support of PERF_RECORD_MISC_GUEST_USER.
--- tools/perf/util/event.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
tools/perf/util/event.c +3 -8
@@ -659,15 +659,10 @@ void thread__find_addr_map(struct thread *thread, al->level ='g' ; mg = &machine->kmaps; load_map = true; + }else if (cpumode ==PERF_RECORD_MISC_GUEST_USER && perf_guest) { + al->level ='u' ; }else { -/* -* 'u' means guest os user space. -* TODO: We don't support guest user space. Might support late. -*/ -if (cpumode ==PERF_RECORD_MISC_GUEST_USER && perf_guest) - al->level ='u' ; -else - al->level ='H' ; + al->level ='H' ; al->map =NULL ; if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
PATCH v2 2/7 perf tools: Find the proc info under machine->root_dir.
In reply to Dongsheng YangWhen we synthesize the threads, we are looking for the infomation under /proc. But it is only for host.
This patch look for the path of proc under machine->root_dir, then XXX__synthesize_threads() functions can support guest machines.
--- tools/perf/util/event.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/event.c +8 -3
@@ -129,7 +129,8 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, goto out; } -snprintf (filename,sizeof (filename),"/proc/%d/task" , pid); +snprintf (filename,sizeof (filename),"%s/proc/%d/task" , + machine->root_dir, pid); tasks =opendir (filename);if (tasks ==NULL ) {
@@ -178,7 +179,8 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,FILE *fp;int rc =0 ; -snprintf (filename,sizeof (filename),"/proc/%d/maps" , pid); +snprintf (filename,sizeof (filename),"%s/proc/%d/maps" , + machine->root_dir, pid); fp =fopen (filename,"r" );if (fp ==NULL ) {
@@ -387,6 +389,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, struct machine *machine, bool mmap_data) {DIR *proc; +char proc_path[PATH_MAX ];struct dirent dirent, *next;union perf_event *comm_event, *mmap_event;int err =-1 ;
@@ -399,7 +402,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,if (mmap_event ==NULL ) goto out_free_comm; - proc =opendir ("/proc" ); +snprintf (proc_path,sizeof (proc_path),"%s/proc" , machine->root_dir); + proc =opendir (proc_path); +if (proc ==NULL ) goto out_free_mmap;
Signature · 1 line
1.8.2.1
tip-bot for Dongsheng Yang
merge bot[tip:perf/core] perf tools: Find the proc info under machine-> root_dir.
perf tools: Find the proc info under machine->root_dir.
Commit-ID: 995634650ef1f907196bd7e9ae45354124a80e47 Gitweb: http://git.kernel.org/tip/995634650ef1f907196bd7e9ae45354124a80e47 Author: Dongsheng Yang <[email protected]> AuthorDate: Fri, 20 Dec 2013 15:52:57 -0500 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Dec 2013 16:49:49 -0300
perf tools: Find the proc info under machine->root_dir.
When we synthesize the threads, we are looking for the infomation under /proc. But it is only for host.
This patch look for the path of proc under machine->root_dir, then XXX__synthesize_threads() functions can support guest machines.
--- tools/perf/util/event.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/event.c +8 -3
@@ -129,7 +129,8 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, goto out; } -snprintf (filename,sizeof (filename),"/proc/%d/task" , pid); +snprintf (filename,sizeof (filename),"%s/proc/%d/task" , + machine->root_dir, pid); tasks =opendir (filename);if (tasks ==NULL ) {
@@ -178,7 +179,8 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,FILE *fp;int rc =0 ; -snprintf (filename,sizeof (filename),"/proc/%d/maps" , pid); +snprintf (filename,sizeof (filename),"%s/proc/%d/maps" , + machine->root_dir, pid); fp =fopen (filename,"r" );if (fp ==NULL ) {
@@ -387,6 +389,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, struct machine *machine, bool mmap_data) {DIR *proc; +char proc_path[PATH_MAX ];struct dirent dirent, *next;union perf_event *comm_event, *mmap_event;int err =-1 ;
@@ -399,7 +402,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,if (mmap_event ==NULL ) goto out_free_comm; - proc =opendir ("/proc" ); +snprintf (proc_path,sizeof (proc_path),"%s/proc" , machine->root_dir); + proc =opendir (proc_path); +if (proc ==NULL ) goto out_free_mmap;
PATCH v2 3/7 perf tools: Set event->header.misc to PERF_RECORD_MISC_GUEST_USER if machine is guest.
In reply to Dongsheng YangWhen we synthesize the mmap events of user space, if machine is guest, we should set the event->header.misc to PERF_RECORD_MISC_GUEST_USER, rather than PERF_RECORD_MISC_USER.
--- tools/perf/util/event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/event.c +4 -1
@@ -220,7 +220,10 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,/* * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c */ - event->header.misc =PERF_RECORD_MISC_USER ; +if (machine__is_host (machine)) + event->header.misc =PERF_RECORD_MISC_USER ; +else + event->header.misc =PERF_RECORD_MISC_GUEST_USER ;if (prot[2 ] !='x' ) {if (!mmap_data || prot[0 ] !='r' )
Signature · 1 line
1.8.2.1
tip-bot for Dongsheng Yang
merge bot[tip:perf/core] perf tools: Set event-> header.misc to PERF_RECORD_MISC_GUEST_USER if machine is guest.
perf tools: Set event->header.misc to PERF_RECORD_MISC_GUEST_USER if machine is guest.
Commit-ID: 73547aacdcd45cdf8b53245ded9593d7c587501a Gitweb: http://git.kernel.org/tip/73547aacdcd45cdf8b53245ded9593d7c587501a Author: Dongsheng Yang <[email protected]> AuthorDate: Fri, 20 Dec 2013 15:52:58 -0500 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Dec 2013 16:49:50 -0300
perf tools: Set event->header.misc to PERF_RECORD_MISC_GUEST_USER if machine is guest.
When we synthesize the mmap events of user space, if machine is guest, we should set the event->header.misc to PERF_RECORD_MISC_GUEST_USER, rather than PERF_RECORD_MISC_USER.
--- tools/perf/util/event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/event.c +4 -1
@@ -220,7 +220,10 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,/* * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c */ - event->header.misc =PERF_RECORD_MISC_USER ; +if (machine__is_host (machine)) + event->header.misc =PERF_RECORD_MISC_USER ; +else + event->header.misc =PERF_RECORD_MISC_GUEST_USER ;if (prot[2 ] !='x' ) {if (!mmap_data || prot[0 ] !='r' )
PATCH v2 4/7 perf tools: Use machine->pid for tgid if mahicne is guest.
In reply to Dongsheng YangWhen we synthesize an comm event, if machine is guest, we should use the pid of machine as the event->comm.pid, rather than tgid of thread.
--- tools/perf/util/event.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/event.c +6 -2
@@ -106,8 +106,12 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool,memset (&event->comm,0 ,sizeof (event->comm)); - tgid =perf_event__get_comm_tgid (pid, event->comm.comm, -sizeof (event->comm.comm)); +if (machine__is_host (machine)) + tgid =perf_event__get_comm_tgid (pid, event->comm.comm, +sizeof (event->comm.comm)); +else + tgid = machine->pid; +if (tgid <0 ) goto out;
Signature · 1 line
1.8.2.1
tip-bot for Dongsheng Yang
merge bot[tip:perf/core] perf tools: Use machine-> pid for tgid if machine is guest.
perf tools: Use machine->pid for tgid if machine is guest.
Commit-ID: f5db57c4c47f3985dfc677152e25636a3401fa13 Gitweb: http://git.kernel.org/tip/f5db57c4c47f3985dfc677152e25636a3401fa13 Author: Dongsheng Yang <[email protected]> AuthorDate: Fri, 20 Dec 2013 15:52:59 -0500 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Dec 2013 16:49:50 -0300
perf tools: Use machine->pid for tgid if machine is guest.
When we synthesize an comm event, if machine is guest, we should use the pid of machine as the event->comm.pid, rather than tgid of thread.
--- tools/perf/util/event.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/event.c +6 -2
@@ -106,8 +106,12 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool,memset (&event->comm,0 ,sizeof (event->comm)); - tgid =perf_event__get_comm_tgid (pid, event->comm.comm, -sizeof (event->comm.comm)); +if (machine__is_host (machine)) + tgid =perf_event__get_comm_tgid (pid, event->comm.comm, +sizeof (event->comm.comm)); +else + tgid = machine->pid; +if (tgid <0 ) goto out;
PATCH v2 5/7 perf tools: Do not synthesize the treads of default guest.
In reply to Dongsheng YangAs the default guest is designed to handle orphan kernel symboles with --guestkallsysms and --guestmoudles, it has no user space. So we should skip synthesizing threads if machine is default guest.
--- tools/perf/util/event.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/util/event.c +9 -0
@@ -133,6 +133,9 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, goto out; } +if (machine__is_default_guest (machine)) +return 0 ; +snprintf (filename,sizeof (filename),"%s/proc/%d/task" , machine->root_dir, pid);
@@ -183,6 +186,9 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,FILE *fp;int rc =0 ; +if (machine__is_default_guest (machine)) +return 0 ; +snprintf (filename,sizeof (filename),"%s/proc/%d/maps" , machine->root_dir, pid);
@@ -409,6 +415,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,if (mmap_event ==NULL ) goto out_free_comm; +if (machine__is_default_guest (machine)) +return 0 ; +snprintf (proc_path,sizeof (proc_path),"%s/proc" , machine->root_dir); proc =opendir (proc_path);
Signature · 1 line
1.8.2.1
tip-bot for Dongsheng Yang
merge bot[tip:perf/core] perf tools: Do not synthesize the treads of default guest.
perf tools: Do not synthesize the treads of default guest.
Commit-ID: c239c25a82808ad2cbc795b69e621c4c24f154d6 Gitweb: http://git.kernel.org/tip/c239c25a82808ad2cbc795b69e621c4c24f154d6 Author: Dongsheng Yang <[email protected]> AuthorDate: Fri, 20 Dec 2013 15:53:00 -0500 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Dec 2013 16:49:51 -0300
perf tools: Do not synthesize the treads of default guest.
As the default guest is designed to handle orphan kernel symboles with --guestkallsysms and --guestmodules, it has no user space.
So we should skip synthesizing threads if machine is default guest.
--- tools/perf/util/event.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/util/event.c +9 -0
@@ -133,6 +133,9 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, goto out; } +if (machine__is_default_guest (machine)) +return 0 ; +snprintf (filename,sizeof (filename),"%s/proc/%d/task" , machine->root_dir, pid);
@@ -183,6 +186,9 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,FILE *fp;int rc =0 ; +if (machine__is_default_guest (machine)) +return 0 ; +snprintf (filename,sizeof (filename),"%s/proc/%d/maps" , machine->root_dir, pid);
@@ -409,6 +415,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,if (mmap_event ==NULL ) goto out_free_comm; +if (machine__is_default_guest (machine)) +return 0 ; +snprintf (proc_path,sizeof (proc_path),"%s/proc" , machine->root_dir); proc =opendir (proc_path);
PATCH v2 6/7 perf tools: Add support of user space symbols for guest in perf kvm top.
In reply to Dongsheng Yang# perf kvm --guestmount /tmp/guestmount/ top Samples: 1K of event 'cycles', Event count (approx.): 259112905 17.34% libcrypto.so.1.0.1e [u] 0x000000000007d971 5.60% [guest.kernel] [g] kallsyms_expand_symbol 5.44% libcrypto.so.1.0.1e [u] md5_block_asm_data_order 4.09% [guest.kernel] [g] number.isra.1 3.59% [guest.kernel] [g] vsnprintf 3.52% sshd [u] 0x00000000000441c0 2.37% [guest.kernel] [g] format_decode 2.36% [guest.kernel] [g] memcpy 2.11% [guest.kernel] [g] strnlen
--- tools/perf/builtin-top.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/perf/builtin-top.c +10 -5
@@ -821,11 +821,9 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)break ;case PERF_RECORD_MISC_GUEST_USER : ++top->guest_us_samples; -/* -* TODO: we don't process guest user from host side -* except simple counting. -*/ -/* Fall thru */ + machine =perf_session__find_machine (session, + sample.pid); +break ;default : goto next_event; }
@@ -912,6 +910,7 @@ static int __cmd_top(struct perf_top *top)struct perf_record_opts *opts = &top->record_opts;pthread_t thread;int ret; +struct rb_node *nd; top->session =perf_session__new (NULL , false,NULL );if (top->session ==NULL )
@@ -931,6 +930,12 @@ static int __cmd_top(struct perf_top *top)machine__synthesize_threads (&top->session->machines.host, &opts->target, top->evlist->threads, false); + +for (nd =rb_first (&top->session->machines.guests); nd; nd =rb_next (nd)) { + struct machine *pos = rb_entry(nd, struct machine, rb_node); +machine__synthesize_threads (pos, &opts->target, top->evlist->threads, false); + } + ret =perf_top__start_counters (top);if (ret) goto out_delete;
Signature · 1 line
1.8.2.1
PATCH v2 7/7 perf tools: Add support of user space symbols for guest in perf kvm record.
In reply to Dongsheng Yang# perf kvm --guestmount /tmp/guestmount/ record -a sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.828 MB perf.data.guest (~36163 samples) ]
# perf kvm --guestmount /tmp/guestmount/ report Samples: 4K of event 'cycles', Event count (approx.): 2662750816 8.67% [guest/9217] dd [u] 0x0000000000004e90 6.62% [guest/9217] [guest.kernel.kallsyms.9217] [g] fget_light 6.17% [guest/9217] [guest.kernel.kallsyms.9217] [g] system_call 5.97% [guest/9217] [guest.kernel.kallsyms.9217] [g] __srcu_read_lock 5.53% [guest/9217] [guest.kernel.kallsyms.9217] [g] __srcu_read_unlock 5.47% [guest/9217] [guest.kernel.kallsyms.9217] [g] __audit_syscall_exit 5.38% [guest/9217] [guest.kernel.kallsyms.9217] [g] fsnotify 5.32% [guest/9217] [guest.kernel.kallsyms.9217] [g] system_call_after_swapgs 4.45% [guest/9217] libc-2.17.so [u] __GI___libc_write 4.15% [guest/9217] [guest.kernel.kallsyms.9217] [g] sys_write 3.97% [guest/9217] [guest.kernel.kallsyms.9217] [g] vfs_read 3.78% [guest/9217] libc-2.17.so [u] __GI___libc_read
--- tools/perf/builtin-record.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/perf/builtin-record.c +10 -0
@@ -279,6 +279,9 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data) {int err;struct perf_tool *tool = data; + struct perf_record *rec = container_of(tool, struct perf_record, tool); +struct perf_record_opts *opts = &rec->opts; +struct perf_evlist *evsel_list = rec->evlist;/* *As for guest kernel when processing subcommand record&report, *we arrange module mmap prior to guest kernel mmap and trigger
@@ -305,6 +308,13 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)if (err <0 )pr_err ("Couldn't record guest kernel [%d]'s reference" " relocation symbol.\n" , machine->pid); + + err =__machine__synthesize_threads (machine, tool, &opts->target, evsel_list->threads, + process_synthesized_event, opts->sample_address); + +if (err <0 ) +pr_err ("Couldn't record guest userspace [%d]'s reference" +" relocation symbol.\n" , machine->pid); }static struct perf_event_header finished_round_event = {
Signature · 1 line
1.8.2.1
Quoted 7 lines · Dongsheng Yang
Hi Arnaldo:
Please help to review this patchset.Changelog:
- v2:
* splite the first commit.
At best you are creating knowledge of running tasks in the VMs when the perf session is started. That's it. That information cannot be used since the host has no idea what task is running in a VM at any given moment. No insight into process creation, mmaps, exits, etc.
David
Quoted 11 lines · David Ahern
Quoted 7 lines · Dongsheng Yang
Hi Arnaldo:
Please help to review this patchset.Changelog:
- v2:
* splite the first commit.At best you are creating knowledge of running tasks in the VMs when the perf session is started. That's it. That information cannot be used since the host has no idea what task is running in a VM at any given moment. No insight into process creation, mmaps, exits, etc.
Yes, you are right. host has no idea what task is running in a VM.
Thanx for your reply.
Yang
Quoted 8 lines
David
Signature · 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/