]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BaseSynchronizationLib: Add spin lock alignment for IA32/x64
authorJeff Fan <jeff.fan@intel.com>
Mon, 21 Mar 2016 05:36:50 +0000 (13:36 +0800)
committerJeff Fan <jeff.fan@intel.com>
Tue, 5 Apr 2016 06:07:15 +0000 (14:07 +0800)
From Intel(R) 64 and IA-32 Architectures Software Developer's Manual, one lock
or semaphore is suggested to be present within a cache line. If the processors
are based on Intel NetBurst microarchitecture, two cache lines are suggested.
This could minimize the bus traffic required to service locks.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLibInternals.h
MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/Ipf/InternalGetSpinLockProperties.c [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c

index bd1bec3fb5e76a3bc545423af14a31046101c955..bcd79355ba69f401d278b5536b83c0e3f27190fa 100755 (executable)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Base Synchronization Library implementation.\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
@@ -30,6 +30,7 @@
   BaseSynchronizationLibInternals.h\r
 \r
 [Sources.IA32]\r
+  Ia32/InternalGetSpinLockProperties.c | MSFT\r
   Ia32/InterlockedCompareExchange64.c | MSFT \r
   Ia32/InterlockedCompareExchange32.c | MSFT \r
   Ia32/InterlockedCompareExchange16.c | MSFT\r
   Ia32/InterlockedIncrement.asm | INTEL \r
   Synchronization.c | INTEL\r
 \r
+  Ia32/InternalGetSpinLockProperties.c | GCC\r
   Ia32/GccInline.c | GCC\r
   SynchronizationGcc.c  | GCC\r
 \r
 [Sources.X64]\r
+  Ia32/InternalGetSpinLockProperties.c | MSFT\r
   X64/InterlockedCompareExchange64.c | MSFT\r
   X64/InterlockedCompareExchange32.c | MSFT\r
   X64/InterlockedCompareExchange16.c | MSFT\r
@@ -64,6 +67,7 @@
   X64/InterlockedIncrement.asm | INTEL \r
   Synchronization.c | INTEL \r
 \r
+  Ia32/InternalGetSpinLockProperties.c | GCC\r
   X64/GccInline.c | GCC\r
   SynchronizationGcc.c  | GCC \r
 \r
@@ -73,6 +77,9 @@
   Ipf/InterlockedCompareExchange32.s\r
   Ipf/InterlockedCompareExchange16.s\r
 \r
+  Ipf/InternalGetSpinLockProperties.c | MSFT\r
+  Ipf/InternalGetSpinLockProperties.c | GCC\r
+\r
   Synchronization.c     | INTEL \r
   SynchronizationMsc.c  | MSFT \r
   SynchronizationGcc.c  | GCC \r
index 76f7023241560f416e510f09523d89103b53477b..9716b9276b4430f52049bc281b5f537c73b3cd09 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declaration of internal functions in BaseSynchronizationLib.\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -138,4 +138,16 @@ InternalSyncCompareExchange64 (
   IN      UINT64                    ExchangeValue\r
   );\r
 \r
+/**\r
+  Internal function to retrieve the architecture specific spin lock alignment\r
+  requirements for optimal spin lock performance.\r
+\r
+  @return The architecture specific spin lock alignment.\r
+  \r
+**/\r
+UINTN\r
+InternalGetSpinLockProperties (\r
+  VOID\r
+  );\r
+\r
 #endif\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c
new file mode 100644 (file)
index 0000000..49f05fb
--- /dev/null
@@ -0,0 +1,60 @@
+/** @file\r
+  Internal function to get spin lock alignment.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "BaseSynchronizationLibInternals.h"\r
+\r
+/**\r
+  Internal function to retrieve the architecture specific spin lock alignment\r
+  requirements for optimal spin lock performance.\r
+\r
+  @return The architecture specific spin lock alignment.\r
+  \r
+**/\r
+UINTN\r
+InternalGetSpinLockProperties (\r
+  VOID\r
+  )\r
+{\r
+  UINT32  RegEax;\r
+  UINT32  RegEbx;\r
+  UINTN   FamilyId;\r
+  UINTN   ModelId;\r
+  UINTN   CacheLineSize;\r
+\r
+  //\r
+  // Retrieve CPUID Version Information\r
+  //\r
+  AsmCpuid (0x01, &RegEax, &RegEbx, NULL, NULL);\r
+  //\r
+  // EBX: Bits 15 - 08: CLFLUSH line size (Value * 8 = cache line size)\r
+  //\r
+  CacheLineSize = ((RegEbx >> 8) & 0xff) * 8;\r
+  //\r
+  // Retrieve CPU Family and Model\r
+  //\r
+  FamilyId = (RegEax >> 8) & 0xf;\r
+  ModelId  = (RegEax >> 4) & 0xf;\r
+  if (FamilyId == 0x0f) {\r
+    //\r
+    // In processors based on Intel NetBurst microarchitecture, use two cache lines\r
+    // \r
+    ModelId = ModelId | ((RegEax >> 12) & 0xf0);\r
+    if (ModelId <= 0x04 || ModelId == 0x06) {\r
+      CacheLineSize *= 2;\r
+    }\r
+  }\r
+\r
+  return CacheLineSize;\r
+}\r
+\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Ipf/InternalGetSpinLockProperties.c b/MdePkg/Library/BaseSynchronizationLib/Ipf/InternalGetSpinLockProperties.c
new file mode 100644 (file)
index 0000000..f6464c2
--- /dev/null
@@ -0,0 +1,29 @@
+/** @file\r
+  Internal function to get spin lock alignment.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+/**\r
+  Internal function to retrieve the architecture specific spin lock alignment\r
+  requirements for optimal spin lock performance.\r
+\r
+  @return The architecture specific spin lock alignment.\r
+  \r
+**/\r
+UINTN\r
+InternalGetSpinLockProperties (\r
+  VOID\r
+  )\r
+{\r
+  return 32;\r
+}\r
+\r
index 31f28ec2c5748191e1e8ba9299f28be4c0c0cef7..4b8c8e59c88ee2154365061af8a82432f1152346 100644 (file)
@@ -45,7 +45,7 @@ GetSpinLockProperties (
   VOID\r
   )\r
 {\r
-  return 32;\r
+  return InternalGetSpinLockProperties ();\r
 }\r
 \r
 /**\r
index 821c79812110aee044e6627e7a6d98c5dbf18f42..db344b7e64202af5d040910d4fac5fc2053be2c6 100644 (file)
@@ -47,7 +47,7 @@ GetSpinLockProperties (
   VOID\r
   )\r
 {\r
-  return 32;\r
+  return InternalGetSpinLockProperties ();\r
 }\r
 \r
 /**\r