From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brlv3-0002RO-8Z for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:07:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brluz-0004jT-VB for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:07:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brluz-0004jM-OH for qemu-devel@nongnu.org; Wed, 05 Oct 2016 09:07:29 -0400 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Date: Wed, 5 Oct 2016 15:06:57 +0200 Message-Id: <20161005130657.3399-9-rkrcmar@redhat.com> In-Reply-To: <20161005130657.3399-1-rkrcmar@redhat.com> References: <20161005130657.3399-1-rkrcmar@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [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: qemu-devel@nongnu.org Cc: Peter Xu , Igor Mammedov , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" 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. Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 --- 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(-) 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) --=20 2.10.0