From nobody Sat May 4 07:37:44 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+78797+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+78797+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1628242707; cv=none; d=zohomail.com; s=zohoarc; b=nDRgqFwNNRCZSzdO6xPLACJg1a/tahMtaXs7ZOSgZiR1TqGM2pMDwdWrwJqKaAiQ+MtxwgpmWh5w83bK233x2o45XmRTbbYOYgdBB2jdlDWlULH2ME796ytTosuKEfmk2rPcD9B9DVQ5+oyNlxWJSOMbvS+n2wRIqGqOb0/8XFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628242707; 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=5dsWzM25qP6om2Bo41j6LA45nhIAF757KZXC0DkTiB0=; b=X2pLlqzJnk0G/OuiqCk9WC+rtTEHqp2EMhGtWl252NBlLie9YDTJ+YksZFsEO6AnZoscMtDY6Ofyhg9vv2g+yc7olvHoB9HOFJzHED88srKfVmpZCFOattUwNadOCWIDfVrToGIyANxOoopQ76wdzlh/bGAt5GAAQeClFVxTpes= 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+78797+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 162824270701723.09783755294302; Fri, 6 Aug 2021 02:38:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gMnIYY1788612xU28fgemzRC; Fri, 06 Aug 2021 02:38:26 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> 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: iBvQxxsDc43j8z38Myb0GfL4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1628242706; bh=wYSqxdbJ/LQqhGCrqK8+0Ue7PWCht+lZLf7V7BBoMSI=; h=Cc:Date:From:Reply-To:Subject:To; b=khzDGqJ8rAp16z1pyhJidc5qmnjmpPWPks63dzTGgUc6Lkqv8x6Q2mfNq8gl/enrzFe E4dCOTfknVlOBQoZ0k4FhhGN5yRV/Wge2ULg2MviuaYq6PKct426O6VE8A7o2fwTQjpKO p8SRreDn/E6wK+ZGJgnwqYBdw69WRxsTKkI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1628242709384100003 Content-Type: text/plain; charset="utf-8" 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")); } =20 +/** + Function to compare CPU package ID, core type, cache level and cache typ= e for use in QuickSort. + + @param[in] Buffer1 pointer to CPU_CACHE_INFO poiner to comp= are + @param[in] Buffer2 pointer to second CPU_CACHE_INFO pointer= to compare + + @retval 0 Buffer1 equal to Buffer2 + @retval 1 Buffer1 is greater than Buffer2 + @retval -1 Buffer1 is less than Buffer2 +**/ +INTN +EFIAPI +CpuCacheInfoCompare ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + CPU_CACHE_INFO_COMPARATOR Comparator1, Comparator2; + + ZeroMem (&Comparator1, sizeof (Comparator1)); + ZeroMem (&Comparator2, sizeof (Comparator2)); + + Comparator1.Fields.Package =3D ((CPU_CACHE_INFO*)Buffer1)->Package; + Comparator1.Fields.CoreType =3D ((CPU_CACHE_INFO*)Buffer1)->CoreType; + Comparator1.Fields.CacheLevel =3D ((CPU_CACHE_INFO*)Buffer1)->CacheLevel; + Comparator1.Fields.CacheType =3D ((CPU_CACHE_INFO*)Buffer1)->CacheType; + + Comparator2.Fields.Package =3D ((CPU_CACHE_INFO*)Buffer2)->Package; + Comparator2.Fields.CoreType =3D ((CPU_CACHE_INFO*)Buffer2)->CoreType; + Comparator2.Fields.CacheLevel =3D ((CPU_CACHE_INFO*)Buffer2)->CacheLevel; + Comparator2.Fields.CacheType =3D ((CPU_CACHE_INFO*)Buffer2)->CacheType; + + if (Comparator1.Data64 =3D=3D Comparator2.Data64) { + return 0; + } else if (Comparator1.Data64 > Comparator2.Data64) { + return 1; + } else { + return -1; + } +} + /** Get the total number of package and package ID in the platform. =20 @@ -325,6 +366,10 @@ CpuCacheInfoCollectCpuCacheInfoData ( if (*CacheInfoCount < LocalCacheInfoCount) { Status =3D EFI_BUFFER_TOO_SMALL; } else { + // + // Sort LocalCacheInfo array by CPU package ID, core type, cache level= and cache type. + // + PerformQuickSort (LocalCacheInfo, LocalCacheInfoCount, sizeof (*LocalC= acheInfo), (SORT_COMPARE) CpuCacheInfoCompare); CopyMem (CacheInfo, LocalCacheInfo, sizeof (*CacheInfo) * LocalCacheIn= foCount); DEBUG_CODE ( CpuCacheInfoPrintCpuCacheInfoTable (CacheInfo, LocalCacheInfoCount); @@ -340,7 +385,7 @@ CpuCacheInfoCollectCpuCacheInfoData ( } =20 /** - Get CpuCacheInfo data array. + Get CpuCacheInfo data array. The array is sorted by CPU package ID, core= type, cache level and cache type. =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..3422997f54 100644 --- a/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h +++ b/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h @@ -59,7 +59,7 @@ typedef struct { } CPU_CACHE_INFO; =20 /** - Get CpuCacheInfo data array. + Get CpuCacheInfo data array. The array is sorted by CPU package ID, core= type, cache level and cache type. =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..6135215e5f 100644 --- a/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h @@ -17,8 +17,35 @@ #include #include #include +#include #include =20 +typedef union { + struct { + // + // Type of the cache that this package's this type of logical processo= r corresponds to. + // Value =3D CPUID.04h:EAX[04:00] + // + UINT32 CacheType : 5; + // + // Level of the cache that this package's this type of logical process= or corresponds to. + // Value =3D CPUID.04h:EAX[07:05] + // + UINT32 CacheLevel : 3; + // + // Core type of logical processor. + // Value =3D CPUID.1Ah:EAX[31:24] + // + UINT32 CoreType : 8; + UINT32 Reserved : 16; + // + // Package number. + // + UINT32 Package; + } Fields; + UINT64 Data64; +} CPU_CACHE_INFO_COMPARATOR; + typedef struct { // // Package ID, the information comes from 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 (#78797): https://edk2.groups.io/g/devel/message/78797 Mute This Topic: https://groups.io/mt/84704801/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-