From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brNyL-0001kt-LO for qemu-devel@nongnu.org; Tue, 04 Oct 2016 07:33:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brNyJ-0000yx-Pq for qemu-devel@nongnu.org; Tue, 04 Oct 2016 07:33:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brNyJ-0000yE-JD for qemu-devel@nongnu.org; Tue, 04 Oct 2016 07:33:19 -0400 Date: Tue, 4 Oct 2016 13:33:15 +0200 From: Igor Mammedov Message-ID: <20161004133315.4e353b0c@nial.brq.redhat.com> In-Reply-To: <20160930161013.9832-9-rkrcmar@redhat.com> References: <20160930161013.9832-1-rkrcmar@redhat.com> <20160930161013.9832-9-rkrcmar@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 8/8] target-i386/kvm: cache the return value of kvm_enable_x2apic() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Radim =?UTF-8?B?S3LEjW3DocWZ?= Cc: qemu-devel@nongnu.org, Peter Xu , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" On Fri, 30 Sep 2016 18:10:13 +0200 Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > Assume that KVM would have returned the same on subsequent runs. > Abstract the memoizaiton pattern into macros. s/memoi/memori/i Throughout whole patch >=20 > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > --- > target-i386/kvm.c | 21 +++++++++++++++++++-- > 1 file changed, 19 insertions(+), 2 deletions(-) >=20 > diff --git a/target-i386/kvm.c b/target-i386/kvm.c > index 0fd664648665..113c5bf058ba 100644 > --- a/target-i386/kvm.c > +++ b/target-i386/kvm.c > @@ -129,10 +129,27 @@ static bool kvm_x2apic_api_set_flags(uint64_t flags) > return !kvm_vm_enable_cap(s, KVM_CAP_X2APIC_API, 0, flags); > } > =20 > +#define MEMOIZE_RESULT(_result, _fn) \ > + ({ \ > + static bool _memoized; \ > + if (_memoized) { \ > + return _result; \ > + } \ > + _memoized =3D true; \ > + _result =3D _fn; \ > + }) > + > +#define MEMOIZE(_fn) \ > + ({ \ > + static typeof(_fn) _result; \ > + MEMOIZE_RESULT(_result, _fn); \ > + }) > + > bool kvm_enable_x2apic(void) > { > - return kvm_x2apic_api_set_flags(KVM_X2APIC_API_USE_32BIT_IDS | > - KVM_X2APIC_API_DISABLE_BROADCAST_QUI= RK); > + return MEMOIZE( > + kvm_x2apic_api_set_flags(KVM_X2APIC_API_USE_32BIT_IDS | > + KVM_X2APIC_API_DISABLE_BROADCAST_Q= UIRK)); > } > =20 > static int kvm_get_tsc(CPUState *cs)