public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chiu, Chasel" <chasel.chiu@intel.com>
To: "Tan, Dun" <dun.tan@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Ni, Ray" <ray.ni@intel.com>, "Lou, Yun" <yun.lou@intel.com>,
	"Desimone, Nathaniel L" <nathaniel.l.desimone@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	"Dong, Eric" <eric.dong@intel.com>
Subject: Re: [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules
Date: Tue, 2 Apr 2024 06:49:56 +0000	[thread overview]
Message-ID: <BN9PR11MB548325ACB7F04E4C146CBAEAE63E2@BN9PR11MB5483.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20240401060411.899-4-dun.tan@intel.com>


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

Thanks,
Chasel


> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Sunday, March 31, 2024 11:04 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Lou, Yun <yun.lou@intel.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by
> special rules
> 
> 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 <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Jason Lou <yun.lou@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> ---
>  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 (#117329): https://edk2.groups.io/g/devel/message/117329
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]
-=-=-=-=-=-=-=-=-=-=-=-



      parent reply	other threads:[~2024-04-02  6:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01  6:04 [edk2-devel] [edk2-platforms V2 0/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 1/3] MinPlatformPkg: Remove the global variable mForceX2ApicId duntan
2024-04-01  7:45   ` Ni, Ray
2024-04-02  6:49   ` Chiu, Chasel
2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 2/3] MinPlatformPkg: Get CoreType for all cores duntan
2024-04-01  7:45   ` Ni, Ray
2024-04-02  6:49   ` Chiu, Chasel
2024-04-01  6:04 ` [edk2-devel] [edk2-platforms V2 3/3] MinPlatformPkg: Sort ApicIdOrderTable by special rules duntan
2024-04-01  7:46   ` Ni, Ray
2024-04-02  6:49   ` Chiu, Chasel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BN9PR11MB548325ACB7F04E4C146CBAEAE63E2@BN9PR11MB5483.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox