summaryrefslogtreecommitdiff
path: root/test/tsan/bench_shadow_flush.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-04-18 10:37:39 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-04-18 10:37:39 +0000
commit9451ab7ed4a06b27c954860f281c5e351c72293f (patch)
treef3e228da9d18af3c47724bbeab1e6221e83f42ce /test/tsan/bench_shadow_flush.cc
parente2a2bb7d09c8c54c6557cdd8d9bdc2995f0773ed (diff)
tsan: add benchmark that allows to investigate shadow memory consumption
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@206578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/bench_shadow_flush.cc')
-rw-r--r--test/tsan/bench_shadow_flush.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/tsan/bench_shadow_flush.cc b/test/tsan/bench_shadow_flush.cc
new file mode 100644
index 000000000..bd85cba51
--- /dev/null
+++ b/test/tsan/bench_shadow_flush.cc
@@ -0,0 +1,42 @@
+// RUN: %clangxx_tsan %s -o %t
+// RUN: %t 2>&1 | FileCheck %s
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <time.h>
+#include <sys/mman.h>
+
+const long kSmallPage = 4 << 10;
+const long kLargePage = 2 << 20;
+
+typedef unsigned long uptr;
+
+int main(int argc, const char **argv) {
+ uptr mem_size = 4 << 20;
+ if (argc > 1)
+ mem_size = (uptr)atoi(argv[1]) << 20;
+ uptr stride = kSmallPage;
+ if (argc > 2)
+ stride = (uptr)atoi(argv[2]) << 10;
+ int niter = 1;
+ if (argc > 3)
+ niter = atoi(argv[3]);
+
+ void *p = mmap(0, mem_size + kLargePage, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+ uptr a = ((uptr)p + kLargePage - 1) & ~(kLargePage - 1);
+ volatile char *mem = (volatile char *)a;
+
+ for (int i = 0; i < niter; i++) {
+ for (uptr off = 0; off < mem_size; off += stride)
+ mem[off] = 42;
+ }
+
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
+