From nobody Sat May 18 23:44:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+78796+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+78796+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1628242493; cv=none; d=zohomail.com; s=zohoarc; b=R0GSfwU09LTMAFJaIDNPJAPVMcqac4g5qHovV18d6OjahIxnMsG1/JyBGZdg9pX9wNHYo1Bgef2805vi35aBUNhAqON5DdQCSMfSJw6eqg/FftGldEwAMv+lj0qsH2o3Csgh+Hgt1WbYUZdclovJcgZePhwOkm5bhtpLUcm6IoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628242493; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=qyKt3UZUIRnaI2SgF2BiU9vHtngDKrFsPq2FX+lsuT4=; b=DAbB7PVT7DYavL6+0zY2Kdwy4zYiQGBlX0lJA0QKb5BrqSrl5C5Y6IMr+i1MSA9ciG4H6YL3fEqnypJQD3Sm/h/nw2GzeK0ZGXjrls0UU79Oe/NUVgBg6JqgEQwQDhbaKMZYDQLGph6JSxgRwzPyhqRR+6fwk9LvzzM0M5Wd8es= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+78796+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1628242493131477.44783987269125; Fri, 6 Aug 2021 02:34:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EybtYY1788612xEYtlRQmiwH; Fri, 06 Aug 2021 02:34:52 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web09.2725.1628242491789858070 for ; Fri, 06 Aug 2021 02:34:51 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10067"; a="201512774" X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="201512774" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 02:34:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="669348384" X-Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.74]) by fmsmga006.fm.intel.com with ESMTP; 06 Aug 2021 02:34:48 -0700 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [edk2-devel] [PATCH v1] UefiCpuPkg/CpuCacheInfoLib: Sort CpuCacheInfo array Date: Fri, 6 Aug 2021 17:34:43 +0800 Message-Id: <20210806093443.4830-1-yun.lou@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yun.lou@intel.com X-Gm-Message-State: sZdLZefKpDi20pMXd8VebEohx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1628242492; bh=WWeMZD9r8YNg3wz/R5ZIWubuezbDO8b/mbMdiNGGV0A=; h=Cc:Date:From:Reply-To:Subject:To; b=e/Efbd1jwb2cH1wp2tZiyktSTo3Ro6ktMZ96JHYNJeAz8u7HGQ1aTcA4HDpUCU6MIM1 KI9imXR7Vk4GtoUXuO0J4PK7Nqih8I6WjOb1q8G7OyyogoOnNgz/x6cD3jkTi0UsdoCta 0b71ipCPbSC9nOwPDTXN60auINu8ph3pKPI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1628242494757100002 Content-Type: text/plain; charset="utf-8" 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")); } =20 +/** + Function to compare core type for use in QuickSort. + + @param[in] Buffer1 pointer to core type poiner to compare + @param[in] Buffer2 pointer to second core type pointer to c= ompare + + @retval 0 Buffer1 equal to Buffer2 + @retval 1 Buffer1 is less than Buffer2 + @retval -1 Buffer1 is greater than Buffer2 +**/ +INTN +EFIAPI +CpuCacheInfoCompareCoreType ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + if (((CPU_CACHE_INFO*)Buffer1)->CoreType =3D=3D ((CPU_CACHE_INFO*)Buffer= 2)->CoreType) { + return 0; + } else if (((CPU_CACHE_INFO*)Buffer1)->CoreType < ((CPU_CACHE_INFO*)Buff= er2)->CoreType) { + return 1; + } else { + return -1; + } +} + +/** + Sort CpuCacheInfo array by the core type values from largest to smallest. + + @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array. + @param[in] CpuCacheInfoCount The length of CpuCacheInfo array. + +**/ +VOID +CpuCacheInfoSort ( + IN OUT CPU_CACHE_INFO *CpuCacheInfo, + IN UINTN CpuCacheInfoCount + ) +{ + UINTN Index; + UINTN NextIndex; + UINT32 CurrentPackage; + UINT8 CacheInfoCountPerPackage; + + for (Index =3D 0; Index < CpuCacheInfoCount; Index +=3D CacheInfoCountPe= rPackage) { + // + // Calculate the number of CpuCacheInfo current processor has. + // + CurrentPackage =3D CpuCacheInfo[Index].Package; + CacheInfoCountPerPackage =3D 1; + for (NextIndex =3D Index + 1; NextIndex < CpuCacheInfoCount; NextIndex= ++) { + if (CurrentPackage =3D=3D CpuCacheInfo[NextIndex].Package) { + CacheInfoCountPerPackage++; + } + } + + // + // Sort CpuCacheInfo for current processor by the core type values fro= m largest to smallest. + // + PerformQuickSort (&CpuCacheInfo[Index], CacheInfoCountPerPackage, size= of (*CpuCacheInfo), (SORT_COMPARE) CpuCacheInfoCompareCoreType); + } +} + /** Get the total number of package and package ID in the platform. =20 @@ -325,6 +388,7 @@ CpuCacheInfoCollectCpuCacheInfoData ( if (*CacheInfoCount < LocalCacheInfoCount) { Status =3D EFI_BUFFER_TOO_SMALL; } else { + CpuCacheInfoSort (LocalCacheInfo, LocalCacheInfoCount); CopyMem (CacheInfo, LocalCacheInfo, sizeof (*CacheInfo) * LocalCacheIn= foCount); DEBUG_CODE ( CpuCacheInfoPrintCpuCacheInfoTable (CacheInfo, LocalCacheInfoCount); @@ -340,7 +404,8 @@ CpuCacheInfoCollectCpuCacheInfoData ( } =20 /** - Get CpuCacheInfo data array. + Get CpuCacheInfo data array. The data array is sorted by CPU package ID = from smallest to largest, + by core type from largest to smallest and by cache level from smallest t= o largest. =20 @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array. @param[in, out] CpuCacheInfoCount As input, point to the length of res= ponse CpuCacheInfo array. 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; =20 /** - Get CpuCacheInfo data array. + Get CpuCacheInfo data array. The data array is sorted by CPU package ID = from smallest to largest, + by core type from largest to smallest and by cache level from smallest t= o largest. =20 @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array. @param[in, out] CpuCacheInfoCount As input, point to the length of res= ponse CpuCacheInfo array. 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 @@ # # Provides cache info for each package, core type, cache level and cache = type. # -# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -25,6 +25,7 @@ =20 [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 [LibraryClasses] @@ -33,6 +34,7 @@ BaseMemoryLib MemoryAllocationLib UefiBootServicesTableLib + SortLib =20 [Protocols] gEfiMpServiceProtocolGuid 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 #include #include +#include #include =20 typedef struct { 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 @@ # # Provides cache info for each package, core type, cache level and cache = type. # -# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -25,6 +25,7 @@ =20 [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 [LibraryClasses] @@ -33,6 +34,7 @@ BaseMemoryLib MemoryAllocationLib PeiServicesTablePointerLib + SortLib =20 [Ppis] gEdkiiPeiMpServices2PpiGuid --=20 2.28.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#78796): https://edk2.groups.io/g/devel/message/78796 Mute This Topic: https://groups.io/mt/84704770/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-