From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.164.1687749271513973121 for ; Sun, 25 Jun 2023 20:14:31 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=NnE8dwZZ; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687749271; x=1719285271; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=mhA5Nb5g8bfbvvYBF3eVm7rVRQSvjWzubFnH51aIR7k=; b=NnE8dwZZDB8EgwpTZPPtAJmRTYDzOhhfnKFOrsEm2o8UCTYnMpYTTY9V hEJW8zy7eWJ97Tf+Np02WaWksS0jc9zwJI5AuFaaDZLn8lgiyGIdr9I8d BeCt0BnrtA6UOc3vu6+AFA8mC3Nnc5i6Qt11iNxg08Mth9Y+kltCxVWka 8MQJ++/tnDNc7+daVHbbe7nj5taNBVJXbSVLMrjXWjYozrQ1Ep1fUb0Wu JS3TQijFCC4ekmagO+SJ/Woj4L4aL4guoqX0NEuAUkoHJL5o3AGYlkimf SdjmnrNs3tH2PAxwAineKjvv2fFeTmlZH3SDch/D+dDB5H9/G4s3+YxNx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="361198072" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="361198072" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 20:14:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="666140076" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="666140076" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga003.jf.intel.com with ESMTP; 25 Jun 2023 20:14:28 -0700 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sun, 25 Jun 2023 20:14:27 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Sun, 25 Jun 2023 20:14:27 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Sun, 25 Jun 2023 20:14:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MiW/HpEYrt3Eddx0uIfIOOM3lZXAnXWlYsy9/MLBIymNtijcj+dPVRi0/9bIieY+i52yq6Z6xa2DT6Io5JNkF/sDy9DdiS5SLIdvbEGPI356/7MdwwgR9/8pw8WeqURl2myGn5dev/5ybGucQqYnLMD1MB3ILYyADtuMtF6VQzchO7LXQntYrtUA0e0wSdBHwvgd/rsAZNF17zolhGlMC8Pk1FwW2I80JPMS50xZxFtJlsqOyQwLD1SgpbFmye/Qtg05FDl6QP1nWd7spZ7v8QUZRfnIBC6luBoSjGmJWDs0+XWeZpigw4NGSL+10DirsQfjhBrH2Q38m6x4THAqjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=P942/IdzNLZGd/Kk0YukCb5b7SgSZQYbEehbJQclVHc=; b=YcvFWhCNUrbLaAVL1A7xTeQmpcMH/q78YxhhoKRo4o1G00kZg/brQuvf70XEog4wjCVxW/vYnHyu488vUSUV/tDLxWuHUR4/1tnw9FkdlYxQHOxCAME4E78uInPBv25lw/YwdLfHMtJsZq9Gy25IaVuF6kKS0y+M9vdOCuhCwscgqcPCBa8Yi948KgNwq7z8E1bioUczaRXjR+KtKBptjGosogWentV1EQCGizIiw08zerbyPfRVieYe8yQ1hWG1x2UlUSuwxFI6BPh8JIKC1dKa2eB0gpaEaEbgYRsvTBaHh/7wxzMxoJeEU+oClcEerwbumtfpebL+aPKEHSeXNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by DS0PR11MB8232.namprd11.prod.outlook.com (2603:10b6:8:15d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Mon, 26 Jun 2023 03:14:07 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%2]) with mapi id 15.20.6521.023; Mon, 26 Jun 2023 03:14:07 +0000 From: "Ni, Ray" To: "Xie, Yuanhao" , "devel@edk2.groups.io" CC: Gerd Hoffmann , "Dong, Eric" , "Kumar, Rahul R" , Tom Lendacky Subject: Re: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. Thread-Topic: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. Thread-Index: AQHZp3Lumf6ccrYrZ0G2RmIh0jyc4q+caDzg Date: Mon, 26 Jun 2023 03:14:06 +0000 Message-ID: References: <20230625143920.57095-1-yuanhao.xie@intel.com> <20230625143920.57095-7-yuanhao.xie@intel.com> In-Reply-To: <20230625143920.57095-7-yuanhao.xie@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|DS0PR11MB8232:EE_ x-ms-office365-filtering-correlation-id: 06c4c29f-b6c0-4ff8-cffa-08db75f36711 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7pC/je91sKWUXILLnDlg0pv53GwlREfdEv1WECLiOWhvIaMK9cXIKvRP3AK/npncoKho3nG2OZVGYUCphk7a2b5vxpcQ68mTbhgwMrxIHwySoNbehaZwxe7KqqGbNdAQntmeBOCcGdU092erfvez2yJ4nxGdFEg4rh/tTBZviFlbkbZxZW2fqd3Bq1n7SB8tyUuZ1W+F05jaYQaYkOG0EYteRZB3mV2potnPbAzBkrvXRxPINOpCcTbvRC8tjfPp9QT7F5asT9t6VOAYSNpamigF9t7GMQRSNQjoOAy2LUaqlOqU/u6Zc5WkV/AgaG4Qo9hlhro4uDpbG7nYZp1jwGNpCXiA0XQOIHYdLmGYqJgYjciGuaLIwWHRFMOceyDgNaPomKeC7jjXqbVJjzRaG+WK6XGErRft0oSAlxl+oz9PFvfl67U7nj/40h/3Di1h+5tCexfA/T7cQ0RKYZm9RyXI7gsXYYMthTo4ps1k1EszS1UekyraNl274K7xitTNK2cw7eGy3IPQySX4QfGIqTvnmd3x8mg3NHoaNd9YKwa30I2ciIuhvPqb8a7e2mClVkS+c877hZUMHHNrlZlrUeDmfnsyggZfKnlugRT1Z4Z/7SaDMlMfZIhpTIYFOrwg x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(6029001)(346002)(396003)(39860400002)(136003)(376002)(366004)(451199021)(7696005)(110136005)(54906003)(478600001)(83380400001)(55016003)(38070700005)(82960400001)(86362001)(66476007)(66446008)(64756008)(33656002)(53546011)(186003)(26005)(30864003)(6506007)(2906002)(71200400001)(9686003)(122000001)(76116006)(4326008)(316002)(66556008)(66946007)(5660300002)(38100700002)(8936002)(52536014)(8676002)(41300700001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?h1kiaCR8ZVzUMTphE39vcI6CGvbLkH6nM4brg3qxXrVM/6lqmxfgayW+L9D5?= =?us-ascii?Q?MeBLG54tkj67kPMOBJO+Xy7QHqNXnNEHrq0P7WAgDx12NwUVmUT08CzkHRUU?= =?us-ascii?Q?tN4CmyKCAS6bLm6imY7OZI5UNaWHFYG1GTj4E65PMwEYex8q0P5L3BHIPECV?= =?us-ascii?Q?ghyxbipAXGFoYzdJvu5G3ESV6wfOFiv8YOEO4fIqcUwqUZnPKU047MNcr4LV?= =?us-ascii?Q?OgIdfmds3gO8gh6FndoNhsmN93tpbvJAo9bbx6iHpoNal1K3LGtgtnUnbreU?= =?us-ascii?Q?YDhRBcU/knXSyjzfwJuW3ThaJ/eHAnXLbUvaKv5duy+0CnABrl+t+L7Jwgpo?= =?us-ascii?Q?HI7ET6vqInbtSG/x7LdySu5PRoT2oDkI43y0VFECV6wF/HiKCS4KGG6g0qmQ?= =?us-ascii?Q?D6sdkgDA7ouaWNlMyN1+oq8siYnzxaJVP6qTyw8EVqGWwckuVKL/+4hfPtCm?= =?us-ascii?Q?G9IfxfUXyhZUFFuKQK0TgPjwANH2GppeApe+iNHAZPNFRNme0IWU0P5tljHY?= =?us-ascii?Q?oa3Tg+7E9euuYr61SLsPuXHCfiTdr/LBdWpAKdfmbDmt2UWUwo0YaB+26cj6?= =?us-ascii?Q?9qv0pfdo7FwJmqLK+Emyt64KlHtclKGJCKSpHSm5dGhO4lqzn2uopOiXqSCW?= =?us-ascii?Q?UCcCX9fE9kIH8XsOO2bsT4zTv2ynpFSBmrmM4X1TLXoGNmiJ8DX0b0F2o20Z?= =?us-ascii?Q?v2cByBS5edLTwdan/7Hi7BV127QEtwkRhJS/ws0JEjbsmtP9mKFR7PGYzyCA?= =?us-ascii?Q?uDHF2C8NMmMXeFgoY2w0WuBlNB7VCO3+4bHbR1TnPt4g2HX9dYY2cnCSQupN?= =?us-ascii?Q?xZW2FClLpVpFNQ0mqmU3AxDr+/r6PwCXHHlHE5IRBeaXf9a82zJ5yWA3jKpZ?= =?us-ascii?Q?BCdU9wFtmWanm5Rs0g6OYKf6CuzUV1I8891BMQsTpRlIEYsy17qHvFTbnL8J?= =?us-ascii?Q?YGDZRYumT3GF7SH6Fp7yZ0dFseNFnb+kLiGKqkkjuClZTaueYaQ2APiKZZHS?= =?us-ascii?Q?X0rIG5PCgvJzne7WFztw00cOxoex5xPZzcNie7P2TtQmZpCeeCpW58KSaxQa?= =?us-ascii?Q?KBWw8RE5tZk6nH6XgaQOhCO4U5ELCKmzt/4f9lvZR5nohT630+L1+ppzq4DB?= =?us-ascii?Q?VeFvUSRaZJjcq9uaIehHkEk9CRV8n/PSono625WJjXTgqQvQljbT8TwQrJn7?= =?us-ascii?Q?aq+TU2Sl5QLqwrWZWJ5MW1iuL9CuK4iwDtupKZYEvxWKE+sWv4IYuRrWehoK?= =?us-ascii?Q?nxArIhoCNoOJsvyUHiBxfcPy/TL8f5kpYWg0KMh7BulJB94aj9y8ZpLsaAwJ?= =?us-ascii?Q?9Nsq3Ij3TSZvT+44+ecEPr/pm2Uk2BJIXkSQvNNPINkNAg8vFnj0JD2vat4M?= =?us-ascii?Q?gkeqcx+DIlsPgrBkKNLXBmzhAOSnRIifokaLlkRBQArRA9a+42myHWxB8e10?= =?us-ascii?Q?UQmGs/SXHapwSZx7417mwTEg5IcKy3R71uZ5vtzIBiu0e4Rs2ex7rWa7t+bS?= =?us-ascii?Q?+lZ6GU9CsHmHJkKEnd6nia9PGWrSuRn/VhIKjCDIICPVGnBCAICg9RamX5cT?= =?us-ascii?Q?PFx2eKosR0H7lE4WAAE=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06c4c29f-b6c0-4ff8-cffa-08db75f36711 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jun 2023 03:14:06.9637 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +uFQm7G8h/hZgaqpqueIAWWO/7jlNd8p7iQ972yUzv6oBlSOH0YBaU5AAS4rV1GfG8JCYSkTUXGXgLK0FlIsRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB8232 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Yuanhao, I suggest we "attack" this "large number of processors" problem in a separa= te patch series. There are several things that need to consider: * Calculate maximum number of processor info within one MP_HAND_OFF hob * Consumer code should not assume there is only one MP_HAND_OFF hob * Consumer code should not assume the MP_HAND_OFF hobs are ordered by MP_HA= ND_OFF.ProcessorIndex * Consumer code should report error if there is gap (some processors are no= t covered by any MP_HAND_OFF hob) * Consumer code should consider to cache the MP_HAND_OFF hobs for performan= ce (iterate the hob list as less as possible) For this patch series, you could add code to cover following: * producer code asserts that the total cpu count can be described by one MP= _HAND_OFF hob * consumer code asserts that there is only one MP_HAND_OFF hob instance and= this one's ProcessorIndex is 0. Thanks, Ray > -----Original Message----- > From: Xie, Yuanhao > Sent: Sunday, June 25, 2023 10:39 PM > To: devel@edk2.groups.io > Cc: Gerd Hoffmann ; Dong, Eric ; = Ni, > Ray ; Kumar, Rahul R ; Tom > Lendacky ; Xie, Yuanhao > > Subject: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. >=20 > Enhance MpHandOff Handling for Systems with a Large Number of > Processors. >=20 > 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 | 128 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++------------------------------------------------------------ > UefiCpuPkg/Library/MpInitLib/MpLib.h | 22 +++++++++------------- > UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 56 > +++++++++++++++++++++++++++++++++++++++----------------- > 3 files changed, 116 insertions(+), 90 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c > b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 391e6f19ef..087bf3ea92 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -1528,32 +1528,48 @@ SwitchContextPerAp ( > This procedure allows the AP to switch to another section of > memory and continue its loop there. >=20 > - @param[in] MpHandOff Pointer to MP hand-off data structure. > + @param[in] BspNumber Bsp Number > **/ > VOID > SwitchApContext ( > - IN MP_HAND_OFF *MpHandOff > + IN UINT32 BspNumber > ) > { > - UINTN Index; > - UINT32 BspNumber; > - > - BspNumber =3D GetBspNumber (MpHandOff); > + UINTN Index; > + UINTN LimitationOfMpHandOffHob; > + UINTN NumberOfProcessorsInCurrentHob; > + UINTN CpuCountInCurrentHob; > + MP_HAND_OFF *MpHandOff; > + BOOLEAN BspFound; > + > + BspFound =3D FALSE; > + > + MpHandOff =3D GetMpHandOffHob (); > + CpuCountInCurrentHob =3D 0; > + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - si= zeof > (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); > + while (CpuCountInCurrentHob < MpHandOff->CpuCount) { > + // > + // Get the processor number for the BSP > + // > + NumberOfProcessorsInCurrentHob =3D MIN (MpHandOff->CpuCount - > CpuCountInCurrentHob, LimitationOfMpHandOffHob); >=20 > - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { > - if (Index !=3D BspNumber) { > - *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = =3D > (UINTN)SwitchContextPerAp; > - *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress = =3D > MpHandOff->StartupSignalValue; > + for (Index =3D 0; Index < NumberOfProcessorsInCurrentHob; Index++) { > + if ((Index =3D=3D BspNumber) && (BspFound =3D=3D FALSE)) { > + BspFound =3D TRUE; > + } else { > + *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = =3D > (UINTN)SwitchContextPerAp; > + *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress = =3D > MpHandOff->StartupSignalValue; > + WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff- > >Info[Index].StartupSignalAddress)); > + } > } > - } >=20 > - // > - // Wait all APs waken up if this is not the 1st broadcast of SIPI > - // > - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { > - if (Index !=3D BspNumber) { > - WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff- > >Info[Index].StartupSignalAddress)); > + if (CpuCountInCurrentHob + NumberOfProcessorsInCurrentHob >=3D > MpHandOff->CpuCount) { > + break; > } > + > + MpHandOff =3D (MP_HAND_OFF *)((UINT8 *)MpHandOff + sizeof > (MP_HAND_OFF) + sizeof (EFI_HOB_GUID_TYPE) + sizeof > (PROCESSOR_HAND_OFF) * NumberOfProcessorsInCurrentHob); > + > + CpuCountInCurrentHob +=3D NumberOfProcessorsInCurrentHob; > } > } >=20 > @@ -1909,37 +1925,6 @@ CheckAllAPs ( > return EFI_NOT_READY; > } >=20 > -/** > - This function Get BspNumber. > - > - @param[in] MpHandOff Pointer to MpHandOff > - @return BspNumber > -**/ > -UINT32 > -GetBspNumber ( > - IN CONST MP_HAND_OFF *MpHandOff > - ) > -{ > - UINT32 ApicId; > - UINT32 BspNumber; > - UINT32 Index; > - > - // > - // Get the processor number for the BSP > - // > - BspNumber =3D MAX_UINT32; > - ApicId =3D GetInitialApicId (); > - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { > - if (MpHandOff->Info[Index].ApicId =3D=3D ApicId) { > - BspNumber =3D Index; > - } > - } > - > - ASSERT (BspNumber !=3D MAX_UINT32); > - > - return BspNumber; > -} > - > /** > Get pointer to CPU MP Data structure from GUIDed HOB. >=20 > @@ -1994,8 +1979,13 @@ MpInitLibInitialize ( > UINTN ApResetVectorSizeAbove1Mb; > UINTN BackupBufferAddr; > UINTN ApIdtBase; > + UINTN LimitationOfMpHandOffHob; > + UINTN NumberOfProcessorsInCurrentHob; > + UINTN ProcessedCpuCount; > + UINTN CurrentProcessorIndex; >=20 > MpHandOff =3D GetMpHandOffHob (); > + > if (MpHandOff =3D=3D NULL) { > MaxLogicalProcessorNumber =3D PcdGet32 > (PcdCpuMaxLogicalProcessorNumber); > } else { > @@ -2156,17 +2146,35 @@ MpInitLibInitialize ( > // from HOB > // > AmdSevUpdateCpuMpData (CpuMpData); > - CpuMpData->CpuCount =3D MpHandOff->CpuCount; > - CpuMpData->BspNumber =3D GetBspNumber (MpHandOff); > - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData- > >CpuInfoInHob; > - for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { > - InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock); > - CpuMpData->CpuData[Index].CpuHealthy =3D (MpHandOff->Info[Index].H= ealth > =3D=3D 0) ? TRUE : FALSE; > - CpuMpData->CpuData[Index].ApFunction =3D 0; > - CpuInfoInHob[Index].InitialApicId =3D MpHandOff->Info[Index].Ap= icId; > - CpuInfoInHob[Index].ApTopOfStack =3D CpuMpData->Buffer + (Inde= x + 1) * > CpuMpData->CpuApStackSize; > - CpuInfoInHob[Index].ApicId =3D MpHandOff->Info[Index].Ap= icId; > - CpuInfoInHob[Index].Health =3D MpHandOff->Info[Index].He= alth; > + CpuMpData->CpuCount =3D MpHandOff->CpuCount; > + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData- > >CpuInfoInHob; > + > + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - = sizeof > (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); > + ProcessedCpuCount =3D 0; > + while (ProcessedCpuCount < MpHandOff->CpuCount) { > + NumberOfProcessorsInCurrentHob =3D MIN (MpHandOff->CpuCount - > ProcessedCpuCount, LimitationOfMpHandOffHob); > + > + for (Index =3D 0; Index < NumberOfProcessorsInCurrentHob; Index++)= { > + CurrentProcessorIndex =3D Index+MpHandOff->ProcessorIndex; > + if (MpHandOff->Info[Index].ApicId =3D=3D GetInitialApicId ()) { > + CpuMpData->BspNumber =3D (UINT32)Index; > + } > + > + InitializeSpinLock (&CpuMpData- > >CpuData[CurrentProcessorIndex].ApLock); > + CpuMpData->CpuData[CurrentProcessorIndex].CpuHealthy =3D (MpHand= Off- > >Info[Index].Health =3D=3D 0) ? TRUE : FALSE; > + CpuMpData->CpuData[CurrentProcessorIndex].ApFunction =3D 0; > + CpuInfoInHob[CurrentProcessorIndex].InitialApicId =3D MpHandO= ff- > >Info[Index].ApicId; > + CpuInfoInHob[CurrentProcessorIndex].ApTopOfStack =3D CpuMpDa= ta- > >Buffer + (Index + 1) * CpuMpData->CpuApStackSize; > + CpuInfoInHob[CurrentProcessorIndex].ApicId =3D MpHandO= ff- > >Info[Index].ApicId; > + CpuInfoInHob[CurrentProcessorIndex].Health =3D MpHandO= ff- > >Info[Index].Health; > + } > + > + if (ProcessedCpuCount+NumberOfProcessorsInCurrentHob >=3D MpHandOf= f- > >CpuCount) { > + break; > + } > + > + MpHandOff =3D (MP_HAND_OFF *)((UINT8 *)MpHandOff + sizeof > (MP_HAND_OFF) + sizeof (EFI_HOB_GUID_TYPE) + sizeof > (PROCESSOR_HAND_OFF) * NumberOfProcessorsInCurrentHob); > + ProcessedCpuCount +=3D NumberOfProcessorsInCurrentHob; > } >=20 > DEBUG ((DEBUG_INFO, "MpHandOff->WaitLoopExecutionMode: %04d, sizeof > (VOID *): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof (VOID *))); > @@ -2183,7 +2191,7 @@ MpInitLibInitialize ( > CpuMpData->FinishedCount =3D 0; > CpuMpData->InitFlag =3D ApInitDone; > SaveCpuMpData (CpuMpData); > - SwitchApContext (MpHandOff); > + SwitchApContext (CpuMpData->BspNumber); > ASSERT (CpuMpData->FinishedCount =3D=3D (CpuMpData->CpuCount - 1))= ; >=20 > // > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h > b/UefiCpuPkg/Library/MpInitLib/MpLib.h > index 468d3a5925..6af635a80c 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h > @@ -497,17 +497,6 @@ SaveCpuMpData ( > IN CPU_MP_DATA *CpuMpData > ); >=20 > -/** > - This function Get BspNumber. > - > - @param[in] MpHandOff Pointer to MpHandOff > - @return BspNumber > -**/ > -UINT32 > -GetBspNumber ( > - IN CONST MP_HAND_OFF *MpHandOff > - ); > - > /** > Get available system memory below 1MB by specified size. >=20 > @@ -522,12 +511,19 @@ GetWakeupBuffer ( > ); >=20 > /** > - Switch Context for each AP. > + This function is intended to be invoked by the BSP in order > + to wake up the AP. The BSP accomplishes this by triggering a > + start-up signal, which in turn causes any APs that are > + currently in a loop on the PEI-prepared memory to awaken and > + begin running the procedure called SwitchContextPerAp. > + This procedure allows the AP to switch to another section of > + memory and continue its loop there. >=20 > + @param[in] BspNumber Bsp Number > **/ > VOID > SwitchApContext ( > - IN MP_HAND_OFF *MpHandOff > + IN UINT32 BspNumber > ); >=20 > /** > diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > index f80e00edcf..18f83d9ed5 100644 > --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c > @@ -131,31 +131,53 @@ SaveCpuMpData ( > CPU_INFO_IN_HOB *CpuInfoInHob; > MP_HAND_OFF *MpHandOff; > UINTN MpHandOffSize; > + UINT32 LimitationOfMpHandOffHob; > + UINT32 NumberOfProcessorsInCurrentHob; > + UINT32 ProcessedCpuCount; > + UINTN CurrentProcessorIndex; >=20 > // > // When APs are in a state that can be waken up by a store operation t= o a > memory address, > // report the MP_HAND_OFF data for DXE to use. > // > - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; > - MpHandOffSize =3D sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * > CpuMpData->CpuCount; > - MpHandOff =3D (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, > MpHandOffSize); > - ASSERT (MpHandOff !=3D NULL); > - ZeroMem (MpHandOff, MpHandOffSize); > - MpHandOff->ProcessorIndex =3D 0; > - > - MpHandOff->CpuCount =3D CpuMpData->CpuCount; > - if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { > - MpHandOff->StartupSignalValue =3D MP_HAND_OFF_SIGNAL; > - MpHandOff->WaitLoopExecutionMode =3D sizeof (VOID *); > - } > + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; > + // > + // Maximum number of processor could be saved in the HOB. > + // > + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - si= zeof > (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); > + ProcessedCpuCount =3D 0; > + while (ProcessedCpuCount < CpuMpData->CpuCount) { > + NumberOfProcessorsInCurrentHob =3D MIN ((UINT32)CpuMpData->CpuCount = - > ProcessedCpuCount, LimitationOfMpHandOffHob); > + MpHandOffSize =3D sizeof (MP_HAND_OFF) + sizeof > (PROCESSOR_HAND_OFF) * NumberOfProcessorsInCurrentHob; > + MpHandOff =3D (MP_HAND_OFF *)BuildGuidHob ( > + &mMpHandOffGuid, > + MpHandOffSize > + ); > + ASSERT (MpHandOff !=3D NULL); > + ZeroMem (MpHandOff, MpHandOffSize); > + // > + // Each individual processor can be uniquely identified by > + // combining the processorIndex with the mMpHandOffGuid. > + // > + MpHandOff->ProcessorIndex =3D ProcessedCpuCount; > + MpHandOff->CpuCount =3D CpuMpData->CpuCount; >=20 > - for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { > - MpHandOff->Info[Index].ApicId =3D CpuInfoInHob[Index].ApicId; > - MpHandOff->Info[Index].Health =3D CpuInfoInHob[Index].Health; > if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { > - MpHandOff->Info[Index].StartupSignalAddress =3D > (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal; > - MpHandOff->Info[Index].StartupProcedureAddress =3D > (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction; > + MpHandOff->StartupSignalValue =3D MP_HAND_OFF_SIGNAL; > + MpHandOff->WaitLoopExecutionMode =3D sizeof (VOID *); > } > + > + for (Index =3D MpHandOff->ProcessorIndex; Index < > NumberOfProcessorsInCurrentHob + MpHandOff->ProcessorIndex; Index++) { > + CurrentProcessorIndex =3D Index-MpHandOff-= >ProcessorIndex; > + MpHandOff->Info[CurrentProcessorIndex].ApicId =3D > CpuInfoInHob[Index].ApicId; > + MpHandOff->Info[CurrentProcessorIndex].Health =3D > CpuInfoInHob[Index].Health; > + if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { > + MpHandOff->Info[CurrentProcessorIndex].StartupSignalAddress = =3D > (UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal; > + MpHandOff->Info[CurrentProcessorIndex].StartupProcedureAddress = =3D > (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction; > + } > + } > + > + ProcessedCpuCount +=3D LimitationOfMpHandOffHob; > } >=20 > // > -- > 2.36.1.windows.1