From nobody Tue Feb 10 10:59:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106461+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106461+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687942153; cv=none; d=zohomail.com; s=zohoarc; b=QV6OVDvdilSeRlbeN4xJLzTPQb7AsLYT1k3yvvgx13SUhM/jWKU7dJzdWsJzBY8Bx1pvllaCgnujeNCSvHPAeMRb2DyeUrX8T8zGTfBkykqs8Kpi3Nc+Sqoh2W4s9KGsG/KLRB9ERAG3fMkM4Eu+zEubHM6y6QWsGdtKLEndk6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687942153; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wRem3iD7grm/VbnfLYVcIBrDJADVtfX0f+LEeFVofeM=; b=GZHR9kDU9NycB+UzgnQOhIEtY9C2FCwv4TNu7HlP7tTilEeZei16iRDB4UHqN4oCdGkxSNbw992y4XQI9hz4dkBpIMlXFP8OWCcwfK+X0VWjERjwze3P7OHOQI4cMHs5wBEn5fslYtiv68krIqnSNitHXb/+6Iicv1SfYOSjgB4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106461+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687942153761295.54348751326734; Wed, 28 Jun 2023 01:49:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dr6nYY1788612xynzo1YPizU; Wed, 28 Jun 2023 01:49:13 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com X-Gm-Message-State: vjvoNBd5culJZANsAuKMTYwjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687942153; bh=bzNE+z/b/ce2VxmPBS/L32TQdcuMirn9zziziBmlcmY=; h=Cc:Date:From:Reply-To:Subject:To; b=sBx71miZc5ol4QFnRC4Ha8muKOy/GYcXbGWjegCyr/NJlw9agQ73/kdWAH83VW8OiMQ xkzhdX+wm5KnmL5GT5vcUUe1qG6xSPJd2NY8TfpLW8O+E9FkTGvsg/UlhxxuddTrWPQOD b5NuEw1b3DM/rC+wWhon/2ligQwVylB5PR8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687942155719100019 Content-Type: text/plain; charset="utf-8" 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/MpIn= itLib/MpLib.c index 9560b39220..e8dd640f9b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -658,6 +658,54 @@ PlaceAPInHltLoop ( } } =20 +/** + This function place APs in Mwait or Run loop. + + @param[in] ApLoopMode Ap Loop Mode + @param[in] ApStartupSignalBuffer Pointer to Ap Startup Signal Buf= fer + @param[in] ApTargetCState Ap Target CState +**/ +VOID +PlaceAPInMwaitLoopOrRunLoop ( + IN UINT8 ApLoopMode, + IN volatile UINT32 *ApStartupSignalBuffer, + IN UINT8 ApTargetCState + ) +{ + while (TRUE) { + DisableInterrupts (); + if (ApLoopMode =3D=3D ApInMwaitLoop) { + // + // Place AP in MWAIT-loop + // + AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); + if (*ApStartupSignalBuffer !=3D 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 =3D=3D 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 =3D=3D WAKEUP_AP_SIGNAL) { + break; + } + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -838,39 +886,8 @@ ApWakeupFunction ( // // Never run here // - } - - while (TRUE) { - DisableInterrupts (); - if (CpuMpData->ApLoopMode =3D=3D ApInMwaitLoop) { - // - // Place AP in MWAIT-loop - // - AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); - if (*ApStartupSignalBuffer !=3D 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 =3D=3D 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 =3D=3D WAKEUP_AP_SIGNAL) { - break; - } + } else { + PlaceAPInMwaitLoopOrRunLoop (CpuMpData->ApLoopMode, ApStartupSignalB= uffer, CpuMpData->ApTargetCState); } } } --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106461): https://edk2.groups.io/g/devel/message/106461 Mute This Topic: https://groups.io/mt/99826556/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-