From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (EUR03-VE1-obe.outbound.protection.outlook.com [40.107.5.45]) by mx.groups.io with SMTP id smtpd.web11.1986.1636567618018822230 for ; Wed, 10 Nov 2021 10:06:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=BGaCwCSG; spf=pass (domain: arm.com, ip: 40.107.5.45, 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=21kdxcR5nYiewbF2oFL/uVHbRgan6Lkc2XdoxqW+I5o=; b=BGaCwCSGCEW9Nig+uZ2+utPrpjbWSD7zU85b8GnmN4F1e3u2FZ35NfVpvaFa+R2T8C0a+S/eCPFJnp9mejcXET0FuyJSc4i1dL8/u1PhX1nVxhSc+jaYSBvWpmG/uoYxyqclmYd6FNrHMIzNMk8dQWAEpI8y0XtGdvUcI+5xIRw= Received: from DU2PR04CA0181.eurprd04.prod.outlook.com (2603:10a6:10:28d::6) by AM0PR08MB3361.eurprd08.prod.outlook.com (2603:10a6:208:db::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.16; Wed, 10 Nov 2021 18:06:47 +0000 Received: from DB5EUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28d:cafe::7f) by DU2PR04CA0181.outlook.office365.com (2603:10a6:10:28d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 18:06:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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 DB5EUR03FT032.mail.protection.outlook.com (10.152.20.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.19 via Frontend Transport; Wed, 10 Nov 2021 18:06:47 +0000 Received: ("Tessian outbound 6ebd41198c5d:v108"); Wed, 10 Nov 2021 18:06:47 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2e1f9dbef5a0efcc X-CR-MTA-TID: 64aa7808 Received: from ffe53df379ba.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A7A9F235-358C-4AD5-83EB-0DF0F9F78DD5.1; Wed, 10 Nov 2021 18:06:35 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ffe53df379ba.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 10 Nov 2021 18:06:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nDu0gnbFv0g06wLJvaotAJYLULy2fj7UUV7jbSNhIJg5CBLjbUTVaBgVJYdxpg/8qZuR12hhSCSIta7JzRb4yjOEdBO8BtFHFic/8EN6vglhhKABrdYO2NFR174VuQdV093ALrQzH2v92+RaxK7KWjNyZo01iJ9SNUuVQcEEuspjixIWvbLGbnXvOPY3qbqzc2tFqSBn7kfIvOUnCR1fz87uzCwr4MDEIDRk53z/XeP5YhYRJLt3iZZKLacjAjZCVRcBEFJnnifoau/S+r+sGb+ozC9oQ8W385GTdXtqBFOEQx63vOviQTwS0NsFroZL8eN/TlJJZd7efutMedTweQ== 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=21kdxcR5nYiewbF2oFL/uVHbRgan6Lkc2XdoxqW+I5o=; b=YbqGhSbnprrFtuDERq1xgiAecai/2vS2UQDcX1xTvuaDzXOIS8HJ7Fg1LADkHsTK1Ub4PoOwlKV5mCi2/TVxsip4d1QlMRrfOtd3AsGcK4GOqq+c9vTfZSfz8RFmnhVcrgkYKfDFH1wDqsHCMw77H7ojl/V7yYMBriwLcs3OpR7qqo2woHaMKYAtqno6YcoXQFGPjg6y/8lp+/hcdNhLDGg0gQ+l1K4M5vm6ZxhfEHKzSLfpH6rcKi1ZYg3NVvPrD3DtcJnG/Ae9NOFfgucRVPr4cZDagc356LHnU1FRj8AShR3xw3auKqL3dWhqUXpNK4RVK3iZEj5nEckAW7u1cA== 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=21kdxcR5nYiewbF2oFL/uVHbRgan6Lkc2XdoxqW+I5o=; b=BGaCwCSGCEW9Nig+uZ2+utPrpjbWSD7zU85b8GnmN4F1e3u2FZ35NfVpvaFa+R2T8C0a+S/eCPFJnp9mejcXET0FuyJSc4i1dL8/u1PhX1nVxhSc+jaYSBvWpmG/uoYxyqclmYd6FNrHMIzNMk8dQWAEpI8y0XtGdvUcI+5xIRw= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by AM5PR0802MB2609.eurprd08.prod.outlook.com (2603:10a6:203:98::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.16; Wed, 10 Nov 2021 18:06:34 +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.4669.010; Wed, 10 Nov 2021 18:06:33 +0000 Subject: Re: [PATCH v3 1/1] MdeModulePkg: Add MpServicesTest application to exercise MP Services To: Rebecca Cran , devel@edk2.groups.io, Ard Biesheuvel , Gerd Hoffmann , Samer El-Haj-Mahmoud , Leif Lindholm , Jian J Wang , Liming Gao , nd References: <20211105203112.24313-1-rebecca@nuviainc.com> From: "Sami Mujawar" Message-ID: Date: Wed, 10 Nov 2021 18:06:39 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 In-Reply-To: <20211105203112.24313-1-rebecca@nuviainc.com> X-ClientProxiedBy: LO2P265CA0143.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::35) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 Received: from [10.1.196.43] (217.140.106.52) by LO2P265CA0143.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Wed, 10 Nov 2021 18:06:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d77222ad-f8ce-4740-6295-08d9a474dc6c X-MS-TrafficTypeDiagnostic: AM5PR0802MB2609:|AM0PR08MB3361: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2399;OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: z0pdmlO7nKpmSvM5lcxrml50Sv1TW8g0srGD8FsPzDfN46ERX5BhLLy/okJABjzYXjiEJVzyJcsaxH097sCRQTrCEdUnIpA1XdrMp5KxBR3/e+yIkSjne57PlUXjLYIhdUfyndM1FMrTvbAGsrvDTY46b0oeEZzhBDpcLtTXc0p/+wfEZkbvafwLvwuAyKLowUkEfHqeNCqmehpiwoZ9o+YT1rgDp9bIFCxQqD+DEAahqIU8JsX643UcNICydWL0F2HTol9nVq4wM2gfV8bQAVA9+IcQh7dfbLnP4owdLfyxs7Kqkqb7fm2ksolCcx8E9xmorNPyDQ+k9e3zqq1L9KKPXpKeKAmIV1LQ8aCOwWIpfjqcZUUIcaH/hSwecQzSNajqxfkbEqUMdGQg+wzJh+viZbLaC6VGJtBtK8k0xa1+37eR9kVA1VdFZ61VBVEe5PqRcAunPaw7IWO8CaSedrHreoh1yQooxTqocdBzA5HpTlE9AzyD36Jtqx6FYd8gcvnCWRsmnsD9FhhC9QoAZDOc8RKMSPw6/CcwCZHm1jkegujkg1HJEs3CwEWXnK8a2qP7QF5v0wyl/HPuDdTr7aiues+ij7on6fMasdf0AYdM6LOoiWw4NpS1bGL1d0FhMTvNpSMu6oftXSW48EAThL4dgijFhhG0CjkVdXAEvnP+246VBRQXR13uI5nbxtzT/YZFcXS/zw9F/lwleI56PkGy7ESWS+MxkIj5nrzkRgcTK8bRujDThr9OTYkqN6HuMro2T2Cyt/zvuNw8AUfuyw== 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)(8676002)(38100700002)(5660300002)(186003)(86362001)(66476007)(38350700002)(53546011)(508600001)(66946007)(66556008)(6486002)(30864003)(52116002)(31696002)(2906002)(36756003)(6636002)(83380400001)(316002)(19627235002)(8936002)(110136005)(26005)(44832011)(16576012)(31686004)(2616005)(956004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2609 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 49daf674-b7e8-42b7-8876-08d9a474d3c3 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: syXVw/S4OewBD1sD6a77gcR9xjm9GClA5Q8A0QTi3CI5/kc90X7xVVwOW9jjERG6moUiznl+mXenbfV0mDdccepK42NeDhhJlh6ChJ31rS/qGeG2BBCREbkPpC8jLtNZw/gptk2rBeHK04N6KEitjaK70JTybB1zW95SrNkZjzDnt9WjSK3kupTO2ooFOiCbavNIZt2xi6Ev3OBtE8H15T7GBNwnhyK6i4OAVlZBOo/3QXlb8VRKsKZFpql28eyDAfTNtGd2fMOGkiZMYDQsh4x5s0IuVXfPFn0HJ6V+QmDVrfaxdtI8gR79mm+5w8JyEvasurHyfspZnmFUL3UpjBprlWSwA8GV5Z/d1jawMjY17EeWibNjqMj0qMp1YUYfrvDLlqUMjWYDbFJy53woCkvDC8H3Wo34d2o9Wux+k3A1XKIwvqCXmE71tiftGrV1AMLovw4T9noQMQ3+SvoqvCPIRdEEKPsuhV0Wcak2o5W5JMzxQx5+KrzPFgUNeWC0C+bETt2+qJ4DJVgTsCItXAB793BwT1JaP/OCF6fnfwkgFLNkp1wtAm+6HX1HpfUTRhgKdFvt7BZFAtgU5Q5CajHmtVYYn4lyEweGIKGwckTIKtv8JeyADWI6WlLGPGYyUJQuMxJGwUt/tWzEl/LzupqjwkTrEQCq5dEO5mIXeUOYoa5CI4gA47f4KCtclbvLLk5SBIU1aqRqhoobvp594qUJRLX50KV7K9HJ3ICR2vs= 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)(46966006)(36840700001)(2906002)(356005)(82310400003)(44832011)(86362001)(956004)(316002)(30864003)(26005)(19627235002)(6486002)(36860700001)(186003)(336012)(5660300002)(6636002)(16576012)(508600001)(83380400001)(110136005)(36756003)(2616005)(81166007)(31696002)(53546011)(70206006)(47076005)(8676002)(70586007)(31686004)(8936002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 18:06:47.0798 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d77222ad-f8ce-4740-6295-08d9a474dc6c 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: DB5EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3361 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-GB Hi Rebecca, Thank you for the updated patch. These changes look good to me. The INF file mentions support for IA32 and X64 so it would be got to get feedback for other architectures and from the MdeModulePkg maintainers. Reviewed-by: Sami Mujawar Regards, Sami Mujawar On 05/11/2021 08:31 PM, Rebecca Cran 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 | 428 ++++++= ++++++++++++++ > MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf | 38 ++ > MdeModulePkg/MdeModulePkg.dsc | 2 + > 3 files changed, 468 insertions(+) > > diff --git a/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c b/M= deModulePkg/Application/MpServicesTest/MpServicesTest.c > new file mode 100644 > index 000000000000..d066bdd530d5 > --- /dev/null > +++ b/MdeModulePkg/Application/MpServicesTest/MpServicesTest.c > @@ -0,0 +1,428 @@ > +/** @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 > + > + > +/** 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 > + ); > + > + if (EFI_ERROR (Status)) { > + Print (L"failed: %r\n", Status); > + return; > + } > + else { > + Print (L"done.\n"); > + } > + > + 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 > + ); > + if (EFI_ERROR (Status)) { > + Print (L"failed: %r\n", Status); > + return; > + } > + else { > + Print (L"done.\n"); > + } > +} > + > +/** 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); > + if (EFI_ERROR (Status)) { > + Print (L"failed: %r\n", Status); > + return; > + } > + else { > + Print (L"done.\n"); > + } > + > + 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 > + ); > + if (EFI_ERROR (Status)) { > + Print (L"failed: %r\n", Status); > + return; > + } > + else { > + Print (L"done.\n"); > + } > +} > + > +/** 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); > + if (EFI_ERROR (Status)) { > + Print (L"failed: %r\n", Status); > + return; > + } > + else { > + Print (L"done.\n"); > + } > + } > + > + 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); > + if (EFI_ERROR (Status)) { > + Print (L"failed: %r\n", Status); > + return; > + } > + else { > + Print (L"done.\n"); > + } > + } > +} > + > +/** > + 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); > + > + 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 IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you.