Skip to content

Commit 94232f9

Browse files
authored
[OpenMP][OMPT] Use global thread id for codeptr_ra in end_critical (llvm#169826)
When a critical construct has finished, it will trigger a critical-released event. If a tool is attached, and the `mutex_released` callback was registered, the tool with receive an event containing the `codeptr_ra`, the return address of the callback invocation. All the way back in 82e94a5, this `codeptr_ra` was implemented by calling `__ompt_load_return_address` with a fixed global thread id of `0`. However, this approach results in a race-condition, and can yield incorrect results to the tool. `__ompt_load_return_address(0)` points to the current return address of the thread 0 in `__kmp_threads`. This thread may already execute some other construct. A tool might therefore receive the return address of e.g. some `libomp` internals, or other parts of the user code. Additionally, a call to `__ompt_load_return_address` resets the `th.ompt_thread_info.return_address` to `NULL`, therefore also affecting the return address of thread 0. Another dispatched event, e.g. parallel-begin might therefore not transfer any `codeptr_ra`. To fix this, replace the fixed thread id by the `global_tid`, which is stored just before dispatching the `mutex_released` callback. Signed-off-by: Jan André Reuter <[email protected]>
1 parent 540fd18 commit 94232f9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

openmp/runtime/src/kmp_csupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid,
17801780
if (ompt_enabled.ompt_callback_mutex_released) {
17811781
ompt_callbacks.ompt_callback(ompt_callback_mutex_released)(
17821782
ompt_mutex_critical, (ompt_wait_id_t)(uintptr_t)lck,
1783-
OMPT_LOAD_RETURN_ADDRESS(0));
1783+
OMPT_LOAD_RETURN_ADDRESS(global_tid));
17841784
}
17851785
#endif
17861786

0 commit comments

Comments
 (0)