From: "duntan" <dun.tan@intel.com>
To: "Ni, Ray" <ray.ni@intel.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Dong, Eric" <eric.dong@intel.com>,
"Kumar, Rahul R" <rahul.r.kumar@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [edk2-devel] [PATCH 6/6] UefiCpuPkg: Avoid assuming only one smmbasehob
Date: Thu, 7 Dec 2023 00:37:50 +0000 [thread overview]
Message-ID: <BN9PR11MB548381B3F4BCBCC0B7F98B4DE58BA@BN9PR11MB5483.namprd11.prod.outlook.com> (raw)
In-Reply-To: <MN6PR11MB8244C1742286F58F6805C34A8C84A@MN6PR11MB8244.namprd11.prod.outlook.com>
Updated in original message.
Thanks,
Dun
-----Original Message-----
From: Ni, Ray <ray.ni@intel.com>
Sent: Wednesday, December 6, 2023 6:15 PM
To: Tan, Dun <dun.tan@intel.com>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com>
Subject: RE: [PATCH 6/6] UefiCpuPkg: Avoid assuming only one smmbasehob
> +EFI_STATUS
> +GetSmBaseFromSmmBaseHob (
> + IN EFI_HOB_GUID_TYPE *FirstSmmBaseGuidHob,
> + IN UINTN MaxNumberOfCpus,
> + OUT UINTN **SmBaseBufferPointer
> + )
1. It's a bit strange that caller should locate the first GuidHob.
Can you update the existing code as follows:
mCpuHotPlugData.SmBase = GetSmBase(mMaxNumberOfCpus); if (mCpuHotPlugData.SmBase != NULL) {
mSmmRelocated = TRUE;
}
Dun: Ok, will change code to this.
> +{
> + UINTN HobCount;
> + EFI_HOB_GUID_TYPE *GuidHob;
> + SMM_BASE_HOB_DATA *SmmBaseHobData;
> + UINTN NumberOfProcessors;
> + SMM_BASE_HOB_DATA **SmBaseHobPointerBuffer;
> + UINTN *SmBaseBuffer;
> + UINTN Index;
> + UINTN SortBuffer;
> + UINTN ProcessorIndex;
> + UINT64 PrevProcessorIndex;
> +
> + SmmBaseHobData = NULL;
> + Index = 0;
> + ProcessorIndex = 0;
> + PrevProcessorIndex = 0;
> + HobCount = 0;
> + NumberOfProcessors = 0;
> + GuidHob = FirstSmmBaseGuidHob;
> +
> + while (GuidHob != NULL) {
> + HobCount++;
> + SmmBaseHobData = GET_GUID_HOB_DATA (GuidHob);
> + NumberOfProcessors += SmmBaseHobData->NumberOfProcessors;
> + GuidHob = GetNextGuidHob (&gSmmBaseHobGuid,
> GET_NEXT_HOB (GuidHob));
2. We could break the while-loop when NumberOfProcessors equals to the value we retrieved from MpInfo2Hob. Right?
This can speed up the code when there are lots of HOBs after the last SmmBaseHob instance.
Dun: If the code flow break before finding all potential SmmBaseHob instance, there may be more SmmBaseHob instance covering NumberOfProcessors more than the expected value. The code is to catch this case. Do you think we should also catch this?
> + }
> +
> + ASSERT (NumberOfProcessors == MaxNumberOfCpus);
3. ASSERT may fail when HotPlug is TRUE?
Dun: If HotPlug, I think the SmBase count should be PcdCpuMaxLogicalProcessorNumber instead of the NumberOfProcessors extracted from MpInfo2Hob?
> +
> + SmBaseHobPointerBuffer = AllocatePool (sizeof (SMM_BASE_HOB_DATA *)
> * HobCount);
4. SmBaseHobPointerBuffer -> SmBaseHobs
Dun: will change the naming.
> + for (Index = 0; Index < HobCount; Index++) {
> + //
> + // Make sure no overlap and no gap in the CPU range covered by
> + each
> HOB
> + //
> + ASSERT (SmBaseHobPointerBuffer[Index]->ProcessorIndex ==
> PrevProcessorIndex);
5. similarly, can you move "PrevProcessorIndex" assignment to just above "for"?
Dun: Will change the code
> +
> + //
> + // Cache each SmBase in order.
> + //
> + if (sizeof (UINTN) == sizeof (UINT64)) {
> + CopyMem (
> + SmBaseBuffer + PrevProcessorIndex,
> + &SmBaseHobPointerBuffer[Index]->SmBase,
> + sizeof (UINT64) *
> SmBaseHobPointerBuffer[Index]->NumberOfProcessors
> + );
> + } else {
> + for (ProcessorIndex = 0; ProcessorIndex <
> SmBaseHobPointerBuffer[Index]->NumberOfProcessors; ProcessorIndex++) {
> + SmBaseBuffer[PrevProcessorIndex + ProcessorIndex] =
> (UINTN)SmBaseHobPointerBuffer[Index]->SmBase[ProcessorIndex];
> + }
> + }
6. I don't like the "if-else" above. Can you just change SmBaseBuffer to UINT64 *?
Or, you always use for-loop to copy SmBase value for each cpu.
Dun: Ok, will always use for-loop to copy SmBase value for each cpu.
> +
> + PrevProcessorIndex +=
> SmBaseHobPointerBuffer[Index]->NumberOfProcessors;
> + }
> +
> + FreePool (SmBaseHobPointerBuffer);
> +
> + *SmBaseBufferPointer = SmBaseBuffer;
7. Similarly, how about return SmBaseBuffer?
Dun: Ok, will change the code
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112148): https://edk2.groups.io/g/devel/message/112148
Mute This Topic: https://groups.io/mt/102987142/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-12-07 0:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 5:48 [edk2-devel] [PATCH 0/6] Create and consume a new gMpInformationHobGuid2 in UefiCpuPkg duntan
2023-12-05 5:48 ` [edk2-devel] [PATCH 1/6] UefiCpuPkg: Create " duntan
2023-12-06 9:09 ` Ni, Ray
2023-12-07 0:21 ` duntan
2023-12-05 5:48 ` [edk2-devel] [PATCH 2/6] UefiCpuPkg: Build MpInfo2HOB in CpuMpPei duntan
2023-12-06 9:24 ` Ni, Ray
2023-12-07 0:21 ` duntan
2023-12-05 5:48 ` [edk2-devel] [PATCH 3/6] UefiCpuPkg: Consume MpInfo2Hob in PiSmmCpuDxe duntan
2023-12-06 9:55 ` Ni, Ray
2023-12-07 0:22 ` duntan
2023-12-07 1:26 ` Ni, Ray
2023-12-05 5:48 ` [edk2-devel] [PATCH 4/6] UefiCpuPkg: Add a new field in MpInfo2 HOB duntan
2023-12-06 9:55 ` Ni, Ray
2023-12-05 5:48 ` [edk2-devel] [PATCH 5/6] UefiCpuPkg: Cache core type " duntan
2023-12-06 10:01 ` Ni, Ray
2023-12-07 0:23 ` duntan
2023-12-05 5:49 ` [edk2-devel] [PATCH 6/6] UefiCpuPkg: Avoid assuming only one smmbasehob duntan
2023-12-06 10:14 ` Ni, Ray
2023-12-07 0:37 ` duntan [this message]
2023-12-07 1:25 ` Ni, Ray
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=BN9PR11MB548381B3F4BCBCC0B7F98B4DE58BA@BN9PR11MB5483.namprd11.prod.outlook.com \
--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