Skip to content

Commit 95f9a87

Browse files
dhruvachakyanyao-wang
authored andcommitted
[OpenMP] [OMPT] Fixed improper notification of helper threads during trace buffer flush.
Fix for ROCm/aomp#840 Change-Id: I98fc6133bae6136ed57b2a664c99df6725de4536
1 parent 0381932 commit 95f9a87

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

openmp/libomptarget/src/ompt_buffer_mgr.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ int OmptTracingBufferMgr::flushAllBuffers(ompt_device_t *device) {
574574
++curr_buf_id;
575575
}
576576

577-
// Wake up all helper threads to invoke buffer-completion callbacks
578-
FlushCv.notify_all();
579-
580577
// This is best effort. It is possible that some trace records are
581578
// not flushed when the wait is done.
582579
waitForFlushCompletion();
@@ -585,10 +582,22 @@ int OmptTracingBufferMgr::flushAllBuffers(ompt_device_t *device) {
585582
}
586583

587584
void OmptTracingBufferMgr::waitForFlushCompletion() {
588-
std::unique_lock<std::mutex> flush_lock(FlushMutex);
589-
for (uint32_t i = 0; i < OMPT_NUM_HELPER_THREADS; ++i)
590-
setThreadFlush(i);
591-
ThreadFlushCv.wait(flush_lock, [this] { return ThreadFlushTracker == 0; });
585+
{
586+
std::unique_lock<std::mutex> flush_lock(FlushMutex);
587+
// Setting the flush bit for a given helper thread indicates that the worker
588+
// thread is ready for the helper thread to do some work.
589+
for (uint32_t i = 0; i < OMPT_NUM_HELPER_THREADS; ++i)
590+
setThreadFlush(i);
591+
}
592+
593+
// Wake up all helper threads to invoke buffer-completion callbacks.
594+
FlushCv.notify_all();
595+
596+
// Now wait for all helper threads to complete flushing.
597+
{
598+
std::unique_lock<std::mutex> flush_lock(FlushMutex);
599+
ThreadFlushCv.wait(flush_lock, [this] { return ThreadFlushTracker == 0; });
600+
}
592601
}
593602

594603
void OmptTracingBufferMgr::init() {

0 commit comments

Comments
 (0)