From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web08.9290.1627381050811872898 for ; Tue, 27 Jul 2021 03:17:31 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: yun.lou@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10057"; a="199594945" X-IronPort-AV: E=Sophos;i="5.84,273,1620716400"; d="scan'208";a="199594945" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2021 03:17:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,273,1620716400"; d="scan'208";a="662587313" Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.74]) by fmsmga006.fm.intel.com with ESMTP; 27 Jul 2021 03:17:27 -0700 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v1] UefiCpuPkg/CpuCacheInfoLib: Sort CpuCacheInfo array Date: Tue, 27 Jul 2021 18:17:23 +0800 Message-Id: <20210727101723.3749-1-yun.lou@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jason REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3508 Sort the CpuCacheInfo array by the core type values from largest to smallest. Signed-off-by: Jason Lou Cc: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek Cc: Rahul Kumar --- UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c | 67 ++++++++= +++++++++++- UefiCpuPkg/Include/Library/CpuCacheInfoLib.h | 3 +- UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf | 4 +- UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h | 1 + UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf | 4 +- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c b/UefiCpu= Pkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c index 126ee0da86..fa4850c4fe 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c @@ -37,6 +37,69 @@ CpuCacheInfoPrintCpuCacheInfoTable ( DEBUG ((DEBUG_INFO, "+-------+------------------------------------------= --------------------------------------------+\n"));=0D }=0D =0D +/**=0D + Function to compare core type for use in QuickSort.=0D +=0D + @param[in] Buffer1 pointer to core type poiner to compare=0D + @param[in] Buffer2 pointer to second core type pointer to c= ompare=0D +=0D + @retval 0 Buffer1 equal to Buffer2=0D + @retval 1 Buffer1 is less than Buffer2=0D + @retval -1 Buffer1 is greater than Buffer2=0D +**/=0D +INTN=0D +EFIAPI=0D +CpuCacheInfoCompareCoreType (=0D + IN CONST VOID *Buffer1,=0D + IN CONST VOID *Buffer2=0D + )=0D +{=0D + if (((CPU_CACHE_INFO*)Buffer1)->CoreType =3D=3D ((CPU_CACHE_INFO*)Buffer= 2)->CoreType) {=0D + return 0;=0D + } else if (((CPU_CACHE_INFO*)Buffer1)->CoreType < ((CPU_CACHE_INFO*)Buff= er2)->CoreType) {=0D + return 1;=0D + } else {=0D + return -1;=0D + }=0D +}=0D +=0D +/**=0D + Sort CpuCacheInfo array by the core type values from largest to smallest= .=0D +=0D + @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array.=0D + @param[in] CpuCacheInfoCount The length of CpuCacheInfo array.=0D +=0D +**/=0D +VOID=0D +CpuCacheInfoSort (=0D + IN OUT CPU_CACHE_INFO *CpuCacheInfo,=0D + IN UINTN CpuCacheInfoCount=0D + )=0D +{=0D + UINTN Index;=0D + UINTN NextIndex;=0D + UINT32 CurrentPackage;=0D + UINT8 CacheInfoCountPerPackage;=0D +=0D + for (Index =3D 0; Index < CpuCacheInfoCount; Index +=3D CacheInfoCountPe= rPackage) {=0D + //=0D + // Calculate the number of CpuCacheInfo current processor has.=0D + //=0D + CurrentPackage =3D CpuCacheInfo[Index].Package;=0D + CacheInfoCountPerPackage =3D 1;=0D + for (NextIndex =3D Index + 1; NextIndex < CpuCacheInfoCount; NextIndex= ++) {=0D + if (CurrentPackage =3D=3D CpuCacheInfo[NextIndex].Package) {=0D + CacheInfoCountPerPackage++;=0D + }=0D + }=0D +=0D + //=0D + // Sort CpuCacheInfo for current processor by the core type values fro= m largest to smallest.=0D + //=0D + PerformQuickSort (&CpuCacheInfo[Index], CacheInfoCountPerPackage, size= of (*CpuCacheInfo), (SORT_COMPARE) CpuCacheInfoCompareCoreType);=0D + }=0D +}=0D +=0D /**=0D Get the total number of package and package ID in the platform.=0D =0D @@ -325,6 +388,7 @@ CpuCacheInfoCollectCpuCacheInfoData ( if (*CacheInfoCount < LocalCacheInfoCount) {=0D Status =3D EFI_BUFFER_TOO_SMALL;=0D } else {=0D + CpuCacheInfoSort (LocalCacheInfo, LocalCacheInfoCount);=0D CopyMem (CacheInfo, LocalCacheInfo, sizeof (*CacheInfo) * LocalCacheIn= foCount);=0D DEBUG_CODE (=0D CpuCacheInfoPrintCpuCacheInfoTable (CacheInfo, LocalCacheInfoCount);= =0D @@ -340,7 +404,8 @@ CpuCacheInfoCollectCpuCacheInfoData ( }=0D =0D /**=0D - Get CpuCacheInfo data array.=0D + Get CpuCacheInfo data array. The data array is sorted by CPU package ID = from smallest to largest,=0D + by core type from largest to smallest and by cache level from smallest t= o largest.=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..d813f53bf7 100644 --- a/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h +++ b/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h @@ -59,7 +59,8 @@ typedef struct { } CPU_CACHE_INFO;=0D =0D /**=0D - Get CpuCacheInfo data array.=0D + Get CpuCacheInfo data array. The data array is sorted by CPU package ID = from smallest to largest,=0D + by core type from largest to smallest and by cache level from smallest t= o largest.=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..089d259b3f 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h @@ -17,6 +17,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D =0D typedef struct {=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