[compiler-rt] [TSan] Increase the number of simultaneously locked mutexes that a thread can hold (PR #116409)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 19 05:21:52 PST 2024
https://github.com/gbMattN updated https://github.com/llvm/llvm-project/pull/116409
>From a2561d5878a02b6955f48a38434c2cc056dd6459 Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Fri, 15 Nov 2024 15:41:24 +0000
Subject: [PATCH 1/3] [TSan] Increase the limit of simultaniously held mutexes
TSan can keep track of from 64 to 128
---
.../sanitizer_deadlock_detector.h | 2 +-
compiler-rt/test/tsan/many_held_mutex.cpp | 23 +++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 compiler-rt/test/tsan/many_held_mutex.cpp
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h b/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h
index 0749f633b4bcf5..1664b92b213692 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h
@@ -120,7 +120,7 @@ class DeadlockDetectorTLS {
u32 lock;
u32 stk;
};
- LockWithContext all_locks_with_contexts_[64];
+ LockWithContext all_locks_with_contexts_[128];
uptr n_all_locks_;
};
diff --git a/compiler-rt/test/tsan/many_held_mutex.cpp b/compiler-rt/test/tsan/many_held_mutex.cpp
new file mode 100644
index 00000000000000..479aa20a7b9df3
--- /dev/null
+++ b/compiler-rt/test/tsan/many_held_mutex.cpp
@@ -0,0 +1,23 @@
+// RUN: %clangxx_tsan %s -fsanitize=thread -o %t && %run %t 2>&1 | Filecheck %s
+
+#include <mutex>
+#include <stdio.h>
+
+int main(){
+ const unsigned short NUM_OF_MTX = 128;
+ std::mutex mutexes[NUM_OF_MTX];
+
+ for(int i = 0; i < NUM_OF_MTX; i++){
+ mutexes[i].lock();
+ }
+ for(int i = 0; i < NUM_OF_MTX; i++){
+ mutexes[i].unlock();
+ }
+
+ printf("Success\n");
+
+ return 0;
+}
+
+// CHECK: Success
+// CHECK-NOT: ThreadSanitizer: CHECK failed
>From d93e959dd33224eb738d0f46394b698cf4c77374 Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Mon, 18 Nov 2024 10:32:32 +0000
Subject: [PATCH 2/3] Fixed the test and its formatting
---
compiler-rt/test/tsan/many_held_mutex.cpp | 24 +++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/compiler-rt/test/tsan/many_held_mutex.cpp b/compiler-rt/test/tsan/many_held_mutex.cpp
index 479aa20a7b9df3..36a599904ffe31 100644
--- a/compiler-rt/test/tsan/many_held_mutex.cpp
+++ b/compiler-rt/test/tsan/many_held_mutex.cpp
@@ -1,22 +1,22 @@
-// RUN: %clangxx_tsan %s -fsanitize=thread -o %t && %run %t 2>&1 | Filecheck %s
+// RUN: %clangxx_tsan %s -fsanitize=thread -o %t && %run %t 2>&1 | FileCheck %s
#include <mutex>
#include <stdio.h>
-int main(){
- const unsigned short NUM_OF_MTX = 128;
- std::mutex mutexes[NUM_OF_MTX];
+int main() {
+ const unsigned short NUM_OF_MTX = 128;
+ std::mutex mutexes[NUM_OF_MTX];
- for(int i = 0; i < NUM_OF_MTX; i++){
- mutexes[i].lock();
- }
- for(int i = 0; i < NUM_OF_MTX; i++){
- mutexes[i].unlock();
- }
+ for (int i = 0; i < NUM_OF_MTX; i++) {
+ mutexes[i].lock();
+ }
+ for (int i = 0; i < NUM_OF_MTX; i++) {
+ mutexes[i].unlock();
+ }
- printf("Success\n");
+ printf("Success\n");
- return 0;
+ return 0;
}
// CHECK: Success
>From a05b828b189e495fc0132b18317ff9d2787573b0 Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Tue, 19 Nov 2024 13:21:40 +0000
Subject: [PATCH 3/3] Tidied up the test further
---
compiler-rt/test/tsan/many_held_mutex.cpp | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/compiler-rt/test/tsan/many_held_mutex.cpp b/compiler-rt/test/tsan/many_held_mutex.cpp
index 36a599904ffe31..94ef02a24628fb 100644
--- a/compiler-rt/test/tsan/many_held_mutex.cpp
+++ b/compiler-rt/test/tsan/many_held_mutex.cpp
@@ -1,23 +1,22 @@
-// RUN: %clangxx_tsan %s -fsanitize=thread -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan %s -fsanitize=thread -o %t
+// RUN: %run %t 128
+// RUN: not %run %t 129
#include <mutex>
-#include <stdio.h>
+#include <string>
-int main() {
- const unsigned short NUM_OF_MTX = 128;
- std::mutex mutexes[NUM_OF_MTX];
+int main(int argc, char *argv[]) {
+ int num_of_mtx = std::stoi(argv[1]);
- for (int i = 0; i < NUM_OF_MTX; i++) {
+ std::mutex* mutexes = new std::mutex[num_of_mtx];
+
+ for (int i = 0; i < num_of_mtx; i++) {
mutexes[i].lock();
}
- for (int i = 0; i < NUM_OF_MTX; i++) {
+ for (int i = 0; i < num_of_mtx; i++) {
mutexes[i].unlock();
}
- printf("Success\n");
-
+ delete[] mutexes;
return 0;
}
-
-// CHECK: Success
-// CHECK-NOT: ThreadSanitizer: CHECK failed
More information about the llvm-commits
mailing list