aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Langsdorf <mark.langsdorf@amd.com>2009-10-06 15:25:02 -0400
committerAvi Kivity <avi@redhat.com>2009-12-03 02:32:17 -0500
commit565d0998ecac8373b9a9ecd5991abe74318cd235 (patch)
tree92b0964145a4e2cd7400eda3a9a8cb83eaa4ab33
parent4b8d54f9726f1159330201c5ed2ea30bce7e63ea (diff)
KVM: SVM: Support Pause Filter in AMD processors
New AMD processors (Family 0x10 models 8+) support the Pause Filter Feature. This feature creates a new field in the VMCB called Pause Filter Count. If Pause Filter Count is greater than 0 and intercepting PAUSEs is enabled, the processor will increment an internal counter when a PAUSE instruction occurs instead of intercepting. When the internal counter reaches the Pause Filter Count value, a PAUSE intercept will occur. This feature can be used to detect contended spinlocks, especially when the lock holding VCPU is not scheduled. Rescheduling another VCPU prevents the VCPU seeking the lock from wasting its quantum by spinning idly. Experimental results show that most spinlocks are held for less than 1000 PAUSE cycles or more than a few thousand. Default the Pause Filter Counter to 3000 to detect the contended spinlocks. Processor support for this feature is indicated by a CPUID bit. On a 24 core system running 4 guests each with 16 VCPUs, this patch improved overall performance of each guest's 32 job kernbench by approximately 3-5% when combined with a scheduler algorithm thati caused the VCPU to sleep for a brief period. Further performance improvement may be possible with a more sophisticated yield algorithm. Signed-off-by: Mark Langsdorf <mark.langsdorf@amd.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r--arch/x86/include/asm/svm.h3
-rw-r--r--arch/x86/kvm/svm.c13
2 files changed, 15 insertions, 1 deletions
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index 85574b7c1bc1..1fecb7e61130 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -57,7 +57,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
57 u16 intercept_dr_write; 57 u16 intercept_dr_write;
58 u32 intercept_exceptions; 58 u32 intercept_exceptions;
59 u64 intercept; 59 u64 intercept;
60 u8 reserved_1[44]; 60 u8 reserved_1[42];
61 u16 pause_filter_count;
61 u64 iopm_base_pa; 62 u64 iopm_base_pa;
62 u64 msrpm_base_pa; 63 u64 msrpm_base_pa;
63 u64 tsc_offset; 64 u64 tsc_offset;
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 69610c5d6dea..170b2d9c6909 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -46,6 +46,7 @@ MODULE_LICENSE("GPL");
46#define SVM_FEATURE_NPT (1 << 0) 46#define SVM_FEATURE_NPT (1 << 0)
47#define SVM_FEATURE_LBRV (1 << 1) 47#define SVM_FEATURE_LBRV (1 << 1)
48#define SVM_FEATURE_SVML (1 << 2) 48#define SVM_FEATURE_SVML (1 << 2)
49#define SVM_FEATURE_PAUSE_FILTER (1 << 10)
49 50
50#define NESTED_EXIT_HOST 0 /* Exit handled on host level */ 51#define NESTED_EXIT_HOST 0 /* Exit handled on host level */
51#define NESTED_EXIT_DONE 1 /* Exit caused nested vmexit */ 52#define NESTED_EXIT_DONE 1 /* Exit caused nested vmexit */
@@ -654,6 +655,11 @@ static void init_vmcb(struct vcpu_svm *svm)
654 svm->nested.vmcb = 0; 655 svm->nested.vmcb = 0;
655 svm->vcpu.arch.hflags = 0; 656 svm->vcpu.arch.hflags = 0;
656 657
658 if (svm_has(SVM_FEATURE_PAUSE_FILTER)) {
659 control->pause_filter_count = 3000;
660 control->intercept |= (1ULL << INTERCEPT_PAUSE);
661 }
662
657 enable_gif(svm); 663 enable_gif(svm);
658} 664}
659 665
@@ -2281,6 +2287,12 @@ static int interrupt_window_interception(struct vcpu_svm *svm)
2281 return 1; 2287 return 1;
2282} 2288}
2283 2289
2290static int pause_interception(struct vcpu_svm *svm)
2291{
2292 kvm_vcpu_on_spin(&(svm->vcpu));
2293 return 1;
2294}
2295
2284static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = { 2296static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = {
2285 [SVM_EXIT_READ_CR0] = emulate_on_interception, 2297 [SVM_EXIT_READ_CR0] = emulate_on_interception,
2286 [SVM_EXIT_READ_CR3] = emulate_on_interception, 2298 [SVM_EXIT_READ_CR3] = emulate_on_interception,
@@ -2316,6 +2328,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = {
2316 [SVM_EXIT_CPUID] = cpuid_interception, 2328 [SVM_EXIT_CPUID] = cpuid_interception,
2317 [SVM_EXIT_IRET] = iret_interception, 2329 [SVM_EXIT_IRET] = iret_interception,
2318 [SVM_EXIT_INVD] = emulate_on_interception, 2330 [SVM_EXIT_INVD] = emulate_on_interception,
2331 [SVM_EXIT_PAUSE] = pause_interception,
2319 [SVM_EXIT_HLT] = halt_interception, 2332 [SVM_EXIT_HLT] = halt_interception,
2320 [SVM_EXIT_INVLPG] = invlpg_interception, 2333 [SVM_EXIT_INVLPG] = invlpg_interception,
2321 [SVM_EXIT_INVLPGA] = invlpga_interception, 2334 [SVM_EXIT_INVLPGA] = invlpga_interception,