Skip to content

Commit ac7137d

Browse files
jprotzeshintaro-iwasaki
authored andcommitted
[OpenMP][Tool] Runtime warning for missing TSan-option
TSan spuriously reports for any OpenMP application a race on the initialization of a runtime internal mutex: ``` Atomic read of size 1 at 0x7b6800005940 by thread T4: #0 pthread_mutex_lock <null> (a.out+0x43f39e) #1 __kmp_resume_64 <null> (libomp.so.5+0x84db4) Previous write of size 1 at 0x7b6800005940 by thread T7: #0 pthread_mutex_init <null> (a.out+0x424793) #1 __kmp_suspend_initialize_thread <null> (libomp.so.5+0x8422e) ``` According to @AndreyChurbanov this is a false positive report, as the control flow of the runtime guarantees the ordering of the mutex initialization and the lock: https://software.intel.com/en-us/forums/intel-open-source-openmp-runtime-library/topic/530363 To suppress this report, I suggest the use of TSAN_OPTIONS='ignore_uninstrumented_modules=1'. With this patch, a runtime warning is provided in case an OpenMP application is built with Tsan and executed without this Tsan-option. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D70412 cherry-pick: 2d4571bf3060f8f3d8417a0ec55e21a280158069 llvm/llvm-project@2d4571b
1 parent e7c59b5 commit ac7137d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

CREDITS.txt

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ N: Steven Noonan
5353
5454
D: Patches for the ARM architecture and removal of several inconsistencies.
5555

56+
N: Joachim Protze
57+
58+
D: OpenMP Tools Interface, Archer tool
59+
5660
N: Alp Toker
5761
5862
D: Making build work for FreeBSD.

tools/archer/ompt-tsan.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,39 @@ class ArcherFlags {
8282
}
8383
};
8484

85+
class TsanFlags {
86+
public:
87+
int ignore_noninstrumented_modules;
88+
89+
TsanFlags(const char *env) : ignore_noninstrumented_modules(0) {
90+
if (env) {
91+
std::vector<std::string> tokens;
92+
std::string token;
93+
std::string str(env);
94+
std::istringstream iss(str);
95+
while (std::getline(iss, token, ' '))
96+
tokens.push_back(token);
97+
98+
for (std::vector<std::string>::iterator it = tokens.begin();
99+
it != tokens.end(); ++it) {
100+
// we are interested in ignore_noninstrumented_modules to print a
101+
// warning
102+
if (sscanf(it->c_str(), "ignore_noninstrumented_modules=%d",
103+
&ignore_noninstrumented_modules))
104+
continue;
105+
}
106+
}
107+
}
108+
};
109+
85110
#if (LLVM_VERSION) >= 40
86111
extern "C" {
87112
int __attribute__((weak)) __archer_get_omp_status();
88113
void __attribute__((weak)) __tsan_flush_memory() {}
89114
}
90115
#endif
91116
ArcherFlags *archer_flags;
117+
TsanFlags *tsan_flags;
92118

93119
// The following definitions are pasted from "llvm/Support/Compiler.h" to allow
94120
// the code
@@ -838,6 +864,8 @@ static int ompt_tsan_initialize(ompt_function_lookup_t lookup,
838864
ompt_data_t *tool_data) {
839865
const char *options = getenv("ARCHER_OPTIONS");
840866
archer_flags = new ArcherFlags(options);
867+
options = getenv("TSAN_OPTIONS");
868+
tsan_flags = new TsanFlags(options);
841869

842870
ompt_set_callback_t ompt_set_callback =
843871
(ompt_set_callback_t)lookup("ompt_set_callback");
@@ -869,6 +897,12 @@ static int ompt_tsan_initialize(ompt_function_lookup_t lookup,
869897
SET_CALLBACK_T(mutex_acquired, mutex);
870898
SET_CALLBACK_T(mutex_released, mutex);
871899
SET_OPTIONAL_CALLBACK_T(reduction, sync_region, hasReductionCallback, ompt_set_never);
900+
901+
if (!tsan_flags->ignore_noninstrumented_modules)
902+
fprintf(
903+
stderr,
904+
"Warning: please export TSAN_OPTIONS='ignore_noninstrumented_modules=1' "
905+
"to avoid false positive reports from the OpenMP runtime.!\n");
872906
return 1; // success
873907
}
874908

0 commit comments

Comments
 (0)