From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.5509.1628260641262417072 for ; Fri, 06 Aug 2021 07:37:21 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: yun.lou@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10068"; a="275424091" X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="275424091" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 07:37:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="513462995" Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.74]) by FMSMGA003.fm.intel.com with ESMTP; 06 Aug 2021 07:37:18 -0700 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v3] UefiCpuPkg/CpuCacheInfoLib: Sort CpuCacheInfo array Date: Fri, 6 Aug 2021 22:37:13 +0800 Message-Id: <20210806143713.5235-1-yun.lou@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3508 Sort the CpuCacheInfo array by CPU package ID, core type, cache level and cache type. Signed-off-by: Jason Lou Cc: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek Cc: Rahul Kumar --- UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c | 47 ++++++++= +++++++++++- UefiCpuPkg/Include/Library/CpuCacheInfoLib.h | 2 +- UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf | 4 +- UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h | 27 ++++++++= +++ UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf | 4 +- 5 files changed, 80 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c b/UefiCpu= Pkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c index 126ee0da86..ae81ea9ce2 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c @@ -37,6 +37,47 @@ CpuCacheInfoPrintCpuCacheInfoTable ( DEBUG ((DEBUG_INFO, "+-------+------------------------------------------= --------------------------------------------+\n"));=0D }=0D =0D +/**=0D + Function to compare CPU package ID, core type, cache level and cache typ= e for use in QuickSort.=0D +=0D + @param[in] Buffer1 pointer to CPU_CACHE_INFO poiner to comp= are=0D + @param[in] Buffer2 pointer to second CPU_CACHE_INFO pointer= to compare=0D +=0D + @retval 0 Buffer1 equal to Buffer2=0D + @retval 1 Buffer1 is greater than Buffer2=0D + @retval -1 Buffer1 is less than Buffer2=0D +**/=0D +INTN=0D +EFIAPI=0D +CpuCacheInfoCompare (=0D + IN CONST VOID *Buffer1,=0D + IN CONST VOID *Buffer2=0D + )=0D +{=0D + CPU_CACHE_INFO_COMPARATOR Comparator1, Comparator2;=0D +=0D + ZeroMem (&Comparator1, sizeof (Comparator1));=0D + ZeroMem (&Comparator2, sizeof (Comparator2));=0D +=0D + Comparator1.Bits.Package =3D ((CPU_CACHE_INFO*)Buffer1)->Package;=0D + Comparator1.Bits.CoreType =3D ((CPU_CACHE_INFO*)Buffer1)->CoreType;=0D + Comparator1.Bits.CacheLevel =3D ((CPU_CACHE_INFO*)Buffer1)->CacheLevel;= =0D + Comparator1.Bits.CacheType =3D ((CPU_CACHE_INFO*)Buffer1)->CacheType;=0D +=0D + Comparator2.Bits.Package =3D ((CPU_CACHE_INFO*)Buffer2)->Package;=0D + Comparator2.Bits.CoreType =3D ((CPU_CACHE_INFO*)Buffer2)->CoreType;=0D + Comparator2.Bits.CacheLevel =3D ((CPU_CACHE_INFO*)Buffer2)->CacheLevel;= =0D + Comparator2.Bits.CacheType =3D ((CPU_CACHE_INFO*)Buffer2)->CacheType;=0D +=0D + if (Comparator1.Uint64 =3D=3D Comparator2.Uint64) {=0D + return 0;=0D + } else if (Comparator1.Uint64 > Comparator2.Uint64) {=0D + return 1;=0D + } else {=0D + return -1;=0D + }=0D +}=0D +=0D /**=0D Get the total number of package and package ID in the platform.=0D =0D @@ -325,6 +366,10 @@ CpuCacheInfoCollectCpuCacheInfoData ( if (*CacheInfoCount < LocalCacheInfoCount) {=0D Status =3D EFI_BUFFER_TOO_SMALL;=0D } else {=0D + //=0D + // Sort LocalCacheInfo array by CPU package ID, core type, cache level= and cache type.=0D + //=0D + PerformQuickSort (LocalCacheInfo, LocalCacheInfoCount, sizeof (*LocalC= acheInfo), (SORT_COMPARE) CpuCacheInfoCompare);=0D CopyMem (CacheInfo, LocalCacheInfo, sizeof (*CacheInfo) * LocalCacheIn= foCount);=0D DEBUG_CODE (=0D CpuCacheInfoPrintCpuCacheInfoTable (CacheInfo, LocalCacheInfoCount);= =0D @@ -340,7 +385,7 @@ CpuCacheInfoCollectCpuCacheInfoData ( }=0D =0D /**=0D - Get CpuCacheInfo data array.=0D + Get CpuCacheInfo data array. The array is sorted by CPU package ID, core= type, cache level and cache type.=0D =0D @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array.=0D @param[in, out] CpuCacheInfoCount As input, point to the length of res= ponse CpuCacheInfo array.=0D diff --git a/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h b/UefiCpuPkg/Incl= ude/Library/CpuCacheInfoLib.h index a66152bce0..3422997f54 100644 --- a/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h +++ b/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h @@ -59,7 +59,7 @@ typedef struct { } CPU_CACHE_INFO;=0D =0D /**=0D - Get CpuCacheInfo data array.=0D + Get CpuCacheInfo data array. The array is sorted by CPU package ID, core= type, cache level and cache type.=0D =0D @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array.=0D @param[in, out] CpuCacheInfoCount As input, point to the length of res= ponse CpuCacheInfo array.=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf b/Ue= fiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf index c481080e49..c3d3f1e799 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf @@ -3,7 +3,7 @@ #=0D # Provides cache info for each package, core type, cache level and cache = type.=0D #=0D -# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
= =0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -25,6 +25,7 @@ =0D [Packages]=0D MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D UefiCpuPkg/UefiCpuPkg.dec=0D =0D [LibraryClasses]=0D @@ -33,6 +34,7 @@ BaseMemoryLib=0D MemoryAllocationLib=0D UefiBootServicesTableLib=0D + SortLib=0D =0D [Protocols]=0D gEfiMpServiceProtocolGuid=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h b= /UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h index b6e6ae5bc5..26e1f46516 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h @@ -17,8 +17,35 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D =0D +typedef union {=0D + struct {=0D + //=0D + // Type of the cache that this package's this type of logical processo= r corresponds to.=0D + // Value =3D CPUID.04h:EAX[04:00]=0D + //=0D + UINT32 CacheType : 5;=0D + //=0D + // Level of the cache that this package's this type of logical process= or corresponds to.=0D + // Value =3D CPUID.04h:EAX[07:05]=0D + //=0D + UINT32 CacheLevel : 3;=0D + //=0D + // Core type of logical processor.=0D + // Value =3D CPUID.1Ah:EAX[31:24]=0D + //=0D + UINT32 CoreType : 8;=0D + UINT32 Reserved : 16;=0D + //=0D + // Package number.=0D + //=0D + UINT32 Package;=0D + } Bits;=0D + UINT64 Uint64;=0D +} CPU_CACHE_INFO_COMPARATOR;=0D +=0D typedef struct {=0D //=0D // Package ID, the information comes from=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf b/Ue= fiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf index 0c73015cac..0864497849 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf @@ -3,7 +3,7 @@ #=0D # Provides cache info for each package, core type, cache level and cache = type.=0D #=0D -# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
= =0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -25,6 +25,7 @@ =0D [Packages]=0D MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D UefiCpuPkg/UefiCpuPkg.dec=0D =0D [LibraryClasses]=0D @@ -33,6 +34,7 @@ BaseMemoryLib=0D MemoryAllocationLib=0D PeiServicesTablePointerLib=0D + SortLib=0D =0D [Ppis]=0D gEdkiiPeiMpServices2PpiGuid=0D --=20 2.28.0.windows.1