[PATCH v2 0/3] perf kvm: Guest Symbol Resolution for powerpc

2016-01-21 Thread Ravi Bangoria
'perf kvm {record|report}' is used to record and report the profiled
performance of any workload on a guest. From the host, we can collect
guest kernel statistics which is useful in finding out any contentions
in guest kernel symbols for a certain workload.
This feature is not available on powerpc because 'perf' relies on the
'cycles' event (a PMU event) to profile the guest. However, for powerpc,
this can't be used from the host because the PMUs are controlled by the
guest rather than the host.

Due to this issue, we need a different approach to profile the
workload in the guest. There exists a tracepoint 'kvm_hv:kvm_guest_exit'
in powerpc which is hit whenever any of the threads exit the guest
context. The guest instruction pointer dumped along with this
tracepoint data in the field 'pc', can be used as guest instruction
pointer while postprocessing the trace data to map this IP to symbol
from guest.kallsyms.

However, to have some kind of periodicity, we can't use all the kvm
exits, rather exits which are bound to happen in certain intervals.
HV_DECREMENTER Interrupt forces the threads to exit after an interval
of 10 ms.

This patch makes use of the 'kvm_guest_exit' tracepoint and checks the
exit reason for any kvm exit. If it is HV_DECREMENTER, then the
instruction pointer dumped along with this tracepoint is retrieved and
mapped with the guest kallsyms. So for powerpc, 'perf kvm record' will
record 'kvm_hv:kvm_guest_exit' events instead of cycles.

This patch will enable --guest option for perf kvm {record|report} on
powerpc. Still --host --guest together won't work.

This patch can be considered as a next iteration to RFC patch sent by
Hemant Kumar: https://lkml.org/lkml/2015/6/15/670. Hemant's patch is used
for enabling 'perf kvm report', while I've added code to enable
'perf kvm record' on powerpc.

Patches are developed on acme's perf/core branch.

 * changes in v2)
- Patch 1,2 are breakdown of v1 patch with little changes
- Patch 3 is new. It fixes output format of perf kvm report

Before applying patch:
[Note: one needs to run vm with kvm enabled]

  $ ./perf kvm --guestkallsyms=guest.kallsyms --guestmodules=guest.modules 
record -a
  [ perf record: Captured and wrote 1.530 MB perf.data.guest (28768 samples) ]

  $ ./perf script -i perf.data.guest
   qemu-system-ppc  9688 [000] 842566.451558:  1 cycles:ppp:  
c01f2860 .mmap_region ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451562:  1 cycles:ppp:  
c00a2d68 .kvmppc_do_h_enter ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451564:  7 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451565:138 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451567:   3128 cycles:ppp:  
c00097d8 ._switch ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451570:  81568 cycles:ppp:  
c00ea8bc .wake_up_new_task ([kernel.kallsyms])
   swapper 0 [004] 842566.451580:  1 cycles:ppp:  
c01f2d88 .sys_munmap ([kernel.kallsyms])
   swapper 0 [004] 842566.451583:  1 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [004] 842566.451584: 11 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [004] 842566.451585:226 cycles:ppp:  
c00097d4 ._switch ([kernel.kallsyms])
   swapper 0 [004] 842566.451586:   5664 cycles:ppp:  
c000990c resume_kernel ([kernel.kallsyms])
   swapper 0 [004] 842566.451591: 147929 cycles:ppp:  
c010a4fc .freeze_set_ops ([kernel.kallsyms])
   swapper 0 [008] 842566.451597:  1 cycles:ppp:  
c01f2d98 .sys_munmap ([kernel.kallsyms])
   swapper 0 [008] 842566.451600:  1 cycles:ppp:  
c00a2ee0 .kvmppc_do_h_enter ([kernel.kallsyms])
   swapper 0 [008] 842566.451602: 11 cycles:ppp:  
c00a2ee0 .kvmppc_do_h_enter ([kernel.kallsyms])
   swapper 0 [008] 842566.451603:224 cycles:ppp:  
c001f274 .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [008] 842566.451604:   5240 cycles:ppp:  
c0009984 fast_exception_return ([kernel.kallsyms])
   swapper 0 [008] 842566.451608: 134752 cycles:ppp:  
c0780af4 .inet_diag_handler_get_info ([kernel.kallsyms])
   swapper 0 [012] 842566.451616:  1 cycles:ppp:  
c01f2828 .mmap_region ([kernel.kallsyms])
   swapper 0 [012] 842566.451619:  1 cycles:ppp:  
c00a2d78 .kvmppc_do_h_enter ([kernel.kallsyms])
   swapper 0 [012] 842566.451620: 11 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [012] 842566.451621:226 

[PATCH v2 0/3] perf kvm: Guest Symbol Resolution for powerpc

2016-01-21 Thread Ravi Bangoria
'perf kvm {record|report}' is used to record and report the profiled
performance of any workload on a guest. From the host, we can collect
guest kernel statistics which is useful in finding out any contentions
in guest kernel symbols for a certain workload.
This feature is not available on powerpc because 'perf' relies on the
'cycles' event (a PMU event) to profile the guest. However, for powerpc,
this can't be used from the host because the PMUs are controlled by the
guest rather than the host.

Due to this issue, we need a different approach to profile the
workload in the guest. There exists a tracepoint 'kvm_hv:kvm_guest_exit'
in powerpc which is hit whenever any of the threads exit the guest
context. The guest instruction pointer dumped along with this
tracepoint data in the field 'pc', can be used as guest instruction
pointer while postprocessing the trace data to map this IP to symbol
from guest.kallsyms.

However, to have some kind of periodicity, we can't use all the kvm
exits, rather exits which are bound to happen in certain intervals.
HV_DECREMENTER Interrupt forces the threads to exit after an interval
of 10 ms.

This patch makes use of the 'kvm_guest_exit' tracepoint and checks the
exit reason for any kvm exit. If it is HV_DECREMENTER, then the
instruction pointer dumped along with this tracepoint is retrieved and
mapped with the guest kallsyms. So for powerpc, 'perf kvm record' will
record 'kvm_hv:kvm_guest_exit' events instead of cycles.

This patch will enable --guest option for perf kvm {record|report} on
powerpc. Still --host --guest together won't work.

This patch can be considered as a next iteration to RFC patch sent by
Hemant Kumar: https://lkml.org/lkml/2015/6/15/670. Hemant's patch is used
for enabling 'perf kvm report', while I've added code to enable
'perf kvm record' on powerpc.

Patches are developed on acme's perf/core branch.

 * changes in v2)
- Patch 1,2 are breakdown of v1 patch with little changes
- Patch 3 is new. It fixes output format of perf kvm report

Before applying patch:
[Note: one needs to run vm with kvm enabled]

  $ ./perf kvm --guestkallsyms=guest.kallsyms --guestmodules=guest.modules 
record -a
  [ perf record: Captured and wrote 1.530 MB perf.data.guest (28768 samples) ]

  $ ./perf script -i perf.data.guest
   qemu-system-ppc  9688 [000] 842566.451558:  1 cycles:ppp:  
c01f2860 .mmap_region ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451562:  1 cycles:ppp:  
c00a2d68 .kvmppc_do_h_enter ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451564:  7 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451565:138 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451567:   3128 cycles:ppp:  
c00097d8 ._switch ([kernel.kallsyms])
   qemu-system-ppc  9688 [000] 842566.451570:  81568 cycles:ppp:  
c00ea8bc .wake_up_new_task ([kernel.kallsyms])
   swapper 0 [004] 842566.451580:  1 cycles:ppp:  
c01f2d88 .sys_munmap ([kernel.kallsyms])
   swapper 0 [004] 842566.451583:  1 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [004] 842566.451584: 11 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [004] 842566.451585:226 cycles:ppp:  
c00097d4 ._switch ([kernel.kallsyms])
   swapper 0 [004] 842566.451586:   5664 cycles:ppp:  
c000990c resume_kernel ([kernel.kallsyms])
   swapper 0 [004] 842566.451591: 147929 cycles:ppp:  
c010a4fc .freeze_set_ops ([kernel.kallsyms])
   swapper 0 [008] 842566.451597:  1 cycles:ppp:  
c01f2d98 .sys_munmap ([kernel.kallsyms])
   swapper 0 [008] 842566.451600:  1 cycles:ppp:  
c00a2ee0 .kvmppc_do_h_enter ([kernel.kallsyms])
   swapper 0 [008] 842566.451602: 11 cycles:ppp:  
c00a2ee0 .kvmppc_do_h_enter ([kernel.kallsyms])
   swapper 0 [008] 842566.451603:224 cycles:ppp:  
c001f274 .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [008] 842566.451604:   5240 cycles:ppp:  
c0009984 fast_exception_return ([kernel.kallsyms])
   swapper 0 [008] 842566.451608: 134752 cycles:ppp:  
c0780af4 .inet_diag_handler_get_info ([kernel.kallsyms])
   swapper 0 [012] 842566.451616:  1 cycles:ppp:  
c01f2828 .mmap_region ([kernel.kallsyms])
   swapper 0 [012] 842566.451619:  1 cycles:ppp:  
c00a2d78 .kvmppc_do_h_enter ([kernel.kallsyms])
   swapper 0 [012] 842566.451620: 11 cycles:ppp:  
c001f26c .vsx_unavailable_tm ([kernel.kallsyms])
   swapper 0 [012] 842566.451621:226