From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Wed, 10 Jul 2019 02:31:26 -0700 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CED9C057E65; Wed, 10 Jul 2019 09:31:25 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-153.ams2.redhat.com [10.36.117.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8D6B1001B19; Wed, 10 Jul 2019 09:31:23 +0000 (UTC) Subject: Re: [PATCH v3 27/35] OvmfPkg/XenPlatformLib: Cache result for XenDetected To: Anthony PERARD , devel@edk2.groups.io Cc: xen-devel@lists.xenproject.org, Ard Biesheuvel , Jordan Justen , Julien Grall References: <20190704144233.27968-1-anthony.perard@citrix.com> <20190704144233.27968-28-anthony.perard@citrix.com> From: "Laszlo Ersek" Message-ID: Date: Wed, 10 Jul 2019 11:31:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190704144233.27968-28-anthony.perard@citrix.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 10 Jul 2019 09:31:25 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/04/19 16:42, Anthony PERARD wrote: > We are going to replace XenDetected() implementation in > PlatformBootManagerLib by the one in XenPlatformLib. > PlatformBootManagerLib's implementation does cache the result of > GetFirstGuidHob(), so we do something similar in XenPlatformLib. > > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689 > Signed-off-by: Anthony PERARD > --- > > Notes: > v3: > - new patch > > .../Library/XenPlatformLib/XenPlatformLib.c | 18 +++++++++++++++--- > 1 file changed, 15 insertions(+), 3 deletions(-) > > diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c > index 6f27cbffa8..b5257b0c97 100644 > --- a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c > +++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c > @@ -26,13 +26,25 @@ XenGetInfoHOB ( > ) > { > EFI_HOB_GUID_TYPE *GuidHob; > + STATIC BOOLEAN Cached = FALSE; > + STATIC EFI_XEN_INFO *XenInfo; (1) The alignment of the variable names is weird. The above is neither condensed nor precisely aligned. Please pick one: EFI_HOB_GUID_TYPE *GuidHob; STATIC BOOLEAN Cached = FALSE; STATIC EFI_XEN_INFO *XenInfo; or EFI_HOB_GUID_TYPE *GuidHob; STATIC BOOLEAN Cached = FALSE; STATIC EFI_XEN_INFO *XenInfo; (The 2nd form is preferred in edk2.) > + > + // > + // Return the cached result for the benefit of XenDetected that can be > + // called many times. > + // > + if (Cached) { > + return XenInfo; > + } > > GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid); > if (GuidHob == NULL) { > - return NULL; > + XenInfo = NULL; > + } else { > + XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob); > } > - > - return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob); > + Cached = TRUE; > + return XenInfo; > } > > /** > This will work fine in DXE modules (and by the end of the series, only DXE modules use XenPlatformLib -- AcpiPlatformDxe, XenIoPvhDxe, and PlatformBootManagerLib, which is only linked into DXE modules). With (1) fixed: Reviewed-by: Laszlo Ersek Thanks Laszlo