diff mbox

[v2,3/5] KVM: VMX: Bring the common code to header file

Message ID 1521232646-79580-4-git-send-email-babu.moger@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Babu Moger March 16, 2018, 8:37 p.m. UTC
This patch brings some of the code from vmx to x86.h header file. Now, we
can share this code between vmx and svm. Modified couple functions to make
it common.

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
 arch/x86/kvm/vmx.c | 48 +++++++++---------------------------------------
 arch/x86/kvm/x86.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 39 deletions(-)

Comments

Radim Krčmář March 28, 2018, 8:26 p.m. UTC | #1
2018-03-16 16:37-0400, Babu Moger:
> This patch brings some of the code from vmx to x86.h header file. Now, we
> can share this code between vmx and svm. Modified couple functions to make
> it common.
> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> @@ -6683,8 +6652,9 @@ static void shrink_ple_window(struct kvm_vcpu *vcpu)
>  	struct vcpu_vmx *vmx = to_vmx(vcpu);
>  	int old = vmx->ple_window;
>  
> -	vmx->ple_window = __shrink_ple_window(old,
> -	                                      ple_window_shrink, ple_window);
> +	vmx->ple_window = __shrink_ple_window(old, ple_window,
> +					      ple_window_shrink,
> +					      0);

I have preserved the old minumum (ple_window, so we could't get
uselessly small values).
Babu Moger March 28, 2018, 9:12 p.m. UTC | #2
> -----Original Message-----
> From: Radim Krčmář <rkrcmar@redhat.com>
> Sent: Wednesday, March 28, 2018 3:27 PM
> To: Moger, Babu <Babu.Moger@amd.com>
> Cc: joro@8bytes.org; tglx@linutronix.de; mingo@redhat.com;
> hpa@zytor.com; x86@kernel.org; pbonzini@redhat.com;
> kvm@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v2 3/5] KVM: VMX: Bring the common code to header
> file
> 
> 2018-03-16 16:37-0400, Babu Moger:
> > This patch brings some of the code from vmx to x86.h header file. Now, we
> > can share this code between vmx and svm. Modified couple functions to
> make
> > it common.
> >
> > Signed-off-by: Babu Moger <babu.moger@amd.com>
> > ---
> > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> > @@ -6683,8 +6652,9 @@ static void shrink_ple_window(struct kvm_vcpu
> *vcpu)
> >  	struct vcpu_vmx *vmx = to_vmx(vcpu);
> >  	int old = vmx->ple_window;
> >
> > -	vmx->ple_window = __shrink_ple_window(old,
> > -	                                      ple_window_shrink, ple_window);
> > +	vmx->ple_window = __shrink_ple_window(old, ple_window,
> > +					      ple_window_shrink,
> > +					      0);
> 
> I have preserved the old minumum (ple_window, so we could't get
> uselessly small values).

Ok. Looks good. Thanks
diff mbox

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b992d81..ba826b6 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -156,25 +156,18 @@ 
  * Time is measured based on a counter that runs at the same rate as the TSC,
  * refer SDM volume 3b section 21.6.13 & 22.1.3.
  */
-#define KVM_VMX_DEFAULT_PLE_GAP           128
-#define KVM_VMX_DEFAULT_PLE_WINDOW        4096
-#define KVM_VMX_DEFAULT_PLE_WINDOW_GROW   2
-#define KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK 0
-#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX    \
-		INT_MAX / KVM_VMX_DEFAULT_PLE_WINDOW_GROW
-
-static uint ple_gap = KVM_VMX_DEFAULT_PLE_GAP;
+static uint ple_gap = KVM_DEFAULT_PLE_GAP;
 module_param(ple_gap, uint, 0444);
 
 static uint ple_window = KVM_VMX_DEFAULT_PLE_WINDOW;
 module_param(ple_window, uint, 0444);
 
 /* Default doubles per-vcpu window every exit. */
-static uint ple_window_grow = KVM_VMX_DEFAULT_PLE_WINDOW_GROW;
+static uint ple_window_grow = KVM_DEFAULT_PLE_WINDOW_GROW;
 module_param(ple_window_grow, uint, 0444);
 
 /* Default resets per-vcpu window every exit to ple_window. */
-static uint ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK;
+static uint ple_window_shrink = KVM_DEFAULT_PLE_WINDOW_SHRINK;
 module_param(ple_window_shrink, uint, 0444);
 
 /* Default is to compute the maximum so we can never overflow. */
@@ -6639,38 +6632,14 @@  static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
 	return ret;
 }
 
-static uint __grow_ple_window(uint val)
-{
-	if (ple_window_grow < 1)
-		return ple_window;
-
-	if (ple_window_grow < ple_window)
-		val *= ple_window_grow;
-	else
-		val += ple_window_grow;
-
-	return min(val, ple_window_max);
-}
-
-static uint __shrink_ple_window(uint val, uint modifier, uint minimum)
-{
-	if (modifier < 1)
-		return ple_window;
-
-	if (modifier < ple_window)
-		val /= modifier;
-	else
-		val -= modifier;
-
-	return max(val, minimum);
-}
-
 static void grow_ple_window(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	int old = vmx->ple_window;
 
-	vmx->ple_window = __grow_ple_window(old);
+	vmx->ple_window = __grow_ple_window(old, ple_window,
+					    ple_window_grow,
+					    ple_window_max);
 
 	if (vmx->ple_window != old)
 		vmx->ple_window_dirty = true;
@@ -6683,8 +6652,9 @@  static void shrink_ple_window(struct kvm_vcpu *vcpu)
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	int old = vmx->ple_window;
 
-	vmx->ple_window = __shrink_ple_window(old,
-	                                      ple_window_shrink, ple_window);
+	vmx->ple_window = __shrink_ple_window(old, ple_window,
+					      ple_window_shrink,
+					      0);
 
 	if (vmx->ple_window != old)
 		vmx->ple_window_dirty = true;
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index d0b95b7..ca051a2 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -8,6 +8,41 @@ 
 #include <asm/pvclock.h>
 #include "kvm_cache_regs.h"
 
+#define KVM_DEFAULT_PLE_GAP		128
+#define KVM_VMX_DEFAULT_PLE_WINDOW	4096
+#define KVM_DEFAULT_PLE_WINDOW_GROW	2
+#define KVM_DEFAULT_PLE_WINDOW_SHRINK	0
+#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX    \
+		(INT_MAX / KVM_DEFAULT_PLE_WINDOW_GROW)
+
+static inline uint __grow_ple_window(uint val, uint base,
+				     uint modifier, uint max)
+{
+	if (modifier < 1)
+		return base;
+
+	if (modifier < base)
+		val *= modifier;
+	else
+		val += modifier;
+
+	return min(val, max);
+}
+
+static inline uint __shrink_ple_window(uint val, uint base,
+				       uint modifier, uint min)
+{
+	if (modifier < 1)
+		return base;
+
+	if (modifier < base)
+		val /= modifier;
+	else
+		val -= modifier;
+
+	return max(val, min);
+}
+
 #define MSR_IA32_CR_PAT_DEFAULT  0x0007040600070406ULL
 
 static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)