perf/kvm: Port perf kvm to powerpc
Subsystems (3)
PATCH v3 1/2 perf/kvm: Port perf kvm to powerpc
From: Srikar Dronamraju <[email protected]>
perf kvm can be used to analyze guest exit reasons. This support already exists in x86. Hence, porting it to powerpc.
- To trace KVM events :
perf kvm stat record
If many guests are running, we can track for a specific guest by using --pid as in : perf kvm stat record --pid <pid>
- To see the results :
perf kvm stat report
The result shows the number of exits (from the guest context to host/hypervisor context) grouped by their respective exit reasons with their frequency.
This patch makes use of the guest exit reasons available in "trace_book3s.h". It records on two already available tracepoints :
"kvm_hv:kvm_guest_exit" and "kvm_hv:kvm_guest_enter".
Note : This patch has a dependency on the patch "kvm/powerpc: Export kvm exit reasons" which exports the KVM exit reasons through the uapi.
Here is a sample o/p:
# pgrep qemu 19378 60515
2 Guests are running on the host.
# perf kvm stat record -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 4.153 MB perf.data.guest (39624 samples) ]
# perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs:
VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% )
HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% )
SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% )
RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% )
EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% )Total Samples:14182, Total events handled time:49264158.30us.
---
Patch has a dependency on : https://patchwork.ozlabs.org/patch/469839/
which exports the exit reasons to perf through uapi.
Changes:
- Original series split into two patchsets now : perf and powerpc side changes.
arch/powerpc/include/uapi/asm/kvm_perf.h | 15 +++++++++++++++ tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/Build | 1 + tools/perf/arch/powerpc/util/kvm-stat.c | 33 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 arch/powerpc/include/uapi/asm/kvm_perf.h create mode 100644 tools/perf/arch/powerpc/util/kvm-stat.c
arch/powerpc/include/uapi/asm/kvm_perf.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef _ASM_POWERPC_KVM_PERF_H +#define _ASM_POWERPC_KVM_PERF_H + +#include <asm/trace_book3s.h> +#include <asm/kvm.h> + +#define DECODE_STR_LEN 20 + +#define VCPU_ID "vcpu_id" + +#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter" +#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit" +#define KVM_EXIT_REASON "trap" + +#endif /* _ASM_POWERPC_KVM_PERF_H */
tools/perf/arch/powerpc/Makefile +1 -0
@@ -1,3 +1,4 @@ ifndef NO_DWARF PERF_HAVE_DWARF_REGS := 1 endif +HAVE_KVM_STAT_SUPPORT := 1
tools/perf/arch/powerpc/util/Build +1 -0
@@ -1,4 +1,5 @@ libperf-y += header.o +libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_DWARF) += skip-callchain-idx.o
tools/perf/arch/powerpc/util/kvm-stat.c new file +33 -0
@@ -0,0 +1,33 @@ +#include "../../util/kvm-stat.h" +#include <asm/kvm_perf.h> + +define_exit_reasons_table (hv_exit_reasons, kvm_trace_symbol_exit); + +static struct kvm_events_ops exit_events = { + .is_begin_event = exit_event_begin, + .is_end_event = exit_event_end, + .decode_key = exit_event_decode_key, + .name ="VM-EXIT" +}; + +const char *const kvm_events_tp[] = { +"kvm_hv:kvm_guest_exit" , +"kvm_hv:kvm_guest_enter" , +NULL , +}; + +struct kvm_reg_events_ops kvm_reg_events_ops[] = { + { .name ="vmexit" , .ops = &exit_events }, + {NULL ,NULL }, +}; + +const char *const kvm_skip_events[] = { +NULL , +}; + +int cpu_isa_init (struct perf_kvm_stat *kvm,const char *cpuid__maybe_unused ) +{ + kvm->exit_reasons = hv_exit_reasons; + kvm->exit_reasons_isa ="HV" ; +return 0 ; +}
Signature · 1 line
1.9.3
PATCH v3 2/2 perf/kvm: Support HCALL events
powerpc provides hcall events that also provide insights into guest behaviour. Enhance perf kvm to record and analyze hcall events.
- To trace hcall events :
perf kvm stat record
- To show the results :
perf kvm stat report --event=hcall
The result shows the number of hypervisor calls from the guest grouped by their respective reasons displayed with the frequency.
This patch makes use of two additional tracepoints "kvm_hv:kvm_hcall_enter" and "kvm_hv:kvm_hcall_exit". It uses the pSeries hypervisor codes exported through uapi to classify the hcalls into their respective reasons.
Note : This patch has a dependency on "kvm/powerpc: Export HCALL reason codes" which exports HCALL reasons through uapi.
# pgrep qemu A sample output : 19378 60515
2 VMs running.
# perf kvm stat record -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 4.153 MB perf.data.guest (39624 samples) ]
# perf kvm stat report -p 60515 --event=hcall Analyze events for pid(s) 60515, all VCPUs:
HCALL-EVENT Samples Samples% Time% Min Time Max Time Avg time
H_VIO_SIGNAL 1034 38.44% 15.77% 0.36us 1.59us 0.44us ( +- 0.66% )
H_SEND_CRQ 652 24.24% 10.97% 0.39us 1.84us 0.49us ( +- 1.20% )
H_IPI 523 19.44% 62.05% 1.35us 19.70us 3.44us ( +- 2.88% )
H_PUT_TERM_CHAR 411 15.28% 8.03% 0.38us 3.77us 0.57us ( +- 1.61% )
H_GET_TERM_CHAR 50 1.86% 0.99% 0.40us 0.98us 0.57us ( +- 3.37% )
H_EOI 20 0.74% 2.19% 2.22us 4.72us 3.17us ( +- 5.96% )Total Samples:2690, Total events handled time:2896.94us.
---
Patch has a dependency on https://patchwork.ozlabs.org/patch/469841/
which exports the HCALL reason codes to perf.
arch/powerpc/include/uapi/asm/kvm_perf.h | 4 +++ tools/perf/arch/powerpc/util/kvm-stat.c | 61 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
arch/powerpc/include/uapi/asm/kvm_perf.h +4 -0
@@ -3,6 +3,7 @@#include <asm/trace_book3s.h> #include <asm/kvm.h> +#include <asm/trace_hcall.h> #define DECODE_STR_LEN 20
@@ -11,5 +12,8 @@#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter"#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit"#define KVM_EXIT_REASON "trap" +#define KVM_HCALL_ENTRY_TRACE "kvm_hv:kvm_hcall_enter" +#define KVM_HCALL_EXIT_TRACE "kvm_hv:kvm_hcall_exit" +#define KVM_HCALL_REASON "req"#endif /* _ASM_POWERPC_KVM_PERF_H */
tools/perf/arch/powerpc/util/kvm-stat.c +61 -0
82 lines not on this page · raw message
Signature · 1 line
1.9.3
Quoted 10 lines · Hemant Kumar
# perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs:VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% ) HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% ) SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% ) RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% ) EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% )
Where is the last line misaligned? Copy & paste error or does perf kvm produce it in such a way?
Thanks,
Ingo
Quoted 7 lines · Ingo Molnar
Quoted 5 lines · Hemant Kumar
# perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs:VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
Quoted 7 lines
Quoted 5 lines
H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% ) HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% ) SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% ) RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% ) EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% )Where is the last line misaligned? Copy & paste error or does perf kvm produce it in such a way?
Its a copy-paste error. Thanks for pointing this out.
Shall I resend the patches with the correct alignment of the o/p?
Quoted 4 lines
Thanks,
Ingo
Signature · 2 lines
Thanks, Hemant Kumar
Quoted 14 lines · Hemant Kumar
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Hemant Kumar
# perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs:VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% ) HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% ) SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% ) RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% ) EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% )
Quoted 6 lines
Quoted 2 lines
Where is the last line misaligned? Copy & paste error or does perf kvm produce it in such a way?
Its a copy-paste error. Thanks for pointing this out.
Shall I resend the patches with the correct alignment of the o/p?
I don't think that's necessary, as long as the code is fine.
Thanks,
Ingo
Quoted 77 lines · Hemant Kumar
From: Srikar Dronamraju <[email protected]>
perf kvm can be used to analyze guest exit reasons. This support already exists in x86. Hence, porting it to powerpc.
- To trace KVM events :
perf kvm stat record
If many guests are running, we can track for a specific guest by using --pid as in : perf kvm stat record --pid <pid>- To see the results :
perf kvm stat reportThe result shows the number of exits (from the guest context to host/hypervisor context) grouped by their respective exit reasons with their frequency.
This patch makes use of the guest exit reasons available in "
trace_book3s.h". It records on two already available tracepoints :
"kvm_hv:kvm_guest_exit" and "kvm_hv:kvm_guest_enter".Note : This patch has a dependency on the patch "kvm/powerpc: Export kvm exit reasons" which exports the KVM exit reasons through the uapi.
Here is a sample o/p:
# pgrep qemu 19378 605152 Guests are running on the host.
# perf kvm stat record -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 4.153 MB perf.data.guest (39624 samples) ]# perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs:VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% ) HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% ) SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% ) RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% ) EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% )Total Samples:14182, Total events handled time:49264158.30us.
Signed-off-by Srikar Dronamraju <[email protected]>Signed-off-by Hemant Kumar <[email protected]>---
Patch has a dependency on : https://patchwork.ozlabs.org/patch/469839/
which exports the exit reasons to perf through uapi.Changes:
- Original series split into two patchsets now : perf and powerpc side changes.arch/powerpc/include/uapi/asm/kvm_perf.h | 15 +++++++++++++++ tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/Build | 1 + tools/perf/arch/powerpc/util/kvm-stat.c | 33 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 arch/powerpc/include/uapi/asm/kvm_perf.h create mode 100644 tools/perf/arch/powerpc/util/kvm-stat.carch/powerpc/include/uapi/asm/kvm_perf.h new file +5
-0@@ -0,0 +1,15 @@ +#ifndef _ASM_POWERPC_KVM_PERF_H +#define _ASM_POWERPC_KVM_PERF_H + +#include <asm/trace_book3s.h> +#include <asm/kvm.h>
arch/powerpc/include/uapi/asm/kvm_perf.h line 15
Quoted 10 lines
arch/powerpc/include/uapi/asm/kvm_perf.h new file +10
-0+ +#define DECODE_STR_LEN 20 + +#define VCPU_ID "vcpu_id" + +#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter" +#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit" +#define KVM_EXIT_REASON "trap" + +#endif /* _ASM_POWERPC_KVM_PERF_H */
Please make sure that anything book3s-specific is named that way.
And shouldn't this be part of the arch/powerpc-side patchset?
tools/perf/arch/powerpc/Makefile line 4
Quoted 9 lines
tools/perf/arch/powerpc/Makefile +1
-0@@ -1,3 +1,4 @@ ifndef NO_DWARF PERF_HAVE_DWARF_REGS := 1 endif +HAVE_KVM_STAT_SUPPORT := 1
Does this stuff fail gracefully if used on a PPC target that doesn't support this?
-Scott
Hi Scott,
Quoted 81 lines · Scott Wood
Quoted 80 lines · Hemant Kumar
From: Srikar Dronamraju <[email protected]>
perf kvm can be used to analyze guest exit reasons. This support already exists in x86. Hence, porting it to powerpc.
- To trace KVM events :
perf kvm stat record
If many guests are running, we can track for a specific guest by using --pid as in : perf kvm stat record --pid <pid>- To see the results :
perf kvm stat reportThe result shows the number of exits (from the guest context to host/hypervisor context) grouped by their respective exit reasons with their frequency.
This patch makes use of the guest exit reasons available in "
trace_book3s.h". It records on two already available tracepoints :
"kvm_hv:kvm_guest_exit" and "kvm_hv:kvm_guest_enter".Note : This patch has a dependency on the patch "kvm/powerpc: Export kvm exit reasons" which exports the KVM exit reasons through the uapi.
Here is a sample o/p:
# pgrep qemu 19378 605152 Guests are running on the host.
# perf kvm stat record -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 4.153 MB perf.data.guest (39624 samples) ]# perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs:VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% ) HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% ) SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% ) RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% ) EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% )Total Samples:14182, Total events handled time:49264158.30us.
Signed-off-by Srikar Dronamraju <[email protected]>Signed-off-by Hemant Kumar <[email protected]>---
Patch has a dependency on : https://patchwork.ozlabs.org/patch/469839/
which exports the exit reasons to perf through uapi.Changes:
- Original series split into two patchsets now : perf and powerpc side changes.arch/powerpc/include/uapi/asm/kvm_perf.h | 15 +++++++++++++++ tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/Build | 1 + tools/perf/arch/powerpc/util/kvm-stat.c | 33 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+)create mode 100644
arch/powerpc/include/uapi/asm/kvm_perf.hcreate mode 100644tools/perf/arch/powerpc/util/kvm-stat.carch/powerpc/include/uapi/asm/kvm_perf.h new file +8
-0@@ -0,0 +1,15 @@ +#ifndef _ASM_POWERPC_KVM_PERF_H +#define _ASM_POWERPC_KVM_PERF_H + +#include <asm/trace_book3s.h> +#include <asm/kvm.h> + +#define DECODE_STR_LEN 20 +
Quoted 8 lines
arch/powerpc/include/uapi/asm/kvm_perf.h line 15
Quoted 7 lines
arch/powerpc/include/uapi/asm/kvm_perf.h new file +7
-0+#define VCPU_ID "vcpu_id" + +#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter" +#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit" +#define KVM_EXIT_REASON "trap" + +#endif /* _ASM_POWERPC_KVM_PERF_H */ Please make sure that anything book3s-specific is named that way.
Are you suggesting to name it to something like _ASM_POWERPC_BOOK3S_PERF_H ?
Quoted 1 line
And shouldn't this be part of the
arch/powerpc-sidepatchset?
It should. Thanks, will move this to arch/powerpc side patchset.
Quoted 11 lines
tools/perf/arch/powerpc/Makefile line 4
Quoted 9 lines
tools/perf/arch/powerpc/Makefile +1
-0@@ -1,3 +1,4 @@ ifndef NO_DWARF PERF_HAVE_DWARF_REGS := 1 endif +HAVE_KVM_STAT_SUPPORT := 1Does this stuff fail gracefully if used on a PPC target that doesn't support this?
Yes, it does.
Quoted 7 lines
-Scott
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Signature · 2 lines
Thanks, Hemant Kumar
Quoted 27 lines · Hemant Kumar
Hi Scott,
Quoted 15 lines · Scott Wood
Quoted 14 lines · Hemant Kumar
arch/powerpc/include/uapi/asm/kvm_perf.h new file +8
-0@@ -0,0 +1,15 @@ +#ifndef _ASM_POWERPC_KVM_PERF_H +#define _ASM_POWERPC_KVM_PERF_H + +#include <asm/trace_book3s.h> +#include <asm/kvm.h> + +#define DECODE_STR_LEN 20 +Quoted 8 lines
arch/powerpc/include/uapi/asm/kvm_perf.h line 15
Quoted 7 lines
arch/powerpc/include/uapi/asm/kvm_perf.h new file +7
-0+#define VCPU_ID "vcpu_id" + +#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter" +#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit" +#define KVM_EXIT_REASON "trap" + +#endif /* _ASM_POWERPC_KVM_PERF_H */ Please make sure that anything book3s-specific is named that way.
Quoted 1 line
Are you suggesting to name it to something like
_ASM_POWERPC_BOOK3S_PERF_H?
My concern is seeing a generically named "kvm_perf.h" include a file called "trace_book3s.h" which defines "kvm_trace_symbol_hcall" with presumably book3s-specific content, as well as wondering how much of the rest of the file would be applicable if booke PPC were to implement perf kvm.
I don't know enough about perf kvm to answer that question, but I've seen enough cases of book3s or pseries specific code that was apparently written with the belief that no other ppc64 implementations exist, or that no other ppc implementations would want to implement a certain feature, to be suspicous. Usually such cases can be dealt with after the fact (albeit not as easily as if things were organized/namespaced properly from the beginning), but this is uapi...
-Scott
Hi Scott,
Quoted 42 lines · Scott Wood
Quoted 26 lines · Hemant Kumar
Hi Scott,
Quoted 15 lines · Scott Wood
Quoted 14 lines · Hemant Kumar
arch/powerpc/include/uapi/asm/kvm_perf.h new file +8
-0@@ -0,0 +1,15 @@ +#ifndef _ASM_POWERPC_KVM_PERF_H +#define _ASM_POWERPC_KVM_PERF_H + +#include <asm/trace_book3s.h> +#include <asm/kvm.h> + +#define DECODE_STR_LEN 20 +Quoted 8 lines
arch/powerpc/include/uapi/asm/kvm_perf.h line 15
Quoted 7 lines
arch/powerpc/include/uapi/asm/kvm_perf.h new file +7
-0+#define VCPU_ID "vcpu_id" + +#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter" +#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit" +#define KVM_EXIT_REASON "trap" + +#endif /* _ASM_POWERPC_KVM_PERF_H */ Please make sure that anything book3s-specific is named that way.
Quoted 1 line
Are you suggesting to name it to something like
_ASM_POWERPC_BOOK3S_PERF_H?My concern is seeing a generically named "
kvm_perf.h" include a file called "trace_book3s.h" which defines "kvm_trace_symbol_hcall" with presumably book3s-specific content, as well as wondering how much of the rest of the file would be applicable if booke PPC were to implement perf kvm.I don't know enough about perf kvm to answer that question, but I've seen enough cases of book3s or pseries specific code that was apparently written with the belief that no other ppc64 implementations exist, or that no other ppc implementations would want to implement a certain feature, to be suspicous. Usually such cases can be dealt with after the fact (albeit not as easily as if things were organized/namespaced properly from the beginning), but this is uapi...
Quoted 8 lines
-Scott
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Tried to address your comments in v4 :
http://www.mail-archive.com/[email protected]/msg89490.html
and
http://www.mail-archive.com/[email protected]/msg89485.html
Signature · 2 lines
Thanks, Hemant Kumar