提交 07031e14 编写于 作者: I Ingo Molnar 提交者: Linus Torvalds

[PATCH] KVM: add VM-exit profiling

This adds the profile=kvm boot option, which enables KVM to profile VM
exits.

Use: "readprofile -m ./System.map | sort -n" to see the resulting
output:

   [...]
   18246 serial_out                               148.3415
   18945 native_flush_tlb                         378.9000
   23618 serial_in                                212.7748
   29279 __spin_unlock_irq                        622.9574
   43447 native_apic_write                        2068.9048
   52702 enable_8259A_irq                         742.2817
   54250 vgacon_scroll                             89.3740
   67394 ide_inb                                  6126.7273
   79514 copy_page_range                           98.1654
   84868 do_wp_page                                86.6000
  140266 pit_read                                 783.6089
  151436 ide_outb                                 25239.3333
  152668 native_io_delay                          21809.7143
  174783 mask_and_ack_8259A                       783.7803
  362404 native_set_pte_at                        36240.4000
 1688747 total                                      0.5009
Signed-off-by: NIngo Molnar <mingo@elte.hu>
Acked-by: NAvi Kivity <avi@qumranet.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 e3881a68
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/profile.h>
#include <asm/desc.h> #include <asm/desc.h>
#include "kvm_svm.h" #include "kvm_svm.h"
...@@ -1558,6 +1559,13 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) ...@@ -1558,6 +1559,13 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
reload_tss(vcpu); reload_tss(vcpu);
/*
* Profile KVM exit RIPs:
*/
if (unlikely(prof_on == KVM_PROFILING))
profile_hit(KVM_PROFILING,
(void *)(unsigned long)vcpu->svm->vmcb->save.rip);
stgi(); stgi();
kvm_reput_irq(vcpu); kvm_reput_irq(vcpu);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/profile.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/desc.h> #include <asm/desc.h>
...@@ -1859,6 +1860,12 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) ...@@ -1859,6 +1860,12 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
#endif #endif
/*
* Profile KVM exit RIPs:
*/
if (unlikely(prof_on == KVM_PROFILING))
profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
kvm_run->exit_type = 0; kvm_run->exit_type = 0;
if (fail) { if (fail) {
kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY; kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
......
...@@ -15,6 +15,7 @@ extern int prof_on __read_mostly; ...@@ -15,6 +15,7 @@ extern int prof_on __read_mostly;
#define CPU_PROFILING 1 #define CPU_PROFILING 1
#define SCHED_PROFILING 2 #define SCHED_PROFILING 2
#define SLEEP_PROFILING 3 #define SLEEP_PROFILING 3
#define KVM_PROFILING 4
struct proc_dir_entry; struct proc_dir_entry;
struct pt_regs; struct pt_regs;
......
...@@ -40,7 +40,10 @@ int (*timer_hook)(struct pt_regs *) __read_mostly; ...@@ -40,7 +40,10 @@ int (*timer_hook)(struct pt_regs *) __read_mostly;
static atomic_t *prof_buffer; static atomic_t *prof_buffer;
static unsigned long prof_len, prof_shift; static unsigned long prof_len, prof_shift;
int prof_on __read_mostly; int prof_on __read_mostly;
EXPORT_SYMBOL_GPL(prof_on);
static cpumask_t prof_cpu_mask = CPU_MASK_ALL; static cpumask_t prof_cpu_mask = CPU_MASK_ALL;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits); static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
...@@ -52,6 +55,7 @@ static int __init profile_setup(char * str) ...@@ -52,6 +55,7 @@ static int __init profile_setup(char * str)
{ {
static char __initdata schedstr[] = "schedule"; static char __initdata schedstr[] = "schedule";
static char __initdata sleepstr[] = "sleep"; static char __initdata sleepstr[] = "sleep";
static char __initdata kvmstr[] = "kvm";
int par; int par;
if (!strncmp(str, sleepstr, strlen(sleepstr))) { if (!strncmp(str, sleepstr, strlen(sleepstr))) {
...@@ -72,6 +76,15 @@ static int __init profile_setup(char * str) ...@@ -72,6 +76,15 @@ static int __init profile_setup(char * str)
printk(KERN_INFO printk(KERN_INFO
"kernel schedule profiling enabled (shift: %ld)\n", "kernel schedule profiling enabled (shift: %ld)\n",
prof_shift); prof_shift);
} else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
prof_on = KVM_PROFILING;
if (str[strlen(kvmstr)] == ',')
str += strlen(kvmstr) + 1;
if (get_option(&str, &par))
prof_shift = par;
printk(KERN_INFO
"kernel KVM profiling enabled (shift: %ld)\n",
prof_shift);
} else if (get_option(&str, &par)) { } else if (get_option(&str, &par)) {
prof_shift = par; prof_shift = par;
prof_on = CPU_PROFILING; prof_on = CPU_PROFILING;
...@@ -318,6 +331,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits) ...@@ -318,6 +331,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
local_irq_restore(flags); local_irq_restore(flags);
put_cpu(); put_cpu();
} }
EXPORT_SYMBOL_GPL(profile_hits);
static int __devinit profile_cpu_callback(struct notifier_block *info, static int __devinit profile_cpu_callback(struct notifier_block *info,
unsigned long action, void *__cpu) unsigned long action, void *__cpu)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册