2014-04-18 10:37:39 +00:00
|
|
|
// RUN: %clangxx_tsan %s -o %t
|
2014-04-30 21:34:17 +00:00
|
|
|
// RUN: %run %t 2>&1 | FileCheck %s
|
2014-04-18 10:37:39 +00:00
|
|
|
|
|
|
|
#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;
|
2014-07-26 16:40:33 +00:00
|
|
|
const long kStride = 1 << 10;
|
2014-04-18 10:37:39 +00:00
|
|
|
|
|
|
|
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]);
|
2014-07-26 16:40:33 +00:00
|
|
|
int stride2 = 1;
|
|
|
|
if (argc > 4)
|
|
|
|
stride2 = atoi(argv[4]);
|
2014-04-18 10:37:39 +00:00
|
|
|
|
2014-07-26 16:40:33 +00:00
|
|
|
uptr sz = mem_size + stride2 * kStride + kLargePage;
|
|
|
|
void *p = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
2014-04-18 10:37:39 +00:00
|
|
|
uptr a = ((uptr)p + kLargePage - 1) & ~(kLargePage - 1);
|
|
|
|
volatile char *mem = (volatile char *)a;
|
|
|
|
|
|
|
|
for (int i = 0; i < niter; i++) {
|
2014-07-26 16:40:33 +00:00
|
|
|
for (uptr off = 0; off < mem_size; off += stride) {
|
|
|
|
for (uptr off2 = 0; off2 < stride2; off2++)
|
|
|
|
mem[off + off2 * kStride] = 42;
|
|
|
|
}
|
2014-04-18 10:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "DONE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: DONE
|
|
|
|
|