From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsUmM-0007Gy-Ih for qemu-devel@nongnu.org; Fri, 07 Oct 2016 09:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsUmG-0005TT-MZ for qemu-devel@nongnu.org; Fri, 07 Oct 2016 09:01:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsUmG-0005SK-GH for qemu-devel@nongnu.org; Fri, 07 Oct 2016 09:01:28 -0400 Date: Fri, 7 Oct 2016 15:01:24 +0200 From: Igor Mammedov Message-ID: <20161007150124.4da88af8@nial.brq.redhat.com> In-Reply-To: <20161005130657.3399-9-rkrcmar@redhat.com> References: <20161005130657.3399-1-rkrcmar@redhat.com> <20161005130657.3399-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 v4 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 Wed, 5 Oct 2016 15:06:57 +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 and call it memorize as > adding the r makes it less obscure. >=20 > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 Reviewed-by: Igor Mammedov > --- > v4: > * changed the name to memorize [Igor] > * remove useless underscores in macro arguments > * merge the two macros, as it seems that the deleted one wouldn't get > other users anytime soon > --- > target-i386/kvm.c | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) >=20 > diff --git a/target-i386/kvm.c b/target-i386/kvm.c > index 0fd664648665..0472f45fd092 100644 > --- a/target-i386/kvm.c > +++ b/target-i386/kvm.c > @@ -129,10 +129,23 @@ static bool kvm_x2apic_api_set_flags(uint64_t flags) > return !kvm_vm_enable_cap(s, KVM_CAP_X2APIC_API, 0, flags); > } > =20 > +#define MEMORIZE(fn) \ > + ({ \ > + static typeof(fn) _result; \ > + static bool _memorized; \ > + \ > + if (_memorized) { \ > + return _result; \ > + } \ > + _memorized =3D true; \ > + _result =3D 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 MEMORIZE( > + 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)