-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HPCC-30156 Instrument CriticalSection #17706
base: master
Are you sure you want to change the base?
HPCC-30156 Instrument CriticalSection #17706
Conversation
https://track.hpccsystems.com/browse/HPCC-30156 |
testing/unittests/unittests.cpp
Outdated
inline void enter() | ||
{ | ||
cycle_t start = get_cycles_now(); | ||
#ifdef CHECK_CS_CONTENTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this after the getCurrentThreadId() call
testing/unittests/unittests.cpp
Outdated
holdStart = get_cycles_now(); | ||
waitCycles += holdStart-start; | ||
#endif | ||
depth++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this before the get_cycles_now() - will be trivial
I'm not 100% sure this is correct code (is the compiler allowed to add 1 to the value of depth it got before the mutex_lock?)
testing/unittests/unittests.cpp
Outdated
inline void leave() | ||
{ | ||
bool isContended = false; | ||
depth--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit early if the contended test is based on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to decrement just before the unlock, and check (depth == 1) here.
testing/unittests/unittests.cpp
Outdated
#ifdef _ASSERT_LOCK_SUPPORT | ||
ThreadId owner = 0; | ||
#endif | ||
unsigned depth = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly better if this is atomic - then the compiler can't magically move the code (and use fastInc(), fastDec()). Still get very inconsistent results though.
testing/unittests/unittests.cpp
Outdated
|
||
inline void enter() | ||
{ | ||
cycle_t start = get_cycles_now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be inside the #ifdef TIME_CRITSECS
@mckellyln this is curious - the number of reported contentions is much lower than the real value. I think the reason is that the overhead of the lock calls/returns is larger than the work being done in the critical section. This may still be useful, but it suggests that quick critical sections will have significantly under-reported contention. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Gavins comments.
We may need to add compiler fences to ensure statements are not moved around ?
Should we increase thread count ? |
65a8331
to
7bea2af
Compare
7bea2af
to
6642430
Compare
Signed-off-by: Richard Chapman <[email protected]>
e74cd91
to
23aeede
Compare
system/jlib/jmutex.cpp
Outdated
} | ||
} | ||
|
||
thread_local CriticalBlockInstrumentation *__cbinst = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does this get created ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting out jtiming looks like a good change.
There are several changes for testing that probably need removing
A few questions about class names etc.
Generally I think it looks good, and I think worth merging with a bit more clean up.
#define __glue(a,b) a ## b | ||
#define glue(a,b) __glue(a,b) | ||
|
||
extern thread_local CriticalBlockInstrumentation* __cbinst; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread local variables generally generate terrible code. It would be better to keep this hidden within jmutex.cpp and provide an accessor function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is used to pass an implicit parameter into the CriticalBlock object without having to change the prototype? If so it is worth adding a comment to explain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. I can add a comment.
Not really sure how an acessor function helps though - makes the code even more obscure, and less efficient (though smaller) I would have thought.
system/jlib/jmutex.hpp
Outdated
extern thread_local CriticalBlockInstrumentation* __cbinst; | ||
|
||
typedef InstrumentedCriticalSection CriticalSection; | ||
typedef InstrumentedCriticalBlock ICriticalBlock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not clear why you would use ICriticalBlock rather than the other classes. Would it make sense for InstrumentedCrtiticalSection to only be defined if the option was selected, and otherwise be typedefed to the uninistrumented.
ICriticalBlock suggests an interface, which this isn't..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea I think is that you can Typedef CriticalBlock == InstrumentedCriticalBlock if you want ALL blocks instrumented, or use InstrumentedCriticalBlock explicitly if you want to investigate the behaviour of individual blocks.
I can add some comments to help explain that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for ICriticalBlock is that when CriticalBlock is a macro, you can't use it without a parameter. There are some instances where that is necessary. Not sure what the best name for it is.
cmake_modules/options.cmake
Outdated
@@ -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" OFF) | |||
option(PROFILING "Set to true if planning to profile so stacks are informative" ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a separate flag to control the new functionality. (I set this on in my release builds by default.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I intended the option to be controlled via editing the definition of USE_INSTRUMENTED_CRITSECS in jmutex.hpp - it's something that will be set temporarily while investigating issues rather than left on.
Rename ICriticalBlock Clean up some unwanted changes Add some comments Signed-off-by: Richard Chapman <[email protected]>
@richardkchapman I just found this branch invaluable for diagnosing a completely confusing set of timings for the stress text example. Please can you rebase, squash and I will rereview and aim to merge. |
dfuserver is currently crashing on startup with this branch enabled |
And dali locks up on closedown. |
Type of change:
Checklist:
Smoketest:
Testing: