]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BaseSynchronizationLib: Do not check timeout if lock released
authorJeff Fan <jeff.fan@intel.com>
Mon, 21 Mar 2016 05:26:46 +0000 (13:26 +0800)
committerJeff Fan <jeff.fan@intel.com>
Tue, 5 Apr 2016 06:07:15 +0000 (14:07 +0800)
Current AcquireSpinLock() will check if timeout happens when PcdSpinLockTimeout
is not zero, even though the spin lock is already released. It may do
unnecessary operation to read timer's counter. This update is trying to acquire
spin lock firstly. If it could be acquired successfully, needn't to check
timeout at all.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@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>
MdePkg/Library/BaseSynchronizationLib/Synchronization.c
MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c

index 4218a265a0ec37d0668647bc5f12c5bcbbf27dda..bb0c8e9469fa45aedcbbda91501caaf0f3201735 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of synchronization functions.\r
 \r
-  Copyright (c) 2006 - 2012, 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
@@ -104,7 +104,11 @@ AcquireSpinLock (
   INT64   Cycle;\r
   INT64   Delta;\r
 \r
-  if (PcdGet32 (PcdSpinLockTimeout) > 0) {\r
+  if (PcdGet32 (PcdSpinLockTimeout) == 0) {\r
+    while (!AcquireSpinLockOrFail (SpinLock)) {\r
+      CpuPause ();\r
+    }\r
+  } else if (!AcquireSpinLockOrFail (SpinLock)) {\r
     //\r
     // Get the current timer value\r
     //\r
@@ -148,10 +152,6 @@ AcquireSpinLock (
       Total += Delta;\r
       ASSERT (Total < Timeout);\r
     }\r
-  } else {\r
-    while (!AcquireSpinLockOrFail (SpinLock)) {\r
-      CpuPause ();\r
-    }\r
   }\r
   return SpinLock;\r
 }\r
index 587f5a771c353b3070e3160fa22eb52abce74bf4..31f28ec2c5748191e1e8ba9299f28be4c0c0cef7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of synchronization functions.\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   Portions copyright (c) 2008 - 2009, Apple Inc. 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
@@ -114,7 +114,11 @@ AcquireSpinLock (
   INT64   Cycle;\r
   INT64   Delta;\r
 \r
-  if (PcdGet32 (PcdSpinLockTimeout) > 0) {\r
+  if (PcdGet32 (PcdSpinLockTimeout) == 0) {\r
+    while (!AcquireSpinLockOrFail (SpinLock)) {\r
+      CpuPause ();\r
+    }\r
+  } else if (!AcquireSpinLockOrFail (SpinLock)) {\r
     //\r
     // Get the current timer value\r
     //\r
@@ -158,10 +162,6 @@ AcquireSpinLock (
       Total += Delta;\r
       ASSERT (Total < Timeout);\r
     }\r
-  } else {\r
-    while (!AcquireSpinLockOrFail (SpinLock)) {\r
-      CpuPause ();\r
-    }\r
   }\r
   return SpinLock;\r
 }\r
index ca21f5dccee52d53ad381b9221a13a50482c776f..821c79812110aee044e6627e7a6d98c5dbf18f42 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of synchronization functions.\r
 \r
-  Copyright (c) 2006 - 2012, 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
@@ -116,7 +116,11 @@ AcquireSpinLock (
   INT64   Cycle;\r
   INT64   Delta;\r
 \r
-  if (PcdGet32 (PcdSpinLockTimeout) > 0) {\r
+  if (PcdGet32 (PcdSpinLockTimeout) == 0) {\r
+    while (!AcquireSpinLockOrFail (SpinLock)) {\r
+      CpuPause ();\r
+    }\r
+  } else if (!AcquireSpinLockOrFail (SpinLock)) {\r
     //\r
     // Get the current timer value\r
     //\r
@@ -160,10 +164,6 @@ AcquireSpinLock (
       Total += Delta;\r
       ASSERT (Total < Timeout);\r
     }\r
-  } else {\r
-    while (!AcquireSpinLockOrFail (SpinLock)) {\r
-      CpuPause ();\r
-    }\r
   }\r
   return SpinLock;\r
 }\r