diff mbox

[7/9] KVM: VMX: abstract ple_window modifiers

Message ID 1408480536-8240-8-git-send-email-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář Aug. 19, 2014, 8:35 p.m. UTC
They were almost identical and thus merged with a loathable macro.

Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
---
 This solution is hopefully more acceptable than function pointers.

 arch/x86/kvm/vmx.c | 53 +++++++++++++++++++----------------------------------
 1 file changed, 19 insertions(+), 34 deletions(-)

Comments

Paolo Bonzini Aug. 20, 2014, 7:02 a.m. UTC | #1
Il 19/08/2014 22:35, Radim Kr?má? ha scritto:
> They were almost identical and thus merged with a loathable macro.
> 
> Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
> ---
>  This solution is hopefully more acceptable than function pointers.

I think a little amount of duplication is not a problem.

Paolo

>  arch/x86/kvm/vmx.c | 53 +++++++++++++++++++----------------------------------
>  1 file changed, 19 insertions(+), 34 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index a236a9f..c6cfb71 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -5694,42 +5694,27 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
>  out:
>  	return ret;
>  }
> -
> -static void grow_ple_window(struct kvm_vcpu *vcpu)
> -{
> -	struct vcpu_vmx *vmx = to_vmx(vcpu);
> -	int old = vmx->ple_window;
> -	int new;
> -
> -	if (ple_window_grow < 1)
> -		new = ple_window;
> -	else if (ple_window_grow < ple_window)
> -		new = old * ple_window_grow;
> -	else
> -		new = old + ple_window_grow;
> -
> -	vmx->ple_window = min(new, ple_window_max);
> -
> -	trace_kvm_ple_window_grow(vcpu->vcpu_id, vmx->ple_window, old);
> +#define make_ple_window_modifier(type, oplt, opge, cmp, bound) \
> +static void type##_ple_window(struct kvm_vcpu *vcpu) \
> +{ \
> +	struct vcpu_vmx *vmx = to_vmx(vcpu); \
> +	int old = vmx->ple_window; \
> +	int new; \
> +\
> +	if (ple_window_##type < 1) \
> +		new = ple_window; \
> +	else if (ple_window_##type < ple_window) \
> +		new = old oplt ple_window_##type; \
> +	else \
> +		new = old opge ple_window_##type; \
> +\
> +	vmx->ple_window = cmp(new, bound); \
> +\
> +	trace_kvm_ple_window_##type(vcpu->vcpu_id, vmx->ple_window, old); \
>  }
>  
> -static void shrink_ple_window(struct kvm_vcpu *vcpu)
> -{
> -	struct vcpu_vmx *vmx = to_vmx(vcpu);
> -	int old = vmx->ple_window;
> -	int new;
> -
> -	if (ple_window_shrink < 1)
> -		new = ple_window;
> -	else if (ple_window_shrink < ple_window)
> -		new = old / ple_window_shrink;
> -	else
> -		new = old - ple_window_shrink;
> -
> -	vmx->ple_window = max(new, ple_window);
> -
> -	trace_kvm_ple_window_shrink(vcpu->vcpu_id, vmx->ple_window, old);
> -}
> +make_ple_window_modifier(grow,   *, +, min, ple_window_max)
> +make_ple_window_modifier(shrink, /, -, max, ple_window)
>  
>  /*
>   * Indicate a busy-waiting vcpu in spinlock. We do not enable the PAUSE
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Radim Krčmář Aug. 20, 2014, 12:25 p.m. UTC | #2
2014-08-20 09:02+0200, Paolo Bonzini:
> Il 19/08/2014 22:35, Radim Kr?má? ha scritto:
> > They were almost identical and thus merged with a loathable macro.
> > 
> > Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
> > ---
> >  This solution is hopefully more acceptable than function pointers.
> 
> I think a little amount of duplication is not a problem.

Ok, I'll drop this patch from from v2.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index a236a9f..c6cfb71 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5694,42 +5694,27 @@  static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
 out:
 	return ret;
 }
-
-static void grow_ple_window(struct kvm_vcpu *vcpu)
-{
-	struct vcpu_vmx *vmx = to_vmx(vcpu);
-	int old = vmx->ple_window;
-	int new;
-
-	if (ple_window_grow < 1)
-		new = ple_window;
-	else if (ple_window_grow < ple_window)
-		new = old * ple_window_grow;
-	else
-		new = old + ple_window_grow;
-
-	vmx->ple_window = min(new, ple_window_max);
-
-	trace_kvm_ple_window_grow(vcpu->vcpu_id, vmx->ple_window, old);
+#define make_ple_window_modifier(type, oplt, opge, cmp, bound) \
+static void type##_ple_window(struct kvm_vcpu *vcpu) \
+{ \
+	struct vcpu_vmx *vmx = to_vmx(vcpu); \
+	int old = vmx->ple_window; \
+	int new; \
+\
+	if (ple_window_##type < 1) \
+		new = ple_window; \
+	else if (ple_window_##type < ple_window) \
+		new = old oplt ple_window_##type; \
+	else \
+		new = old opge ple_window_##type; \
+\
+	vmx->ple_window = cmp(new, bound); \
+\
+	trace_kvm_ple_window_##type(vcpu->vcpu_id, vmx->ple_window, old); \
 }
 
-static void shrink_ple_window(struct kvm_vcpu *vcpu)
-{
-	struct vcpu_vmx *vmx = to_vmx(vcpu);
-	int old = vmx->ple_window;
-	int new;
-
-	if (ple_window_shrink < 1)
-		new = ple_window;
-	else if (ple_window_shrink < ple_window)
-		new = old / ple_window_shrink;
-	else
-		new = old - ple_window_shrink;
-
-	vmx->ple_window = max(new, ple_window);
-
-	trace_kvm_ple_window_shrink(vcpu->vcpu_id, vmx->ple_window, old);
-}
+make_ple_window_modifier(grow,   *, +, min, ple_window_max)
+make_ple_window_modifier(shrink, /, -, max, ple_window)
 
 /*
  * Indicate a busy-waiting vcpu in spinlock. We do not enable the PAUSE