From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11788.1687942151408549511 for ; Wed, 28 Jun 2023 01:49:12 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=H72EaIJY; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: yuanhao.xie@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687942151; x=1719478151; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t35vZGxhOUgBCiqBL1VEONDTF/UGF6xW16pRBMYG7o4=; b=H72EaIJYjaxiJ3A3djbQ3u+PPIgEW5N/EPIJnNxBP6RY3YF7zOqyfecC uj3g51hNBLZdh8M98ZbfcoNaI2wiwt8UDFKhbJuaUew098W/0kQaG73TZ gxOa/O50EFhxihc3ws+v+lebolZTDs/Hx5TGcXFgtG7YI34tMQDbFYNTi pVcpZq/HrcchHdytfdCkWJOTa/MOPSrxbwP0G1TzjXUd7MZ2LoI68Vf1O hPcwfyMUARiyfgiAVmKc5ZT6ZpHPFGobm1UYOZaogWQBQVkFfxEREdBsG YHE55Fz5FV61mzh2DrD6/aflFqcDD4lU6rxIrw+IaZSAqsoRiDwsxFxk4 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="341373528" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="341373528" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="890964578" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="890964578" Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:53 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [Patch V4 2/5] UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop. Date: Wed, 28 Jun 2023 16:47:21 +0800 Message-Id: <20230628084724.57574-3-yuanhao.xie@intel.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Refactor the logic for placing APs in Mwait/Runloop into a separate function. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index 9560b39220..e8dd640f9b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -658,6 +658,54 @@ PlaceAPInHltLoop ( } } +/** + This function place APs in Mwait or Run loop. + + @param[in] ApLoopMode Ap Loop Mode + @param[in] ApStartupSignalBuffer Pointer to Ap Startup Signal Buffer + @param[in] ApTargetCState Ap Target CState +**/ +VOID +PlaceAPInMwaitLoopOrRunLoop ( + IN UINT8 ApLoopMode, + IN volatile UINT32 *ApStartupSignalBuffer, + IN UINT8 ApTargetCState + ) +{ + while (TRUE) { + DisableInterrupts (); + if (ApLoopMode == ApInMwaitLoop) { + // + // Place AP in MWAIT-loop + // + AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); + if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) { + // + // Check AP start-up signal again. + // If AP start-up signal is not set, place AP into + // the specified C-state + // + AsmMwait (ApTargetCState << 4, 0); + } + } else if (ApLoopMode == ApInRunLoop) { + // + // Place AP in Run-loop + // + CpuPause (); + } else { + ASSERT (FALSE); + } + + // + // If AP start-up signal is written, AP is waken up + // otherwise place AP in loop again + // + if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) { + break; + } + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. @@ -838,39 +886,8 @@ ApWakeupFunction ( // // Never run here // - } - - while (TRUE) { - DisableInterrupts (); - if (CpuMpData->ApLoopMode == ApInMwaitLoop) { - // - // Place AP in MWAIT-loop - // - AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); - if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) { - // - // Check AP start-up signal again. - // If AP start-up signal is not set, place AP into - // the specified C-state - // - AsmMwait (CpuMpData->ApTargetCState << 4, 0); - } - } else if (CpuMpData->ApLoopMode == ApInRunLoop) { - // - // Place AP in Run-loop - // - CpuPause (); - } else { - ASSERT (FALSE); - } - - // - // If AP start-up signal is written, AP is waken up - // otherwise place AP in loop again - // - if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) { - break; - } + } else { + PlaceAPInMwaitLoopOrRunLoop (CpuMpData->ApLoopMode, ApStartupSignalBuffer, CpuMpData->ApTargetCState); } } } -- 2.36.1.windows.1