1 // RUN: %clangxx_tsan %s -o %t 2 // RUN: %run %t 2>&1 | FileCheck %s 3 4 #include <pthread.h> 5 #include <stdlib.h> 6 #include <stddef.h> 7 #include <unistd.h> 8 #include <stdio.h> 9 #include <time.h> 10 #include <sys/mman.h> 11 12 const long kSmallPage = 4 << 10; 13 const long kLargePage = 2 << 20; 14 const long kStride = 1 << 10; 15 16 typedef unsigned long uptr; 17 18 int main(int argc, const char **argv) { 19 uptr mem_size = 4 << 20; 20 if (argc > 1) 21 mem_size = (uptr)atoi(argv[1]) << 20; 22 uptr stride = kSmallPage; 23 if (argc > 2) 24 stride = (uptr)atoi(argv[2]) << 10; 25 int niter = 1; 26 if (argc > 3) 27 niter = atoi(argv[3]); 28 int stride2 = 1; 29 if (argc > 4) 30 stride2 = atoi(argv[4]); 31 32 uptr sz = mem_size + stride2 * kStride + kLargePage; 33 void *p = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); 34 uptr a = ((uptr)p + kLargePage - 1) & ~(kLargePage - 1); 35 volatile char *mem = (volatile char *)a; 36 37 for (int i = 0; i < niter; i++) { 38 for (uptr off = 0; off < mem_size; off += stride) { 39 for (uptr off2 = 0; off2 < stride2; off2++) 40 mem[off + off2 * kStride] = 42; 41 } 42 } 43 44 fprintf(stderr, "DONE\n"); 45 } 46 47 // CHECK: DONE 48 49