[PATCH 3/3] KVM: perf: kvm events analysis tool
Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: - trace kvm events: perf kvm-events record, or, if other tracepoints are also interesting, we can append the events like this: perf kvm-events record -e timer:* - show the result: perf kvm-events report The output example is following: #./perf kvm-events report --event mmio --vcpu 3 Analyze events for VCPU 3: MMIO AccessSamples Samples% Time% Avg time 0xfee00380:W 2968861.16%64.52% 3.37us ( +- 0.86% ) 0xfee00300:W 628512.95%20.06% 4.95us ( +- 2.34% ) 0xfee00300:R 628512.95% 8.08% 1.99us ( +- 0.59% ) 0xfee00310:W 628512.95% 7.34% 1.81us ( +- 6.76% ) Total Samples:48543, Total events handled time:155156.31us. Signed-off-by: Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com --- tools/perf/MANIFEST |3 + tools/perf/Makefile |1 + tools/perf/builtin-kvm-events.c | 855 +++ tools/perf/builtin.h|1 + tools/perf/command-list.txt |1 + tools/perf/perf.c |1 + tools/perf/util/header.c| 55 +++- tools/perf/util/header.h|1 + tools/perf/util/thread.h|2 + 9 files changed, 919 insertions(+), 1 deletions(-) create mode 100644 tools/perf/builtin-kvm-events.c diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index 5476bc0..e01ec73 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST @@ -13,3 +13,6 @@ arch/*/lib/memset*.S include/linux/poison.h include/linux/magic.h include/linux/hw_breakpoint.h +arch/x86/include/asm/svm.h +arch/x86/include/asm/vmx.h +arch/x86/include/asm/kvm_host.h diff --git a/tools/perf/Makefile b/tools/perf/Makefile index fa04340..d8d7f67 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -400,6 +400,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-probe.o BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o BUILTIN_OBJS += $(OUTPUT)builtin-lock.o BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o +BUILTIN_OBJS += $(OUTPUT)builtin-kvm-events.o BUILTIN_OBJS += $(OUTPUT)builtin-test.o BUILTIN_OBJS += $(OUTPUT)builtin-inject.o diff --git a/tools/perf/builtin-kvm-events.c b/tools/perf/builtin-kvm-events.c new file mode 100644 index 000..6857047 --- /dev/null +++ b/tools/perf/builtin-kvm-events.c @@ -0,0 +1,855 @@ +#include builtin.h +#include perf.h +#include util/util.h +#include util/cache.h +#include util/symbol.h +#include util/thread.h +#include util/header.h +#include util/parse-options.h +#include util/trace-event.h +#include util/debug.h +#include util/debugfs.h +#include util/session.h +#include util/tool.h + +#include math.h + +#include ../../arch/x86/include/asm/svm.h +#include ../../arch/x86/include/asm/vmx.h +#include ../../arch/x86/include/asm/kvm_host.h + +struct event_key { + #define INVALID_KEY (~0ULL) + u64 key; + int info; +}; + +struct kvm_events_ops { + bool (*is_begin_event)(struct event *event, void *data, + struct event_key *key); + bool (*is_end_event)(struct event *event, void *data, +struct event_key *key); + void (*decode_key)(struct event_key *key, char decode[20]); + const char *name; +}; + +static void exit_event_get_key(struct event *event, void *data, + struct event_key *key) +{ + key-info = 0; + key-key = raw_field_value(event, exit_reason, data); +} + +static bool kvm_exit_event(struct event *event) +{ + return !strcmp(event-name, kvm_exit); +} + +static bool exit_event_begin(struct event *event, void *data, +struct event_key *key) +{ + if (kvm_exit_event(event)) { + exit_event_get_key(event, data, key); + return true; + } + + return false; +} + +static bool kvm_entry_event(struct event *event) +{ + return !strcmp(event-name, kvm_entry); +} + +static bool exit_event_end(struct event *event, void *data __unused, + struct event_key *key __unused) +{ + return kvm_entry_event(event); +} + +struct exit_reasons_table { + unsigned long exit_code; + const char *reason; +}; + +struct exit_reasons_table vmx_exit_reasons[] = { + VMX_EXIT_REASONS +}; + +struct exit_reasons_table svm_exit_reasons[] = { + SVM_EXIT_REASONS +}; + +static int cpu_isa; + +static const char *get_exit_reason(u64 exit_code) +{ + int table_size = ARRAY_SIZE(svm_exit_reasons); + struct exit_reasons_table *table = svm_exit_reasons; + + if (cpu_isa == 1) { + table = vmx_exit_reasons; + table_size = ARRAY_SIZE(vmx_exit_reasons); + } + + while (table_size--) { + if (table-exit_code == exit_code) + return table-reason; + table++; + } + +
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/21/2012 07:47 AM, David Ahern wrote: diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 70c2c13..c48ebf3 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -16,6 +16,8 @@ struct thread { boolcomm_set; char*comm; intcomm_len; + +void*private; Arnaldo: Are you ok with this design for now? I can fix this command to whatever API we agree to when it gets committed. Hi Arnaldo, What do you think of it? :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
Finally got back to this. Overall nicely written command. Few comments and one for Arnaldo at the bottom. On 2/9/12 2:09 AM, Xiao Guangrong wrote: Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: - trace kvm events: perf kvm-events record, or, if other tracepoints are also interesting, we can append the events like this: perf kvm-events record -e timer:* - show the result: perf kvm-events report It would be nice to have example reports in this commit message. Signed-off-by: Xiao Guangrongxiaoguangr...@linux.vnet.ibm.com --- tools/perf/Documentation/perf-kvm-events.txt | 52 ++ tools/perf/Makefile |1 + tools/perf/builtin-kvm-events.c | 851 ++ tools/perf/builtin.h |1 + tools/perf/command-list.txt |1 + tools/perf/perf.c|1 + tools/perf/util/header.c | 54 ++- tools/perf/util/header.h |1 + tools/perf/util/thread.h |2 + 9 files changed, 963 insertions(+), 1 deletions(-) create mode 100644 tools/perf/Documentation/perf-kvm-events.txt create mode 100644 tools/perf/builtin-kvm-events.c diff --git a/tools/perf/Documentation/perf-kvm-events.txt b/tools/perf/Documentation/perf-kvm-events.txt new file mode 100644 index 000..ed36550 --- /dev/null +++ b/tools/perf/Documentation/perf-kvm-events.txt @@ -0,0 +1,52 @@ +perf-kvm-events(1) + + +NAME + +perf-kvm-events - Analyze kvm events + +SYNOPSIS + +[verse] +'perf kvm-events' {record|report} + +DESCRIPTION +--- +You can analyze some crucial kvm events and statistics with this +'perf kvm-events' command. Currently, vmexit, mmio and ioport events +are supported. First sentence should be written in the 3rd person. eg., This command generates a statistical analysis of KVM events. + + 'perf kvm-events recordcommand' records kvm events(vmexit, + mmio and ioport) and the events between start and endcommand. + And this command produces the file perf.data which contains + tracing results of kvm events. + + 'perf kvm-events report' reports statistical data which includes + events handled time, samples, and so on. + +COMMON OPTIONS +-- + +-i:: +--input=file:: +Input file name. (default: perf.data unless stdin is a fifo) + +-D:: +--dump-raw-trace:: +Dump raw trace in ASCII. + +REPORT OPTIONS +-- +--vcpu=value:: + analyze events which occures on this vcpu + +--events=value:: + events to be analyzed. Possible values: vmexit, mmio, ioport. Add a comment stating which event type is the default. +-k:: +--key=value:: +Sorting key. Possible values: sample(default, sort by samples number), +time(sort by average time). Space before both of the '('. + +SEE ALSO + +linkperf:perf[1] diff --git a/tools/perf/Makefile b/tools/perf/Makefile index ac86d67..ee43451 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -382,6 +382,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-probe.o BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o BUILTIN_OBJS += $(OUTPUT)builtin-lock.o BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o +BUILTIN_OBJS += $(OUTPUT)builtin-kvm-events.o BUILTIN_OBJS += $(OUTPUT)builtin-test.o BUILTIN_OBJS += $(OUTPUT)builtin-inject.o diff --git a/tools/perf/builtin-kvm-events.c b/tools/perf/builtin-kvm-events.c new file mode 100644 index 000..9903d2b --- /dev/null +++ b/tools/perf/builtin-kvm-events.c @@ -0,0 +1,851 @@ +#include builtin.h +#include perf.h +#include util/util.h +#include util/cache.h +#include util/symbol.h +#include util/thread.h +#include util/header.h +#include util/parse-options.h +#include util/trace-event.h +#include util/debug.h +#include util/debugfs.h +#include util/session.h +#include util/tool.h + +#includemath.h + +#includelinux/kvm.h + +#include ../../arch/x86/include/asm/svm.h +#include ../../arch/x86/include/asm/vmx.h +#include ../../arch/x86/include/asm/kvm_host.h + +struct event_key { + #define INVALID_KEY (~0ULL) + u64 key; + int info; +}; + +struct kvm_events_ops { + bool (*is_begin_event)(struct event *event, void *data, + struct event_key *key); + bool (*is_end_event)(struct event *event, void *data, +struct event_key *key); + void (*decode_key)(struct event_key *key, char decode[20]); + const char *name; +}; + +static int cpu_isa; + +static void exit_event_get_key(struct event *event, void *data, + struct event_key *key) +{ + key-info = cpu_isa; + key-key = raw_field_value(event, exit_reason, data); +} + +static bool kvm_exit_event(struct event *event) +{ + return !strcmp(event-name, kvm_exit); +} + +static bool exit_event_begin(struct event *event, void *data, +
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/21/2012 07:47 AM, David Ahern wrote: - show the result: perf kvm-events report It would be nice to have example reports in this commit message. Okay. +DESCRIPTION +--- +You can analyze some crucial kvm events and statistics with this +'perf kvm-events' command. Currently, vmexit, mmio and ioport events +are supported. First sentence should be written in the 3rd person. eg., This command generates a statistical analysis of KVM events. Okay. +--events=value:: +events to be analyzed. Possible values: vmexit, mmio, ioport. Add a comment stating which event type is the default. OK, will fix. +-k:: +--key=value:: +Sorting key. Possible values: sample(default, sort by samples number), +time(sort by average time). Space before both of the '('. Yes, will fix. +static const char *get_exit_reason(u64 exit_code, int isa) +{ +int table_size = ARRAY_SIZE(svm_exit_reasons); +struct exit_reasons_table *table = svm_exit_reasons; + +if (isa == 1) { +table = vmx_exit_reasons; +table_size = ARRAY_SIZE(vmx_exit_reasons); +} Why not use globals that are set once in read_events() after looking up cpu_isa? Then you don't have to state a preference on default init here -- AMD or Intel. And the isa argument will not be needed here. I agree. +#define DEFAULT_VCPU_NUM 32 Why 32 for the default number of vcpus in a guest? Seems like a lot for the typical VM. Versus something like 4 or 8. Hmm, since 32 is the default vcpu number in the old kernel (IIRC), but your suggestion sounds good. +/* Both begin and end events did not get the key. */ +if (!event key-key == INVALID_KEY) +return; + Should not be able to get here with event unset, so the next 2 lines should not be needed. ie., you only want to process events where the begin event was seen in which case event is defined. In some case, the 'begin event' just records the start timestamp, the actually event is recognised in the 'end event'. Take mmio-read for example, in the old kernel, we use kvm-exit as the 'begin event' and kvm_mmio(KVM_TRACE_MMIO_READ...) is the 'end event'. +perf kvm events report [options], missing '-' between kvm and events ... +static const char * const kvm_events_usage[] = { +perf kvm events [options] {record|report}, missing '-' between kvm and events Sorry for my careless, these will be fixed in the next version. Thanks very much for your review, David! :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 2/20/12 8:52 PM, Xiao Guangrong wrote: +/* Both begin and end events did not get the key. */ +if (!event key-key == INVALID_KEY) +return; + Should not be able to get here with event unset, so the next 2 lines should not be needed. ie., you only want to process events where the begin event was seen in which case event is defined. In some case, the 'begin event' just records the start timestamp, the actually event is recognised in the 'end event'. Take mmio-read for example, in the old kernel, we use kvm-exit as the 'begin event' and kvm_mmio(KVM_TRACE_MMIO_READ...) is the 'end event'. ah, ok. Please add a comment about this path. David -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
Em Wed, Feb 15, 2012 at 10:05:08PM -0700, David Ahern escreveu: On 2/15/12 9:59 PM, Xiao Guangrong wrote: Okay, i will post the next version after collecting your new comments! Thanks for your time, David! :) I had more comments, but got sidetracked and forgot to come back to this. I still haven't looked at the code yet, but some comments from testing: 1. The error message: Warning: Error: expected type 5 but read 4 Warning: Error: expected type 5 but read 0 Warning: unknown op '}' is fixed by this patch which has not yet made its way into perf: https://lkml.org/lkml/2011/9/4/41 The most recent request: https://lkml.org/lkml/2012/2/8/479 Arnaldo: the patch still applies cleanly (but with an offset of -2 lines). I'll merge this one now, recall Steven asked me to, thanks for the reminder, - Arnaldo -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/13/2012 11:52 PM, David Ahern wrote: The first patch is only needed for code compilation, after kvm-events is compiled, you can analyse any kernels. :) understood. Now that I recall perf's way of handling out of tree builds, a couple of comments: 1. you need to add the following to tools/perf/MANIFEST arch/x86/include/asm/svm.h arch/x86/include/asm/vmx.h arch/x86/include/asm/kvm_host.h Right. 2.scripts/checkpatch.pl is an unhappy camper. It seems checkpath always complains about TRACE_EVENT and many more than-80-characters lines in perf tools. I'll take a look at the code and try out the command when I get some time. Okay, i will post the next version after collecting your new comments! Thanks for your time, David! :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 2/15/12 9:59 PM, Xiao Guangrong wrote: Okay, i will post the next version after collecting your new comments! Thanks for your time, David! :) I had more comments, but got sidetracked and forgot to come back to this. I still haven't looked at the code yet, but some comments from testing: 1. The error message: Warning: Error: expected type 5 but read 4 Warning: Error: expected type 5 but read 0 Warning: unknown op '}' is fixed by this patch which has not yet made its way into perf: https://lkml.org/lkml/2011/9/4/41 The most recent request: https://lkml.org/lkml/2012/2/8/479 Arnaldo: the patch still applies cleanly (but with an offset of -2 lines). 2. negatve testing: perf kvm-events record -e kvm:* -p 2603 -- sleep 10 Warning: Error: expected type 4 but read 7 Warning: Error: expected type 5 but read 0 Warning: failed to read event print fmt for kvm_apic Warning: Error: expected type 4 but read 7 Warning: Error: expected type 5 but read 0 Warning: failed to read event print fmt for kvm_inj_exception Fatal: bad op token { If other kvm events are specified in the record line they appear to be silently ignored in the report in which case why allow the -e option to record? 3. What is happening for multiple VMs? a. perf kvm-events report data is collected for all VMs. What is displayed in the report? An average for all VMs? b. perf kvm-events report --vcpu 1 Does this given an average of all vcpu 1's? Perhaps a -p option for the report to pull out events related to a single VM. Really this could be a generic option (to perf-report and perf-script as well) to only show/analyze events for the specified pid. ie., data is recorded for all VMs (or system wide for the regular perf-record) and you want to only consider events for a specific pid. e.g., in process_sample_event() skip event if event-ip.pid != report_pid (works for perf code because PERF_SAMPLE_TID attribute is always set). David -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/16/2012 01:05 PM, David Ahern wrote: On 2/15/12 9:59 PM, Xiao Guangrong wrote: Okay, i will post the next version after collecting your new comments! Thanks for your time, David! :) I had more comments, but got sidetracked and forgot to come back to this. I still haven't looked at the code yet, but some comments from testing: 1. The error message: Warning: Error: expected type 5 but read 4 Warning: Error: expected type 5 but read 0 Warning: unknown op '}' is fixed by this patch which has not yet made its way into perf: https://lkml.org/lkml/2011/9/4/41 The most recent request: https://lkml.org/lkml/2012/2/8/479 Arnaldo: the patch still applies cleanly (but with an offset of -2 lines). Great, it is a good fix. But, it does not hurt the development of kvm-events. 2. negatve testing: perf kvm-events record -e kvm:* -p 2603 -- sleep 10 Warning: Error: expected type 4 but read 7 Warning: Error: expected type 5 but read 0 Warning: failed to read event print fmt for kvm_apic Warning: Error: expected type 4 but read 7 Warning: Error: expected type 5 but read 0 Warning: failed to read event print fmt for kvm_inj_exception Fatal: bad op token { If other kvm events are specified in the record line they appear to be silently ignored in the report in which case why allow the -e option to record? Yes, kvm-events doese not analyse these events specified by -e option since these events are not needed by vmexit/ioport/mmio analysis. And after kvm-evnets record, you can see these events by perf script 3. What is happening for multiple VMs? a. perf kvm-events report data is collected for all VMs. What is displayed in the report? An average for all VMs? Yes b. perf kvm-events report --vcpu 1 Does this given an average of all vcpu 1's? Yes Perhaps a -p option for the report to pull out events related to a single VM. Really this could be a generic option (to perf-report and perf-script as well) to only show/analyze events for the specified pid. ie., data is recorded for all VMs (or system wide for the regular perf-record) and you want to only consider events for a specific pid. e.g., in process_sample_event() skip event if event-ip.pid != report_pid (works for perf code because PERF_SAMPLE_TID attribute is always set). Analysis for per VMs is good idea, but please allow me put it into my TODO list. :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/13/2012 01:32 PM, David Ahern wrote: [sorry for the top post - you would think Android would have a better mail client] If the first patch is needed then kvm-events will not work with older, unpatched kernels. That's a big limitation from a perf perpective. The first patch is only needed for code compilation, after kvm-events is compiled, you can analyse any kernels. :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/13/2012 03:06 AM, Xiao Guangrong wrote: On 02/13/2012 01:32 PM, David Ahern wrote: [sorry for the top post - you would think Android would have a better mail client] If the first patch is needed then kvm-events will not work with older, unpatched kernels. That's a big limitation from a perf perpective. The first patch is only needed for code compilation, after kvm-events is compiled, you can analyse any kernels. :) understood. Now that I recall perf's way of handling out of tree builds, a couple of comments: 1. you need to add the following to tools/perf/MANIFEST arch/x86/include/asm/svm.h arch/x86/include/asm/vmx.h arch/x86/include/asm/kvm_host.h 2.scripts/checkpatch.pl is an unhappy camper. I'll take a look at the code and try out the command when I get some time. David -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
Compile fails on Fedora 16, x86_64 with latest tip-perf-core branch: In file included from builtin-kvm-events.c:19:0: ../../arch/x86/include/asm/svm.h:133:1: error: packed attribute is unnecessary for ‘vmcb_seg’ [-Werror=packed] ../../arch/x86/include/asm/svm.h:178:1: error: packed attribute is unnecessary for ‘vmcb_save_area’ [-Werror=packed] ../../arch/x86/include/asm/svm.h:183:1: error: packed attribute is unnecessary for ‘vmcb’ [-Werror=packed] In file included from builtin-kvm-events.c:20:0: ../../arch/x86/include/asm/vmx.h:334:0: error: REG_R8 redefined [-Werror] /usr/include/sys/ucontext.h:46:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:335:0: error: REG_R9 redefined [-Werror] /usr/include/sys/ucontext.h:48:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:336:0: error: REG_R10 redefined [-Werror] /usr/include/sys/ucontext.h:50:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:337:0: error: REG_R11 redefined [-Werror] /usr/include/sys/ucontext.h:52:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:338:0: error: REG_R12 redefined [-Werror] /usr/include/sys/ucontext.h:54:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:339:0: error: REG_R13 redefined [-Werror] /usr/include/sys/ucontext.h:56:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:340:0: error: REG_R14 redefined [-Werror] /usr/include/sys/ucontext.h:58:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:341:0: error: REG_R15 redefined [-Werror] /usr/include/sys/ucontext.h:60:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:443:13: error: expected declaration specifiers or ‘...’ before numeric constant In file included from builtin-kvm-events.c:21:0: ../../arch/x86/include/asm/kvm_host.h:15:22: fatal error: linux/mm.h: No such file or directory cc1: all warnings being treated as errors On 02/09/2012 02:09 AM, Xiao Guangrong wrote: Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: - trace kvm events: perf kvm-events record, or, if other tracepoints are also interesting, we can append the events like this: perf kvm-events record -e timer:* - show the result: perf kvm-events report Signed-off-by: Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com --- tools/perf/Documentation/perf-kvm-events.txt | 52 ++ tools/perf/Makefile |1 + tools/perf/builtin-kvm-events.c | 851 ++ tools/perf/builtin.h |1 + tools/perf/command-list.txt |1 + tools/perf/perf.c|1 + tools/perf/util/header.c | 54 ++- tools/perf/util/header.h |1 + tools/perf/util/thread.h |2 + 9 files changed, 963 insertions(+), 1 deletions(-) create mode 100644 tools/perf/Documentation/perf-kvm-events.txt create mode 100644 tools/perf/builtin-kvm-events.c diff --git a/tools/perf/Documentation/perf-kvm-events.txt b/tools/perf/Documentation/perf-kvm-events.txt new file mode 100644 index 000..ed36550 --- /dev/null +++ b/tools/perf/Documentation/perf-kvm-events.txt @@ -0,0 +1,52 @@ +perf-kvm-events(1) + + +NAME + +perf-kvm-events - Analyze kvm events + +SYNOPSIS + +[verse] +'perf kvm-events' {record|report} + +DESCRIPTION +--- +You can analyze some crucial kvm events and statistics with this +'perf kvm-events' command. Currently, vmexit, mmio and ioport events +are supported. + + 'perf kvm-events record command' records kvm events(vmexit, + mmio and ioport) and the events between start and end command. + And this command produces the file perf.data which contains + tracing results of kvm events. + + 'perf kvm-events report' reports statistical data which includes + events handled time, samples, and so on. + +COMMON OPTIONS +-- + +-i:: +--input=file:: +Input file name. (default: perf.data unless stdin is a fifo) + +-D:: +--dump-raw-trace:: +Dump raw trace in ASCII. + +REPORT OPTIONS +-- +--vcpu=value:: + analyze events which occures on this vcpu + +--events=value:: + events to be analyzed. Possible values: vmexit, mmio, ioport. +-k:: +--key=value:: +Sorting key. Possible values: sample(default, sort by samples number), +time(sort by average time). + +SEE ALSO + +linkperf:perf[1] diff --git a/tools/perf/Makefile b/tools/perf/Makefile index ac86d67..ee43451 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -382,6 +382,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-probe.o BUILTIN_OBJS +=
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 02/13/2012 11:04 AM, David Ahern wrote: Compile fails on Fedora 16, x86_64 with latest tip-perf-core branch: In file included from builtin-kvm-events.c:19:0: ../../arch/x86/include/asm/svm.h:133:1: error: packed attribute is unnecessary for ‘vmcb_seg’ [-Werror=packed] ../../arch/x86/include/asm/svm.h:178:1: error: packed attribute is unnecessary for ‘vmcb_save_area’ [-Werror=packed] ../../arch/x86/include/asm/svm.h:183:1: error: packed attribute is unnecessary for ‘vmcb’ [-Werror=packed] In file included from builtin-kvm-events.c:20:0: ../../arch/x86/include/asm/vmx.h:334:0: error: REG_R8 redefined [-Werror] /usr/include/sys/ucontext.h:46:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:335:0: error: REG_R9 redefined [-Werror] /usr/include/sys/ucontext.h:48:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:336:0: error: REG_R10 redefined [-Werror] /usr/include/sys/ucontext.h:50:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:337:0: error: REG_R11 redefined [-Werror] /usr/include/sys/ucontext.h:52:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:338:0: error: REG_R12 redefined [-Werror] /usr/include/sys/ucontext.h:54:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:339:0: error: REG_R13 redefined [-Werror] /usr/include/sys/ucontext.h:56:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:340:0: error: REG_R14 redefined [-Werror] /usr/include/sys/ucontext.h:58:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:341:0: error: REG_R15 redefined [-Werror] /usr/include/sys/ucontext.h:60:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:443:13: error: expected declaration specifiers or ‘...’ before numeric constant In file included from builtin-kvm-events.c:21:0: ../../arch/x86/include/asm/kvm_host.h:15:22: fatal error: linux/mm.h: No such file or directory cc1: all warnings being treated as errors The first patch(patch 1/3) should be applied! Thank you, David! :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
[sorry for the top post - you would think Android would have a better mail client] If the first patch is needed then kvm-events will not work with older, unpatched kernels. That's a big limitation from a perf perpective. David Sent from my ASUS Eee Pad Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com wrote: On 02/13/2012 11:04 AM, David Ahern wrote: Compile fails on Fedora 16, x86_64 with latest tip-perf-core branch: In file included from builtin-kvm-events.c:19:0: ../../arch/x86/include/asm/svm.h:133:1: error: packed attribute is unnecessary for ‘vmcb_seg’ [-Werror=packed] ../../arch/x86/include/asm/svm.h:178:1: error: packed attribute is unnecessary for ‘vmcb_save_area’ [-Werror=packed] ../../arch/x86/include/asm/svm.h:183:1: error: packed attribute is unnecessary for ‘vmcb’ [-Werror=packed] In file included from builtin-kvm-events.c:20:0: ../../arch/x86/include/asm/vmx.h:334:0: error: REG_R8 redefined [-Werror] /usr/include/sys/ucontext.h:46:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:335:0: error: REG_R9 redefined [-Werror] /usr/include/sys/ucontext.h:48:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:336:0: error: REG_R10 redefined [-Werror] /usr/include/sys/ucontext.h:50:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:337:0: error: REG_R11 redefined [-Werror] /usr/include/sys/ucontext.h:52:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:338:0: error: REG_R12 redefined [-Werror] /usr/include/sys/ucontext.h:54:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:339:0: error: REG_R13 redefined [-Werror] /usr/include/sys/ucontext.h:56:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:340:0: error: REG_R14 redefined [-Werror] /usr/include/sys/ucontext.h:58:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:341:0: error: REG_R15 redefined [-Werror] /usr/include/sys/ucontext.h:60:0: note: this is the location of the previous definition ../../arch/x86/include/asm/vmx.h:443:13: error: expected declaration specifiers or ‘...’ before numeric constant In file included from builtin-kvm-events.c:21:0: ../../arch/x86/include/asm/kvm_host.h:15:22: fatal error: linux/mm.h: No such file or directory cc1: all warnings being treated as errors The first patch(patch 1/3) should be applied! Thank you, David! :) N�r��yb�X��ǧv�^�){.n�+h����ܨ}���Ơz�j:+v���zZ+��+zf���h���~i���z��w���?��)ߢf
[PATCH 3/3] KVM: perf: kvm events analysis tool
Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: - trace kvm events: perf kvm-events record, or, if other tracepoints are also interesting, we can append the events like this: perf kvm-events record -e timer:* - show the result: perf kvm-events report Signed-off-by: Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com --- tools/perf/Documentation/perf-kvm-events.txt | 52 ++ tools/perf/Makefile |1 + tools/perf/builtin-kvm-events.c | 851 ++ tools/perf/builtin.h |1 + tools/perf/command-list.txt |1 + tools/perf/perf.c|1 + tools/perf/util/header.c | 54 ++- tools/perf/util/header.h |1 + tools/perf/util/thread.h |2 + 9 files changed, 963 insertions(+), 1 deletions(-) create mode 100644 tools/perf/Documentation/perf-kvm-events.txt create mode 100644 tools/perf/builtin-kvm-events.c diff --git a/tools/perf/Documentation/perf-kvm-events.txt b/tools/perf/Documentation/perf-kvm-events.txt new file mode 100644 index 000..ed36550 --- /dev/null +++ b/tools/perf/Documentation/perf-kvm-events.txt @@ -0,0 +1,52 @@ +perf-kvm-events(1) + + +NAME + +perf-kvm-events - Analyze kvm events + +SYNOPSIS + +[verse] +'perf kvm-events' {record|report} + +DESCRIPTION +--- +You can analyze some crucial kvm events and statistics with this +'perf kvm-events' command. Currently, vmexit, mmio and ioport events +are supported. + + 'perf kvm-events record command' records kvm events(vmexit, + mmio and ioport) and the events between start and end command. + And this command produces the file perf.data which contains + tracing results of kvm events. + + 'perf kvm-events report' reports statistical data which includes + events handled time, samples, and so on. + +COMMON OPTIONS +-- + +-i:: +--input=file:: +Input file name. (default: perf.data unless stdin is a fifo) + +-D:: +--dump-raw-trace:: +Dump raw trace in ASCII. + +REPORT OPTIONS +-- +--vcpu=value:: + analyze events which occures on this vcpu + +--events=value:: + events to be analyzed. Possible values: vmexit, mmio, ioport. +-k:: +--key=value:: +Sorting key. Possible values: sample(default, sort by samples number), +time(sort by average time). + +SEE ALSO + +linkperf:perf[1] diff --git a/tools/perf/Makefile b/tools/perf/Makefile index ac86d67..ee43451 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -382,6 +382,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-probe.o BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o BUILTIN_OBJS += $(OUTPUT)builtin-lock.o BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o +BUILTIN_OBJS += $(OUTPUT)builtin-kvm-events.o BUILTIN_OBJS += $(OUTPUT)builtin-test.o BUILTIN_OBJS += $(OUTPUT)builtin-inject.o diff --git a/tools/perf/builtin-kvm-events.c b/tools/perf/builtin-kvm-events.c new file mode 100644 index 000..9903d2b --- /dev/null +++ b/tools/perf/builtin-kvm-events.c @@ -0,0 +1,851 @@ +#include builtin.h +#include perf.h +#include util/util.h +#include util/cache.h +#include util/symbol.h +#include util/thread.h +#include util/header.h +#include util/parse-options.h +#include util/trace-event.h +#include util/debug.h +#include util/debugfs.h +#include util/session.h +#include util/tool.h + +#include math.h + +#include linux/kvm.h + +#include ../../arch/x86/include/asm/svm.h +#include ../../arch/x86/include/asm/vmx.h +#include ../../arch/x86/include/asm/kvm_host.h + +struct event_key { + #define INVALID_KEY (~0ULL) + u64 key; + int info; +}; + +struct kvm_events_ops { + bool (*is_begin_event)(struct event *event, void *data, + struct event_key *key); + bool (*is_end_event)(struct event *event, void *data, +struct event_key *key); + void (*decode_key)(struct event_key *key, char decode[20]); + const char *name; +}; + +static int cpu_isa; + +static void exit_event_get_key(struct event *event, void *data, + struct event_key *key) +{ + key-info = cpu_isa; + key-key = raw_field_value(event, exit_reason, data); +} + +static bool kvm_exit_event(struct event *event) +{ + return !strcmp(event-name, kvm_exit); +} + +static bool exit_event_begin(struct event *event, void *data, +struct event_key *key) +{ + if (kvm_exit_event(event)) { + exit_event_get_key(event, data, key); + return true; + } + + return false; +} + +static bool kvm_entry_event(struct event *event) +{ + return !strcmp(event-name, kvm_entry); +} + +static bool exit_event_end(struct event *event, void *data __unused, + struct event_key *key __unused) +{ +
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 01/17/2012 04:30 AM, Xiao Guangrong wrote: On 01/16/2012 06:04 PM, Avi Kivity wrote: On 01/16/2012 11:32 AM, Xiao Guangrong wrote: Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: perf kvm-events record Why not 'perf record -e kvm'? It works, many perf tools have this style, like: perf lock record, perf sched record, perf kmem record, I think the reason is that only enable the tracepoints we need to avoid unnecessary overload so that the result is more exacter. Maybe a virtual event list: perf record -e kvm-pio This allows us to combine the event list with other events: perf record -e kvm-pio -e timer + + while (table_size--) { + if (table-exit_code == exit_code) + return table-reason; ... table[exit_code] ... Actually, this array is not indexed by exit_code, it means: table[exit_code].exit_code != exit_code. So make it indexed by exit code. -- error compiling committee.c: too many arguments to function -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 01/17/2012 01:59 PM, Marcelo Tosatti wrote: All this copy-paste could be avoided by sharing this stuff with the arch/x86/kvm/ code. Yes, same for KVM_MAX_VCPUS. This is an internal define. perf kvm should work with different kernel versions, so it needs to query the value dynamically. -- error compiling committee.c: too many arguments to function -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On Mon, Jan 16, 2012 at 10:08:40AM +, Stefan Hajnoczi wrote: On Mon, Jan 16, 2012 at 9:32 AM, Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com wrote: +DESCRIPTION +--- +You can analyze some crucial events and statistics with this +'perf kvm-events' command. This line is very general and does not explain which events/statistics can be collected or how you can use that information. I suggest making this description more specific. Explain that this subcommand observers kvm.ko tracepoints and annotates/decodes them with additional information (this is why I would use this command and not raw perf record -e kvm:\*). + { SVM_EXIT_MONITOR, monitor }, \ + { SVM_EXIT_MWAIT, mwait }, \ + { SVM_EXIT_XSETBV, xsetbv }, \ + { SVM_EXIT_NPF, npf } All this copy-paste could be avoided by sharing this stuff with the arch/x86/kvm/ code. Yes, same for KVM_MAX_VCPUS. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/3] KVM: perf: kvm events analysis tool
Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: perf kvm-events record perf kvm-events report Signed-off-by: Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com --- tools/perf/Documentation/perf-kvm-events.txt | 54 ++ tools/perf/Makefile |1 + tools/perf/builtin-kvm-events.c | 860 ++ tools/perf/builtin.h |1 + tools/perf/perf.c|1 + 5 files changed, 917 insertions(+), 0 deletions(-) create mode 100644 tools/perf/Documentation/perf-kvm-events.txt create mode 100644 tools/perf/builtin-kvm-events.c diff --git a/tools/perf/Documentation/perf-kvm-events.txt b/tools/perf/Documentation/perf-kvm-events.txt new file mode 100644 index 000..73bcb82 --- /dev/null +++ b/tools/perf/Documentation/perf-kvm-events.txt @@ -0,0 +1,54 @@ +perf-kvm-events(1) + + +NAME + +perf-kvm-events - Analyze kvm events + +SYNOPSIS + +[verse] +'perf kvm-events' {record|report} + +DESCRIPTION +--- +You can analyze some crucial events and statistics with this +'perf kvm-events' command. + + 'perf kvm-events record command' records kvm events + between start and end command. And this command + produces the file perf.data which contains tracing + results of kvm events. + + 'perf kvm-events report' reports statistical data. + +COMMON OPTIONS +-- + +-i:: +--input=file:: +Input file name. (default: perf.data unless stdin is a fifo) + +-v:: +--verbose:: +Be more verbose (show symbol address, etc). + +-D:: +--dump-raw-trace:: +Dump raw trace in ASCII. + +REPORT OPTIONS +-- +--vcpu=value:: + analyze events which occures on this vcpu + +--events=value:: + events to be analyzed. Possible values: vmexit, mmio, ioport. +-k:: +--key=value:: +Sorting key. Possible values: sample(default, sort by samples number), +time(sort by time%). + +SEE ALSO + +linkperf:perf[1] diff --git a/tools/perf/Makefile b/tools/perf/Makefile index ac86d67..ee43451 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -382,6 +382,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-probe.o BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o BUILTIN_OBJS += $(OUTPUT)builtin-lock.o BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o +BUILTIN_OBJS += $(OUTPUT)builtin-kvm-events.o BUILTIN_OBJS += $(OUTPUT)builtin-test.o BUILTIN_OBJS += $(OUTPUT)builtin-inject.o diff --git a/tools/perf/builtin-kvm-events.c b/tools/perf/builtin-kvm-events.c new file mode 100644 index 000..55dc680 --- /dev/null +++ b/tools/perf/builtin-kvm-events.c @@ -0,0 +1,860 @@ +#include builtin.h +#include perf.h +#include util/util.h +#include util/cache.h +#include util/symbol.h +#include util/thread.h +#include util/header.h +#include util/parse-options.h +#include util/trace-event.h +#include util/debug.h +#include util/session.h +#include util/tool.h + +#include linux/hash.h + +/* + * Todo: improve the print format of kvm_exit to let it is easier + * parsed by perf, then we can get the exit reason from print + * format directly. + */ +#define EXIT_REASON_EXCEPTION_NMI 0 +#define EXIT_REASON_EXTERNAL_INTERRUPT 1 +#define EXIT_REASON_TRIPLE_FAULT2 + +#define EXIT_REASON_PENDING_INTERRUPT 7 +#define EXIT_REASON_NMI_WINDOW 8 +#define EXIT_REASON_TASK_SWITCH 9 +#define EXIT_REASON_CPUID 10 +#define EXIT_REASON_HLT 12 +#define EXIT_REASON_INVD13 +#define EXIT_REASON_INVLPG 14 +#define EXIT_REASON_RDPMC 15 +#define EXIT_REASON_RDTSC 16 +#define EXIT_REASON_VMCALL 18 +#define EXIT_REASON_VMCLEAR 19 +#define EXIT_REASON_VMLAUNCH20 +#define EXIT_REASON_VMPTRLD 21 +#define EXIT_REASON_VMPTRST 22 +#define EXIT_REASON_VMREAD 23 +#define EXIT_REASON_VMRESUME24 +#define EXIT_REASON_VMWRITE 25 +#define EXIT_REASON_VMOFF 26 +#define EXIT_REASON_VMON27 +#define EXIT_REASON_CR_ACCESS 28 +#define EXIT_REASON_DR_ACCESS 29 +#define EXIT_REASON_IO_INSTRUCTION 30 +#define EXIT_REASON_MSR_READ31 +#define EXIT_REASON_MSR_WRITE 32 +#define EXIT_REASON_INVALID_STATE 33 +#define EXIT_REASON_MWAIT_INSTRUCTION 36 +#define EXIT_REASON_MONITOR_INSTRUCTION 39 +#define EXIT_REASON_PAUSE_INSTRUCTION 40 +#define EXIT_REASON_MCE_DURING_VMENTRY 41 +#define EXIT_REASON_TPR_BELOW_THRESHOLD 43 +#define EXIT_REASON_APIC_ACCESS 44 +#define EXIT_REASON_EPT_VIOLATION 48 +#define EXIT_REASON_EPT_MISCONFIG 49 +#define EXIT_REASON_WBINVD 54 +#define EXIT_REASON_XSETBV 55 + +#define SVM_EXIT_READ_CR0 0x000 +#define SVM_EXIT_READ_CR3 0x003 +#define SVM_EXIT_READ_CR4 0x004 +#define SVM_EXIT_READ_CR8 0x008 +#define
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 01/16/2012 11:32 AM, Xiao Guangrong wrote: Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: perf kvm-events record Why not 'perf record -e kvm'? perf kvm-events report +static const char *get_exit_reason(long isa, u64 exit_code) +{ + int table_size = ARRAY_SIZE(svm_exit_reasons); + struct exit_reasons_table *table = svm_exit_reasons; + + + if (isa == 1) { + table = vmx_exit_reasons; + table_size = ARRAY_SIZE(vmx_exit_reasons); + } + + while (table_size--) { + if (table-exit_code == exit_code) + return table-reason; ... table[exit_code] ... + table++; + } + + die(unkonw kvm exit code:%ld on %s\n, exit_code, isa == 1 ? + VMX : SVM); unknown + +struct kvm_events_ops { + bool (*is_begain_event)(struct event *event, void *data); begin + bool (*is_end_event)(struct event *event); + struct event_key (*get_key)(struct event *event, void *data); + void (*decode_key)(struct event_key *key, char decode[20]); + const char *name; +}; + + +static struct event_key exit_event_get_key(struct event *event, void *data) +{ + struct event_key key; + + key.key = raw_field_value(event, exit_reason, data); + key.info = raw_field_value(event, isa, data); isa is not available on all kernel versions; need to fall back to /proc/cpuid detection. + return key; +} -- error compiling committee.c: too many arguments to function -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On Mon, Jan 16, 2012 at 9:32 AM, Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com wrote: +DESCRIPTION +--- +You can analyze some crucial events and statistics with this +'perf kvm-events' command. This line is very general and does not explain which events/statistics can be collected or how you can use that information. I suggest making this description more specific. Explain that this subcommand observers kvm.ko tracepoints and annotates/decodes them with additional information (this is why I would use this command and not raw perf record -e kvm:\*). + { SVM_EXIT_MONITOR, monitor }, \ + { SVM_EXIT_MWAIT, mwait }, \ + { SVM_EXIT_XSETBV, xsetbv }, \ + { SVM_EXIT_NPF, npf } All this copy-paste could be avoided by sharing this stuff with the arch/x86/kvm/ code. +static void exit_event_decode_key(struct event_key *key, char decode[20]) +{ + const char *exit_reason = get_exit_reason(key-info, key-key); + + memset(decode, 0, 20); + strncpy(decode, exit_reason, 20); This is a bad pattern to follow when using strncpy(3) because if there was a strlen(exit_reason) == 20 string then decode[] would not be NUL-terminated. Right now it's safe but it's better to just use strlcpy() and drop the memset(3). +} + +static struct kvm_events_ops exit_events = { + .is_begain_event = exit_event_begain, + .is_end_event = exit_event_end, + .get_key = exit_event_get_key, + .decode_key = exit_event_decode_key, + .name = VM-EXIT +}; + +#define KVM_TRACE_MMIO_READ_UNSATISFIED 0 +#define KVM_TRACE_MMIO_READ 1 +#define KVM_TRACE_MMIO_WRITE 2 +static bool mmio_event_begain(struct event *event, void *data) +{ + if (!strcmp(event-name, kvm_mmio)) { + long type = raw_field_value(event, type, data); + + if (type != KVM_TRACE_MMIO_READ_UNSATISFIED) + return true; + }; + + return false; +} + +static bool mmio_event_end(struct event *event) +{ + return !strcmp(event-name, kvm_mmio_done); +} + +static struct event_key mmio_event_get_key(struct event *event, void *data) +{ + struct event_key key; + + key.key = raw_field_value(event, gpa, data); + key.info = raw_field_value(event, type, data); + + return key; +} + +static void mmio_event_decode_key(struct event_key *key, char decode[20]) +{ + memset(decode, 0, 20); + sprintf(decode, %#lx:%s, key-key, + key-info == KVM_TRACE_MMIO_READ ? R : W); Please drop the memset and use snprintf(3) instead of sprintf(3). It places the NUL-terminator and ensures you don't exceed the buffer size. Same pattern below. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 01/16/2012 06:04 PM, Avi Kivity wrote: On 01/16/2012 11:32 AM, Xiao Guangrong wrote: Add 'perf kvm-events' support to analyze kvm vmexit/mmio/ioport smartly Usage: perf kvm-events record Why not 'perf record -e kvm'? It works, many perf tools have this style, like: perf lock record, perf sched record, perf kmem record, I think the reason is that only enable the tracepoints we need to avoid unnecessary overload so that the result is more exacter. perf kvm-events report +static const char *get_exit_reason(long isa, u64 exit_code) +{ +int table_size = ARRAY_SIZE(svm_exit_reasons); +struct exit_reasons_table *table = svm_exit_reasons; + + +if (isa == 1) { +table = vmx_exit_reasons; +table_size = ARRAY_SIZE(vmx_exit_reasons); +} + +while (table_size--) { +if (table-exit_code == exit_code) +return table-reason; ... table[exit_code] ... Actually, this array is not indexed by exit_code, it means: table[exit_code].exit_code != exit_code. +table++; +} + +die(unkonw kvm exit code:%ld on %s\n, exit_code, isa == 1 ? +VMX : SVM); unknown .. + +struct kvm_events_ops { +bool (*is_begain_event)(struct event *event, void *data); begin Sorry for my careless. +bool (*is_end_event)(struct event *event); +struct event_key (*get_key)(struct event *event, void *data); +void (*decode_key)(struct event_key *key, char decode[20]); +const char *name; +}; + + +static struct event_key exit_event_get_key(struct event *event, void *data) +{ +struct event_key key; + +key.key = raw_field_value(event, exit_reason, data); +key.info = raw_field_value(event, isa, data); isa is not available on all kernel versions; need to fall back to /proc/cpuid detection. Got it, will do it in the next version. Thanks Avi! -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] KVM: perf: kvm events analysis tool
On 01/16/2012 06:08 PM, Stefan Hajnoczi wrote: On Mon, Jan 16, 2012 at 9:32 AM, Xiao Guangrong xiaoguangr...@linux.vnet.ibm.com wrote: +DESCRIPTION +--- +You can analyze some crucial events and statistics with this +'perf kvm-events' command. This line is very general and does not explain which events/statistics can be collected or how you can use that information. I suggest making this description more specific. Explain that this subcommand observers kvm.ko tracepoints and annotates/decodes them with additional information (this is why I would use this command and not raw perf record -e kvm:\*). Okay. + � � � { SVM_EXIT_MONITOR, � � � � � � � � � � monitor }, \ + � � � { SVM_EXIT_MWAIT, � � � � � � � � � � � mwait }, \ + � � � { SVM_EXIT_XSETBV, � � � � � � � � � � �xsetbv }, \ + � � � { SVM_EXIT_NPF, � � � � � � � � � � � � npf } All this copy-paste could be avoided by sharing this stuff with the arch/x86/kvm/ code. I will try to combine them in the next version. +static void exit_event_decode_key(struct event_key *key, char decode[20]) +{ + � � � const char *exit_reason = get_exit_reason(key-info, key-key); + + � � � memset(decode, 0, 20); + � � � strncpy(decode, exit_reason, 20); This is a bad pattern to follow when using strncpy(3) because if there was a strlen(exit_reason) == 20 string then decode[] would not be NUL-terminated. Right now it's safe but it's better to just use strlcpy() and drop the memset(3). Good point. +static void mmio_event_decode_key(struct event_key *key, char decode[20]) +{ + � � � memset(decode, 0, 20); + � � � sprintf(decode, %#lx:%s, key-key, + � � � � � � � key-info == KVM_TRACE_MMIO_READ ? R : W); Please drop the memset and use snprintf(3) instead of sprintf(3). It places the NUL-terminator and ensures you don't exceed the buffer size. Same pattern below. Will do, thanks Stefan! :) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html