summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/PiSmmCpuDxeSmm
diff options
context:
space:
mode:
authorEric Dong <eric.dong@intel.com>2018-11-10 10:53:41 +0800
committerEric Dong <eric.dong@intel.com>2018-11-11 10:02:47 +0800
commit9bae7811d9433a4bb7123c6eca5c2995877360f1 (patch)
tree7c6cbae2e6cf352581d041764e525881fe992f68 /UefiCpuPkg/PiSmmCpuDxeSmm
parent91ff5bba02b2ba58d016c0503ecdd532b2e4be90 (diff)
downloadedk2-9bae7811d9433a4bb7123c6eca5c2995877360f1.tar.gz
edk2-9bae7811d9433a4bb7123c6eca5c2995877360f1.tar.bz2
edk2-9bae7811d9433a4bb7123c6eca5c2995877360f1.zip
UefiCpuPkg/PiSmmCpuDxeSmm: Separate semaphore container.
In current implementation, core and package level sync uses same semaphores. Sharing the semaphore may cause wrong execution order. For example: 1. Feature A has CPU_FEATURE_CORE_BEFORE dependency with Feature B. 2. Feature C has CPU_FEATURE_PACKAGE_AFTER dependency with Feature B. The expected feature initialization order is A B C: A ---- (Core Depends) ----> B ---- (Package Depends) ----> C For a CPU has 1 package, 2 cores and 4 threads. The feature initialization order may like below: Thread#1 Thread#2 Thread#3 Thread#4 [A.Init] [A.Init] [A.Init] Release(S1, S2) Release(S1, S2) Release(S3, S4) Wait(S1) * 2 Wait(S2) * 2 <------------------------------- Core sync [B.Init] [B.Init] Release (S1,S2,S3,S4) Wait (S1) * 4 <----------------------------------------------------- Package sync Wait(S4 * 2) <- Core sync [B.Init] In above case, for thread#4, when it syncs in core level, Wait(S4) * 2 isn't blocked and [B.Init] runs. But [A.Init] hasn't run in thread#3. It's wrong! Thread#4 should execute [B.Init] after thread#3 executes [A.Init] because B core level depends on A. The reason of the wrong execution order is that S4 is released in thread#1 by calling Release (S1, S2, S3, S4) and in thread #4 by calling Release (S3, S4). To fix this issue, core level sync and package level sync should use separate semaphores. In above example, the S4 released in Release (S1, S2, S3, S4) should not be the same semaphore as that in Release (S3, S4). Related BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1311 Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'UefiCpuPkg/PiSmmCpuDxeSmm')
-rw-r--r--UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
index a45e2dd3d7..79372ce17a 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
@@ -41,9 +41,12 @@ typedef struct {
// Flags used when program the register.
//
typedef struct {
- volatile UINTN ConsoleLogLock; // Spinlock used to control console.
- volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
- volatile UINT32 *SemaphoreCount; // Semaphore used to program semaphore.
+ volatile UINTN ConsoleLogLock; // Spinlock used to control console.
+ volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
+ volatile UINT32 *CoreSemaphoreCount; // Semaphore container used to program
+ // core level semaphore.
+ volatile UINT32 *PackageSemaphoreCount; // Semaphore container used to program
+ // package level semaphore.
} PROGRAM_CPU_REGISTER_FLAGS;
//
@@ -348,11 +351,12 @@ ProgramProcessorRegister (
ASSERT (
(ApLocation != NULL) &&
(CpuStatus->ValidCoreCountPerPackage != 0) &&
- (CpuFlags->SemaphoreCount) != NULL
+ (CpuFlags->CoreSemaphoreCount != NULL) &&
+ (CpuFlags->PackageSemaphoreCount != NULL)
);
- SemaphorePtr = CpuFlags->SemaphoreCount;
switch (RegisterTableEntry->Value) {
case CoreDepType:
+ SemaphorePtr = CpuFlags->CoreSemaphoreCount;
//
// Get Offset info for the first thread in the core which current thread belongs to.
//
@@ -373,6 +377,7 @@ ProgramProcessorRegister (
break;
case PackageDepType:
+ SemaphorePtr = CpuFlags->PackageSemaphoreCount;
ValidCoreCountPerPackage = (UINT32 *)(UINTN)CpuStatus->ValidCoreCountPerPackage;
//
// Get Offset info for the first thread in the package which current thread belongs to.
@@ -1037,10 +1042,16 @@ GetAcpiCpuData (
ASSERT (mAcpiCpuData.ApLocation != 0);
}
if (CpuStatus->PackageCount != 0) {
- mCpuFlags.SemaphoreCount = AllocateZeroPool (
- sizeof (UINT32) * CpuStatus->PackageCount *
- CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount);
- ASSERT (mCpuFlags.SemaphoreCount != NULL);
+ mCpuFlags.CoreSemaphoreCount = AllocateZeroPool (
+ sizeof (UINT32) * CpuStatus->PackageCount *
+ CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount
+ );
+ ASSERT (mCpuFlags.CoreSemaphoreCount != NULL);
+ mCpuFlags.PackageSemaphoreCount = AllocateZeroPool (
+ sizeof (UINT32) * CpuStatus->PackageCount *
+ CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount
+ );
+ ASSERT (mCpuFlags.PackageSemaphoreCount != NULL);
}
InitializeSpinLock((SPIN_LOCK*) &mCpuFlags.MemoryMappedLock);
InitializeSpinLock((SPIN_LOCK*) &mCpuFlags.ConsoleLogLock);