Reviewed-by: Liming Gao <liming....@intel.com>
> -----Original Message----- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Jeff Fan > Sent: Tuesday, March 22, 2016 2:53 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D; Gao, Liming > Subject: [edk2] [Patch] MdePkg/BaseSynchronizationLib: Do not check > timeout if lock released > > 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.kin...@intel.com> > Cc: Liming Gao <liming....@intel.com> > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jeff Fan <jeff....@intel.com> > --- > MdePkg/Library/BaseSynchronizationLib/Synchronization.c | 12 ++++++---- > -- > MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c | 12 ++++++- > ----- > MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c | 12 > ++++++------ > 3 files changed, 18 insertions(+), 18 deletions(-) > > diff --git a/MdePkg/Library/BaseSynchronizationLib/Synchronization.c > b/MdePkg/Library/BaseSynchronizationLib/Synchronization.c > index 4218a26..bb0c8e9 100644 > --- a/MdePkg/Library/BaseSynchronizationLib/Synchronization.c > +++ b/MdePkg/Library/BaseSynchronizationLib/Synchronization.c > @@ -1,7 +1,7 @@ > /** @file > Implementation of synchronization functions. > > - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> > + Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > which accompanies this distribution. The full text of the license may be > found at > @@ -104,7 +104,11 @@ AcquireSpinLock ( > INT64 Cycle; > INT64 Delta; > > - if (PcdGet32 (PcdSpinLockTimeout) > 0) { > + if (PcdGet32 (PcdSpinLockTimeout) == 0) { > + while (!AcquireSpinLockOrFail (SpinLock)) { > + CpuPause (); > + } > + } else if (!AcquireSpinLockOrFail (SpinLock)) { > // > // Get the current timer value > // > @@ -148,10 +152,6 @@ AcquireSpinLock ( > Total += Delta; > ASSERT (Total < Timeout); > } > - } else { > - while (!AcquireSpinLockOrFail (SpinLock)) { > - CpuPause (); > - } > } > return SpinLock; > } > diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c > b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c > index 587f5a7..31f28ec 100644 > --- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c > +++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c > @@ -1,7 +1,7 @@ > /** @file > Implementation of synchronization functions. > > - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> > + Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> > Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > @@ -114,7 +114,11 @@ AcquireSpinLock ( > INT64 Cycle; > INT64 Delta; > > - if (PcdGet32 (PcdSpinLockTimeout) > 0) { > + if (PcdGet32 (PcdSpinLockTimeout) == 0) { > + while (!AcquireSpinLockOrFail (SpinLock)) { > + CpuPause (); > + } > + } else if (!AcquireSpinLockOrFail (SpinLock)) { > // > // Get the current timer value > // > @@ -158,10 +162,6 @@ AcquireSpinLock ( > Total += Delta; > ASSERT (Total < Timeout); > } > - } else { > - while (!AcquireSpinLockOrFail (SpinLock)) { > - CpuPause (); > - } > } > return SpinLock; > } > diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c > b/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c > index ca21f5d..821c798 100644 > --- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c > +++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c > @@ -1,7 +1,7 @@ > /** @file > Implementation of synchronization functions. > > - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> > + Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > which accompanies this distribution. The full text of the license may be > found at > @@ -116,7 +116,11 @@ AcquireSpinLock ( > INT64 Cycle; > INT64 Delta; > > - if (PcdGet32 (PcdSpinLockTimeout) > 0) { > + if (PcdGet32 (PcdSpinLockTimeout) == 0) { > + while (!AcquireSpinLockOrFail (SpinLock)) { > + CpuPause (); > + } > + } else if (!AcquireSpinLockOrFail (SpinLock)) { > // > // Get the current timer value > // > @@ -160,10 +164,6 @@ AcquireSpinLock ( > Total += Delta; > ASSERT (Total < Timeout); > } > - } else { > - while (!AcquireSpinLockOrFail (SpinLock)) { > - CpuPause (); > - } > } > return SpinLock; > } > -- > 1.9.5.msysgit.0 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel