From nobody Thu May 2 15:24:05 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+68474+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+68474+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1607439989; cv=none; d=zohomail.com; s=zohoarc; b=DzOU1tKRrf5/60YH16DSQFZy1XGhdEdIysDTcw8Cpldrd8XPRglr5N8zBY+3atj4NcMk8BigFN0VUUd2Py30ji2O3provp3/6BWyT/FvoICT4E0rM79OUVEh5FdA+C10eZoZsoyIa9eogbSxBT7MYTEImmQaPUK4IoKPwRkTYeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607439989; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=ZTISK8SFAK2YP5E3tBHWaTya8CF9C+laUoxbGAQqk7g=; b=Vgmyg1nfPas+wWAzIbeQpNNcD5Bv685ryO7+xpcgJOEo6PFvtIMV1I2yzbQXw4j9nW4iroyDf8CAQm18Ck5h0soKllzo4W7r6jQ6s1zJYsVCy0rdAMbt6l/68dmyeQPyBSHqweA8/9R9Dfkxqv2paB3RyV/kW8fISB2ulUAxjk4= 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+68474+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1607439989903561.4371519276176; Tue, 8 Dec 2020 07:06:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SSXDYY1788612xtb62iUYzJH; Tue, 08 Dec 2020 07:06:27 -0800 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web09.9685.1607439806416376466 for ; Tue, 08 Dec 2020 07:03:26 -0800 IronPort-SDR: fDPzUZG1KZEYl4kvQBH70flUQttNX7j1vEaMCJIURFWUNuI9UadkHDAjgHKkSKJoxDDVPtfqOi QTOzW9APOurw== X-IronPort-AV: E=McAfee;i="6000,8403,9828"; a="173138723" X-IronPort-AV: E=Sophos;i="5.78,402,1599548400"; d="scan'208";a="173138723" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 07:03:15 -0800 IronPort-SDR: tAsFvegOthcqK5Px2KBGsbyxMEQbKUw4a43yvcRXgGH/gclNX8YmIxWYhz75p2ddnnGzGbaAc1 y9LQb2UVrtDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,402,1599548400"; d="scan'208";a="407647094" X-Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by orsmga001.jf.intel.com with ESMTP; 08 Dec 2020 07:03:13 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Star Zeng , Yun Lou , Laszlo Ersek Subject: [edk2-devel] [PATCH] UefiCpuPkg/CpuFeature: reduce time complexty to calc CpuInfo.First Date: Tue, 8 Dec 2020 23:01:42 +0800 Message-Id: <20201208150142.1894-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: IN4dd0UQSdEb1hQSm6tx2XuWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1607439987; bh=PzXypOUaJwRde4LDhHtON4kh5vMzDr5fc+Tv+nTI5/Q=; h=Cc:Date:From:Reply-To:Subject:To; b=iuYmDlDEHuF78UwdL4Os7gMmOLwBl92W0ibXPC3R8mM96cL7wQCBZw8nO3kyswCzL7A a+Og1F9eBeMVIYF9Rfpov+v0m8+8h3mMpU/hC0PRa3Dge96lLBJe0kH8AABF0kXk49V2y 18HyU/HKpn3+jcht0kUx8F9rAoYBaH+QSxQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" CpuInfo.First stores whether the current thread belongs to the first package in the platform, first core in a package, first thread in a core. But the time complexity of original algorithm to calculate the CpuInfo.First is O (n) * O (p) * O (c). n: number of processors p: number of packages c: number of cores per package The patch trades time with space by storing the first package, first core per package, first thread per core in an array. The time complexity becomes O (n). Signed-off-by: Ray Ni Cc: Eric Dong Cc: Star Zeng Cc: Yun Lou Cc: Laszlo Ersek --- .../CpuFeaturesInitialize.c | 87 ++++++++----------- 1 file changed, 36 insertions(+), 51 deletions(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ= e.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c index d4a576385f..d21a1eaf38 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c @@ -105,7 +105,10 @@ CpuInitDataInitialize ( EFI_CPU_PHYSICAL_LOCATION *Location; UINT32 PackageIndex; UINT32 CoreIndex; - UINT32 First; + UINTN Pages; + UINT32 FirstPackage; + UINT32 *FirstCore; + UINT32 *FirstThread; ACPI_CPU_DATA *AcpiCpuData; CPU_STATUS_INFORMATION *CpuStatus; UINT32 *ThreadCountPerPackage; @@ -236,74 +239,56 @@ CpuInitDataInitialize ( =20 // // Initialize CpuFeaturesData->InitOrder[].CpuInfo.First + // Use AllocatePages () instead of AllocatePool () because pool cannot b= e freed in PEI phase but page can. // + Pages =3D EFI_SIZE_TO_PAGES (CpuStatus->PackageCount * sizeof (UINT3= 2) + CpuStatus->PackageCount * CpuStatus->MaxCoreCount * sizeof (UINT32)); + FirstCore =3D AllocatePages (Pages); + ASSERT (FirstCore !=3D NULL); + FirstThread =3D FirstCore + CpuStatus->PackageCount; + + FirstPackage =3D MAX_UINT32; + for (PackageIndex =3D 0; PackageIndex < CpuStatus->PackageCount; Package= Index++) { + FirstCore[PackageIndex] =3D MAX_UINT32; + for (CoreIndex =3D 0; CoreIndex < CpuStatus->MaxCoreCount; CoreIndex++= ) { + FirstThread[PackageIndex * CpuStatus->MaxCoreCount + CoreIndex] =3D = MAX_UINT32; + } + } =20 - // - // Set First.Package for each thread belonging to the first package. - // - First =3D MAX_UINT32; for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) { Location =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.Proc= essorInfo.Location; - First =3D MIN (Location->Package, First); + + FirstPackage =3D MIN (Location->Package, FirstPackage); + FirstCore[Location->Package] =3D MIN (Location->Core, FirstCore[Locati= on->Package]); + FirstThread[Location->Package * CpuStatus->MaxCoreCount + Location->Co= re] =3D MIN ( + Location->Thread, + FirstThread[Location->Package * CpuStatus->MaxCoreCount + Location->= Core] + ); } + for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) { Location =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.Proc= essorInfo.Location; - if (Location->Package =3D=3D First) { + + if (Location->Package =3D=3D FirstPackage) { CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Package = =3D 1; } - } =20 - // - // Set First.Die/Tile/Module for each thread assuming: - // single Die under each package, single Tile under each Die, single Mo= dule under each Tile - // - for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) { + // + // Set First.Die/Tile/Module for each thread assuming: + // single Die under each package, single Tile under each Die, single = Module under each Tile + // CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Die =3D 1; CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Tile =3D 1; CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Module =3D 1; - } =20 - for (PackageIndex =3D 0; PackageIndex < CpuStatus->PackageCount; Package= Index++) { - // - // Set First.Core for each thread in the first core of each package. - // - First =3D MAX_UINT32; - for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorN= umber++) { - Location =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.Pr= ocessorInfo.Location; - if (Location->Package =3D=3D PackageIndex) { - First =3D MIN (Location->Core, First); - } + if (Location->Core =3D=3D FirstCore[Location->Package]) { + CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Core =3D 1; } - - for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorN= umber++) { - Location =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.Pr= ocessorInfo.Location; - if (Location->Package =3D=3D PackageIndex && Location->Core =3D=3D F= irst) { - CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Core =3D= 1; - } + if (Location->Thread =3D=3D FirstThread[Location->Package * CpuStatus-= >MaxCoreCount + Location->Core]) { + CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Thread =3D= 1; } } =20 - for (PackageIndex =3D 0; PackageIndex < CpuStatus->PackageCount; Package= Index++) { - for (CoreIndex =3D 0; CoreIndex < CpuStatus->MaxCoreCount; CoreIndex++= ) { - // - // Set First.Thread for the first thread of each core. - // - First =3D MAX_UINT32; - for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; Processo= rNumber++) { - Location =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.= ProcessorInfo.Location; - if (Location->Package =3D=3D PackageIndex && Location->Core =3D=3D= CoreIndex) { - First =3D MIN (Location->Thread, First); - } - } - - for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; Processo= rNumber++) { - Location =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.= ProcessorInfo.Location; - if (Location->Package =3D=3D PackageIndex && Location->Core =3D=3D= CoreIndex && Location->Thread =3D=3D First) { - CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo.First.Thread= =3D 1; - } - } - } - } + FreePages (FirstCore, Pages); } =20 /** --=20 2.27.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 (#68474): https://edk2.groups.io/g/devel/message/68474 Mute This Topic: https://groups.io/mt/78804897/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-