From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.4629.1609915201814242836 for ; Tue, 05 Jan 2021 22:40:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=vBdFk902; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: star.zeng@intel.com) IronPort-SDR: dY3sih9w6BLcut2g9ccMQyoOafXWOdakufBTTHRUsW8jg+x5FjCN4sU67gZj7jPOfXoPxc9kpC 0eKPrmsWvV5w== X-IronPort-AV: E=McAfee;i="6000,8403,9855"; a="164937399" X-IronPort-AV: E=Sophos;i="5.78,479,1599548400"; d="scan'208";a="164937399" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2021 22:40:01 -0800 IronPort-SDR: HrYga1JPvPhknYp6PaQNz/88MIshxvqie8zG/abySHmLacMH8p4gIhQ3TVMCJeK9w3ffkOH1Ia Yu8O/0OGg+sw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,479,1599548400"; d="scan'208";a="497054448" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga004.jf.intel.com with ESMTP; 05 Jan 2021 22:40:00 -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; Tue, 5 Jan 2021 22:40:00 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) 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; Tue, 5 Jan 2021 22:40:00 -0800 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.54) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Tue, 5 Jan 2021 22:39:58 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hxGF6k1U3iCI55b/peiNkCT+hZaZVvUiEJz3zeL+b5FvFUqFVStdN+TyHIbu9ysIhqUxjQC26/1aWsTsMF/qAZwPe02wN7tcVDG9U84ymFQ1dWifFDJNcpSx3lQ+oU1EvwFdIjFlOCq6+ERloHSP10cpLXtSKkmnGHJlaMxNMqE4iVkDoldcqRIF8zABI03/2kag4g1noUv3KyIElvFGtuPJ6fV3y/xj/uTXk8nYvG/e7+aZL9fIDgcTlUbtixxmJRPSseo3sMuZU3ZYuyre9ywZwl8POY9Gkfa8o1MVvoND67ouzQ9RfSrirsb+A7iMYEvQxtKSMz0HnKV17ulSdQ== 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=5ezS2SAtyOTnGd2DEle2yfBbcgOUyDkj3U7KY4+yfLw=; b=GuLTsbHrml48jJkqqLfrGIzLp9edAbBVRn8ISkq86MxHI4LRV5+G7gfoAarGOXd5RS3AQVUxmuEIGZrGGucT8px451bz2KUyZWKcC5BgCpUvu18Zav09Z4y9icudaK57Fk/VR1UnJa6+mnGY66M4XZ5mQdDdJK05wgcLafn7FNEO2QhN4zUj/e7rryz7Nus2G17gg6EsdjzoJbYJ0iZctmICjJjXgbeiNrnCvjSzhWx768ofrRgJV8UG+5hhnxRz0wKtDeC4/6LLpaRLK5UCuCctJ16OtT3e6M6vJlgaXa6BWde68MLCr+FAG0ITPNa4gVG76cCygdvLaeIc2GY8ZA== 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=5ezS2SAtyOTnGd2DEle2yfBbcgOUyDkj3U7KY4+yfLw=; b=vBdFk9025jWBYn+FmC03sYz4a0Yvrymg8iUndKkhDyZmTWAVeHKlcAj/sdIGeDM/f6Qh/6laXjKvtn2XPiJ7HsMHfknwt9ACj6gsYArp2UPDezKlmDscEvCkBeuG34mjj0XTdPbnO9Qnj1QPlnS/9rxT0EKJaOreCRQL7tpyuCI= Received: from DM6PR11MB4058.namprd11.prod.outlook.com (2603:10b6:5:193::13) by DM6PR11MB2699.namprd11.prod.outlook.com (2603:10b6:5:ce::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.19; Wed, 6 Jan 2021 06:39:55 +0000 Received: from DM6PR11MB4058.namprd11.prod.outlook.com ([fe80::880f:c15b:574a:a9eb]) by DM6PR11MB4058.namprd11.prod.outlook.com ([fe80::880f:c15b:574a:a9eb%6]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 06:39:55 +0000 From: "Zeng, Star" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Dong, Eric" , Laszlo Ersek , "Zeng, Star" Subject: Re: [PATCH] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c Thread-Topic: [PATCH] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c Thread-Index: AQHW4lh6bNXPqzAr4k+sqUu2GsiMN6oaJxKAgAABIZA= Date: Wed, 6 Jan 2021 06:39:55 +0000 Message-ID: References: <20210104051418.18140-1-star.zeng@intel.com> In-Reply-To: Accept-Language: zh-CN, 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.202] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9975a02b-01b0-4066-02cc-08d8b20de159 x-ms-traffictypediagnostic: DM6PR11MB2699: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RojWaKA114qQM8LgsLH4Ja5DBC2njjvzz/OMR2CZb/YLbWi2eA6n0Mlzxoxnx9opZe29QipvS77uT36FIu/HdVr6maSgWl3CbyYzGSCCauYGWs1mtFRUH6PY0JxPu/X5KPJLsL42VUOEcaNf24fojCIr+hZnaiVGexq8hwhRVCynk4ZI2oB3XSRMjSYPmq3MxnR2a+r7wJ0SCxFZs3Dew9Feh83zMhoazbKX+VP/3LEOY1JHOqAevDboOdO1GcyBIdAit4hKIC6sV4q28JnpHYb3aubRVOidmHJy3vYVEJYrsPK3pLePxBx3FLETIYOZf3CYoh6SSRla6Ru/YVUibillp7oEy4cdpuMYc2RFw1dB0cbTJEeRTMCK6XwuV8qumrqBRQYvqBUC/fBuuUG13Q== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4058.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(346002)(39860400002)(366004)(376002)(136003)(396003)(19627235002)(83380400001)(186003)(26005)(33656002)(54906003)(110136005)(64756008)(66556008)(66446008)(66946007)(52536014)(5660300002)(8936002)(7696005)(2906002)(76116006)(9686003)(55016002)(478600001)(107886003)(6506007)(8676002)(86362001)(4326008)(71200400001)(316002)(66476007)(53546011);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?XpC40gvhKGvlElp/m1Nktb9yA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?Q?S/kVP2fRLBXsyh8Vmb1X2V8m78JBqKQEgxPJbCS2h6s8vI4iYM4WGKi2TV0y?= =?us-ascii?Q?AWgjxSu7DvZFqmHJWdpsiVkHkJhysPvdXzc/wIv9s78=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4058.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9975a02b-01b0-4066-02cc-08d8b20de159 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2021 06:39:55.7351 (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: t+vzhP+CjJvJmDzTsG2z7iHE9lrsShjNPpnqsd04YrDjK1c1zif412YCEmKOQLUOhRoSW1KLj3hW478ElZ8Pxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB2699 Return-Path: star.zeng@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Good catch, thanks. It was my over consideration. Let me send a new version patch. Thanks, Star -----Original Message----- From: Ni, Ray =20 Sent: Wednesday, January 6, 2021 2:34 PM To: Zeng, Star ; devel@edk2.groups.io Cc: Dong, Eric ; Laszlo Ersek Subject: RE: [PATCH] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in= CpuS3.c Star, Just one minor comments: DestinationRegisterTableList[Index].AllocatedSize =3D (UINT32) MultU6= 4x32 (DestinationRegisterTableList[Index].TableLength, sizeof (CPU_REGISTER= _TABLE_ENTRY)); Please directly use " DestinationRegisterTableList[Index].TableLength * siz= eof (CPU_REGISTER_TABLE_ENTRY)". Thanks, Ray > -----Original Message----- > From: Zeng, Star > Sent: Monday, January 4, 2021 1:14 PM > To: devel@edk2.groups.io > Cc: Zeng, Star ; Ni, Ray ;=20 > Dong, Eric ; Laszlo Ersek > Subject: [PATCH] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption=20 > 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=20 > 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=20 > 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=20 > 4096 - > 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..d87c2efb87e7 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=20 > reserved.
> +Copyright (c) 2006 - 2021, Intel Corporation. All rights=20 > +reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -487,6 +487,9 @@ SetRegister ( > } else { > RegisterTables =3D (CPU_REGISTER_TABLE=20 > *)(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,=20 > 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 (UINT32)=20 > + MultU64x32 > (DestinationRegisterTableList[Index].TableLength, sizeof=20 > (CPU_REGISTER_TABLE_ENTRY)); > RegisterTableEntry =3D AllocateCopyPool ( > DestinationRegisterTableList[Index].AllocatedSize, > (VOID=20 > *)(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=20 > *)(UINTN)AcpiCpuData->IdtrProfile, sizeof (IA32_DESCRIPTOR)); >=20 > - mAcpiCpuData.PreSmmInitRegisterTable =3D=20 > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (mAcpiCpuData.NumberOfCpus > * sizeof (CPU_REGISTER_TABLE)); > - ASSERT (mAcpiCpuData.PreSmmInitRegisterTable !=3D 0); > + if (!IsRegisterTableEmpty ((CPU_REGISTER_TABLE=20 > + *)(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=20 > + *)(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