From: zhuyanming@byosoft.com.cn
To: devel@edk2.groups.io
Subject: [PATCH] MdeModulePkg:fix memory wasting issue
Date: Mon, 26 Oct 2020 17:59:01 +0800 [thread overview]
Message-ID: <661812a7ab20f93e5929507d0bdd761270e789a3.1603706303.git.zhuyanming@byosoft.com.cn> (raw)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2964
Use GuidHob instead of AllocatePool.
In PEI phase, variable is read only.
So, GuidHob can be used to cache the variable data
for the following usage.
This GuidHob is the private GUID hob for PcdPei.
So I add one internal guid for this guidhob.
GuidHob data include VariableGuid, VariableName and VariableBuffer.
One GuidHob is for one EFI variable.
Signed-off-by: Yanming Zhu <zhuyanming@byosoft.com.cn>
---
MdeModulePkg/Universal/PCD/Pei/Service.c | 34 ++++++++++++++++--------
MdeModulePkg/Universal/PCD/Pei/Service.h | 14 +++++++++-
2 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Universal/PCD/Pei/Service.c
index 5b037353ad..38ed4546d6 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Service.c
+++ b/MdeModulePkg/Universal/PCD/Pei/Service.c
@@ -472,9 +472,12 @@ GetHiiVariable (
OUT UINTN *VariableSize
)
{
- UINTN Size;
- EFI_STATUS Status;
- VOID *Buffer;
+ UINTN Size;
+ EFI_STATUS Status;
+ TEST_DATA TestData;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ TEST_DATA *DataPtr;
+ UINT32 DataSize;
EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);
@@ -489,23 +492,32 @@ GetHiiVariable (
&Size,
NULL
);
-
if (Status == EFI_BUFFER_TOO_SMALL) {
- Status = PeiServicesAllocatePool (Size, &Buffer);
- ASSERT_EFI_ERROR (Status);
-
+ //Status = PeiServicesAllocatePool (Size, &Buffer);
+ //create guid hob
+ BuildGuidDataHob (
+ (EFI_GUID *)VariableGuid,
+ &TestData,
+ sizeof (TestData)
+ );
+ // find guid hob
+ GuidHob = GetFirstGuidHob ((EFI_GUID *)VariableGuid);
+ if (GuidHob != NULL) {
+ DataPtr = GET_GUID_HOB_DATA (GuidHob);
+ DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
+ }
Status = VariablePpi->GetVariable (
VariablePpi,
(UINT16 *) VariableName,
(EFI_GUID *) VariableGuid,
NULL,
- &Size,
- Buffer
+ &DataSize,
+ DataPtr
);
ASSERT_EFI_ERROR (Status);
- *VariableSize = Size;
- *VariableData = Buffer;
+ *VariableSize = DataSize;
+ *VariableData = DataPtr;
return EFI_SUCCESS;
}
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.h b/MdeModulePkg/Universal/PCD/Pei/Service.h
index 547094fe8a..2fa57a768e 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Service.h
+++ b/MdeModulePkg/Universal/PCD/Pei/Service.h
@@ -26,7 +26,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
-
//
// Please make sure the PCD Serivce PEIM Version is consistent with
// the version of the generated PEIM PCD Database by build tool.
@@ -40,6 +39,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#error "Please make sure the version of PCD PEIM Service and the generated PCD PEI Database match."
#endif
+/**
+ GuidHob can be used to cache the variable data for the following usage.
+ This GuidHob is the private GUID hob for PcdPei
+ One GuidHob will be for one EFI variable.
+
+ This structure contains three members:VariableGuid,VariableName,VariableBuffer.
+**/
+typedef struct {
+ IN CONST EFI_GUID *VariableGuid;
+ IN UINT16 *VariableName;
+ VOID *VariableBuffer;
+} TEST_DATA;
+
/**
Retrieve additional information associated with a PCD token in the default token space.
--
2.28.0.windows.1
next reply other threads:[~2020-10-26 9:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 9:59 zhuyanming [this message]
2020-10-30 1:04 ` 回复: [edk2-devel] [PATCH] MdeModulePkg:fix memory wasting issue gaoliming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=661812a7ab20f93e5929507d0bdd761270e789a3.1603706303.git.zhuyanming@byosoft.com.cn \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox