From patchwork Wed Oct 5 13:06:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9362903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 775E56075E for ; Wed, 5 Oct 2016 13:12:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67283286B6 for ; Wed, 5 Oct 2016 13:12:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BEA8286CB; Wed, 5 Oct 2016 13:12:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=2.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0E0B7286B6 for ; Wed, 5 Oct 2016 13:12:20 +0000 (UTC) Received: from localhost ([::1]:49063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brlzf-00066h-JC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Oct 2016 09:12:19 -0400 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 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5648AC04B926; Wed, 5 Oct 2016 13:07:29 +0000 (UTC) Received: from potion (dhcp-1-247.brq.redhat.com [10.34.1.247]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u95D7QYk025963; Wed, 5 Oct 2016 09:07:26 -0400 Received: by potion (sSMTP sendmail emulation); Wed, 05 Oct 2016 15:07:26 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: qemu-devel@nongnu.org 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 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 05 Oct 2016 13:07:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 8/8] target-i386/kvm: cache the return value of kvm_enable_x2apic() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , Peter Xu , Paolo Bonzini , Igor Mammedov , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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čmář 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(-) 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); } +#define MEMORIZE(fn) \ + ({ \ + static typeof(fn) _result; \ + static bool _memorized; \ + \ + if (_memorized) { \ + return _result; \ + } \ + _memorized = true; \ + _result = fn; \ + }) + bool kvm_enable_x2apic(void) { - return kvm_x2apic_api_set_flags(KVM_X2APIC_API_USE_32BIT_IDS | - KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK); + return MEMORIZE( + kvm_x2apic_api_set_flags(KVM_X2APIC_API_USE_32BIT_IDS | + KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK)); } static int kvm_get_tsc(CPUState *cs)