Skip to content

Commit

Permalink
HPCC-30156 Instrument CriticalSection
Browse files Browse the repository at this point in the history
Rename ICriticalBlock
Clean up some unwanted changes
Add some comments

Signed-off-by: Richard Chapman <[email protected]>
  • Loading branch information
richardkchapman committed May 15, 2024
1 parent 23aeede commit 44d8b8e
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 21 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ unset ( ENV{CC} )
unset ( ENV{CXX} )

set(TOP_LEVEL_PROJECT ON)
unset(PROFILING)
set(PROFILING ON)
if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(TOP_LEVEL_PROJECT OFF)
endif(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
Expand Down
2 changes: 1 addition & 1 deletion cmake_modules/commonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
endif()
endif()
endif ()
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
if (PROFILING AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX))
add_definitions (-fno-omit-frame-pointer)
add_definitions (-D_PROFILING)
endif ()
Expand Down
2 changes: 1 addition & 1 deletion cmake_modules/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ option(SKIP_ECLWATCH "Skip building ECL Watch" OFF)
option(USE_ADDRESS_SANITIZER "Use address sanitizer to spot leaks" OFF)
option(INSTALL_VCPKG_CATALOG "Install vcpkg-catalog.txt" ON)
option(PORTALURL "Set url to hpccsystems portal download page")
option(PROFILING "Set to true if planning to profile so stacks are informative" ON)
option(PROFILING "Set to true if planning to profile so stacks are informative" OFF)

if ( NOT PORTALURL )
set( PORTALURL "http://hpccsystems.com/download" )
Expand Down
2 changes: 1 addition & 1 deletion common/thorhelper/roxiehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ bool CSafeSocket::sendHeartBeat(const IContextLogger &logctx)
class HttpResponseHandler
{
private:
ICriticalBlock c; // should not be anyone writing but better to be safe
CCriticalBlock c; // should not be anyone writing but better to be safe
StringBuffer header;
StringBuffer content;
ISocket *sock = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions common/workunit/wujobq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,13 +972,13 @@ class CJobQueue: public CJobQueueBase, implements IJobQueue
}
}

class Cconnlockblock: public ICriticalBlock
class Cconnlockblock: public CCriticalBlock
{
CJobQueue *parent;
bool rollback;
public:
Cconnlockblock(CJobQueue *_parent,bool exclusive)
: ICriticalBlock(_parent->crit)
: CCriticalBlock(_parent->crit)
{
parent = _parent;
parent->connlock(exclusive);
Expand Down
2 changes: 1 addition & 1 deletion ecl/hql/hqlexpr.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public:
};

#ifdef HQLEXPR_MULTI_THREADED
typedef ICriticalBlock HqlCriticalBlock;
typedef CCriticalBlock HqlCriticalBlock;
#else
typedef NullCriticalBlock HqlCriticalBlock;
#endif
Expand Down
2 changes: 1 addition & 1 deletion plugins/Rembed/Rembed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ class REmbedFunctionContext: public CInterfaceOf<IEmbedFunctionContext>
RInside &R;
RInside::Proxy result;
StringAttr func;
ICriticalBlock block;
CCriticalBlock block;
Owned<REnvironment> env;
};

Expand Down
4 changes: 2 additions & 2 deletions roxie/roxiemem/roxiemem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ class HeapCompactState
}
}
public:
ICriticalBlock lock;
CCriticalBlock lock;
unsigned numPagesEmptied;
CHeap * heap;
Heaplet * next; // which heaplet to try to compact into next. Not so good if > 1 heaps in use.
Expand Down Expand Up @@ -3516,7 +3516,7 @@ class NewHeapCompactState
bool processHeap(unsigned low, unsigned max);

protected:
ICriticalBlock lock;
CCriticalBlock lock;
PointerArrayOf<ChunkedHeaplet> heaplets;
};

Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jmutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ MODULE_EXIT()
}
}

thread_local CriticalBlockInstrumentation *__cbinst = nullptr;
thread_local CriticalBlockInstrumentation *__cbinst = nullptr; // Used as an extra parameter to CriticalBlock macro, so we don't have to change every call

std::size_t CriticalBlockInstrumentation::StackHash::operator()(const Stack& k) const
{
Expand Down
19 changes: 14 additions & 5 deletions system/jlib/jmutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ extern jlib_decl void spinUntilReady(std::atomic_uint &value);
#endif

#if defined(_PROFILING)
#define USE_INSTRUMENTED_CRITSECS
// Instrumented critsecs work best if PROFILING Cmake option is in use
//#define USE_INSTRUMENTED_CRITSECS
#endif

#ifdef SPINLOCK_USE_MUTEX
Expand Down Expand Up @@ -685,21 +686,29 @@ template<typename T> class CLeavableCriticalBlockOf
typedef CLeavableCriticalBlockOf<UninstrumentedCriticalSection> UninstrumentedLeavableCriticalBlock;
typedef CLeavableCriticalBlockOf<InstrumentedCriticalSection> InstrumentedLeavableCriticalBlock;

// The CriticalBlock instrumentation works by replacing all references to the normal CriticalBlock constructor with a macro
// that instantiates a new (local static) CriticalBlockInstrumentation object, and passes it in to the constructor via a thread-local variable.
// It's done this way to avoid any overhead or code changes in the uninstrumented case, at the expense of some complexity and size overhead in the
// instrumented case.
//
// Because CriticalBlock may be a macro in the instrumented case, any place that a parameter or member variable of type CriticalBlock is needed
// must ust CCriticalBlock rather than CriticalBlock to avoid the macro expansion.

#ifdef USE_INSTRUMENTED_CRITSECS
#define __glue(a,b) a ## b
#define glue(a,b) __glue(a,b)

extern thread_local CriticalBlockInstrumentation* __cbinst;

typedef InstrumentedCriticalSection CriticalSection;
typedef InstrumentedCriticalBlock ICriticalBlock;
#define CriticalBlock static CriticalBlockInstrumentation *glue(instrumenter,__LINE__) = new CriticalBlockInstrumentation(__FILE__, __func__, __LINE__); __cbinst = glue(instrumenter,__LINE__); ICriticalBlock
typedef InstrumentedCriticalBlock CCriticalBlock;
#define CriticalBlock static CriticalBlockInstrumentation *glue(instrumenter,__LINE__) = new CriticalBlockInstrumentation(__FILE__, __func__, __LINE__); __cbinst = glue(instrumenter,__LINE__); CCriticalBlock
typedef InstrumentedCriticalUnblock CriticalUnblock;
typedef InstrumentedLeavableCriticalBlock CLeavableCriticalBlock;
#else
typedef UninstrumentedCriticalSection CriticalSection;
typedef UninstrumentedCriticalBlock ICriticalBlock;
typedef ICriticalBlock CriticalBlock;
typedef UninstrumentedCriticalBlock CCriticalBlock;
typedef CCriticalBlock CriticalBlock; // Use in place of CriticalBlock when declaring members/parameters, to avoid macro expansion
typedef UninstrumentedCriticalUnblock CriticalUnblock;
typedef UninstrumentedLeavableCriticalBlock CLeavableCriticalBlock;
#endif
Expand Down
8 changes: 4 additions & 4 deletions testing/unittests/jlibtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2463,10 +2463,10 @@ class AtomicTimingTest : public CppUnit::TestFixture
const unsigned numCores = std::max(getAffinityCpus(), 16U);
void runAllTests()
{
DO_TEST(CriticalSection, ICriticalBlock, unsigned __int64, 1, 1);
DO_TEST(CriticalSection, ICriticalBlock, unsigned __int64, 2, 1);
DO_TEST(CriticalSection, ICriticalBlock, unsigned __int64, 5, 1);
DO_TEST(CriticalSection, ICriticalBlock, unsigned __int64, 1, 2);
DO_TEST(CriticalSection, CCriticalBlock, unsigned __int64, 1, 1);
DO_TEST(CriticalSection, CCriticalBlock, unsigned __int64, 2, 1);
DO_TEST(CriticalSection, CCriticalBlock, unsigned __int64, 5, 1);
DO_TEST(CriticalSection, CCriticalBlock, unsigned __int64, 1, 2);
DO_TEST(SpinLock, SpinBlock, unsigned __int64, 1, 1);
DO_TEST(SpinLock, SpinBlock, unsigned __int64, 2, 1);
DO_TEST(SpinLock, SpinBlock, unsigned __int64, 5, 1);
Expand Down

0 comments on commit 44d8b8e

Please sign in to comment.