From nobody Mon Dec 15 02:55:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106715+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106715+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1688707750; cv=none; d=zohomail.com; s=zohoarc; b=SQTT+Ry4T2ImOmoO3ZD/TJwg88yw385dZvLHxWomv+AidHbNkPeDqclYKfDcJn3IaKpf5VgP1PaSG/WTST7vvlN85POnDIEB1Y9jESdOKxQSn+jGp1g9NEfn4SFleJvRohOGKvn/aqTuaxKGqDYlCRIWfn/8nNoy1A6kl9ZuRTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688707750; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=9RDOkiM2oBFQXuoQ6EGQzqKrSf64ldRQbhnrT+JS3ec=; b=EmYVAR6E7w/nln48B/DKxrMGtyloyYfqTY+H/7h6HOIBWSLbGyAf1M7kfI1N3OIgwQKKW+ryTWI0hLcvyI8Skc2aoU9T6XfGhzisD2wZZYo31vhJ4EZwH/CJAi+F9Op8MQQrfAWGa83EO1F5NJrDKJq+xp8vyhCL9e0wKp1tiC0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106715+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1688707750879139.43798349572205; Thu, 6 Jul 2023 22:29:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eqooYY1788612xmkhzAogZCs; Thu, 06 Jul 2023 22:29:10 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.6404.1688707749454802251 for ; Thu, 06 Jul 2023 22:29:10 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="353650624" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="353650624" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2023 22:29:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10763"; a="833232027" X-IronPort-AV: E=Sophos;i="6.01,187,1684825200"; d="scan'208";a="833232027" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.55.95]) by fmsmga002.fm.intel.com with ESMTP; 06 Jul 2023 22:29:08 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 1/4] UefiCpuPkg/MpInitLib: Separate X2APIC enabling to subfunction Date: Fri, 7 Jul 2023 13:28:58 +0800 Message-Id: <20230707052901.869-2-ray.ni@intel.com> In-Reply-To: <20230707052901.869-1-ray.ni@intel.com> References: <20230707052901.869-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ray.ni@intel.com X-Gm-Message-State: XzYsr0si1V1qsmkR20tvHQrzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688707750; bh=l/cmBGDw+7bUcqZml1RvX8fMCg3tXpfOOfNtcU2ZB6A=; h=Cc:Date:From:Reply-To:Subject:To; b=rHZz/qC2do2eq27AObSTrEo6BLZQjSlmruNQoWmSEgWfzbHVIWgv2aruVYGfO6AjIZx k5I33Ldpz3QZITjBwam6pbzISDLdLK1G1ii7cGgD0Foieg+fb9K33T41tfzxO0sxfCENg ckWf+TRQcuEQmpoCrckweFIjGBSpX8PNTjU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688707752215100004 Content-Type: text/plain; charset="utf-8" It's very confusing that auto X2 APIC enabling and APIC ID sorting are all performed inside CollectProcessorCount(). The change is to separate the X2 APIC enabling to AutoEnableX2Apic() and call that from MpInitLibInitialize(). SortApicId() is called from MpInitLibInitialize() as well. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 65 ++++++++++++++++++---------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index f1f2840714..bf80455965 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -495,33 +495,20 @@ GetProcessorNumber ( } =20 /** - This function will get CPU count in the system. + Enable x2APIC mode if + 1. Number of CPU is greater than 255; or + 2. There are any logical processors reporting an Initial APIC ID of 255 = or greater. =20 @param[in] CpuMpData Pointer to PEI CPU MP Data - - @return CPU count detected **/ -UINTN -CollectProcessorCount ( +VOID +AutoEnableX2Apic ( IN CPU_MP_DATA *CpuMpData ) { + BOOLEAN X2Apic; UINTN Index; CPU_INFO_IN_HOB *CpuInfoInHob; - BOOLEAN X2Apic; - - // - // Send 1st broadcast IPI to APs to wakeup APs - // - CpuMpData->InitFlag =3D ApInitConfig; - WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); - CpuMpData->InitFlag =3D ApInitDone; - // - // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs are= checked in. - // FinishedCount is the number of check-in APs. - // - CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; - ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); =20 // // Enable x2APIC mode if @@ -570,12 +557,32 @@ CollectProcessorCount ( } =20 DEBUG ((DEBUG_INFO, "APIC MODE is %d\n", GetApicMode ())); +} + +/** + This function will get CPU count in the system. + + @param[in] CpuMpData Pointer to PEI CPU MP Data + + @return CPU count detected +**/ +UINTN +CollectProcessorCount ( + IN CPU_MP_DATA *CpuMpData + ) +{ // - // Sort BSP/Aps by CPU APIC ID in ascending order + // Send 1st broadcast IPI to APs to wakeup APs // - SortApicId (CpuMpData); - - DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", CpuMpD= ata->CpuCount)); + CpuMpData->InitFlag =3D ApInitConfig; + WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE); + CpuMpData->InitFlag =3D ApInitDone; + // + // When InitFlag =3D=3D ApInitConfig, WakeUpAP () guarantees all APs are= checked in. + // FinishedCount is the number of check-in APs. + // + CpuMpData->CpuCount =3D CpuMpData->FinishedCount + 1; + ASSERT (CpuMpData->CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumb= er)); =20 return CpuMpData->CpuCount; } @@ -1976,6 +1983,18 @@ MpInitLibInitialize ( // Wakeup all APs and calculate the processor count in system // CollectProcessorCount (CpuMpData); + + // + // Enable X2APIC if needed. + // + AutoEnableX2Apic (CpuMpData); + + // + // Sort BSP/Aps by CPU APIC ID in ascending order + // + SortApicId (CpuMpData); + + DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", Cp= uMpData->CpuCount)); } } else { // --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106715): https://edk2.groups.io/g/devel/message/106715 Mute This Topic: https://groups.io/mt/100000875/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-