Skip to content

Commit 36d2676

Browse files
fix tsan warning
- silent false positive warning of tsan - CMake: warn user that the system must reconfigured if tsan is used - add `-fno-omit-frame-pointer` for nicer messages
1 parent aba7ef1 commit 36d2676

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ jobs:
166166
export CC=clang
167167
export CXX=clang++
168168
fi
169+
if [ "${{ matrix.config.sanitizer == 'tsan' ]; then
170+
# required to to avoid compile error: 'FATAL: ThreadSanitizer: unexpected memory mapping'
171+
# see: https://stackoverflow.com/questions/77850769/fatal-threadsanitizer-unexpected-memory-mapping-when-running-on-linux-kernels
172+
sysctl vm.mmap_rnd_bits=28
173+
fi
174+
169175
cmake -G Ninja \
170176
-DCMAKE_BUILD_TYPE=Release \
171177
${alpaka_cmake_flags} -Dalpaka_DEP_OMP=ON \

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,10 @@ option(alpaka_ASAN "Enable/Disable linking the address sanitizer for cpu targets
497497
option(alpaka_TSAN "Enable/Disable linking the thread sanitizer for cpu targets" OFF)
498498
option(alpaka_LSAN "Enable/Disable linking the memory leak sanitizer for cpu targets" OFF)
499499
option(alpaka_UBSAN "Enable/Disable linking the undefined behavior sanitizer for cpu targets" OFF)
500+
501+
if(alpaka_TSAN)
502+
message(
503+
WARNING
504+
"Threadsanitizers enabled: You should reduce mmap rnd bits to avoid compile issues: call as root 'sysctl vm.mmap_rnd_bits=28'"
505+
)
506+
endif()

cmake/finalize.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ function(alpaka_finalize target)
224224
message(STATUS "Linking TSAN to ${target}")
225225
target_compile_options(${target} PRIVATE -fsanitize=thread)
226226
target_link_options(${target} PRIVATE -fsanitize=thread)
227+
# - to get nicer stack-traces:
228+
target_link_options(${target} PRIVATE -fno-omit-frame-pointer)
227229
if(alpaka_LSAN OR alpaka_UBSAN)
228230
message(
229231
WARNING

include/alpaka/api/host/Queue.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,20 @@ namespace alpaka::onHost
9292
{
9393
std::lock_guard<std::mutex> lk(m_mutex);
9494
fn();
95+
// silent tsan warnings: The promise is fulfilled directly and only a future which is true is
96+
// returned, there can not be a data race in between.
97+
#if defined(__GNUC__) && !defined(__clang__)
98+
# pragma GCC diagnostic push
99+
# pragma GCC diagnostic ignored "-Wtsan"
100+
#endif
95101
// return a ready future-like placeholder; reuse CallbackThread interface minimally
96102
std::promise<void> p;
97-
auto f = p.get_future();
98103
p.set_value();
104+
#if defined(__GNUC__) && !defined(__clang__)
105+
# pragma GCC diagnostic pop
106+
#endif
107+
auto f = p.get_future();
108+
99109
// to keep the uniform interface with the non-blocking case,
100110
// return by moving the f since it is move-only
101111
return f;

sanitizers/tsan_suppressions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# suppression list for the thread sanitizer
22

33
# the active waiting in the events unit test is detected as a data race, but is fine
4-
race:unit_test_event
4+
race:unit_test_event_event
55
race:docs_test_cheatsheet
66

77
# omp library is not instrumented, exclude it

0 commit comments

Comments
 (0)