[compiler-rt] r206578 - tsan: add benchmark that allows to investigate shadow memory consumption
Dmitry Vyukov
dvyukov at google.com
Fri Apr 18 03:37:39 PDT 2014
Author: dvyukov
Date: Fri Apr 18 05:37:39 2014
New Revision: 206578
URL: http://llvm.org/viewvc/llvm-project?rev=206578&view=rev
Log:
tsan: add benchmark that allows to investigate shadow memory consumption
Added:
compiler-rt/trunk/test/tsan/bench_shadow_flush.cc
Added: compiler-rt/trunk/test/tsan/bench_shadow_flush.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/bench_shadow_flush.cc?rev=206578&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/bench_shadow_flush.cc (added)
+++ compiler-rt/trunk/test/tsan/bench_shadow_flush.cc Fri Apr 18 05:37:39 2014
@@ -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
+
More information about the llvm-commits
mailing list