From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web08.2769.1628242705323146134 for ; Fri, 06 Aug 2021 02:38:26 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: yun.lou@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10067"; a="201524969" X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="201524969" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 02:38:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="669349370" Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.74]) by fmsmga006.fm.intel.com with ESMTP; 06 Aug 2021 02:38:21 -0700 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v2] UefiCpuPkg/CpuCacheInfoLib: Sort CpuCacheInfo array Date: Fri, 6 Aug 2021 17:38:18 +0800 Message-Id: <20210806093818.4924-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..7474fe0f50 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.Fields.Package =3D ((CPU_CACHE_INFO*)Buffer1)->Package;=0D + Comparator1.Fields.CoreType =3D ((CPU_CACHE_INFO*)Buffer1)->CoreType;= =0D + Comparator1.Fields.CacheLevel =3D ((CPU_CACHE_INFO*)Buffer1)->CacheLevel= ;=0D + Comparator1.Fields.CacheType =3D ((CPU_CACHE_INFO*)Buffer1)->CacheType;= =0D +=0D + Comparator2.Fields.Package =3D ((CPU_CACHE_INFO*)Buffer2)->Package;=0D + Comparator2.Fields.CoreType =3D ((CPU_CACHE_INFO*)Buffer2)->CoreType;= =0D + Comparator2.Fields.CacheLevel =3D ((CPU_CACHE_INFO*)Buffer2)->CacheLevel= ;=0D + Comparator2.Fields.CacheType =3D ((CPU_CACHE_INFO*)Buffer2)->CacheType;= =0D +=0D + if (Comparator1.Data64 =3D=3D Comparator2.Data64) {=0D + return 0;=0D + } else if (Comparator1.Data64 > Comparator2.Data64) {=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..6135215e5f 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 + } Fields;=0D + UINT64 Data64;=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