From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.49]) by mx.groups.io with SMTP id smtpd.web10.7787.1634367273328605186 for ; Fri, 15 Oct 2021 23:54:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=KRT8qdBf; spf=pass (domain: arm.com, ip: 40.107.20.49, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oNADv+77cunczFEA8kz7fdgu0GfuM4vyoKVxBexw+Jc=; b=KRT8qdBf318yik3Lq+1eV4QyQkCqGpH4RxwkVUfFDYccc0fIGTpUkCKgn6FL8+Ejwke8sLK630CQg1qXcK5Uz1GKWU+9FDhVL4RVd7yMqfoF7B6FpyLSbYYDX59KxVyNnDLu8n1oqluTjSztlaqrICCAh1IvS/lheXrBNtdNjd0= Received: from AS9PR06CA0213.eurprd06.prod.outlook.com (2603:10a6:20b:45e::12) by PAXPR08MB6862.eurprd08.prod.outlook.com (2603:10a6:102:136::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Sat, 16 Oct 2021 06:54:29 +0000 Received: from AM5EUR03FT024.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::f3) by AS9PR06CA0213.outlook.office365.com (2603:10a6:20b:45e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Sat, 16 Oct 2021 06:54:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT024.mail.protection.outlook.com (10.152.16.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Sat, 16 Oct 2021 06:54:29 +0000 Received: ("Tessian outbound 2e7020cc8961:v103"); Sat, 16 Oct 2021 06:54:28 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a396996803490e13 X-CR-MTA-TID: 64aa7808 Received: from 974e24d195a7.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 5706EF6F-C455-4FF4-9AED-35BDF11D1B3E.1; Sat, 16 Oct 2021 06:54:17 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 974e24d195a7.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Sat, 16 Oct 2021 06:54:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QldlcAdYJP4Wuna0Pe99ewg8MWb0Dvq/mLda25eBF/TqLzjS8ru8zX/so+osislESME9hc/MOozLhTZrYw2zBeFGiuroHHBPX7fUcJzP3KrwkyTSja0kTuXZevWdaWEpFeHQAXaIev1MIyTf2f1E/blk3Vor664qXb5eChVZznPIFxFvLUqx5HSNfvtbGmwmnHtL7xwTuq42n86XzDNJHC3QgaNDTsfXdwArJjmCcFhEi28TvpXEJy2PL74ZsOdoi1uVNSTx+q3prYF2AguWFzl5KjjhijUHxRAc5R9vpJTcpTSvtghxFyAA9u7DWW7wVBqsQT3sqzfPlsUiq3cDEg== 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=oNADv+77cunczFEA8kz7fdgu0GfuM4vyoKVxBexw+Jc=; b=KQXS2lSOp6oL4+8jy/0P2QpOlzcunQ8f/QPSF/3H41UKVn/OWCbVTQqWZacM0E8Z+j+t5dOC7HuJsY9vUkfM4h+AhHEklapYRl1GeFaPzAfA9fpXv0rdipuhI84vG7C1+zOciezVAz7EBILglpr6foxlQoaxc6O8Ld0DwAFE8qmIKPZXHCpK4PrWnwfK7wQrwNIB7LEVUNPci13bJVd+uiOfkyW+VwKAbWZ/wY1FqD8wIrPJ3tX6kX0uunIacPfeFRP+FDcZAe4iJpU1OUyOecVmMxpC0dtIegXvlgPLPqOukkOBAGuWrTQIY2OCCn75Xphaz73QdWIQGGf7MoxWKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oNADv+77cunczFEA8kz7fdgu0GfuM4vyoKVxBexw+Jc=; b=KRT8qdBf318yik3Lq+1eV4QyQkCqGpH4RxwkVUfFDYccc0fIGTpUkCKgn6FL8+Ejwke8sLK630CQg1qXcK5Uz1GKWU+9FDhVL4RVd7yMqfoF7B6FpyLSbYYDX59KxVyNnDLu8n1oqluTjSztlaqrICCAh1IvS/lheXrBNtdNjd0= Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by AM5PR0801MB1908.eurprd08.prod.outlook.com (2603:10a6:203:4b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Sat, 16 Oct 2021 06:54:14 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::54b5:239d:9896:ee65]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::54b5:239d:9896:ee65%4]) with mapi id 15.20.4608.018; Sat, 16 Oct 2021 06:54:13 +0000 From: "Sami Mujawar" To: Rebecca Cran , "devel@edk2.groups.io" , Jian J Wang , Liming Gao CC: Ard Biesheuvel , Samer El-Haj-Mahmoud , Leif Lindholm , Gerd Hoffmann , nd Subject: Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Add MpServicesTest application to exercise MP Services Thread-Topic: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Add MpServicesTest application to exercise MP Services Thread-Index: AQHXwleyO5NBACPGhE2mlCj9GwrYSKvVMC6n Date: Sat, 16 Oct 2021 06:54:13 +0000 Message-ID: References: <20210920154732.10181-1-rebecca@nuviainc.com> <16A69264F30D2680.28782@groups.io> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Authentication-Results-Original: nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: 59d7cc72-10fd-4338-bba6-08d99071ccf5 x-ms-traffictypediagnostic: AM5PR0801MB1908:|PAXPR08MB6862: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:619;OLM:619; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: LTEn+6lrHhBMXuzJyNsWTNMXcGSrV8vztDL7C3l5jJpB/OdxpRpq+ti9VyOYKdNq9VzKadKXSx1HqlfOYJ7zkwkY9l5aMR69ZXXBo9fTFvdnC7tKjJ4zkW6FmhW6yu9Y3VLm+pOcOmsUH3nG0Ps+kAi2q7Ni6WVJnXkWTe4t86EykaYmok4hU362BfkjjcBZKAqFt83E9ZDKPXFKsgOk0Fksfp4TkJrHHFWHtxMs/YTPMuosjoYl5vEmF+QudovQc4Q6Vb+Cnc6BkTij+FV9qibJWJJ12bZQy/bztjnDgQK94kGfFN+nwlgq7UkJA4UeD9llgZWPaRT/FxJd5kTBMzOwNjvODdaL1qaroSfWxcWZrZ9+p9jzGu/JgtqX/IjkP/r8RAowpzMmLb2FFDrF8cFQ6P1bkwvTe6s8FKI+oWUaiRucG5oIIKjByhOwR3XRfMUycR6W89JK0GXCCMAdIYjljosh71zBJh2Yja1TlhusKfjnjD/pv3CF3BfnI0ekiqka3XJpjy4KbWeD8c8FTHzTH/7ZaSVPizRDnmhjY66YVcKzpEwv9sAPWH8Be+lQFt9aX82ztkNTehFV577oADDMhdrZbJZ2Q2T0zcVTxdxZKEwD5ibsNYTWok5jLC2WZn0lpF/LGM5FS8vDzAoO7BzzUgSPFktOgIM1GUsuc5aHoUCIsOcEvs0rOCZcIYmqpOtlcHtwHyOHFOB8oBRZtQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(366004)(316002)(38100700002)(30864003)(54906003)(110136005)(55016002)(9686003)(66946007)(66556008)(86362001)(66446008)(7696005)(66476007)(71200400001)(5660300002)(8676002)(8936002)(91956017)(53546011)(186003)(52536014)(6506007)(76116006)(26005)(4326008)(64756008)(508600001)(38070700005)(122000001)(33656002)(83380400001)(2906002);DIR:OUT;SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1908 Original-Authentication-Results: nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 617e3355-7ed8-4ed4-6a6f-08d99071c3a7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oPL7u2GScoJVAELfxt67wCLziTvG19IZ3nSRtfBVsteKjE1dT2YrldNrQ4Y0OdL6qsA+g4jc8+QZWuBLXkICUpsNjZK/XlsdIEQDyMhybVQrE+DMNKBOZm9Ic71itv3NcEIAxgEXkkho/IxTnul4oT6nWRQpWN0vHSaaubx8XT/zT41YtSc2fT2utw471JtLmjx8eqWzDKtbiShIS2JvbKtmr97XsTQ1hbQM5B/sb245riH+jd665c9jBUC7C4axXlIWZeywwAdhyvmgW65trJheja2TbLoY1x/5olkAsfqEcntLAcF2bXnW49ysmCAfs+UjW6CtZua2rTIt/Tr2vj0rE/+V+vzdLXYOsdrSwHTzaM6s7Hp6QUNCVK39UcCuXJbChWm9HqWiSr4ER0P4KVsaKlgnqbXI+jh+oKBqGR7O0DWU75LHuW/zUbzB/Q21MsL8y6tGuXr1M9Wyt0joNzPrNBiA7+qn/bF9J7FpQBzx0yAlBHvkoEveI76v6HMGdFf4gFoxgjPZKJtgg3ZQkaQQJVZ/lZyXjvu1WaF23Z919BmLoXukp9FBfONFJfNRV5rLdyyl0lm1I32D48tPAcJVE5DV5qkKDjMHS58DePKj0mGJ/NZN4xoohZEOL72W0cAQs4fhVopUHlvVTCfMVPa5dYZhCsCGua77c9HEwdVbShfX80otD6/kQFKaICD621juag7xaEXxZ0gh5dIQZA== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(6029001)(4636009)(36840700001)(46966006)(316002)(86362001)(26005)(6506007)(186003)(53546011)(356005)(336012)(8676002)(30864003)(4326008)(33656002)(47076005)(9686003)(5660300002)(81166007)(54906003)(52536014)(2906002)(70206006)(8936002)(508600001)(7696005)(83380400001)(55016002)(70586007)(19627235002)(110136005)(82310400003)(36860700001)(579004);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2021 06:54:29.3296 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59d7cc72-10fd-4338-bba6-08d99071ccf5 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT024.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6862 Content-Language: en-GB Content-Type: multipart/alternative; boundary="_000_AS8PR08MB680637AAF1C7296853DB68B584BA9AS8PR08MB6806eurp_" --_000_AS8PR08MB680637AAF1C7296853DB68B584BA9AS8PR08MB6806eurp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Rebecca, I will review this next week. Regard Sami Mujawar ________________________________ From: Rebecca Cran Sent: Saturday, 16 October 2021, 7:33 am To: devel@edk2.groups.io; Jian J Wang; Liming Gao Cc: Ard Biesheuvel; Samer El-Haj-Mahmoud; Leif Lindholm; Sami Mujawar; Gerd= Hoffmann Subject: Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Add MpServicesTest a= pplication to exercise MP Services (cc Leif, Ard, Sami, Samer, Gerd) Could someone review this please? -- Rebecca Cran On 9/20/21 9:47 AM, Rebecca Cran via groups.io wrote: > Add a new MpServicesTest application under MdeModulePkg/Application that > exercises the EFI_MP_SERVICES_PROTOCOL. > > Signed-off-by: Rebecca Cran > --- > MdeModulePkg/Application/MpServicesTest/MpServicesTest.c | 433 ++++++= ++++++++++++++ > MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf | 38 ++ > MdeModulePkg/MdeModulePkg.dsc | 2 + > 3 files changed, 473 insertions(+) > > diff --git a/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c b/M= deModulePkg/Application/MpServicesTest/MpServicesTest.c > new file mode 100644 > index 000000000000..4eb06e6b7cbd > --- /dev/null > +++ b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c > @@ -0,0 +1,433 @@ > +/** @file > + > + Copyright (c) 2021, NUVIA Inc. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define MAX_RANDOM_PROCESSOR_RETRIES 10 > + > +#define AP_STARTUP_TEST_TIMEOUT_US 50000 > +#define INFINITE_TIMEOUT 0 > + > +#define RETURN_IF_EFI_ERROR(x) \ > + if (EFI_ERROR (x)) { \ > + Print (L"failed: %r\n", x); \ > + return; \ > + } \ > + else { \ > + Print (L"done.\n"); \ > + } > + > +/** The procedure to run with the MP Services interface. > + > + @param Buffer The procedure argument. > + > +**/ > +STATIC > +VOID > +EFIAPI > +ApFunction ( > + IN OUT VOID *Buffer > + ) > +{ > +} > + > +/** Displays information returned from MP Services Protocol. > + > + @param Mp The MP Services Protocol > + > + @return The number of CPUs in the system. > + > +**/ > +STATIC > +UINTN > +PrintProcessorInformation ( > + IN EFI_MP_SERVICES_PROTOCOL *Mp > + ) > +{ > + EFI_STATUS Status; > + EFI_PROCESSOR_INFORMATION CpuInfo; > + UINTN Index; > + UINTN NumCpu; > + UINTN NumEnabledCpu; > + > + Status =3D Mp->GetNumberOfProcessors (Mp, &NumCpu, &NumEnabledCpu); > + if (EFI_ERROR (Status)) { > + Print (L"GetNumberOfProcessors failed: %r\n", Status); > + } else { > + Print (L"Number of CPUs: %ld, Enabled: %d\n", NumCpu, NumEnabledCpu)= ; > + } > + > + for (Index =3D 0; Index < NumCpu; Index++) { > + Status =3D Mp->GetProcessorInfo (Mp, CPU_V2_EXTENDED_TOPOLOGY | Inde= x, &CpuInfo); > + if (EFI_ERROR (Status)) { > + Print (L"GetProcessorInfo for Processor %d failed: %r\n", Index, S= tatus); > + } else { > + Print ( > + L"Processor %d:\n" > + L"\tID: %016lx\n" > + L"\tStatus: %s | ", > + Index, > + CpuInfo.ProcessorId, > + (CpuInfo.StatusFlag & PROCESSOR_AS_BSP_BIT) ? L"BSP" : L"AP" > + ); > + > + Print (L"%s | ", (CpuInfo.StatusFlag & PROCESSOR_ENABLED_BIT) ? L"= Enabled" : L"Disabled"); > + Print (L"%s\n", (CpuInfo.StatusFlag & PROCESSOR_HEALTH_STATUS_BIT)= ? L"Healthy" : L"Faulted"); > + > + Print ( > + L"\tLocation: Package %d, Core %d, Thread %d\n" > + L"\tExtended Information: Package %d, Module %d, Tile %d, Die %d= , Core %d, Thread %d\n\n", > + CpuInfo.Location.Package, > + CpuInfo.Location.Core, > + CpuInfo.Location.Thread, > + CpuInfo.ExtendedInformation.Location2.Package, > + CpuInfo.ExtendedInformation.Location2.Module, > + CpuInfo.ExtendedInformation.Location2.Tile, > + CpuInfo.ExtendedInformation.Location2.Die, > + CpuInfo.ExtendedInformation.Location2.Core, > + CpuInfo.ExtendedInformation.Location2.Thread > + ); > + } > + } > + > + return NumCpu; > +} > + > +/** Returns the index of an enabled AP selected at random. > + > + @param Mp The MP Services Protocol. > + @param ProcessorIndex The index of a random enabled AP. > + > + @retval EFI_SUCCESS An enabled processor was found and returned. > + @retval EFI_NOT_FOUND A processor was unable to be selected. > + > +**/ > +STATIC > +EFI_STATUS > +GetRandomEnabledProcessorIndex ( > + IN EFI_MP_SERVICES_PROTOCOL *Mp, > + OUT UINTN *ProcessorIndex > + ) > +{ > + UINTN Index; > + UINTN IndexOfEnabledCpu; > + UINTN NumCpus; > + UINTN NumEnabledCpus; > + UINTN IndexOfEnabledCpuToUse; > + UINT16 RandomNumber; > + BOOLEAN Success; > + EFI_STATUS Status; > + EFI_PROCESSOR_INFORMATION CpuInfo; > + > + IndexOfEnabledCpu =3D 0; > + > + Success =3D GetRandomNumber16 (&RandomNumber); > + ASSERT (Success =3D=3D TRUE); > + > + Status =3D Mp->GetNumberOfProcessors (Mp, &NumCpus, &NumEnabledCpus); > + ASSERT_EFI_ERROR (Status); > + > + if (NumEnabledCpus =3D=3D 1) { > + Print (L"All APs are disabled\n"); > + return EFI_NOT_FOUND; > + } > + > + IndexOfEnabledCpuToUse =3D RandomNumber % NumEnabledCpus; > + > + for (Index =3D 0; Index < NumCpus; Index++) { > + Status =3D Mp->GetProcessorInfo (Mp, Index, &CpuInfo); > + ASSERT_EFI_ERROR (Status); > + if ((CpuInfo.StatusFlag & PROCESSOR_ENABLED_BIT) && > + !(CpuInfo.StatusFlag & PROCESSOR_AS_BSP_BIT)) { > + if (IndexOfEnabledCpuToUse =3D=3D IndexOfEnabledCpu) { > + *ProcessorIndex =3D Index; > + Status =3D EFI_SUCCESS; > + break; > + } > + > + IndexOfEnabledCpu++; > + } > + } > + > + if (Index =3D=3D NumCpus) { > + Status =3D EFI_NOT_FOUND; > + } > + > + return Status; > +} > + > +/** Tests for the StartupThisAP function. > + > + @param Mp The MP Services Protocol. > + > +**/ > +STATIC > +VOID > +StartupThisApTests ( > + IN EFI_MP_SERVICES_PROTOCOL *Mp > + ) > +{ > + EFI_STATUS Status; > + UINTN ProcessorIndex; > + UINT32 Retries; > + > + Retries =3D 0; > + > + do { > + Status =3D GetRandomEnabledProcessorIndex (Mp, &ProcessorIndex); > + } while (EFI_ERROR (Status) && Retries++ < MAX_RANDOM_PROCESSOR_RETRIE= S); > + > + if (EFI_ERROR (Status)) { > + return; > + } > + > + Print ( > + L"StartupThisAP on Processor %d with 0 (infinite) timeout...", > + ProcessorIndex > + ); > + > + Status =3D Mp->StartupThisAP ( > + Mp, > + ApFunction, > + ProcessorIndex, > + NULL, > + INFINITE_TIMEOUT, > + NULL, > + NULL > + ); > + > + RETURN_IF_EFI_ERROR (Status); > + > + Retries =3D 0; > + > + do { > + Status =3D GetRandomEnabledProcessorIndex (Mp, &ProcessorIndex); > + } while (EFI_ERROR (Status) && Retries++ < MAX_RANDOM_PROCESSOR_RETRIE= S); > + > + if (EFI_ERROR (Status)) { > + return; > + } > + > + Print ( > + L"StartupThisAP on Processor %d with %dms timeout...", > + ProcessorIndex, > + AP_STARTUP_TEST_TIMEOUT_US / 1000 > + ); > + Status =3D Mp->StartupThisAP ( > + Mp, > + ApFunction, > + ProcessorIndex, > + NULL, > + AP_STARTUP_TEST_TIMEOUT_US, > + NULL, > + NULL > + ); > + RETURN_IF_EFI_ERROR (Status); > +} > + > +/** Tests for the StartupAllAPs function. > + > + @param Mp The MP Services Protocol. > + @param NumCpus The number of CPUs in the system. > + > +**/ > +STATIC > +VOID > +StartupAllAPsTests ( > + IN EFI_MP_SERVICES_PROTOCOL *Mp, > + IN UINTN NumCpus > + ) > +{ > + EFI_STATUS Status; > + UINTN Timeout; > + > + Print (L"Running with SingleThread FALSE, 0 (infinite) timeout..."); > + Status =3D Mp->StartupAllAPs (Mp, ApFunction, FALSE, NULL, INFINITE_TI= MEOUT, NULL, NULL); > + RETURN_IF_EFI_ERROR (Status); > + > + Timeout =3D NumCpus * AP_STARTUP_TEST_TIMEOUT_US; > + > + Print (L"Running with SingleThread TRUE, %dms timeout...", Timeout / 1= 000); > + Status =3D Mp->StartupAllAPs ( > + Mp, > + ApFunction, > + TRUE, > + NULL, > + Timeout, > + NULL, > + NULL > + ); > + RETURN_IF_EFI_ERROR (Status); > +} > + > +/** Tests for the EnableDisableAP function. > + > + @param Mp The MP Services Protocol. > + @param NumCpus The number of CPUs in the system. > + > +**/ > +STATIC > +VOID > +EnableDisableAPTests ( > + IN EFI_MP_SERVICES_PROTOCOL *Mp, > + IN UINTN NumCpus > + ) > +{ > + EFI_STATUS Status; > + UINTN Index; > + UINT32 HealthFlag; > + > + HealthFlag =3D 0; > + > + for (Index =3D 1; Index < NumCpus; Index++) { > + Print (L"Disabling Processor %d with HealthFlag faulted...", Index); > + Status =3D Mp->EnableDisableAP (Mp, Index, FALSE, &HealthFlag); > + RETURN_IF_EFI_ERROR (Status); > + } > + > + HealthFlag =3D PROCESSOR_HEALTH_STATUS_BIT; > + > + for (Index =3D 1; Index < NumCpus; Index++) { > + Print (L"Enabling Processor %d with HealthFlag healthy...", Index); > + Status =3D Mp->EnableDisableAP (Mp, Index, TRUE, &HealthFlag); > + RETURN_IF_EFI_ERROR (Status); > + } > +} > + > +/** Tests for the SwitchBSP function. > + > + @param Mp The MP Services Protocol. > + @param NumCpus The number of CPUs in the system. > + > +**/ > +STATIC > +VOID > +SwitchBSPTests ( > + IN EFI_MP_SERVICES_PROTOCOL *Mp, > + IN UINTN NumCpus > + ) > +{ > + EFI_STATUS Status; > + UINTN Index; > + > + for (Index =3D 1; Index < NumCpus; Index++) { > + Print (L"Switching BSP to Processor %d with EnableOldBSP FALSE...", = Index); > + Status =3D Mp->SwitchBSP (Mp, Index, FALSE); > + RETURN_IF_EFI_ERROR (Status); > + } > + > + for (Index =3D 0; Index < NumCpus; Index++) { > + Print (L"Switching BSP to Processor %d with EnableOldBSP TRUE...", I= ndex); > + Status =3D Mp->SwitchBSP (Mp, Index, TRUE); > + RETURN_IF_EFI_ERROR (Status); > + } > +} > + > +/** > + The user Entry Point for Application. The user code starts with this f= unction > + as the real entry point for the application. > + > + @param[in] ImageHandle The firmware allocated handle for the EFI im= age. > + @param[in] SystemTable A pointer to the EFI System Table. > + > + @retval EFI_SUCCESS The entry point is executed successfully. > + @retval other Some error occurs when executing this entry = point. > + > +**/ > +EFI_STATUS > +EFIAPI > +UefiMain ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + EFI_MP_SERVICES_PROTOCOL *Mp; > + EFI_HANDLE *pHandle; > + UINTN HandleCount; > + UINTN BspId; > + UINTN NumCpus; > + UINTN Index; > + > + pHandle =3D NULL; > + HandleCount =3D 0; > + BspId =3D 0; > + > + Status =3D gBS->LocateHandleBuffer ( > + ByProtocol, > + &gEfiMpServiceProtocolGuid, > + NULL, > + &HandleCount, > + &pHandle > + ); > + > + if (EFI_ERROR (Status)) { > + Print (L"Failed to locate EFI_MP_SERVICES_PROTOCOL (%r). Not install= ed on platform?\n", Status); > + return EFI_NOT_FOUND; > + } > + > + for (Index =3D 0; Index < HandleCount; Index++) { > + Status =3D gBS->OpenProtocol ( > + *pHandle, > + &gEfiMpServiceProtocolGuid, > + (VOID **)&Mp, > + NULL, > + gImageHandle, > + EFI_OPEN_PROTOCOL_GET_PROTOCOL > + ); > + > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + pHandle++; > + } > + > + Print (L"Exercising WhoAmI\n\n"); > + Status =3D Mp->WhoAmI (Mp, &BspId); > + if (EFI_ERROR (Status)) { > + Print (L"WhoAmI failed: %r\n", Status); > + return Status; > + } else { > + Print (L"WhoAmI: %016lx\n", BspId); > + } > + > + Print (L"\n"); > + Print ( > + L"Exercising GetNumberOfProcessors and GetProcessorInformation with = " > + L"CPU_V2_EXTENDED_TOPOLOGY\n\n" > + ); > + NumCpus =3D PrintProcessorInformation (Mp); > + if (NumCpus < 2) { > + Print (L"UP system found. Not running further tests.\n"); > + return EFI_INVALID_PARAMETER; > + } > + > + Print (L"\n"); > + Print (L"Exercising StartupThisAP:\n\n"); > + StartupThisApTests (Mp); > + > + Print (L"\n"); > + Print (L"Exercising StartupAllAPs:\n\n"); > + StartupAllAPsTests (Mp, NumCpus); > + > + Print (L"\n"); > + Print (L"Exercising EnableDisableAP:\n\n"); > + EnableDisableAPTests (Mp, NumCpus); > + > + Print (L"\n"); > + Print (L"Exercising SwitchBSP\n\n"); > + SwitchBSPTests (Mp, NumCpus); > + > + gBS->CloseProtocol (pHandle, &gEfiMpServiceProtocolGuid, gImageHandle,= NULL); > + return EFI_SUCCESS; > +} > diff --git a/MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf b= /MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf > new file mode 100644 > index 000000000000..8a21ca70d8fa > --- /dev/null > +++ b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf > @@ -0,0 +1,38 @@ > +## @file > +# UEFI Application to exercise EFI_MP_SERVICES_PROTOCOL. > +# > +# Copyright (c) 2021, NUVIA Inc. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION =3D 1.29 > + BASE_NAME =3D MpServicesTest > + FILE_GUID =3D 43e9defa-7209-4b0d-b136-cc4ca02cb46= 9 > + MODULE_TYPE =3D UEFI_APPLICATION > + VERSION_STRING =3D 0.1 > + ENTRY_POINT =3D UefiMain > + > +# > +# The following information is for reference only and not required by th= e build tools. > +# > +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 > +# > + > +[Sources] > + MpServicesTest.c > + > +[Packages] > + MdePkg/MdePkg.dec > + > +[LibraryClasses] > + BaseLib > + RngLib > + UefiApplicationEntryPoint > + UefiLib > + > +[Protocols] > + gEfiMpServiceProtocolGuid ## CONSUMES > + > diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.ds= c > index b1d83461865e..1cf5ccd30d40 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -164,6 +164,7 @@ > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > DebugLib|MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf > FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf > + RngLib|MdePkg/Library/DxeRngLib/DxeRngLib.inf > > [LibraryClasses.common.MM_STANDALONE] > HobLib|MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.inf > @@ -215,6 +216,7 @@ > MdeModulePkg/Application/HelloWorld/HelloWorld.inf > MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.inf > MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.inf > + MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf > > MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf > MdeModulePkg/Logo/Logo.inf --_000_AS8PR08MB680637AAF1C7296853DB68B584BA9AS8PR08MB6806eurp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi Rebecca,

I will review this next week.

Regard

Sami Mujawar


From: Rebecca Cran <rebecca@n= uviainc.com>
Sent: Saturday, 16 October 2021, 7:33 am
To: devel@edk2.groups.io; Jian J Wang; Liming Gao
Cc: Ard Biesheuvel; Samer El-Haj-Mahmoud; Leif Lindholm; S= ami Mujawar; Gerd Hoffmann
Subject: Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Add= MpServicesTest application to exercise MP Services

(cc Leif, Ard, Sami, Samer, Gerd)


Could someone review this please?


--
Rebecca Cran


On 9/20/21 9:47 AM, Rebecca Cran via groups.io wrote:
> Add a new MpServicesTest application under MdeModulePkg/Application th= at
> exercises the EFI_MP_SERVICES_PROTOCOL.
>
> Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
> ---
>   MdeModulePkg/Application/MpServicesTest/MpServicesTest.c&n= bsp;  | 433 ++++++++++++++++++++
>   MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf= |  38 ++
>   MdeModulePkg/MdeModulePkg.dsc     = ;            &n= bsp;            |&nb= sp;  2 +
>   3 files changed, 473 insertions(+)
>
> diff --git a/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c = b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c
> new file mode 100644
> index 000000000000..4eb06e6b7cbd
> --- /dev/null
> +++ b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c
> @@ -0,0 +1,433 @@
> +/** @file
> +
> +    Copyright (c) 2021, NUVIA Inc. All rights reserved= .<BR>
> +    SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#include <Uefi.h>
> +#include <Library/DebugLib.h>
> +#include <Library/RngLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiLib.h>
> +#include <Pi/PiMultiPhase.h>
> +#include <Protocol/MpService.h>
> +
> +#define MAX_RANDOM_PROCESSOR_RETRIES 10
> +
> +#define AP_STARTUP_TEST_TIMEOUT_US  50000
> +#define INFINITE_TIMEOUT       &nb= sp;    0
> +
> +#define RETURN_IF_EFI_ERROR(x)   \
> +  if (EFI_ERROR (x)) {       =     \
> +    Print (L"failed: %r\n", x);  \
> +    return;       &= nbsp;           &nbs= p;  \
> +  }          &= nbsp;           &nbs= p;       \
> +  else {         &n= bsp;            = ;   \
> +    Print (L"done.\n");   &nb= sp;      \
> +  }
> +
> +/** The procedure to run with the MP Services interface.
> +
> +  @param Buffer The procedure argument.
> +
> +**/
> +STATIC
> +VOID
> +EFIAPI
> +ApFunction (
> +  IN OUT VOID *Buffer
> +  )
> +{
> +}
> +
> +/** Displays information returned from MP Services Protocol.
> +
> +  @param Mp  The MP Services Protocol
> +
> +  @return The number of CPUs in the system.
> +
> +**/
> +STATIC
> +UINTN
> +PrintProcessorInformation (
> +  IN EFI_MP_SERVICES_PROTOCOL *Mp
> +  )
> +{
> +  EFI_STATUS        &nbs= p;        Status;
> +  EFI_PROCESSOR_INFORMATION  CpuInfo;
> +  UINTN         &nb= sp;            Index= ;
> +  UINTN         &nb= sp;            NumCp= u;
> +  UINTN         &nb= sp;            NumEn= abledCpu;
> +
> +  Status =3D Mp->GetNumberOfProcessors (Mp, &NumCpu, &= ;NumEnabledCpu);
> +  if (EFI_ERROR (Status)) {
> +    Print (L"GetNumberOfProcessors failed: %r\n&q= uot;, Status);
> +  } else {
> +    Print (L"Number of CPUs: %ld, Enabled: %d\n&q= uot;, NumCpu, NumEnabledCpu);
> +  }
> +
> +  for (Index =3D 0; Index < NumCpu; Index++) {
> +    Status =3D Mp->GetProcessorInfo (Mp, CPU_V2_EXT= ENDED_TOPOLOGY | Index, &CpuInfo);
> +    if (EFI_ERROR (Status)) {
> +      Print (L"GetProcessorInfo for Pro= cessor %d failed: %r\n", Index, Status);
> +    } else {
> +      Print (
> +        L"Processor %d:\n&quo= t;
> +        L"\tID: %016lx\n"= ;
> +        L"\tStatus: %s | &quo= t;,
> +        Index,
> +        CpuInfo.ProcessorId,
> +        (CpuInfo.StatusFlag & = PROCESSOR_AS_BSP_BIT) ? L"BSP" : L"AP"
> +        );
> +
> +      Print (L"%s | ", (CpuInfo.St= atusFlag & PROCESSOR_ENABLED_BIT) ? L"Enabled" : L"Disab= led");
> +      Print (L"%s\n", (CpuInfo.Sta= tusFlag & PROCESSOR_HEALTH_STATUS_BIT) ? L"Healthy" : L"= Faulted");
> +
> +      Print (
> +        L"\tLocation: Package= %d, Core %d, Thread %d\n"
> +        L"\tExtended Informat= ion: Package %d, Module %d, Tile %d, Die %d, Core %d, Thread %d\n\n",<= br> > +        CpuInfo.Location.Package,<= br> > +        CpuInfo.Location.Core,
> +        CpuInfo.Location.Thread, > +        CpuInfo.ExtendedInformatio= n.Location2.Package,
> +        CpuInfo.ExtendedInformatio= n.Location2.Module,
> +        CpuInfo.ExtendedInformatio= n.Location2.Tile,
> +        CpuInfo.ExtendedInformatio= n.Location2.Die,
> +        CpuInfo.ExtendedInformatio= n.Location2.Core,
> +        CpuInfo.ExtendedInformatio= n.Location2.Thread
> +        );
> +    }
> +  }
> +
> +  return NumCpu;
> +}
> +
> +/** Returns the index of an enabled AP selected at random.
> +
> +  @param Mp         = ;    The MP Services Protocol.
> +  @param ProcessorIndex The index of a random enabled AP.
> +
> +  @retval EFI_SUCCESS   An enabled processor was found= and returned.
> +  @retval EFI_NOT_FOUND A processor was unable to be selected. > +
> +**/
> +STATIC
> +EFI_STATUS
> +GetRandomEnabledProcessorIndex (
> +  IN EFI_MP_SERVICES_PROTOCOL *Mp,
> +  OUT UINTN *ProcessorIndex
> +  )
> +{
> +  UINTN         &nb= sp;            Index= ;
> +  UINTN         &nb= sp;            Index= OfEnabledCpu;
> +  UINTN         &nb= sp;            NumCp= us;
> +  UINTN         &nb= sp;            NumEn= abledCpus;
> +  UINTN         &nb= sp;            Index= OfEnabledCpuToUse;
> +  UINT16         &n= bsp;           RandomNumb= er;
> +  BOOLEAN         &= nbsp;          Success;
> +  EFI_STATUS        &nbs= p;        Status;
> +  EFI_PROCESSOR_INFORMATION  CpuInfo;
> +
> +  IndexOfEnabledCpu =3D 0;
> +
> +  Success =3D GetRandomNumber16 (&RandomNumber);
> +  ASSERT (Success =3D=3D TRUE);
> +
> +  Status =3D Mp->GetNumberOfProcessors (Mp, &NumCpus, &am= p;NumEnabledCpus);
> +  ASSERT_EFI_ERROR (Status);
> +
> +  if (NumEnabledCpus =3D=3D 1) {
> +    Print (L"All APs are disabled\n");
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  IndexOfEnabledCpuToUse =3D RandomNumber % NumEnabledCpus;
> +
> +  for (Index =3D 0; Index < NumCpus; Index++) {
> +    Status =3D Mp->GetProcessorInfo (Mp, Index, &am= p;CpuInfo);
> +    ASSERT_EFI_ERROR (Status);
> +    if ((CpuInfo.StatusFlag & PROCESSOR_ENABLED_BI= T) &&
> +        !(CpuInfo.StatusFlag &= PROCESSOR_AS_BSP_BIT)) {
> +      if (IndexOfEnabledCpuToUse =3D=3D Inde= xOfEnabledCpu) {
> +        *ProcessorIndex =3D Index;=
> +        Status =3D EFI_SUCCESS; > +        break;
> +      }
> +
> +      IndexOfEnabledCpu++;
> +    }
> +  }
> +
> +  if (Index =3D=3D NumCpus) {
> +    Status =3D EFI_NOT_FOUND;
> +  }
> +
> +  return Status;
> +}
> +
> +/** Tests for the StartupThisAP function.
> +
> +  @param Mp The MP Services Protocol.
> +
> +**/
> +STATIC
> +VOID
> +StartupThisApTests (
> +  IN EFI_MP_SERVICES_PROTOCOL *Mp
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN       ProcessorIndex;
> +  UINT32      Retries;
> +
> +  Retries =3D 0;
> +
> +  do {
> +    Status =3D GetRandomEnabledProcessorIndex (Mp, &am= p;ProcessorIndex);
> +  } while (EFI_ERROR (Status) && Retries++ < MAX_RAND= OM_PROCESSOR_RETRIES);
> +
> +  if (EFI_ERROR (Status)) {
> +    return;
> +  }
> +
> +  Print (
> +    L"StartupThisAP on Processor %d with 0 (infin= ite) timeout...",
> +    ProcessorIndex
> +    );
> +
> +  Status =3D Mp->StartupThisAP (
> +    Mp,
> +    ApFunction,
> +    ProcessorIndex,
> +    NULL,
> +    INFINITE_TIMEOUT,
> +    NULL,
> +    NULL
> +    );
> +
> +  RETURN_IF_EFI_ERROR (Status);
> +
> +  Retries =3D 0;
> +
> +  do {
> +    Status =3D GetRandomEnabledProcessorIndex (Mp, &am= p;ProcessorIndex);
> +  } while (EFI_ERROR (Status) && Retries++ < MAX_RAND= OM_PROCESSOR_RETRIES);
> +
> +  if (EFI_ERROR (Status)) {
> +    return;
> +  }
> +
> +  Print (
> +    L"StartupThisAP on Processor %d with %dms tim= eout...",
> +    ProcessorIndex,
> +    AP_STARTUP_TEST_TIMEOUT_US / 1000
> +    );
> +  Status =3D Mp->StartupThisAP (
> +           &nb= sp;     Mp,
> +           &nb= sp;     ApFunction,
> +           &nb= sp;     ProcessorIndex,
> +           &nb= sp;     NULL,
> +           &nb= sp;     AP_STARTUP_TEST_TIMEOUT_US,
> +           &nb= sp;     NULL,
> +           &nb= sp;     NULL
> +           &nb= sp;     );
> +  RETURN_IF_EFI_ERROR (Status);
> +}
> +
> +/** Tests for the StartupAllAPs function.
> +
> +  @param Mp      The MP Services Protoc= ol.
> +  @param NumCpus The number of CPUs in the system.
> +
> +**/
> +STATIC
> +VOID
> +StartupAllAPsTests (
> +  IN EFI_MP_SERVICES_PROTOCOL *Mp,
> +  IN UINTN NumCpus
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN       Timeout;
> +
> +  Print (L"Running with SingleThread FALSE, 0 (infinite) ti= meout...");
> +  Status =3D Mp->StartupAllAPs (Mp, ApFunction, FALSE, NULL, = INFINITE_TIMEOUT, NULL, NULL);
> +  RETURN_IF_EFI_ERROR (Status);
> +
> +  Timeout =3D NumCpus * AP_STARTUP_TEST_TIMEOUT_US;
> +
> +  Print (L"Running with SingleThread TRUE, %dms timeout...&= quot;, Timeout / 1000);
> +  Status =3D Mp->StartupAllAPs (
> +           &nb= sp;     Mp,
> +           &nb= sp;     ApFunction,
> +           &nb= sp;     TRUE,
> +           &nb= sp;     NULL,
> +           &nb= sp;     Timeout,
> +           &nb= sp;     NULL,
> +           &nb= sp;     NULL
> +           &nb= sp;     );
> +  RETURN_IF_EFI_ERROR (Status);
> +}
> +
> +/** Tests for the EnableDisableAP function.
> +
> +  @param Mp      The MP Services Protoc= ol.
> +  @param NumCpus The number of CPUs in the system.
> +
> +**/
> +STATIC
> +VOID
> +EnableDisableAPTests (
> +  IN EFI_MP_SERVICES_PROTOCOL *Mp,
> +  IN UINTN         =            NumCpus
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN       Index;
> +  UINT32      HealthFlag;
> +
> +  HealthFlag =3D 0;
> +
> +  for (Index =3D 1; Index < NumCpus; Index++) {
> +    Print (L"Disabling Processor %d with HealthFl= ag faulted...", Index);
> +    Status =3D Mp->EnableDisableAP (Mp, Index, FALS= E, &HealthFlag);
> +    RETURN_IF_EFI_ERROR (Status);
> +  }
> +
> +  HealthFlag =3D PROCESSOR_HEALTH_STATUS_BIT;
> +
> +  for (Index =3D 1; Index < NumCpus; Index++) {
> +    Print (L"Enabling Processor %d with HealthFla= g healthy...", Index);
> +    Status =3D Mp->EnableDisableAP (Mp, Index, TRUE= , &HealthFlag);
> +    RETURN_IF_EFI_ERROR (Status);
> +  }
> +}
> +
> +/** Tests for the SwitchBSP function.
> +
> +  @param Mp      The MP Services Protoc= ol.
> +  @param NumCpus The number of CPUs in the system.
> +
> +**/
> +STATIC
> +VOID
> +SwitchBSPTests (
> +  IN EFI_MP_SERVICES_PROTOCOL *Mp,
> +  IN UINTN         =            NumCpus
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN       Index;
> +
> +  for (Index =3D 1; Index < NumCpus; Index++) {
> +    Print (L"Switching BSP to Processor %d with E= nableOldBSP FALSE...", Index);
> +    Status =3D Mp->SwitchBSP (Mp, Index, FALSE); > +    RETURN_IF_EFI_ERROR (Status);
> +  }
> +
> +  for (Index =3D 0; Index < NumCpus; Index++) {
> +    Print (L"Switching BSP to Processor %d with E= nableOldBSP TRUE...", Index);
> +    Status =3D Mp->SwitchBSP (Mp, Index, TRUE);
> +    RETURN_IF_EFI_ERROR (Status);
> +  }
> +}
> +
> +/**
> +  The user Entry Point for Application. The user code starts wit= h this function
> +  as the real entry point for the application.
> +
> +  @param[in] ImageHandle    The firmware allocate= d handle for the EFI image.
> +  @param[in] SystemTable    A pointer to the EFI = System Table.
> +
> +  @retval EFI_SUCCESS       The en= try point is executed successfully.
> +  @retval other        &= nbsp;    Some error occurs when executing this entry point.<= br> > +
> +**/
> +EFI_STATUS
> +EFIAPI
> +UefiMain (
> +  IN EFI_HANDLE        ImageH= andle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  EFI_STATUS        &nbs= p;       Status;
> +  EFI_MP_SERVICES_PROTOCOL  *Mp;
> +  EFI_HANDLE        &nbs= p;       *pHandle;
> +  UINTN         &nb= sp;           HandleCount= ;
> +  UINTN         &nb= sp;           BspId;
> +  UINTN         &nb= sp;           NumCpus; > +  UINTN         &nb= sp;           Index;
> +
> +  pHandle     =3D NULL;
> +  HandleCount =3D 0;
> +  BspId =3D 0;
> +
> +  Status =3D gBS->LocateHandleBuffer (
> +           &nb= sp;      ByProtocol,
> +           &nb= sp;      &gEfiMpServiceProtocolGuid,
> +           &nb= sp;      NULL,
> +           &nb= sp;      &HandleCount,
> +           &nb= sp;      &pHandle
> +           &nb= sp;      );
> +
> +  if (EFI_ERROR (Status)) {
> +    Print (L"Failed to locate EFI_MP_SERVICES_PRO= TOCOL (%r). Not installed on platform?\n", Status);
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  for (Index =3D 0; Index < HandleCount; Index++) {
> +    Status =3D gBS->OpenProtocol (
> +           &nb= sp;        *pHandle,
> +           &nb= sp;        &gEfiMpServiceProtocolGui= d,
> +           &nb= sp;        (VOID **)&Mp,
> +           &nb= sp;        NULL,
> +           &nb= sp;        gImageHandle,
> +           &nb= sp;        EFI_OPEN_PROTOCOL_GET_PROTOCO= L
> +           &nb= sp;        );
> +
> +    if (EFI_ERROR (Status)) {
> +      return Status;
> +    }
> +
> +    pHandle++;
> +  }
> +
> +  Print (L"Exercising WhoAmI\n\n");
> +  Status =3D Mp->WhoAmI (Mp, &BspId);
> +  if (EFI_ERROR (Status)) {
> +    Print (L"WhoAmI failed: %r\n", Status);<= br> > +    return Status;
> +  } else {
> +    Print (L"WhoAmI: %016lx\n", BspId);
> +  }
> +
> +  Print (L"\n");
> +  Print (
> +    L"Exercising GetNumberOfProcessors and GetPro= cessorInformation with "
> +    L"CPU_V2_EXTENDED_TOPOLOGY\n\n"
> +    );
> +  NumCpus =3D PrintProcessorInformation (Mp);
> +  if (NumCpus < 2) {
> +    Print (L"UP system found. Not running further= tests.\n");
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  Print (L"\n");
> +  Print (L"Exercising StartupThisAP:\n\n");
> +  StartupThisApTests (Mp);
> +
> +  Print (L"\n");
> +  Print (L"Exercising StartupAllAPs:\n\n");
> +  StartupAllAPsTests (Mp, NumCpus);
> +
> +  Print (L"\n");
> +  Print (L"Exercising EnableDisableAP:\n\n");
> +  EnableDisableAPTests (Mp, NumCpus);
> +
> +  Print (L"\n");
> +  Print (L"Exercising SwitchBSP\n\n");
> +  SwitchBSPTests (Mp, NumCpus);
> +
> +  gBS->CloseProtocol (pHandle, &gEfiMpServiceProtocolGuid= , gImageHandle, NULL);
> +  return EFI_SUCCESS;
> +}
> diff --git a/MdeModulePkg/Application/MpServicesTest/MpServicesTest.in= f b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf
> new file mode 100644
> index 000000000000..8a21ca70d8fa
> --- /dev/null
> +++ b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf
> @@ -0,0 +1,38 @@
> +## @file
> +#  UEFI Application to exercise EFI_MP_SERVICES_PROTOCOL.
> +#
> +#  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>=
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION        &nb= sp;           =3D 1.29 > +  BASE_NAME         = ;             = =3D MpServicesTest
> +  FILE_GUID         = ;             = =3D 43e9defa-7209-4b0d-b136-cc4ca02cb469
> +  MODULE_TYPE        &nb= sp;           =3D UEFI_AP= PLICATION
> +  VERSION_STRING        =          =3D 0.1
> +  ENTRY_POINT        &nb= sp;           =3D UefiMai= n
> +
> +#
> +# The following information is for reference only and not required by= the build tools.
> +#
> +#  VALID_ARCHITECTURES       =     =3D IA32 X64 AARCH64
> +#
> +
> +[Sources]
> +  MpServicesTest.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  RngLib
> +  UefiApplicationEntryPoint
> +  UefiLib
> +
> +[Protocols]
> +  gEfiMpServiceProtocolGuid    ## CONSUMES
> +
> diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg= .dsc
> index b1d83461865e..1cf5ccd30d40 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -164,6 +164,7 @@
>     MemoryAllocationLib|MdePkg/Library/UefiMemoryA= llocationLib/UefiMemoryAllocationLib.inf
>     DebugLib|MdePkg/Library/UefiDebugLibStdErr/Uef= iDebugLibStdErr.inf
>     FileHandleLib|MdePkg/Library/UefiFileHandleLib= /UefiFileHandleLib.inf
> +  RngLib|MdePkg/Library/DxeRngLib/DxeRngLib.inf
>  
>   [LibraryClasses.common.MM_STANDALONE]
>     HobLib|MdeModulePkg/Library/BaseHobLibNull/Bas= eHobLibNull.inf
> @@ -215,6 +216,7 @@
>     MdeModulePkg/Application/HelloWorld/HelloWorld= .inf
>     MdeModulePkg/Application/DumpDynPcd/DumpDynPcd= .inf
>     MdeModulePkg/Application/MemoryProfileInfo/Mem= oryProfileInfo.inf
> +  MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf
>  
>     MdeModulePkg/Library/UefiSortLib/UefiSortLib.i= nf
>     MdeModulePkg/Logo/Logo.inf

--_000_AS8PR08MB680637AAF1C7296853DB68B584BA9AS8PR08MB6806eurp_--