From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 1D67481E08 for ; Sun, 27 Nov 2016 21:37:39 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP; 27 Nov 2016 21:37:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,562,1473145200"; d="scan'208";a="35010630" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga004.jf.intel.com with ESMTP; 27 Nov 2016 21:37:38 -0800 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 27 Nov 2016 21:37:37 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 27 Nov 2016 21:37:37 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.239]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.239]) with mapi id 14.03.0248.002; Mon, 28 Nov 2016 13:37:35 +0800 From: "Fan, Jeff" To: Laszlo Ersek , edk2-devel-01 CC: "Kinney, Michael D" , "Justen, Jordan L" Thread-Topic: [edk2] [PATCH v2 2/3] UefiCpuPkg/MpInitLib: wait no longer than necessary for initial AP startup Thread-Index: AQHSRwO8HsiFT///l02PPbcx8V1nKqDt4gyQ Date: Mon, 28 Nov 2016 05:37:34 +0000 Message-ID: <542CF652F8836A4AB8DBFAAD40ED192A4A2E9AAC@shsmsx102.ccr.corp.intel.com> References: <20161124205652.12113-1-lersek@redhat.com> <20161124205652.12113-3-lersek@redhat.com> In-Reply-To: <20161124205652.12113-3-lersek@redhat.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYTU5ZDA3MzQtNTcyNy00NzA4LWI0NmItMGFjMTEzN2VjZWE4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjcwWHlja0pmT1hzY2p4RDRvSlNFdTkzUUorcGlTSjBmenF3WEZSZmxxUkU9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 2/3] UefiCpuPkg/MpInitLib: wait no longer than necessary for initial AP startup X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Nov 2016 05:37:39 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Laszlo, Setting PcdCpuApInitTimeOutInMicroSeconds to infinity (marked with 0) is be= havior changing.=20 Even there is no any multi-processor supporting platform set this PCD to ze= ro, this PCD maybe set to 0 on single processor platform. I prefer to setting PcdCpuApInitTimeOutInMicroSeconds to 0xFFFFFFFF (about = 1.1 hour) for such purpose. Thanks! Jeff -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Lasz= lo Ersek Sent: Friday, November 25, 2016 4:57 AM To: edk2-devel-01 Cc: Kinney, Michael D; Fan, Jeff; Justen, Jordan L Subject: [edk2] [PATCH v2 2/3] UefiCpuPkg/MpInitLib: wait no longer than ne= cessary for initial AP startup Sometimes a platform knows exactly how many CPUs it has at boot. It should = be able to - set PcdCpuMaxLogicalProcessorNumber dynamically to this number, - set PcdCpuApInitTimeOutInMicroSeconds to infinity (marked with 0), - and expect that MpInitLib wait exactly as long as necessary for all APs to report in. Other platforms should be able to continue setting a reasonably large upper= bound on supported CPUs, and waiting for a reasonable, fixed amount of tim= e for all APs to report in. Add this functionality. The TimedWaitForApFinish() function will return whe= n all APs have reported in, or the timeout has expired -- whichever happens= first. (Accessing these PCDs dynamically is safe. The PEI and DXE phase instances = of this library are restricted to PEIM and DXE_DRIVER client modules, thus = the PCD accesses cannot be linked into runtime code.) Cc: Igor Mammedov Cc: Jeff Fan Cc: Jordan Justen Cc: Michael Kinney Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D116 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- UefiCpuPkg/UefiCpuPkg.dec | 3 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 67 +++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index ca= 560398bbef..8607ae8b7ae8 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -174,7 +174,8 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, = PcdsDynamicEx] # @Prompt Configure max supported number of Logical Processors gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64|UINT32|0x00= 000002 ## Specifies timeout value in microseconds for the BSP to detect all APs= for the first time. - # @Prompt Timeout for the BSP to detect all APs for the first time. + # When set to zero, the BSP will wait forever for all (PcdCpuMaxLogical= ProcessorNumber-1) APs to report in. + # @Prompt Timeout for the BSP to detect all APs for the first time (zero= means await maximum supported AP count). gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000|UINT32= |0x00000004 ## Specifies the base address of the first microcode Patch in the microc= ode Region. # @Prompt Microcode Region base address. diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 15dbfa1e7d6c..76de92fa552a 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -684,6 +684,22 @@ FillExchangeInfoData ( } =20 /** + Helper function that waits until the finished AP count reaches the=20 + specified limit, or the specified timeout elapses (whichever comes first= ). + + @param[in] CpuMpData Pointer to CPU MP Data. + @param[in] FinishedApLimit The number of finished APs to wait for. + @param[in] TimeLimit The number of microseconds to wait for. Zero + means infinity. +**/ +VOID +TimedWaitForApFinish ( + IN CPU_MP_DATA *CpuMpData, + IN UINT32 FinishedApLimit, + IN UINT32 TimeLimit + ); + +/** This function will be called by BSP to wakeup AP. =20 @param[in] CpuMpData Pointer to CPU MP Data @@ -748,7 +764,11 @@ WakeUpAP ( // // Wait for all potential APs waken up in one specified period // - MicroSecondDelay (PcdGet32(PcdCpuApInitTimeOutInMicroSeconds)); + TimedWaitForApFinish ( + CpuMpData, + PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1, + PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds) + ); } else { // // Wait all APs waken up if this is not the 1st broadcast of SIPI @@= -895,6 +915,51 @@ CheckTimeout ( } =20 /** + Helper function that waits until the finished AP count reaches the=20 + specified limit, or the specified timeout elapses (whichever comes first= ). + + @param[in] CpuMpData Pointer to CPU MP Data. + @param[in] FinishedApLimit The number of finished APs to wait for. + @param[in] TimeLimit The number of microseconds to wait for. Zero + means infinity. +**/ +VOID +TimedWaitForApFinish ( + IN CPU_MP_DATA *CpuMpData, + IN UINT32 FinishedApLimit, + IN UINT32 TimeLimit + ) +{ + CpuMpData->TotalTime =3D 0; + CpuMpData->ExpectedTime =3D CalculateTimeout ( + TimeLimit, + &CpuMpData->CurrentTime + ); + while (CpuMpData->FinishedCount < FinishedApLimit && + !CheckTimeout ( + &CpuMpData->CurrentTime, + &CpuMpData->TotalTime, + CpuMpData->ExpectedTime + )) { + CpuPause (); + } + + if (CpuMpData->FinishedCount >=3D FinishedApLimit) { + DEBUG (( + DEBUG_VERBOSE, + "%a: reached FinishedApLimit=3D%u in %Lu microseconds\n", + __FUNCTION__, + FinishedApLimit, + DivU64x64Remainder ( + MultU64x32 (CpuMpData->TotalTime, 1000000), + GetPerformanceCounterProperties (NULL, NULL), + NULL + ) + )); + } +} + +/** Reset an AP to Idle state. =20 Any task being executed by the AP will be aborted and the AP -- 2.9.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel