From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web12.3541.1574923063101197498 for ; Wed, 27 Nov 2019 22:37:43 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: ray.ni@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2019 22:37:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,252,1571727600"; d="scan'208";a="207106779" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga007.fm.intel.com with ESMTP; 27 Nov 2019 22:37:42 -0800 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 27 Nov 2019 22:37:37 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 27 Nov 2019 22:37:37 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.127]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.248]) with mapi id 14.03.0439.000; Thu, 28 Nov 2019 14:37:35 +0800 From: "Ni, Ray" To: "devel@edk2.groups.io" , "Dong, Eric" CC: Laszlo Ersek Subject: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: Avoid allocate Token every time. Thread-Topic: [edk2-devel] [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: Avoid allocate Token every time. Thread-Index: AQHVpbOEjxawuMZqxUCIlJcsGNuT36egIJhQ Date: Thu, 28 Nov 2019 06:37:34 +0000 Deferred-Delivery: Thu, 28 Nov 2019 06:36:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C371687@SHSMSX104.ccr.corp.intel.com> References: <20191128061716.196-1-eric.dong@intel.com> In-Reply-To: <20191128061716.196-1-eric.dong@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: ray.ni@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: devel@edk2.groups.io On Behalf Of Dong, > Eric > Sent: Thursday, November 28, 2019 2:17 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Laszlo Ersek > Subject: [edk2-devel] [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: Avoid > allocate Token every time. >=20 > v2 changes: >=20 > Minor update based on comments. >=20 >=20 >=20 > v1 changes: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2388 >=20 > Current logic allocate Token every time when need to use it. The logic > caused SMI latency raised to very high. Update logic to allocate Token > buffer at driver's entry point. Later use the token from the allocated > token buffer. Only when all the buffer have been used, then need to > allocate new buffer. >=20 > Signed-off-by: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > --- > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 56 > ++++++++++++++++++++-- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 16 +++++++ > 2 files changed, 68 insertions(+), 4 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > index d8d2b6f444..4632e5b0c2 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > @@ -492,6 +492,23 @@ FreeTokens ( > { >=20 > LIST_ENTRY *Link; >=20 > PROCEDURE_TOKEN *ProcToken; >=20 > + TOKEN_BUFFER *TokenBuf; >=20 > + >=20 > + // >=20 > + // Not free the buffer, just clear the UsedTokenNum. In order to >=20 > + // avoid later trig allcate action again when need to use token. >=20 > + // >=20 > + gSmmCpuPrivate->UsedTokenNum =3D 0; >=20 > + >=20 > + Link =3D GetFirstNode (&gSmmCpuPrivate->OldTokenBufList); >=20 > + while (!IsNull (&gSmmCpuPrivate->OldTokenBufList, Link)) { >=20 > + TokenBuf =3D TOKEN_BUFFER_FROM_LINK (Link); >=20 > + >=20 > + Link =3D RemoveEntryList (&TokenBuf->Link); >=20 > + >=20 > + FreePool (TokenBuf->Buffer); >=20 > + FreePool (TokenBuf); >=20 > + } >=20 >=20 >=20 > while (!IsListEmpty (&gSmmCpuPrivate->TokenList)) { >=20 > Link =3D GetFirstNode (&gSmmCpuPrivate->TokenList); >=20 > @@ -499,7 +516,6 @@ FreeTokens ( >=20 >=20 > RemoveEntryList (&ProcToken->Link); >=20 >=20 >=20 > - FreePool ((VOID *)ProcToken->ProcedureToken); >=20 > FreePool (ProcToken); >=20 > } >=20 > } >=20 > @@ -1115,13 +1131,35 @@ CreateToken ( > VOID >=20 > ) >=20 > { >=20 > - PROCEDURE_TOKEN *ProcToken; >=20 > + PROCEDURE_TOKEN *ProcToken; >=20 > SPIN_LOCK *CpuToken; >=20 > UINTN SpinLockSize; >=20 > + TOKEN_BUFFER *TokenBuf; >=20 >=20 >=20 > SpinLockSize =3D GetSpinLockProperties (); >=20 > - CpuToken =3D AllocatePool (SpinLockSize); >=20 > - ASSERT (CpuToken !=3D NULL); >=20 > + >=20 > + if (gSmmCpuPrivate->UsedTokenNum =3D=3D > MAX_PRE_RESERVE_TOKEN_COUNT) { >=20 > + DEBUG((DEBUG_INFO, "CpuSmm: No free token buffer, allocate new > buffer!\n")); >=20 > + >=20 > + // >=20 > + // Record current token buffer for later free action usage. >=20 > + // Current used token buffer not in this list. >=20 > + // >=20 > + TokenBuf =3D AllocatePool (sizeof (TOKEN_BUFFER)); >=20 > + ASSERT (TokenBuf !=3D NULL); >=20 > + TokenBuf->Signature =3D TOKEN_BUFFER_SIGNATURE; >=20 > + TokenBuf->Buffer =3D gSmmCpuPrivate->CurrentTokenBuf; >=20 > + >=20 > + InsertTailList (&gSmmCpuPrivate->OldTokenBufList, &TokenBuf->Link); >=20 > + >=20 > + gSmmCpuPrivate->CurrentTokenBuf =3D AllocateZeroPool (SpinLockSize= * > MAX_PRE_RESERVE_TOKEN_COUNT); >=20 > + ASSERT (gSmmCpuPrivate->CurrentTokenBuf !=3D NULL); >=20 > + gSmmCpuPrivate->UsedTokenNum =3D 0; >=20 > + } >=20 > + >=20 > + CpuToken =3D (SPIN_LOCK *)(gSmmCpuPrivate->CurrentTokenBuf + > SpinLockSize * gSmmCpuPrivate->UsedTokenNum); >=20 > + gSmmCpuPrivate->UsedTokenNum++; >=20 > + >=20 > InitializeSpinLock (CpuToken); >=20 > AcquireSpinLock (CpuToken); >=20 >=20 >=20 > @@ -1737,10 +1775,20 @@ InitializeDataForMmMp ( > VOID >=20 > ) >=20 > { >=20 > + UINTN SpinLockSize; >=20 > + >=20 > + SpinLockSize =3D GetSpinLockProperties (); >=20 > + DEBUG((DEBUG_INFO, "CpuSmm: SpinLock Size =3D 0x%x\n", SpinLockSize)); >=20 > + >=20 > + gSmmCpuPrivate->CurrentTokenBuf =3D AllocateZeroPool (SpinLockSize * > MAX_PRE_RESERVE_TOKEN_COUNT); >=20 > + ASSERT (gSmmCpuPrivate->CurrentTokenBuf !=3D NULL); >=20 > + gSmmCpuPrivate->UsedTokenNum =3D 0; >=20 > + >=20 > gSmmCpuPrivate->ApWrapperFunc =3D AllocatePool (sizeof > (PROCEDURE_WRAPPER) * gSmmCpuPrivate- > >SmmCoreEntryContext.NumberOfCpus); >=20 > ASSERT (gSmmCpuPrivate->ApWrapperFunc !=3D NULL); >=20 >=20 >=20 > InitializeListHead (&gSmmCpuPrivate->TokenList); >=20 > + InitializeListHead (&gSmmCpuPrivate->OldTokenBufList); >=20 > } >=20 >=20 >=20 > /** >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > index 8c29f1a558..36fd0dae92 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > @@ -198,6 +198,7 @@ typedef UINT32 > SMM_CPU_ARRIVAL_EXCEPTIONS; > #define ARRIVAL_EXCEPTION_DELAYED 0x2 >=20 > #define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4 >=20 >=20 >=20 > +#define MAX_PRE_RESERVE_TOKEN_COUNT 0x512 >=20 > // >=20 > // Wrapper used to convert EFI_AP_PROCEDURE2 and EFI_AP_PROCEDURE. >=20 > // >=20 > @@ -217,6 +218,17 @@ typedef struct { >=20 >=20 > #define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, > Link, PROCEDURE_TOKEN_SIGNATURE) >=20 >=20 >=20 > +#define TOKEN_BUFFER_SIGNATURE SIGNATURE_32 ('T', 'K', 'B', 'S') >=20 > + >=20 > +typedef struct { >=20 > + UINTN Signature; >=20 > + LIST_ENTRY Link; >=20 > + >=20 > + UINT8 *Buffer; >=20 > +} TOKEN_BUFFER; >=20 > + >=20 > +#define TOKEN_BUFFER_FROM_LINK(a) CR (a, TOKEN_BUFFER, Link, > TOKEN_BUFFER_SIGNATURE) >=20 > + >=20 > // >=20 > // Private structure for the SMM CPU module that is stored in DXE Runtim= e > memory >=20 > // Contains the SMM Configuration Protocols that is produced. >=20 > @@ -243,6 +255,10 @@ typedef struct { > PROCEDURE_WRAPPER *ApWrapperFunc; >=20 > LIST_ENTRY TokenList; >=20 >=20 >=20 > + LIST_ENTRY OldTokenBufList; >=20 > + >=20 > + UINT8 *CurrentTokenBuf; >=20 > + UINTN UsedTokenNum; // Only record token= s used in > CurrentTokenBuf. >=20 > } SMM_CPU_PRIVATE_DATA; >=20 >=20 >=20 > extern SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate; >=20 > -- > 2.23.0.windows.1 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. >=20 > View/Reply Online (#51442): https://edk2.groups.io/g/devel/message/51442 > Mute This Topic: https://groups.io/mt/63850169/1712937 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [ray.ni@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D