From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E7E9E2063D77A for ; Thu, 12 Jul 2018 15:00:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40094818F6FF; Thu, 12 Jul 2018 22:00:19 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-124-188.rdu2.redhat.com [10.10.124.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9531916874; Thu, 12 Jul 2018 22:00:18 +0000 (UTC) To: Eric Dong , edk2-devel@lists.01.org Cc: Ruiyu Ni References: <20180712104927.12220-1-eric.dong@intel.com> <20180712104927.12220-3-eric.dong@intel.com> From: Laszlo Ersek Message-ID: Date: Fri, 13 Jul 2018 00:00:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180712104927.12220-3-eric.dong@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Jul 2018 22:00:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Jul 2018 22:00:19 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: [Patch v2 2/3] UefiCpuPkg/MpInitLib: Use BSP uCode for APs if possible. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2018 22:00:20 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/12/18 12:49, Eric Dong wrote: > Search uCode costs much time, if AP has same processor type > with BSP, AP can use BSP saved uCode info to get better performance. > > This change enables this solution. > > Cc: Laszlo Ersek > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > UefiCpuPkg/Library/MpInitLib/Microcode.c | 34 +++++++++++++++++++++++++++++--- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 4 ++-- > UefiCpuPkg/Library/MpInitLib/MpLib.h | 11 +++++++++-- > 3 files changed, 42 insertions(+), 7 deletions(-) > > diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/MpInitLib/Microcode.c > index e47f9f4f8f..351975e2a2 100644 > --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c > +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c > @@ -35,11 +35,13 @@ GetCurrentMicrocodeSignature ( > /** > Detect whether specified processor can find matching microcode patch and load it. > > - @param[in] CpuMpData The pointer to CPU MP Data structure. > + @param[in] CpuMpData The pointer to CPU MP Data structure. > + @param[in] IsBspCallIn Indicate whether the caller is BSP or not. > **/ > VOID > MicrocodeDetect ( > - IN CPU_MP_DATA *CpuMpData > + IN CPU_MP_DATA *CpuMpData, > + IN BOOLEAN IsBspCallIn > ) > { > UINT32 ExtendedTableLength; > @@ -58,6 +60,7 @@ MicrocodeDetect ( > BOOLEAN CorrectMicrocode; > VOID *MicrocodeData; > MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr; > + UINT32 ProcessorFlags; > > if (CpuMpData->MicrocodePatchRegionSize == 0) { > // > @@ -67,7 +70,7 @@ MicrocodeDetect ( > } > > CurrentRevision = GetCurrentMicrocodeSignature (); > - if (CurrentRevision != 0) { > + if (CurrentRevision != 0 && !IsBspCallIn) { > // > // Skip loading microcode if it has been loaded successfully > // > @@ -87,6 +90,19 @@ MicrocodeDetect ( > PlatformIdMsr.Uint64 = AsmReadMsr64 (MSR_IA32_PLATFORM_ID); > PlatformId = (UINT8) PlatformIdMsr.Bits.PlatformId; > > + // > + // Check whether AP has same processor with BSP. > + // If yes, direct use microcode info saved by BSP. > + // > + if (!IsBspCallIn) { > + if ((CpuMpData->ProcessorSignature == Eax.Uint32) && > + (CpuMpData->ProcessorFlags & (1 << PlatformId)) != 0) { > + MicrocodeData = (VOID *)(UINTN) CpuMpData->MicrocodeDataAddress; > + LatestRevision = CpuMpData->MicrocodeRevision; > + goto Done; > + } > + } > + > LatestRevision = 0; > MicrocodeData = NULL; > MicrocodeEnd = (UINTN) (CpuMpData->MicrocodePatchAddress + CpuMpData->MicrocodePatchRegionSize); > @@ -117,6 +133,7 @@ MicrocodeDetect ( > } > if (CheckSum32 == 0) { > CorrectMicrocode = TRUE; > + ProcessorFlags = MicrocodeEntryPoint->ProcessorFlags; > } > } else if ((MicrocodeEntryPoint->DataSize != 0) && > (MicrocodeEntryPoint->UpdateRevision > LatestRevision)) { > @@ -151,6 +168,7 @@ MicrocodeDetect ( > // Find one > // > CorrectMicrocode = TRUE; > + ProcessorFlags = ExtendedTable->ProcessorFlag; > break; > } > } > @@ -188,6 +206,7 @@ MicrocodeDetect ( > MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEntryPoint) + TotalSize); > } while (((UINTN) MicrocodeEntryPoint < MicrocodeEnd)); > > +Done: > if (LatestRevision > CurrentRevision) { > // > // BIOS only authenticate updates that contain a numerically larger revision > @@ -211,4 +230,13 @@ MicrocodeDetect ( > ReleaseSpinLock(&CpuMpData->MpLock); > } > } > + > + if (IsBspCallIn && (LatestRevision != 0)) { > + CpuMpData->ProcessorSignature = Eax.Uint32; > + CpuMpData->ProcessorFlags = ProcessorFlags; > + CpuMpData->MicrocodeDataAddress = (UINTN) MicrocodeData; > + CpuMpData->MicrocodeRevision = LatestRevision; > + DEBUG ((DEBUG_INFO, "BSP Microcode:: signature [0x%08x], ProcessorFlags [0x%08x], \ > + MicroData [0x%08x], Revision [0x%08x]\n", Eax.Uint32, ProcessorFlags, (UINTN) MicrocodeData, LatestRevision)); > + } > } > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index c3cd6d7d51..3a7bdfa00b 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -410,7 +410,7 @@ ApInitializeSync ( > // > // Load microcode on AP > // > - MicrocodeDetect (CpuMpData); > + MicrocodeDetect (CpuMpData, FALSE); > // > // Sync BSP's MTRR table to AP > // > @@ -1659,7 +1659,7 @@ MpInitLibInitialize ( > // > // Load Microcode on BSP > // > - MicrocodeDetect (CpuMpData); > + MicrocodeDetect (CpuMpData, TRUE); > // > // Store BSP's MTRR setting > // > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h > index 9aedb52636..6958080ac1 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h > @@ -245,6 +245,11 @@ struct _CPU_MP_DATA { > BOOLEAN TimerInterruptState; > UINT64 MicrocodePatchAddress; > UINT64 MicrocodePatchRegionSize; > + > + UINT32 ProcessorSignature; > + UINT32 ProcessorFlags; > + UINT64 MicrocodeDataAddress; > + UINT32 MicrocodeRevision; > }; > > extern EFI_GUID mCpuInitMpLibHobGuid; > @@ -546,11 +551,13 @@ CheckAndUpdateApsStatus ( > /** > Detect whether specified processor can find matching microcode patch and load it. > > - @param[in] CpuMpData The pointer to CPU MP Data structure. > + @param[in] CpuMpData The pointer to CPU MP Data structure. > + @param[in] IsBspCallIn Indicate whether the caller is BSP or not. > **/ > VOID > MicrocodeDetect ( > - IN CPU_MP_DATA *CpuMpData > + IN CPU_MP_DATA *CpuMpData, > + IN BOOLEAN IsBspCallIn > ); > > /** > Acked-by: Laszlo Ersek