ia64/xen-unstable

changeset 19656:87c411a7c1df

x86 svm: Add support for Pause Filtering to AMD SVM

New AMD processors will 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
ntercepting 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 1%. Further performance
improvement may be possible with a more sophisticated
yield algorithm.

Signed-off-by: Mark Langsdorf <mark.langsdorf@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed May 27 11:27:13 2009 +0100 (2009-05-27)
parents 494c2ebf9d19
children 9ff5c79b0ceb
files xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/svm/vmcb.c xen/include/asm-x86/hvm/svm/svm.h xen/include/asm-x86/hvm/svm/vmcb.h
line diff
     1.1 --- a/xen/arch/x86/hvm/svm/svm.c	Wed May 27 11:21:59 2009 +0100
     1.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Wed May 27 11:27:13 2009 +0100
     1.3 @@ -1508,6 +1508,14 @@ asmlinkage void svm_vmexit_handler(struc
     1.4          vmcb->interrupt_shadow = 1;
     1.5          break;
     1.6  
     1.7 +    case VMEXIT_PAUSE:
     1.8 +        /*
     1.9 +         * The guest is running a contended spinlock and we've detected it.
    1.10 +         * Do something useful, like reschedule the guest
    1.11 +         */
    1.12 +       do_sched_op_compat(SCHEDOP_yield, 0);
    1.13 +       break;
    1.14 +
    1.15      default:
    1.16      exit_and_crash:
    1.17          gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = 0x%x, "
     2.1 --- a/xen/arch/x86/hvm/svm/vmcb.c	Wed May 27 11:21:59 2009 +0100
     2.2 +++ b/xen/arch/x86/hvm/svm/vmcb.c	Wed May 27 11:27:13 2009 +0100
     2.3 @@ -247,6 +247,12 @@ static int construct_vmcb(struct vcpu *v
     2.4          vmcb->exception_intercepts |= (1U << TRAP_page_fault);
     2.5      }
     2.6  
     2.7 +    if ( cpu_has_pause_filter )
     2.8 +    {
     2.9 +        vmcb->pause_filter_count = 3000;
    2.10 +        vmcb->general1_intercepts |= GENERAL1_INTERCEPT_PAUSE;
    2.11 +    }
    2.12 +
    2.13      return 0;
    2.14  }
    2.15  
     3.1 --- a/xen/include/asm-x86/hvm/svm/svm.h	Wed May 27 11:21:59 2009 +0100
     3.2 +++ b/xen/include/asm-x86/hvm/svm/svm.h	Wed May 27 11:27:13 2009 +0100
     3.3 @@ -67,10 +67,12 @@ extern u32 svm_feature_flags;
     3.4  #define SVM_FEATURE_LBRV    1
     3.5  #define SVM_FEATURE_SVML    2
     3.6  #define SVM_FEATURE_NRIPS   3
     3.7 +#define SVM_FEATURE_PAUSEF  10
     3.8  
     3.9  #define cpu_has_svm_npt     test_bit(SVM_FEATURE_NPT, &svm_feature_flags)
    3.10  #define cpu_has_svm_lbrv    test_bit(SVM_FEATURE_LBRV, &svm_feature_flags)
    3.11  #define cpu_has_svm_svml    test_bit(SVM_FEATURE_SVML, &svm_feature_flags)
    3.12  #define cpu_has_svm_nrips   test_bit(SVM_FEATURE_NRIPS, &svm_feature_flags)
    3.13 +#define cpu_has_pause_filter  test_bit(SVM_FEATURE_PAUSEF, &svm_feature_flags)
    3.14  
    3.15  #endif /* __ASM_X86_HVM_SVM_H__ */
     4.1 --- a/xen/include/asm-x86/hvm/svm/vmcb.h	Wed May 27 11:21:59 2009 +0100
     4.2 +++ b/xen/include/asm-x86/hvm/svm/vmcb.h	Wed May 27 11:27:13 2009 +0100
     4.3 @@ -375,7 +375,9 @@ struct vmcb_struct {
     4.4      u64 res03;                  /* offset 0x20 */
     4.5      u64 res04;                  /* offset 0x28 */
     4.6      u64 res05;                  /* offset 0x30 */
     4.7 -    u64 res06;                  /* offset 0x38 */
     4.8 +    u32 res06;                  /* offset 0x38 */
     4.9 +    u16 res06a;                 /* offset 0x3C */
    4.10 +    u16 pause_filter_count;     /* offset 0x3E */
    4.11      u64 iopm_base_pa;           /* offset 0x40 */
    4.12      u64 msrpm_base_pa;          /* offset 0x48 */
    4.13      u64 tsc_offset;             /* offset 0x50 */