From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 2EDA09411F3 for ; Thu, 28 Mar 2024 08:45:17 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JL+lZFDG/O6CnHmSkarpPEJVewRAjStBfpVtHwubLak=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1711615516; v=1; b=hVxrE6xJiCUoL4z1A0uhwUqg03pc88VJpyzzAYMQ+n1MGNC/uSOIuj8oBhz7iF9zQN9+eyJn HxfUdgAVt4C8h4AqQMeq2VfDezJgxAwNDQGB+5VdZSWOJ2j+rlq+4EloWjfJEfhBGzBISykTILd pURF542B0K09KIhDqrLjBTvb3rW/LCOEUC+Ki0LPHdXbIT/nv5nqP8mbHtyEPAN0WQOHNGqtWYb wK3jBJ6WhWRtRCAajumBKvuU8HaNU5+dpvKpclmxmNSkAlEGaVun2E0DS/ouQpOLjVHuXjA2TbB 5m+PpA6l42pd4LJCKvDlmTl7wqnELlF2vUNQmE/XsMC3w== X-Received: by 127.0.0.2 with SMTP id 5YF7YY7687511xfKok2fHiwu; Thu, 28 Mar 2024 01:45:16 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mx.groups.io with SMTP id smtpd.web11.10813.1711615515932336233 for ; Thu, 28 Mar 2024 01:45:16 -0700 X-CSE-ConnectionGUID: 6BP3ewItRPW+RodvChvlAQ== X-CSE-MsgGUID: EJPXVOtkTp+fnNaXkn/WbA== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="10537644" X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="10537644" X-Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 01:45:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="21263853" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 01:45:14 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Ray Ni , Jason Lou , Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong Subject: [edk2-devel] [edk2-platforms] MinPlatformPkg: Sort ApicIdOrderTable by special rules Date: Thu, 28 Mar 2024 16:43:00 +0800 Message-Id: <20240328084300.1158-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 28 Mar 2024 01:45:16 -0700 Reply-To: devel@edk2.groups.io,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: VrRuakzqesVpg3PLIcJq0oHpx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=hVxrE6xJ; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Sort ApicIdOrderTable by following special rules: 1. Make sure BSP is the first entry. 2. For APs, big core first, then small core. 3. For APs, if the core type are the same, sort them by AcpiProcessorUid. With this implementation, BIOS can present cores in order of relative performance in MADT. Linux OS would schedule cores by the order that they are presented in the MADT LocalX2ApicStruct entries.Then Linux OS would think of this as relative performance order. This implementation can benefit the linux os usage case. Signed-off-by: Dun Tan Cc: Ray Ni Cc: Jason Lou Cc: Chasel Chiu Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong --- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 109 insertions(+), 4 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index 2a833ec99c..1216a42eb4 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -18,6 +18,8 @@ typedef struct { UINT32 Flags; UINT32 SocketNum; UINT32 Thread; + UINT8 CoreType; + BOOLEAN IsBsp; } EFI_CPU_ID_ORDER_MAP; // @@ -72,15 +74,16 @@ DebugDisplayReOrderTable ( { UINT32 Index; - DEBUG ((DEBUG_INFO, "Index AcpiProcId ApicId Thread Flags Skt\n")); + DEBUG ((DEBUG_INFO, "Index AcpiProcId ApicId Thread Flags Skt CoreType\n")); for (Index = 0; Index < mNumberOfCpus; Index++) { - DEBUG ((DEBUG_INFO, " %02d 0x%02X 0x%02X %d %d %d\n", + DEBUG ((DEBUG_INFO, " %02d 0x%02X 0x%02X %d %d %d 0X%x\n", Index, CpuApicIdOrderTable[Index].AcpiProcessorUid, CpuApicIdOrderTable[Index].ApicId, CpuApicIdOrderTable[Index].Thread, CpuApicIdOrderTable[Index].Flags, - CpuApicIdOrderTable[Index].SocketNum)); + CpuApicIdOrderTable[Index].SocketNum, + CpuApicIdOrderTable[Index].CoreType)); } } @@ -131,6 +134,82 @@ AppendCpuMapTableEntry ( } +/** + Get CPU core type. + + @param[in] CpuApicIdOrderTable Point to a buffer which will be filled in Core type information. +**/ +VOID +EFIAPI +CollectCpuCoreType ( + IN EFI_CPU_ID_ORDER_MAP *CpuApicIdOrderTable + ) +{ + UINTN ApNumber; + EFI_STATUS Status; + CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX NativeModelIdAndCoreTypeEax; + + Status = mMpService->WhoAmI ( + mMpService, + &ApNumber + ); + ASSERT_EFI_ERROR (Status); + + AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL); + CpuApicIdOrderTable[ApNumber].CoreType = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType; +} + +/** + Function to compare 2 EFI_CPU_ID_ORDER_MAP entry based on special rules. + + @param[in] Buffer1 pointer to EFI_CPU_ID_ORDER_MAP poiner to compare + @param[in] Buffer2 pointer to second EFI_CPU_ID_ORDER_MAP pointer to compare + + @retval 0 Buffer1 equal to Buffer2 + @retval <0 Buffer1 is less than Buffer2 + @retval >0 Buffer1 is greater than Buffer2 +**/ +INTN +EFIAPI +ApicIdOrderTableCompare ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + // + // Make sure BSP is the first entry. + // + if (((EFI_CPU_ID_ORDER_MAP *)Buffer1)->IsBsp) { + return -1; + } else if (((EFI_CPU_ID_ORDER_MAP *)Buffer2)->IsBsp) { + return 1; + } + + // + // Make sure big core first, then small core + // + if ((((EFI_CPU_ID_ORDER_MAP *)Buffer1)->CoreType == CPUID_CORE_TYPE_INTEL_CORE) && + ((((EFI_CPU_ID_ORDER_MAP *)Buffer2)->CoreType == CPUID_CORE_TYPE_INTEL_ATOM))) + { + return -1; + } else if ((((EFI_CPU_ID_ORDER_MAP *)Buffer1)->CoreType == CPUID_CORE_TYPE_INTEL_ATOM) && + ((((EFI_CPU_ID_ORDER_MAP *)Buffer2)->CoreType == CPUID_CORE_TYPE_INTEL_CORE))) + { + return 1; + } + + // + // If both cores are not BSP and the core type are the same, sort them by AcpiProcessorUid. + // + if (((EFI_CPU_ID_ORDER_MAP *)Buffer1)->AcpiProcessorUid < ((EFI_CPU_ID_ORDER_MAP *)Buffer2)->AcpiProcessorUid) { + return -1; + } else if (((EFI_CPU_ID_ORDER_MAP *)Buffer1)->AcpiProcessorUid > ((EFI_CPU_ID_ORDER_MAP *)Buffer2)->AcpiProcessorUid) { + return 1; + } + + return 0; +} + /** Collect all processors information and create a Cpu Apic Id table. @@ -147,8 +226,24 @@ CreateCpuLocalApicInTable ( UINT32 CurrProcessor; EFI_CPU_ID_ORDER_MAP *CpuIdMapPtr; UINT32 Socket; + UINT32 CpuidMaxInput; + EFI_CPU_ID_ORDER_MAP SortBuffer; + + Status = EFI_SUCCESS; - Status = EFI_SUCCESS; + AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL); + if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) { + CollectCpuCoreType (CpuApicIdOrderTable); + mMpService->StartupAllAPs ( + mMpService, // This + (EFI_AP_PROCEDURE) CollectCpuCoreType, // Procedure + TRUE, // SingleThread + NULL, // WaitEvent + 0, // TimeoutInMicrosecsond + CpuApicIdOrderTable, // ProcedureArgument + NULL // FailedCpuList + ); + } for (CurrProcessor = 0, Index = 0; CurrProcessor < mNumberOfCpus; CurrProcessor++, Index++) { Status = mMpService->GetProcessorInfo ( @@ -158,6 +253,11 @@ CreateCpuLocalApicInTable ( ); CpuIdMapPtr = (EFI_CPU_ID_ORDER_MAP *) &CpuApicIdOrderTable[Index]; + + if (ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) { + CpuIdMapPtr->IsBsp = TRUE; + } + if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0) { CpuIdMapPtr->ApicId = (UINT32)ProcessorInfoBuffer.ProcessorId; CpuIdMapPtr->Thread = ProcessorInfoBuffer.Location.Thread; @@ -197,6 +297,11 @@ CreateCpuLocalApicInTable ( } } + // + // Perform quick sort + // + QuickSort (CpuApicIdOrderTable, mNumberOfCpus, sizeof (EFI_CPU_ID_ORDER_MAP), (BASE_SORT_COMPARE)ApicIdOrderTableCompare, &SortBuffer); + DEBUG ((DEBUG_INFO, "::ACPI:: APIC ID Order Table Init. mNumOfBitShift = %x\n", mNumOfBitShift)); DebugDisplayReOrderTable (CpuApicIdOrderTable); -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117201): https://edk2.groups.io/g/devel/message/117201 Mute This Topic: https://groups.io/mt/105193257/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-