From: "Laszlo Ersek" <lersek@redhat.com>
To: Ray Ni <ray.ni@intel.com>, devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>
Subject: Re: [PATCH 2/2] UefiCpuPkg/MpInitLib: Remove global variable X2ApicEnable
Date: Thu, 31 Oct 2019 10:20:02 +0100 [thread overview]
Message-ID: <0a73f7c5-7ac3-bf35-9a39-8b576acb4656@redhat.com> (raw)
In-Reply-To: <20191030095233.565420-3-ray.ni@intel.com>
On 10/30/19 10:52, Ray Ni wrote:
> MpInitLib sets X2ApicEnable in two places.
> 1. CollectProcessorCount()
> This function is called when MpInitLibInitialize() hasn't been
> called before.
> It sets X2ApicEnable and later in the same function it configures
> all CPUs to operate in X2 APIC mode.
> 2. MpInitLibInitialize()
> The X2ApicEnable setting happens when this function is called in
> second time. But after that setting, no code consumes that flag.
>
> With the above analysis and with the purpose of simplifying the code,
> the X2ApicEnable in #1 is changed to local variable and the #2 can be
> changed to remove the setting of X2ApicEnable.
>
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> ---
> UefiCpuPkg/Library/MpInitLib/MpLib.c | 14 ++++++--------
> UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 -
> 2 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 8f62a8d965..49be5d5385 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -459,12 +459,12 @@ CollectProcessorCount (
> {
> UINTN Index;
> CPU_INFO_IN_HOB *CpuInfoInHob;
> + BOOLEAN X2Apic;
>
> //
> // Send 1st broadcast IPI to APs to wakeup APs
> //
> - CpuMpData->InitFlag = ApInitConfig;
> - CpuMpData->X2ApicEnable = FALSE;
> + CpuMpData->InitFlag = ApInitConfig;
> WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
> CpuMpData->InitFlag = ApInitDone;
> ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
> @@ -481,22 +481,23 @@ CollectProcessorCount (
> // 1. Number of CPU is greater than 255; or
> // 2. There are any logical processors reporting an Initial APIC ID of 255 or greater.
> //
> + X2Apic = FALSE;
> if (CpuMpData->CpuCount > 255) {
> //
> // If there are more than 255 processor found, force to enable X2APIC
> //
> - CpuMpData->X2ApicEnable = TRUE;
> + X2Apic = TRUE;
> } else {
> CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
> for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
> if (CpuInfoInHob[Index].InitialApicId >= 0xFF) {
> - CpuMpData->X2ApicEnable = TRUE;
> + X2Apic = TRUE;
> break;
> }
> }
> }
>
> - if (CpuMpData->X2ApicEnable) {
> + if (X2Apic) {
> DEBUG ((DEBUG_INFO, "Force x2APIC mode!\n"));
> //
> // Wakeup all APs to enable x2APIC mode
> @@ -1780,9 +1781,6 @@ MpInitLibInitialize (
> CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
> for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
> InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);
> - if (CpuInfoInHob[Index].InitialApicId >= 255 || Index > 254) {
> - CpuMpData->X2ApicEnable = TRUE;
> - }
> CpuMpData->CpuData[Index].CpuHealthy = (CpuInfoInHob[Index].Health == 0)? TRUE:FALSE;
> CpuMpData->CpuData[Index].ApFunction = 0;
> CopyMem (&CpuMpData->CpuData[Index].VolatileRegisters, &VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index 107872b367..8fa07b12c5 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -227,7 +227,6 @@ struct _CPU_MP_DATA {
> UINTN **FailedCpuList;
>
> AP_INIT_STATE InitFlag;
> - BOOLEAN X2ApicEnable;
> BOOLEAN SwitchBspFlag;
> UINTN NewBspNumber;
> CPU_EXCHANGE_ROLE_INFO BSPInfo;
>
Assuming the previous patch does the right thing in the series (and I
think that's plausible), this patch looks correct as well.
For a second I got concerned as to whether the field removal from
CPU_MP_DATA would require updates to the offset constants in the
assembly code. However, assembly code seems to know offsets into
MP_CPU_EXCHANGE_INFO only, and doesn't care about CPU_MP_DATA. So the
patch is OK I think.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
next prev parent reply other threads:[~2019-10-31 9:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-30 9:52 [PATCH 0/2] Set X2ApicEnable flag from BSP Ni, Ray
2019-10-30 9:52 ` [PATCH 1/2] UefiCpuPkg/MpInitLib: " Ni, Ray
2019-10-31 9:11 ` Laszlo Ersek
2019-11-05 1:47 ` [edk2-devel] " Dong, Eric
2019-10-30 9:52 ` [PATCH 2/2] UefiCpuPkg/MpInitLib: Remove global variable X2ApicEnable Ni, Ray
2019-10-31 9:20 ` Laszlo Ersek [this message]
2019-11-05 1:47 ` [edk2-devel] " Dong, Eric
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=0a73f7c5-7ac3-bf35-9a39-8b576acb4656@redhat.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