From nobody Tue Nov 26 14:24:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51442+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51442+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1574921842; cv=none; d=zohomail.com; s=zohoarc; b=mUC2Rtp5IvIJ6tLGgDGC0UYsGN/z+PggIr0aZv9CAaYFWDmPCsigImsIT2+cF7wyaLHQZgq6Oc1CpN10uNb9GjcJ1oIBiRGLBKzg9IA71YqRM59yl3gD3W/zPGElq1IEoF+uCsivhaR7ALmX25JUZROpNzD1ursVgblf1dLPLVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574921842; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=x6sFrTB3MqGuEQqwt8tm+WqWmmzdPCDpULfnTrwuVVk=; b=cDazB6O/Y7qur8JkY1gakDV0hCaGbrFQGFSobr4uydvkEnYzi8M9wimQ6rE2gtsBrW+ShDSlJbIz+YePS1C2eKo6GyCVQOzkSrfJAmS/b+/8AqensCim485rQ27wVpsXK9LI22SlW063kPdEnLU/VkFJzHhcamVhdTr7o2GCb68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51442+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1574921842878600.8887915989043; Wed, 27 Nov 2019 22:17:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id BYn1YY1788612xu1K2aDI2L6; Wed, 27 Nov 2019 22:17:21 -0800 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.3375.1574921840839820554 for ; Wed, 27 Nov 2019 22:17:21 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2019 22:17:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,252,1571727600"; d="scan'208";a="234340508" X-Received: from ydong10-desktop.ccr.corp.intel.com ([10.239.158.133]) by fmsmga004.fm.intel.com with ESMTP; 27 Nov 2019 22:17:18 -0800 From: "Dong, Eric" To: devel@edk2.groups.io Cc: Ray Ni , Laszlo Ersek Subject: [edk2-devel] [PATCH v2] UefiCpuPkg/PiSmmCpuDxeSmm: Avoid allocate Token every time. Date: Thu, 28 Nov 2019 14:17:16 +0800 Message-Id: <20191128061716.196-1-eric.dong@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,eric.dong@intel.com X-Gm-Message-State: TuAKvyKAsFfEWzoLwO5bg6Ccx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574921841; bh=yODo0Khkvc+hsDOJ7JUI68Nz0m62WvyqC7Pi3jypFKw=; h=Cc:Date:From:Reply-To:Subject:To; b=eyto+zceCJ3dyvUsSQqFuyLd6Jm9EtCW8RuxFXQiz6GLlxvzY6k86QBqECxHH+mrsMi enUSVd8Am1IO80WVdi4hiNYWb+VAdhfDDswagESZmmdnnu3fLl/lJnHZz1Zd+2/wQUCZE jGsqKoWmRXEMnEOfd5+XN70vGs/W/FGlTnc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" v2 changes: Minor update based on comments. v1 changes: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2388 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. Signed-off-by: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 56 ++++++++++++++++++++-- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 16 +++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index d8d2b6f444..4632e5b0c2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -492,6 +492,23 @@ FreeTokens ( { LIST_ENTRY *Link; PROCEDURE_TOKEN *ProcToken; + TOKEN_BUFFER *TokenBuf; + + // + // Not free the buffer, just clear the UsedTokenNum. In order to + // avoid later trig allcate action again when need to use token. + // + gSmmCpuPrivate->UsedTokenNum =3D 0; + + Link =3D GetFirstNode (&gSmmCpuPrivate->OldTokenBufList); + while (!IsNull (&gSmmCpuPrivate->OldTokenBufList, Link)) { + TokenBuf =3D TOKEN_BUFFER_FROM_LINK (Link); + + Link =3D RemoveEntryList (&TokenBuf->Link); + =20 + FreePool (TokenBuf->Buffer); + FreePool (TokenBuf); + } =20 while (!IsListEmpty (&gSmmCpuPrivate->TokenList)) { Link =3D GetFirstNode (&gSmmCpuPrivate->TokenList); @@ -499,7 +516,6 @@ FreeTokens ( =20 RemoveEntryList (&ProcToken->Link); =20 - FreePool ((VOID *)ProcToken->ProcedureToken); FreePool (ProcToken); } } @@ -1115,13 +1131,35 @@ CreateToken ( VOID ) { - PROCEDURE_TOKEN *ProcToken; + PROCEDURE_TOKEN *ProcToken; SPIN_LOCK *CpuToken; UINTN SpinLockSize; + TOKEN_BUFFER *TokenBuf; =20 SpinLockSize =3D GetSpinLockProperties (); - CpuToken =3D AllocatePool (SpinLockSize); - ASSERT (CpuToken !=3D NULL); + + if (gSmmCpuPrivate->UsedTokenNum =3D=3D MAX_PRE_RESERVE_TOKEN_COUNT) { + DEBUG((DEBUG_INFO, "CpuSmm: No free token buffer, allocate new buffer!= \n")); + + // + // Record current token buffer for later free action usage. + // Current used token buffer not in this list. + // + TokenBuf =3D AllocatePool (sizeof (TOKEN_BUFFER)); + ASSERT (TokenBuf !=3D NULL); + TokenBuf->Signature =3D TOKEN_BUFFER_SIGNATURE; + TokenBuf->Buffer =3D gSmmCpuPrivate->CurrentTokenBuf; + + InsertTailList (&gSmmCpuPrivate->OldTokenBufList, &TokenBuf->Link); + + gSmmCpuPrivate->CurrentTokenBuf =3D AllocateZeroPool (SpinLockSize *= MAX_PRE_RESERVE_TOKEN_COUNT); + ASSERT (gSmmCpuPrivate->CurrentTokenBuf !=3D NULL); + gSmmCpuPrivate->UsedTokenNum =3D 0; + } + + CpuToken =3D (SPIN_LOCK *)(gSmmCpuPrivate->CurrentTokenBuf + SpinLockSiz= e * gSmmCpuPrivate->UsedTokenNum); + gSmmCpuPrivate->UsedTokenNum++; + InitializeSpinLock (CpuToken); AcquireSpinLock (CpuToken); =20 @@ -1737,10 +1775,20 @@ InitializeDataForMmMp ( VOID ) { + UINTN SpinLockSize; + + SpinLockSize =3D GetSpinLockProperties (); + DEBUG((DEBUG_INFO, "CpuSmm: SpinLock Size =3D 0x%x\n", SpinLockSize)); + + gSmmCpuPrivate->CurrentTokenBuf =3D AllocateZeroPool (SpinLockSize * MAX= _PRE_RESERVE_TOKEN_COUNT); + ASSERT (gSmmCpuPrivate->CurrentTokenBuf !=3D NULL); + gSmmCpuPrivate->UsedTokenNum =3D 0; + gSmmCpuPrivate->ApWrapperFunc =3D AllocatePool (sizeof (PROCEDURE_WRAPPE= R) * gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus); ASSERT (gSmmCpuPrivate->ApWrapperFunc !=3D NULL); =20 InitializeListHead (&gSmmCpuPrivate->TokenList); + InitializeListHead (&gSmmCpuPrivate->OldTokenBufList); } =20 /** diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 8c29f1a558..36fd0dae92 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -198,6 +198,7 @@ typedef UINT32 SMM_CPU_ARR= IVAL_EXCEPTIONS; #define ARRIVAL_EXCEPTION_DELAYED 0x2 #define ARRIVAL_EXCEPTION_SMI_DISABLED 0x4 =20 +#define MAX_PRE_RESERVE_TOKEN_COUNT 0x512 // // Wrapper used to convert EFI_AP_PROCEDURE2 and EFI_AP_PROCEDURE. // @@ -217,6 +218,17 @@ typedef struct { =20 #define PROCEDURE_TOKEN_FROM_LINK(a) CR (a, PROCEDURE_TOKEN, Link, PROCED= URE_TOKEN_SIGNATURE) =20 +#define TOKEN_BUFFER_SIGNATURE SIGNATURE_32 ('T', 'K', 'B', 'S') + +typedef struct { + UINTN Signature; + LIST_ENTRY Link; + + UINT8 *Buffer; +} TOKEN_BUFFER; + +#define TOKEN_BUFFER_FROM_LINK(a) CR (a, TOKEN_BUFFER, Link, TOKEN_BUFFER= _SIGNATURE) + // // Private structure for the SMM CPU module that is stored in DXE Runtime = memory // Contains the SMM Configuration Protocols that is produced. @@ -243,6 +255,10 @@ typedef struct { PROCEDURE_WRAPPER *ApWrapperFunc; LIST_ENTRY TokenList; =20 + LIST_ENTRY OldTokenBufList; + + UINT8 *CurrentTokenBuf; + UINTN UsedTokenNum; // Only record tokens = used in CurrentTokenBuf. } SMM_CPU_PRIVATE_DATA; =20 extern SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate; --=20 2.23.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 (#51442): https://edk2.groups.io/g/devel/message/51442 Mute This Topic: https://groups.io/mt/63850169/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-