From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web08.5723.1609926247250455459 for ; Wed, 06 Jan 2021 01:44:07 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=eimb6zqC; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: ray.ni@intel.com) IronPort-SDR: vZrgvvn7u7o94pDIppbcvswFD2RrDsmbaII8OhMhS09yql2k6dxkqIuWP1Qrlmo38paZwB2XTA uqgh0EGDSJZw== X-IronPort-AV: E=McAfee;i="6000,8403,9855"; a="195800859" X-IronPort-AV: E=Sophos;i="5.78,479,1599548400"; d="scan'208";a="195800859" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2021 01:44:05 -0800 IronPort-SDR: PvyPlWS5e6UBu4pB/rHrxn3PrCtIXMgtqMkihIClRsQFk1CS877jyZcOWkM7wreSljML29tKBF zbkawR6xPSng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,479,1599548400"; d="scan'208";a="346592511" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga003.jf.intel.com with ESMTP; 06 Jan 2021 01:44:03 -0800 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 6 Jan 2021 01:44:02 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 6 Jan 2021 01:44:02 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.174) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Wed, 6 Jan 2021 01:44:02 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FyNtP+n//YeLSGB/X4JR0Jst35sfZdclF1knnb4kiOdoLbI77evliubgERtBQba9O/zJxIDcyga1wtMeYaROWU00R4DLnbin49X3REcqriKGg3WAdqaprT+yq42t7nMWKqpYadR6CqccBIcFOwnVMKWaxt//e59HteKq3HQMxW9vfJEyVkzStic/8UOSMP2/lM1mJW4U6QKZKXg+NbouRe59YR8y5DX6TAFFuivelocnF99PqX/T/gTvn+SPiST6RPvoyFBrne9RRsSS5fhJ9nHdyYIBJFjL2Kd+kV8/2uW8A9a5Z40j+wZEkTJ7uDIFqnrpQaoq4obRJlYFUGOjpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ld+5IB6RM2zeKlaSuT9BXXD3Qs1Y0PeD+m0INmuvLEo=; b=QzywGEyymR0RNnhv3z3i2/phMLD+rmOXXLCb8dCV6B5gHWN0DQ9vD23Iv2ojA5fXxIC316D3EfpWKFoFkC6dqKSNE1XjLhNd6pcIz17ytN2cicO9EjaOf8XqErE9NSOGXTieYaP5llRExe27F6eFufqfbvVuYv53KMFhx/xQNGPc9h5/3IrSRNsuDFvCkF9k7WtJZbdWTwjoTF3SOv1gjll4I+h4Z5OcoRykDbLC9LGSXSCyAnkhswOIyvLDDg2RqsgnS7W4trE3XbPhEr57ujZt8690BpMgdjqEyzIiV8hQNPSQlT/4/Uu626VFUwa5/2qIUL1MyqF86sU6+9Axxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ld+5IB6RM2zeKlaSuT9BXXD3Qs1Y0PeD+m0INmuvLEo=; b=eimb6zqCNfxw36mttD+71OCF9hARKt/RdK3QtMAzBs7B+oUDOJxQinMpoZS5WOFgNKTnnuAoXzB6yQ6WHksVjVXB9A+o0UU/R8UguwnGUpRSdLWiKmQRZ0PItZGSOJcXy5wLdYMvV2275Go603CmGxgK2jfk7m1GOgLWCl8f528= Received: from CO1PR11MB4930.namprd11.prod.outlook.com (2603:10b6:303:9b::11) by CO1PR11MB5044.namprd11.prod.outlook.com (2603:10b6:303:92::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.21; Wed, 6 Jan 2021 09:44:01 +0000 Received: from CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::d18:1234:c1d6:5936]) by CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::d18:1234:c1d6:5936%7]) with mapi id 15.20.3742.006; Wed, 6 Jan 2021 09:44:01 +0000 From: "Ni, Ray" To: "Zeng, Star" , "devel@edk2.groups.io" CC: "Dong, Eric" , Laszlo Ersek Subject: Re: [PATCH V2] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c Thread-Topic: [PATCH V2] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c Thread-Index: AQHW4/fzH7OxwFJ1nUa/dwxha6BjPKoaWHvg Date: Wed, 6 Jan 2021 09:44:01 +0000 Message-ID: References: <20210106064825.18984-1-star.zeng@intel.com> In-Reply-To: <20210106064825.18984-1-star.zeng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.194] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7b0cf9bb-7cc0-4362-d304-08d8b227993e x-ms-traffictypediagnostic: CO1PR11MB5044: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +C/kgtsmxTYJQKpA3pfvql8bFb6103PRkT09vt599p97fho+rtAdGDrUKmqbij+oDiwQ7JnNRvgGrrBWDhWvDK/ABpBs89o0WlH+RVYqygh0ow1rUa9QzqVFlX+epBOUXS6HvlbCSShobMqU1xJH/ezqiv+8gqTr77oXGIJ4lI/cfj419ne6X69aF0jT4bGIQoGytuVkeIRLYH02OxBvEh46eDrwd5b3B4OhXnd8ZKismuBnXtgJVDQCmuAZqPwyOBa5fxFZ02Z4kLYp6/RHCCCtlSEHVd5xMvFK06wFIISrB/aq3sVw8+icFEO35uYTJ9zo2StH/Wjwo7vusyHGhAOMV9xnuDbozJXOTOjfKCGhOUwHBcj0A+atbDn3ExvpeXTedDHc1Ds1PDoaCd0rjA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4930.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(366004)(396003)(376002)(346002)(136003)(39860400002)(4326008)(6506007)(53546011)(33656002)(9686003)(86362001)(478600001)(83380400001)(71200400001)(2906002)(5660300002)(19627235002)(52536014)(66556008)(76116006)(66476007)(66946007)(55016002)(7696005)(64756008)(66446008)(110136005)(54906003)(26005)(186003)(316002)(8676002)(8936002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?Wk1lDLyp/FvaJveMfLOIsFThG2uG8X5oWTUk9FWObdMEk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idJE6LkcIsYowsFMaDi190yi2vBqm4t2vbp4r?= =?us-ascii?Q?EOgMSTDbuZFWGOnfNyZc65OHWmKSi3RHrpoD8iqv/fc=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4930.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7b0cf9bb-7cc0-4362-d304-08d8b227993e X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2021 09:44:01.6320 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: O/vP1r9FCoPsFSiYPsaRm15Jf425qIKyeeWm3J0+Nx7exMTzRqH8Pwut9kARQVSE6vSg5gnM2tkSsvGs1xAVEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR11MB5044 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Zeng, Star > Sent: Wednesday, January 6, 2021 2:48 PM > To: devel@edk2.groups.io > Cc: Zeng, Star ; Ni, Ray ; Dong, E= ric > ; Laszlo Ersek > Subject: [PATCH V2] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM > consumption in CpuS3.c >=20 > This patch makes two refinements to reduce SMRAM consumption in CpuS3.c. > 1. Only do CopyRegisterTable() when register table is not empty, > IsRegisterTableEmpty() is created to check whether the register table > is empty or not. >=20 > Take empty PreSmmInitRegisterTable as example, about 24K SMRAM > consumption > could be reduced when mAcpiCpuData.NumberOfCpus=3D1024. > sizeof (CPU_REGISTER_TABLE) =3D 24 > mAcpiCpuData.NumberOfCpus =3D 1024 =3D 1K > mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE) =3D 24K >=20 > 2. Only copy table entries buffer instead of whole buffer. > AllocatedSize in SourceRegisterTableList is the whole buffer size. > Actually, only the table entries buffer needs to be copied, and the siz= e > is TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY). >=20 > Take AllocatedSize=3D0x1000=3D4096, TableLength=3D100 and NumberOfCpus= =3D1024 > as example, > about 1696K SMRAM consumption could be reduced. > sizeof (CPU_REGISTER_TABLE_ENTRY) =3D 24 > TableLength =3D 100 > TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY) =3D 2400 > AllocatedSize =3D 0x1000 =3D 4096 > AllocatedSize - TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY) =3D 409= 6 - > 2400 =3D 1696 > NumberOfCpus =3D 1024 =3D 1K > NumberOfCpus * (AllocatedSize - TableLength * sizeof > (CPU_REGISTER_TABLE_ENTRY)) =3D 1696K >=20 > This patch also corrects the CopyRegisterTable() function description. >=20 > Signed-off-by: Star Zeng > Cc: Ray Ni > Cc: Eric Dong > Cc: Laszlo Ersek > --- > UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 71 +++++++++++++++++++++++------ > -- > 1 file changed, 54 insertions(+), 17 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c > index 9592430636ec..9b1f952c8a74 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c > @@ -1,7 +1,7 @@ > /** @file > Code for Processor S3 restoration >=20 > -Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -487,6 +487,9 @@ SetRegister ( > } else { > RegisterTables =3D (CPU_REGISTER_TABLE > *)(UINTN)mAcpiCpuData.RegisterTable; > } > + if (RegisterTables =3D=3D NULL) { > + return; > + } >=20 > InitApicId =3D GetInitialApicId (); > RegisterTable =3D NULL; > @@ -948,7 +951,7 @@ InitSmmS3ResumeState ( > } >=20 > /** > - Copy register table from ACPI NVS memory into SMRAM. > + Copy register table from non-SMRAM into SMRAM. >=20 > @param[in] DestinationRegisterTableList Points to destination registe= r table. > @param[in] SourceRegisterTableList Points to source register tab= le. > @@ -967,7 +970,8 @@ CopyRegisterTable ( >=20 > CopyMem (DestinationRegisterTableList, SourceRegisterTableList, > NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); > for (Index =3D 0; Index < NumberOfCpus; Index++) { > - if (DestinationRegisterTableList[Index].AllocatedSize !=3D 0) { > + if (DestinationRegisterTableList[Index].TableLength !=3D 0) { > + DestinationRegisterTableList[Index].AllocatedSize =3D > DestinationRegisterTableList[Index].TableLength * sizeof > (CPU_REGISTER_TABLE_ENTRY); > RegisterTableEntry =3D AllocateCopyPool ( > DestinationRegisterTableList[Index].AllocatedSize, > (VOID *)(UINTN)SourceRegisterTableList[Index].RegisterTableEntry > @@ -978,6 +982,31 @@ CopyRegisterTable ( > } > } >=20 > +/** > + Check whether the register table is empty or not. > + > + @param[in] RegisterTable Point to the register table. > + > + @retval TRUE The register table is empty. > + @retval FALSE The register table is not empty. > +**/ > +BOOLEAN > +IsRegisterTableEmpty ( > + IN CPU_REGISTER_TABLE *RegisterTable, > + IN UINT32 NumberOfCpus > + ) > +{ > + UINTN Index; > + > + for (Index =3D 0; Index < NumberOfCpus; Index++) { > + if (RegisterTable[Index].TableLength !=3D 0) { > + return FALSE; > + } > + } > + > + return TRUE; > +} > + > /** > Get ACPI CPU data. >=20 > @@ -1032,23 +1061,31 @@ GetAcpiCpuData ( >=20 > CopyMem ((VOID *)(UINTN)mAcpiCpuData.IdtrProfile, (VOID > *)(UINTN)AcpiCpuData->IdtrProfile, sizeof (IA32_DESCRIPTOR)); >=20 > - mAcpiCpuData.PreSmmInitRegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus > * sizeof (CPU_REGISTER_TABLE)); > - ASSERT (mAcpiCpuData.PreSmmInitRegisterTable !=3D 0); > + if (!IsRegisterTableEmpty ((CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData- > >PreSmmInitRegisterTable, mAcpiCpuData.NumberOfCpus)) { > + mAcpiCpuData.PreSmmInitRegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus > * sizeof (CPU_REGISTER_TABLE)); > + ASSERT (mAcpiCpuData.PreSmmInitRegisterTable !=3D 0); >=20 > - CopyRegisterTable ( > - (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.PreSmmInitRegisterTable, > - (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->PreSmmInitRegisterTable, > - mAcpiCpuData.NumberOfCpus > - ); > + CopyRegisterTable ( > + (CPU_REGISTER_TABLE > *)(UINTN)mAcpiCpuData.PreSmmInitRegisterTable, > + (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->PreSmmInitRegisterTable, > + mAcpiCpuData.NumberOfCpus > + ); > + } else { > + mAcpiCpuData.PreSmmInitRegisterTable =3D 0; > + } >=20 > - mAcpiCpuData.RegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus > * sizeof (CPU_REGISTER_TABLE)); > - ASSERT (mAcpiCpuData.RegisterTable !=3D 0); > + if (!IsRegisterTableEmpty ((CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData- > >RegisterTable, mAcpiCpuData.NumberOfCpus)) { > + mAcpiCpuData.RegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus > * sizeof (CPU_REGISTER_TABLE)); > + ASSERT (mAcpiCpuData.RegisterTable !=3D 0); >=20 > - CopyRegisterTable ( > - (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterTable, > - (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->RegisterTable, > - mAcpiCpuData.NumberOfCpus > - ); > + CopyRegisterTable ( > + (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterTable, > + (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->RegisterTable, > + mAcpiCpuData.NumberOfCpus > + ); > + } else { > + mAcpiCpuData.RegisterTable =3D 0; > + } >=20 > // > // Copy AP's GDT, IDT and Machine Check handler into SMRAM. > -- > 2.21.0.windows.1