diff --git a/modules/ripple_basics/events/ripple_UptimeTimer.cpp b/modules/ripple_basics/events/ripple_UptimeTimer.cpp index 22200efd4a..e6aa127f11 100644 --- a/modules/ripple_basics/events/ripple_UptimeTimer.cpp +++ b/modules/ripple_basics/events/ripple_UptimeTimer.cpp @@ -17,8 +17,9 @@ //============================================================================== UptimeTimer::UptimeTimer () - : m_shadowPointer (0) + : m_elapsedTime (0) , m_startTime (::time (0)) + , m_isUpdatingManually (false) { } @@ -26,41 +27,47 @@ UptimeTimer::~UptimeTimer () { } -void UptimeTimer::initializeShadowPointerIfNecessary (int* shadowPointer) -{ - if (m_shadowPointer == 0) - { - m_shadowPointer = static_cast (shadowPointer); - } - -} - -void UptimeTimer::resetShadowPointerIfSet (int* shadowPointer) -{ - if (m_shadowPointer == shadowPointer) - { - m_shadowPointer = 0; - } -} - -int UptimeTimer::getElapsedSeconds () +int UptimeTimer::getElapsedSeconds () const { int result; - if (m_shadowPointer != 0) + if (m_isUpdatingManually) { - result = *m_shadowPointer; + // vf::memoryBarrier(); + result = m_elapsedTime; } else { + // VFALCO: TODO, use time_t instead of int return result = static_cast (::time (0) - m_startTime); } return result; } +void UptimeTimer::beginManualUpdates () +{ + //assert (!m_isUpdatingManually); + + m_isUpdatingManually = true; +} + +void UptimeTimer::endManualUpdates () +{ + //assert (m_isUpdatingManually); + + m_isUpdatingManually = false; +} + +void UptimeTimer::incrementElapsedTime () +{ + //assert (m_isUpdatingManually); + ++m_elapsedTime; +} + UptimeTimer& UptimeTimer::getInstance () { static UptimeTimer instance; + return instance; } diff --git a/modules/ripple_basics/events/ripple_UptimeTimer.h b/modules/ripple_basics/events/ripple_UptimeTimer.h index 6eb59382df..d0ea915301 100644 --- a/modules/ripple_basics/events/ripple_UptimeTimer.h +++ b/modules/ripple_basics/events/ripple_UptimeTimer.h @@ -19,8 +19,13 @@ #ifndef RIPPLE_UPTIMETIMER_H #define RIPPLE_UPTIMETIMER_H -/** Singleton for tracking uptime. +/** Tracks program uptime. + + The timer can be switched to a manual system of updating, to reduce + system calls. (?) */ +// VFALCO: TODO, determine if the non-manual timing is actually needed + class UptimeTimer { private: @@ -28,17 +33,31 @@ private: ~UptimeTimer (); public: - void initializeShadowPointerIfNecessary (int* shadowPointer); + int getElapsedSeconds () const; - void resetShadowPointerIfSet (int* shadowPointer); + void beginManualUpdates (); + void endManualUpdates (); - int getElapsedSeconds (); + void incrementElapsedTime (); static UptimeTimer& getInstance (); private: + // VFALCO: DEPRECATED, Use a memory barrier instead of forcing a cache line + int m_pad1; // make sure m_uptimeSeconds fits in its own cache line + int m_elapsedTime; + int m_pad2; + time_t m_startTime; - int volatile* m_shadowPointer; + + bool m_isUpdatingManually; }; +// VFALCO: DEPRECATED, legacy compatibility function +// +inline int upTime () +{ + return UptimeTimer::getInstance ().getElapsedSeconds (); +} + #endif diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index 404c3a9d57..ea5ed0acbf 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -8,6 +8,7 @@ #include "Config.h" #include "Application.h" +/* static volatile int* uptimePtr = NULL; int upTime() @@ -17,10 +18,11 @@ int upTime() return *uptimePtr; return static_cast(time(NULL) - firstCall); } +*/ LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int debitLimit) : mCreditRate(creditRate), mCreditLimit(creditLimit), mDebitWarn(debitWarn), mDebitLimit(debitLimit), - mShutdown(false), mArmed(false), mUptime(0), mDeadLock(0), mCosts(LT_MAX) + mShutdown(false), mArmed(false), /*mUptime(0),*/ mDeadLock(0), mCosts(LT_MAX) { addLoadCost(LoadCost(LT_InvalidRequest, -10, LC_CPU | LC_Network)); addLoadCost(LoadCost(LT_RequestNoReply, -1, LC_CPU | LC_Disk)); @@ -39,19 +41,22 @@ LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int deb void LoadManager::init() { + /* if (uptimePtr == NULL) uptimePtr = static_cast(&mUptime); + */ + UptimeTimer::getInstance().beginManualUpdates (); + boost::thread(boost::bind(&LoadManager::threadEntry, this)).detach(); } LoadManager::~LoadManager() { + /* if (uptimePtr == &mUptime) uptimePtr = NULL; - { - boost::mutex::scoped_lock sl(mLock); - mShutdown = true; - } + */ + UptimeTimer::getInstance().endManualUpdates (); do { @@ -68,7 +73,8 @@ LoadManager::~LoadManager() void LoadManager::noDeadLock() { boost::mutex::scoped_lock sl(mLock); - mDeadLock = mUptime; + //mDeadLock = mUptime; + mDeadLock = UptimeTimer::getInstance ().getElapsedSeconds (); } int LoadManager::getCreditRate() const @@ -342,9 +348,11 @@ void LoadManager::threadEntry() mShutdown = false; return; } - ++mUptime; + + //++mUptime; + UptimeTimer::getInstance ().incrementElapsedTime (); - int dlTime = mUptime - mDeadLock; + int dlTime = UptimeTimer::getInstance ().getElapsedSeconds () - mDeadLock; if (mArmed && (dlTime >= 10)) { if ((dlTime % 10) == 0) diff --git a/src/cpp/ripple/LoadManager.h b/src/cpp/ripple/LoadManager.h index 91f6b200b8..551f4b5eb9 100644 --- a/src/cpp/ripple/LoadManager.h +++ b/src/cpp/ripple/LoadManager.h @@ -102,9 +102,11 @@ protected: bool mShutdown; bool mArmed; + /* int mSpace1[4]; // We want mUptime to have its own cache line int mUptime; int mSpace2[4]; + */ int mDeadLock; // Detect server deadlocks diff --git a/src/cpp/ripple/Log.h b/src/cpp/ripple/Log.h index fa8c833f33..4b89bc330c 100644 --- a/src/cpp/ripple/Log.h +++ b/src/cpp/ripple/Log.h @@ -55,6 +55,15 @@ public: static std::vector< std::pair > getSeverities(); private: + /** Retrieve file name from a log partition. + + Key must have this shape: + + struct Key + { + static char const* getFileName (); + }; + */ template inline static LogPartition getFileName () {