From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.1878.1687759446215637763 for ; Sun, 25 Jun 2023 23:04:06 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=kkyfbQoU; spf=pass (domain: intel.com, ip: 192.55.52.120, 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=1687759446; x=1719295446; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=EGnF2Gg+2smYf/SDeETOiW2q0wN4Y4C9Klpej8LILZk=; b=kkyfbQoUHUPCy5x/BzR/Yoa6lhuz+9P6vjOU+/F5fVln8x8ICqSi6KK4 G3aYHqiKmDZ1cbUNf3+fFxjIwkYEkAEeWIzhnPRwUSAIHvQmCQV0tgBrq 2otXX1ALMDiQ/MuTgWqmnNpQjh2pc4/Ao0d6ZlkfGmZrHeBPHLu6b9faG 9cSCk91gz/bc8DjaTek7OQVGWMD4arI4/4t1CQ3cGYXl92QdKyUngEp3n LipbvZRKLXvv5R13WWl5jeKPqJoyFfR+0IIEi3sIHKObBSSQ3bD+gL62u D+Luu78cbISwyK7B2qAj+Ws3NOy4V2BwWWAMbx9pBe4lHAQw5EVH97Kdi Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="360048568" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="360048568" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 23:04:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="719212766" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="719212766" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga007.fm.intel.com with ESMTP; 25 Jun 2023 23:04:05 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) 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 23:04:04 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Sun, 25 Jun 2023 23:04:04 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.172) by edgegateway.intel.com (134.134.137.103) 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 23:04:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kx9LLpZDQLk2qjHkYE0m+pfGENQ0112vgNv3kgstqB2kxwhWYb/CnXIIrqChIAsF5g7RbxlbdqeAHc4dNlfJW8uJgGvLa1Gfr+tsYaMyNlGOHI9nfaa1pv7JVkb/kcctfk+hdDzDPVUFjPAa32XVRJjZqH5TraR8bixiIukL9YNyzIRIqzGBtCY9kIvp0lZusfP6h7YwyjavG4LFodE1clwazH8LGLZEyX5u7CG3okXI7pZx5R2OFWuVPrDNo7IuLpPoRkAp/mkXOy/q+X9L3QA/1RwU7TB+vK/18jC6+VZkbrE7YB3U8Krv2eISuQp85Fmjl/WPHvXNFQowQKMoww== 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=qxNS/9XjQSevAAHyvcXMukpRq8zCivtybQQVayhmPgE=; b=NzD1qHq8mzabwBpE/4/tpBTubFUgcZys00kY7FbmRfHZFo2iJCiarDnMJDfaDaOpjUS4K+DkhXfpw6FyQJ/KzOjxhxCAJrO1Lg7ssVh9zzljtZTGYPEXRTFRH3AlePJBe/H1uW8MeL7rkr2ld8bZbhHK+FGIlWiVJ5wh0dtJe+2h/KZIpsEBzR5SXm28QC8lQvIw08b6a1aH7Q6J54Xja+6W3PBtPEe8JSmaHerfnlsItOIZNWc8mz2RqnX7RsSOcDs5Y91hOWprfGqORgAwsklbY7hn2SD7MJ3dPPCei5snMz4ScRqcLPiryaBztNnGERMOpu9C2TkDjdG5BrqlJA== 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 CO1PR11MB5026.namprd11.prod.outlook.com (2603:10b6:303:9c::13) by CH0PR11MB5562.namprd11.prod.outlook.com (2603:10b6:610:d5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Mon, 26 Jun 2023 06:03:56 +0000 Received: from CO1PR11MB5026.namprd11.prod.outlook.com ([fe80::95dc:1690:6fc8:790c]) by CO1PR11MB5026.namprd11.prod.outlook.com ([fe80::95dc:1690:6fc8:790c%7]) with mapi id 15.20.6521.023; Mon, 26 Jun 2023 06:03:56 +0000 From: "Yuanhao Xie" To: "Ni, Ray" CC: Gerd Hoffmann , "Dong, Eric" , "Kumar, Rahul R" , Tom Lendacky , "devel@edk2.groups.io" Subject: Re: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. Thread-Topic: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. Thread-Index: AQHZp3LuB/5gvKCgb0eFkvvLBfxwh6+caaIAgAAu88A= Date: Mon, 26 Jun 2023 06:03:56 +0000 Message-ID: References: <20230625143920.57095-1-yuanhao.xie@intel.com> <20230625143920.57095-7-yuanhao.xie@intel.com> In-Reply-To: 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: CO1PR11MB5026:EE_|CH0PR11MB5562:EE_ x-ms-office365-filtering-correlation-id: 0ff195bc-d8bd-4947-d889-08db760b205e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LE085ENQgkcoo4/yJ/SuYcBcP+vSvkLCqnRDnUsvxgBlKL+GCGCwfEwsWRyJlxdMPkLdSV/SgrWbrkd900O8TAxONAot9tOTeZ8s8ILmBLbhT48WScTXL/FVxB0CAuoAsVqrbsxwKCXLtwF8oxES9wisz5VgBLs1SmFTtZLewM7Ldst25ofLL5dCD6PhE0tI8TUhPYHkUExk5e3CFNbeHKeBX835nu5EOQNOCp3lfaDUYDvTsOWSRQNSwLip8UHKt27/pJo5U44NKrhTRQxEaks6NulcGisCwmr6hHdJVKwG/g3hi7+Ck21cvt5jIk6AU9R26hTXnWHvy+eB4n167X5zHEAuGCUcXxvKKjoE7VLRS5G1NjHhXwa8vdApjK+mvFNTrldERxZAkYlGd0VHdmII1cuGZ0Bugm4FsU5zJVw/yuoJ/oaosG145XJ0AP95D4VdaOLsSjzxGJWx5kyrTBxSIy3j822rY+QvcWcwbmB4fLkNnNg2+3Kq2oc0m4auRI42GUx+k7xICNhgrRXjzBMh3JLbWrJY5fh5/xoeibVzOhNpqUOkYcG2Lo0B57EeTCn/3/tl5dLazQwSqhXpv2EytVLYZIn2XsNxaC3RQn5v1feaJ4bN1itibgh5hPc2 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB5026.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(6029001)(376002)(346002)(136003)(396003)(39860400002)(366004)(451199021)(478600001)(71200400001)(83380400001)(54906003)(7696005)(53546011)(6506007)(26005)(9686003)(186003)(2906002)(30864003)(5660300002)(52536014)(33656002)(6862004)(38100700002)(122000001)(66946007)(82960400001)(55016003)(6636002)(8936002)(8676002)(316002)(86362001)(66476007)(66446008)(4326008)(66556008)(76116006)(41300700001)(38070700005)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?BxrN7YsUeh+JMPsPW6OBwhBS6TEGi042mLYL/Lry7D1Mt/pJcJMuueOXLQVO?= =?us-ascii?Q?PGo28y0z1XHeEYVbLu7vKn+mAggT9sQ/3pRQLSKnHgtf4G6VU9XfiV/a7KWO?= =?us-ascii?Q?JQu8YLLtvv7/cRFiMM6VAUh5DKXOs1WVhngfPQekB1UNhnkLXodICFeZFs9X?= =?us-ascii?Q?t7Y/3pRL/GjbbdHJu1v1D/flM6YCbD5HOw7UND4L76NMimR9zAXHI2jhGUw1?= =?us-ascii?Q?E7k2omRsvkMAKyJ9JnlOHQQETKW2pzw+xakIAf2uWimQFUeImR+utBIJEXUf?= =?us-ascii?Q?noJdxhxUzFUAazmf8JpV+x/QyL/TFpK+MkxBZWQDoR0/6ATJmRscrhMt6qkD?= =?us-ascii?Q?M8mThpHArungif6aqKTOdRAveO3zo/Hy7L0VOVVZdjhISccRwQa00i3ePO3a?= =?us-ascii?Q?DxN/V8Toy13rnQ25vBng5MLYSNj5GmppsK/QDB3YwbCna7qp9JFkr4QIDwwX?= =?us-ascii?Q?B46KaMxkyAC1cdLP1lS+mmKdHmlQA/UP94c7QQVMcbjvjPPWaPQac0QBL98h?= =?us-ascii?Q?0jFwEPhOl0L3LJDxR1xmjth2TxLYAemW8y22WiQkI1c280VdN+hpg7hOuRRT?= =?us-ascii?Q?jjIZsNDJoY01At8FYewGORv/S771NXo8PMlJzK5bqXpRoUoRsH7vZ6r1b3yz?= =?us-ascii?Q?hkh4a255ib442ObxWxZW97UHQvcj/jijOLs1mL55ZbF2QH9ObB8JCzSjHJr3?= =?us-ascii?Q?qYG7X3k9+Qi/F6rXl8D5RxA3i9v4Rz8QYzVH6gnfl92V3NofZHMW4yXvV2xa?= =?us-ascii?Q?ESbo41GseZ58i/l/y3QAZ+xDrE1J+WJrbl+KSXnSrvqM1lhTrAbg3cD9jzDg?= =?us-ascii?Q?0bjZcqFT26ejARWIA6yp6OF+eGvwQC7yqFUEFLoaMX6xPTwpvSJjhcVoNIBA?= =?us-ascii?Q?PXJeP4xm57AQUBhG16dF0ApyvPrlpu8W1THBPomROL2rRmyBCgWlBCTUHIBl?= =?us-ascii?Q?4NB354XjP+Np9GwOjwo2hV4O9CHPd3nawIYZzqtJjg2GquqyrNzL6+doDkr/?= =?us-ascii?Q?qHlq0COL+aj6QGPpumHV+hFJ4No9c49Kqw1rPsXUAM1W6axetF65VqVu3N7I?= =?us-ascii?Q?aDcwFkRkk86K4CAmXv0l/l9eIHTCdP0EENEKj93nkVNRgf+qzDcx76LMy9SE?= =?us-ascii?Q?Hy8Udk3JLf1TOE4pKZ6k1am6c33C4nG3SCOi2TlyY5KXHoW49we7iOOhhiAf?= =?us-ascii?Q?9QPFaCxhGRMYJIG9m/b1HWcZZatChuwVOzEwGKKmNBZxviFdQPt8elMsd+W+?= =?us-ascii?Q?KAOLNN+6R3a1tbKQst7rgaX3hTmLe7519IesUhG4msqNPxUW7U8WklKbn2ov?= =?us-ascii?Q?gAx+RrheeNKlaIjTYdhy30SfndA5KS0opX/4IPfBdqdArsHKqdMNhmfYTlKW?= =?us-ascii?Q?/uxs77twVqrsZETiMqWqSWcVVjZ08OUYB1jTI69fQSSdJ9z5DALjnROSR3BQ?= =?us-ascii?Q?m2r/lKzC5D5hzRetwv1JLpsR2jJMWUdE/F6Ilcx3xJCevu5k9cONMLqXsrCk?= =?us-ascii?Q?TgwZlaXEfEsWWakCDwAarKy0fOfAY1glP4xdfXvZE9GcjNQU02CpvlHTAzT5?= =?us-ascii?Q?Gn5l4KXcIDjiIHpd6HXoc9xdmCgr8LRe/3+KOp92?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB5026.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ff195bc-d8bd-4947-d889-08db760b205e X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jun 2023 06:03:56.2595 (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: JoGqcahmj8WC6wEBvr0X7e5KYDhIpjUKJDCnD4bNOdfFhWPfZljjL1ocSnv+uRVb28HEThb53FfQyR2s6WL/lA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5562 Return-Path: yuanhao.xie@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Ray, I will leave the enhance patch as the separated one and send it later on. Thanks for the feedback. Yuanhao -----Original Message----- From: Ni, Ray =20 Sent: Monday, June 26, 2023 11:14 AM To: Xie, Yuanhao ; devel@edk2.groups.io Cc: Gerd Hoffmann ; Dong, Eric ; Ku= mar, Rahul R ; Tom Lendacky Subject: RE: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. 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=20 > ; Ni, Ray ; Kumar, Rahul R=20 > ; Tom Lendacky ;=20 > Xie, Yuanhao > Subject: [Patch V2 6/6] UefiCpuPkg: Enhance MpHandOff Handling. >=20 > Enhance MpHandOff Handling for Systems with a Large Number of=20 > 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) -=20 > + sizeof > (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=20 > + *)(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=20 > (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) -= =20 > + 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=20 > + (MpHandOff- > >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=20 > + MpHandOff- > >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,=20 > sizeof (VOID *): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof=20 > (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=20 > + wake up the AP. The BSP accomplishes this by triggering a start-up=20 > + signal, which in turn causes any APs that are currently in a loop=20 > + on the PEI-prepared memory to awaken and begin running the=20 > + procedure called SwitchContextPerAp. > + This procedure allows the AP to switch to another section of =20 > + 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=20 > operation to 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)=20 > * > 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; =20 > + // // Maximum number of processor could be saved in the HOB. > + // > + LimitationOfMpHandOffHob =3D (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) -=20 > + sizeof > (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); > + ProcessedCpuCount =3D 0; > + while (ProcessedCpuCount < CpuMpData->CpuCount) { > + NumberOfProcessorsInCurrentHob =3D MIN ((UINT32)CpuMpData->CpuCount= =20 > + - > 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; > + =20 > + MpHandOff->Info[CurrentProcessorIndex].StartupProcedureAddress =3D > (UINT64)(UINTN)&CpuMpData->CpuData[Index].ApFunction; > + } > + } > + > + ProcessedCpuCount +=3D LimitationOfMpHandOffHob; > } >=20 > // > -- > 2.36.1.windows.1