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 97FA4740046 for ; Mon, 1 Apr 2024 06:04:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=m8AwYqdXxYvaBRbyWZnw+LkdgGyah07sz9YyNM20/s0=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: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=1711951477; v=1; b=q5QW5teNVoQqbd/5vko5uhC5U3lkX8l6BK+R47nb6pYXi1nZ+3DAVs8v3yYC/n8Zan8mezON GcalCvgB41StZ1Btntgd939RUEYMWeYoV4z8pDQhAMoNvzjwInw/jMPg1Ivz00HIFaGBA9gG7ZO wkEkC4uGXC0U0wn/6Z0JGp+9/rfV/TY4MZfIeNRJrGZZCldT4VwyHzOuw0eDR1u2AX2HnZwlyqM 8eJTJT0/orrJKAE6l0Ey6sT8GC7/xhbT2kIqQ2q2fLCc8hupM5iYoQj9sVfTqyVVaipLvNt1s9v N3Lytt5E+OfPvxI4J0tSoJKPxrWplvimWdsysA6Dnn5Lg== X-Received: by 127.0.0.2 with SMTP id fiRPYY7687511xlE8HfhZZHb; Sun, 31 Mar 2024 23:04:37 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by mx.groups.io with SMTP id smtpd.web10.31899.1711951462693257400 for ; Sun, 31 Mar 2024 23:04:36 -0700 X-CSE-ConnectionGUID: ROYejsZQT4un4CYnE3d5Lw== X-CSE-MsgGUID: KsOUhU6LSyuCn3H405q5Xg== X-IronPort-AV: E=McAfee;i="6600,9927,11030"; a="7214065" X-IronPort-AV: E=Sophos;i="6.07,171,1708416000"; d="scan'208";a="7214065" X-Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2024 23:04:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,171,1708416000"; d="scan'208";a="17438933" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2024 23:04:35 -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 V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules Date: Mon, 1 Apr 2024 14:04:11 +0800 Message-Id: <20240401060411.899-4-dun.tan@intel.com> In-Reply-To: <20240401060411.899-1-dun.tan@intel.com> References: <20240401060411.899-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: Sun, 31 Mar 2024 23:04:36 -0700 Reply-To: devel@edk2.groups.io,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: HWlKxFwqiKg5ZuzgpbiSDnSrx7686176AA= 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=q5QW5teN; 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. 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 | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index 1fa70e3df9..389df48824 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -132,6 +132,62 @@ AppendCpuMapTableEntry ( } +/** + Sort CpuApicIdOrderTable based on the following rules: + 1.Make sure BSP is the first entry. + 2.Big core first, then small core. + + @param[in] CpuApicIdOrderTable Pointer to EFI_CPU_ID_ORDER_MAP + @param[in] Count Number to EFI_CPU_ID_ORDER_MAP + @param[in] BspIndex BSP index +**/ +VOID +SortApicIdOrderTable ( + IN EFI_CPU_ID_ORDER_MAP *CpuApicIdOrderTable, + IN UINTN Count, + IN UINTN BspIndex + ) +{ + UINTN Index; + UINTN SubIndex; + EFI_CPU_ID_ORDER_MAP SortBuffer; + + // + // Put BSP at the first entry. + // + if (BspIndex != 0) { + CopyMem (&SortBuffer, &CpuApicIdOrderTable[BspIndex], sizeof (EFI_CPU_ID_ORDER_MAP)); + CopyMem (&CpuApicIdOrderTable[1], CpuApicIdOrderTable, (BspIndex) * sizeof (EFI_CPU_ID_ORDER_MAP)); + CopyMem (CpuApicIdOrderTable, &SortBuffer, sizeof (EFI_CPU_ID_ORDER_MAP)); + } + + // + // If there are more than 2 cores, perform insertion sort for rest cores except the bsp in first entry + // to move big cores in front of small cores. + // Also the original order based on the MpService index inside big cores and small cores are retained. + // + for (Index = 2; Index < Count; Index++) { + if (CpuApicIdOrderTable[Index].CoreType == CPUID_CORE_TYPE_INTEL_ATOM) { + continue; + } + + CopyMem (&SortBuffer, &CpuApicIdOrderTable[Index], sizeof (EFI_CPU_ID_ORDER_MAP)); + + for (SubIndex = Index - 1; SubIndex >= 1; SubIndex--) { + if (CpuApicIdOrderTable[SubIndex].CoreType == CPUID_CORE_TYPE_INTEL_ATOM) { + CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &CpuApicIdOrderTable[SubIndex], sizeof (EFI_CPU_ID_ORDER_MAP)); + } else { + // + // Except the BSP, all cores in front of SubIndex must be big cores. + // + break; + } + } + + CopyMem (&CpuApicIdOrderTable[SubIndex + 1], &SortBuffer, sizeof (EFI_CPU_ID_ORDER_MAP)); + } +} + /** Get CPU core type. @@ -174,6 +230,7 @@ CreateCpuLocalApicInTable ( EFI_CPU_ID_ORDER_MAP *CpuIdMapPtr; UINT32 Socket; UINT32 CpuidMaxInput; + UINTN BspIndex; Status = EFI_SUCCESS; @@ -198,6 +255,10 @@ CreateCpuLocalApicInTable ( &ProcessorInfoBuffer ); + if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) != 0) { + BspIndex = Index; + } + CpuIdMapPtr = (EFI_CPU_ID_ORDER_MAP *) &CpuApicIdOrderTable[Index]; if ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT) != 0) { CpuIdMapPtr->ApicId = (UINT32)ProcessorInfoBuffer.ProcessorId; @@ -230,6 +291,8 @@ CreateCpuLocalApicInTable ( } } + SortApicIdOrderTable (CpuApicIdOrderTable, mNumberOfCpus, BspIndex); + 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 (#117281): https://edk2.groups.io/g/devel/message/117281 Mute This Topic: https://groups.io/mt/105259125/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-