From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 7/9] KVM: VMX: abstract ple_window modifiers Date: Wed, 20 Aug 2014 09:02:45 +0200 Message-ID: <53F44815.9020309@redhat.com> References: <1408480536-8240-1-git-send-email-rkrcmar@redhat.com> <1408480536-8240-8-git-send-email-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-kernel@vger.kernel.org, Gleb Natapov , Raghavendra KT , Vinod Chegu , Hui-Zhi To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , kvm@vger.kernel.org Return-path: In-Reply-To: <1408480536-8240-8-git-send-email-rkrcmar@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Il 19/08/2014 22:35, Radim Kr=C4=8Dm=C3=A1=C5=99 ha scritto: > They were almost identical and thus merged with a loathable macro. >=20 > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > --- > 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(-) >=20 > 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 =3D to_vmx(vcpu); > - int old =3D vmx->ple_window; > - int new; > - > - if (ple_window_grow < 1) > - new =3D ple_window; > - else if (ple_window_grow < ple_window) > - new =3D old * ple_window_grow; > - else > - new =3D old + ple_window_grow; > - > - vmx->ple_window =3D 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 =3D to_vmx(vcpu); \ > + int old =3D vmx->ple_window; \ > + int new; \ > +\ > + if (ple_window_##type < 1) \ > + new =3D ple_window; \ > + else if (ple_window_##type < ple_window) \ > + new =3D old oplt ple_window_##type; \ > + else \ > + new =3D old opge ple_window_##type; \ > +\ > + vmx->ple_window =3D cmp(new, bound); \ > +\ > + trace_kvm_ple_window_##type(vcpu->vcpu_id, vmx->ple_window, old); \ > } > =20 > -static void shrink_ple_window(struct kvm_vcpu *vcpu) > -{ > - struct vcpu_vmx *vmx =3D to_vmx(vcpu); > - int old =3D vmx->ple_window; > - int new; > - > - if (ple_window_shrink < 1) > - new =3D ple_window; > - else if (ple_window_shrink < ple_window) > - new =3D old / ple_window_shrink; > - else > - new =3D old - ple_window_shrink; > - > - vmx->ple_window =3D 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) > =20 > /* > * Indicate a busy-waiting vcpu in spinlock. We do not enable the PA= USE >=20