From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.58885.1686577140495656780 for ; Mon, 12 Jun 2023 06:39:00 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=mzWJDQGc; spf=pass (domain: intel.com, ip: 192.55.52.151, 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=1686577140; x=1718113140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fOwKFstaLTuC//PPgjFyoWJ3bk+szi/HMvBSVBUkrsE=; b=mzWJDQGcaYuBdmcwuJpzr+FVkgRdRBODDAG/GaVoMFQv8iRNU5PnpHDv xpKHsPphEulh6fhE2MhK7/aZDSm77uuUSlKpq/U62DUcLlrRUdYSpAnmA aMGNiUyFw1yVqEXOixo3XOoD35I995t654ocW0yE1LFS8rUTSZvP83buZ CCyw7TxDojrBLT/dxU51tuzZGlVF2nVL8M4wDdTI2H+LRSnrXAsiPEno/ cYf0iC74lFKZeJ/HrQbIkHex0fsyKR1oByM4E+H+Ca9Fz+DkxTn1jrA1g 2Wqt7VUIOjFjnWGuM/Kl7NJh3I+yngBIYDrYn+l2l8ktnVVEI/wuTyUL7 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="338400664" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="338400664" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 06:37:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="958033011" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="958033011" Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 06:37:51 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Yuanhao Xie Subject: [PATCH 3/5] UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop. Date: Mon, 12 Jun 2023 21:37:18 +0800 Message-Id: <20230612133720.15501-4-yuanhao.xie@intel.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20230612133720.15501-1-yuanhao.xie@intel.com> References: <20230612133720.15501-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: Eric Dong Cc: Ray Ni Cc: Rahul Kumar 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 4e517a9b19..8aecd29a94 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -659,6 +659,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) && (*ApStartupSignalBuffer != MP_HAND_OFF_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) || (*ApStartupSignalBuffer == MP_HAND_OFF_SIGNAL)) { + break; + } + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. @@ -839,39 +887,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