From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EE65620D7B8F3 for ; Sun, 16 Apr 2017 21:58:46 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2017 21:58:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,213,1488873600"; d="scan'208";a="90288203" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 16 Apr 2017 21:58:45 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 16 Apr 2017 21:58:45 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 16 Apr 2017 21:58:45 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.178]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.217]) with mapi id 14.03.0319.002; Mon, 17 Apr 2017 12:58:43 +0800 From: "Wu, Hao A" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code Thread-Index: AQHStzcI4w7UUSGJ0USR5kLcnzQUO6HI//lQ Date: Mon, 17 Apr 2017 04:58:43 +0000 Message-ID: References: <20170417045636.102048-1-ruiyu.ni@intel.com> In-Reply-To: <20170417045636.102048-1-ruiyu.ni@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Apr 2017 04:58:47 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hao Wu Best Regards, Hao Wu > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ru= iyu > Ni > Sent: Monday, April 17, 2017 12:57 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A > Subject: [edk2] [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary cod= e >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni > Cc: Hao A Wu > --- > UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 35 +++++++++++++++++++-----------= ---- > - > 1 file changed, 19 insertions(+), 16 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c > b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c > index c38191a..9d19272 100644 > --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c > +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c > @@ -1536,6 +1536,7 @@ MtrrLibAddVariableMtrr ( >=20 > MTRR_LIB_ASSERT_ALIGNED (BaseAddress, Length); > if (Type =3D=3D CacheInvalid) { > + ASSERT (Ranges !=3D NULL); > for (Index =3D 0; Index < RangeCount; Index++) { > if (Ranges[Index].BaseAddress <=3D BaseAddress && BaseAddress < > Ranges[Index].BaseAddress + Ranges[Index].Length) { >=20 > @@ -2027,25 +2028,27 @@ MtrrSetMemoryAttributeWorker ( > ASSERT (OriginalVariableMtrrCount - FreeVariableMtrrCount <=3D > FirmwareVariableMtrrCount); >=20 > // > - // Move MTRRs after the FirmwraeVariableMtrrCount position to beginnin= g > + // Move MTRRs after the FirmwareVariableMtrrCount position to beginnin= g > // > - WorkingIndex =3D FirmwareVariableMtrrCount; > - for (Index =3D 0; Index < FirmwareVariableMtrrCount; Index++) { > - if (!OriginalVariableMtrr[Index].Valid) { > - // > - // Found an empty MTRR in WorkingIndex position > - // > - for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) { > - if (OriginalVariableMtrr[WorkingIndex].Valid) { > - break; > + if (FirmwareVariableMtrrCount < OriginalVariableMtrrCount) { > + WorkingIndex =3D FirmwareVariableMtrrCount; > + for (Index =3D 0; Index < FirmwareVariableMtrrCount; Index++) { > + if (!OriginalVariableMtrr[Index].Valid) { > + // > + // Found an empty MTRR in WorkingIndex position > + // > + for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++)= { > + if (OriginalVariableMtrr[WorkingIndex].Valid) { > + break; > + } > } > - } >=20 > - if (WorkingIndex !=3D OriginalVariableMtrrCount) { > - CopyMem (&OriginalVariableMtrr[Index], > &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR)); > - VariableSettingModified[Index] =3D TRUE; > - VariableSettingModified[WorkingIndex] =3D TRUE; > - OriginalVariableMtrr[WorkingIndex].Valid =3D FALSE; > + if (WorkingIndex !=3D OriginalVariableMtrrCount) { > + CopyMem (&OriginalVariableMtrr[Index], > &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR)); > + VariableSettingModified[Index] =3D TRUE; > + VariableSettingModified[WorkingIndex] =3D TRUE; > + OriginalVariableMtrr[WorkingIndex].Valid =3D FALSE; > + } > } > } > } > -- > 2.9.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel