diff options
author | Zane Shelley <zshelle@us.ibm.com> | 2014-04-07 15:52:41 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2014-04-08 16:55:57 -0500 |
commit | ba41c4e29f3a7a6ae5127f80fcbc239e00195a0a (patch) | |
tree | b4c390fade5db0d3aed4ea272074e1c5001bff89 /src/usr/diag | |
parent | ed6d7133031da2790f31826f9a5ff99da3a8c963 (diff) | |
download | talos-hostboot-ba41c4e29f3a7a6ae5127f80fcbc239e00195a0a.tar.gz talos-hostboot-ba41c4e29f3a7a6ae5127f80fcbc239e00195a0a.zip |
PRD: global mutex during MDIA functions
Ensures neither PRDF::main(), PRDF::restoreDramRepairs() nor
PRDF::analyzeIplCEStats() are executed at the same time.
Change-Id: Ibb9c824377a99ecfc88d38c812c10f33c1abc830
CQ: SW256002
Backport: release-fips810
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/10239
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/usr/diag')
-rwxr-xr-x | src/usr/diag/prdf/common/prdfMain_common.C | 7 | ||||
-rw-r--r-- | src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C | 8 | ||||
-rw-r--r-- | src/usr/diag/prdf/prdfGlobal.H | 109 | ||||
-rwxr-xr-x | src/usr/diag/prdf/prdfMain.C | 8 |
4 files changed, 119 insertions, 13 deletions
diff --git a/src/usr/diag/prdf/common/prdfMain_common.C b/src/usr/diag/prdf/common/prdfMain_common.C index be56e4835..d36e14b84 100755 --- a/src/usr/diag/prdf/common/prdfMain_common.C +++ b/src/usr/diag/prdf/common/prdfMain_common.C @@ -5,7 +5,7 @@ /* */ /* IBM CONFIDENTIAL */ /* */ -/* COPYRIGHT International Business Machines Corp. 2002,2013 */ +/* COPYRIGHT International Business Machines Corp. 2002,2014 */ /* */ /* p1 */ /* */ @@ -156,6 +156,11 @@ errlHndl_t main( ATTENTION_VALUE_TYPE i_attentionType, { PRDF_ENTER( "PRDF::main() Global attnType=%04X", i_attentionType ); + // TODO RTC 103728: This is only needed for Hostboot code at this time, + // however, this issue is intented to address code changes needed to + // make PRD thread safe, either part or as a whole. + PRDF_SYSTEM_SCOPE_MUTEX; + // will unlock when going out of scope PRDF_SYSTEM_SCOPELOCK; diff --git a/src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C b/src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C index 7d57f8152..d909a725d 100644 --- a/src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C +++ b/src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C @@ -39,7 +39,6 @@ #include "common/plat/pegasus/prdfMemoryMru.H" #include "framework/service/prdfPlatServices.H" #include "plat/pegasus/prdfPlatCalloutUtil.H" -#include <sys/sync.h> using namespace HWAS; using namespace std; @@ -329,11 +328,10 @@ int32_t restoreDramRepairs( TargetHandle_t i_mba ) { #define PRDF_FUNC "PRDF::restoreDramRepairs" - static mutex_t lock = MUTEX_INITIALIZER; - mutex_lock(&lock); - PRDF_ENTER( PRDF_FUNC"(0x%08x)", getHuid(i_mba) ); + PRDF_SYSTEM_SCOPE_MUTEX; + bool calloutMade = false; do @@ -401,8 +399,6 @@ int32_t restoreDramRepairs( TargetHandle_t i_mba ) PRDF_EXIT( PRDF_FUNC"(0x%08x)", getHuid(i_mba) ); - mutex_unlock(&lock); - return calloutMade ? FAIL : SUCCESS; #undef PRDF_FUNC diff --git a/src/usr/diag/prdf/prdfGlobal.H b/src/usr/diag/prdf/prdfGlobal.H index 33203931a..6f3a16548 100644 --- a/src/usr/diag/prdf/prdfGlobal.H +++ b/src/usr/diag/prdf/prdfGlobal.H @@ -37,6 +37,7 @@ /*--------------------------------------------------------------------*/ #include <prdfGlobal_common.H> #include <util/singleton.H> +#include <sys/sync.h> // for mutex support /*--------------------------------------------------------------------*/ /* Singleton macros common to both FSP and Hostboot */ @@ -95,4 +96,112 @@ typedef uint32_t hwTableContent; */ const uint32_t CONTENT_HW = 0x40000000; +/** + * @brief This class provides general purpose mutual + * exclusion (mutex) class for locking static or + * member data to ensure thread safety. + */ +class prdfMutex +{ +public: + + /** + * Constructor + */ + prdfMutex(); + + /** + * Destructor + */ + ~prdfMutex(); + + /** + * Lock this mutex + */ + void lock(); + + /** + * Unlock this mutex + */ + void unlock(); + +private: + mutex_t ivMutex; + + // No copies or assignments allowed + prdfMutex(prdfMutex& r); + prdfMutex& operator=(prdfMutex& r); +}; + +inline prdfMutex::prdfMutex() +{ + mutex_init(&ivMutex); +} + +inline prdfMutex::~prdfMutex() +{ + mutex_destroy(&ivMutex); +} + +inline void prdfMutex::lock() +{ + mutex_lock( &ivMutex ); +} + +inline void prdfMutex::unlock() +{ + mutex_unlock( &ivMutex ); +} + +/** + * @brief This class provides interfaces to + * acquire a scope mutex + */ +class prdfScopeMutex +{ +public: + /** + * Constructor (locks the specified mutex) + * + * @param i_mutex the mutex to be locked + * for the scope of this function + */ + prdfScopeMutex(prdfMutex& i_mutex); + + /** + * Destructor + */ + ~prdfScopeMutex(); + +private: + prdfMutex* ivMutex; + + // No copies or assignments allowed + prdfScopeMutex(prdfScopeMutex& r); + prdfScopeMutex& operator=(prdfScopeMutex& r); +}; + +inline prdfScopeMutex::prdfScopeMutex(prdfMutex& i_mutex) +: ivMutex(&i_mutex) +{ + ivMutex->lock(); +} + +inline prdfScopeMutex::~prdfScopeMutex() +{ + ivMutex->unlock(); +} + +/** + * @brief Mutex to prevent concurrent accesses + * + */ +static prdfMutex g_mutex; + +/** + * @brief macro to acquire global scope mutex + */ +#define PRDF_SYSTEM_SCOPE_MUTEX \ + prdfScopeMutex dataLock(g_mutex); + #endif // PRDF_GLOBAL_HB_H diff --git a/src/usr/diag/prdf/prdfMain.C b/src/usr/diag/prdf/prdfMain.C index b6fc3355d..c75044970 100755 --- a/src/usr/diag/prdf/prdfMain.C +++ b/src/usr/diag/prdf/prdfMain.C @@ -35,7 +35,6 @@ #include <prdfErrlUtil.H> #include <prdfPlatServices.H> #include <prdfMbaDomain.H> -#include <sys/sync.h> using namespace TARGETING; using namespace HWAS; @@ -62,11 +61,10 @@ int32_t analyzeIplCEStats( TargetHandle_t i_mba, bool &o_calloutMade ) { #define PRDF_FUNC "PRDF::analyzeIplCEStats" - static mutex_t lock = MUTEX_INITIALIZER; - mutex_lock(&lock); - PRDF_ENTER( PRDF_FUNC"(0x%08x)", getHuid(i_mba) ); + PRDF_SYSTEM_SCOPE_MUTEX; + int32_t o_rc = SUCCESS; o_calloutMade = false; @@ -103,8 +101,6 @@ int32_t analyzeIplCEStats( TargetHandle_t i_mba, bool &o_calloutMade ) PRDF_EXIT( PRDF_FUNC"(0x%08x), o_calloutMade:%u", getHuid(i_mba), o_calloutMade ); - mutex_unlock(&lock); - return o_rc; #undef PRDF_FUNC |