提交 f51e9863 创建 作者: Austin Clements's avatar Austin Clements 提交者: Silas Boyd-Wickizer

asharing vm2 test that does lots of non-commutative operations

The only unexpected sharing is on the VMA refcount, which is exactly what we expected.
上级 69cbd10a
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "atomic.hh" #include "atomic.hh"
#include <utility>
static int cpu; static int cpu;
std::atomic<int> barrier; std::atomic<int> barrier;
...@@ -38,6 +39,14 @@ ready(void) ...@@ -38,6 +39,14 @@ ready(void)
} }
} }
u64
rnd(void)
{
static u64 rseed;
rseed = rseed * 6364136223846793005 + 1442695040888963407;
return rseed;
}
void* void*
vmsharing(void* arg) vmsharing(void* arg)
{ {
...@@ -55,6 +64,48 @@ vmsharing(void* arg) ...@@ -55,6 +64,48 @@ vmsharing(void* arg)
return 0; return 0;
} }
std::atomic<int> round;
void*
vm2sharing(void *arg)
{
u64 i = (u64) arg;
char *base = (char*)0x1000;
ready();
while (true) {
while (round % ncore != i)
asm volatile("pause");
if (round >= 50) {
round++;
return 0;
}
int op = rnd() % 2;
int lo = rnd() % 10, hi = rnd() % 10;
if (lo > hi)
std::swap(lo, hi);
if (lo == hi)
continue;
if (op == 0) {
// Map
void *res = mmap(base + lo * 4096, (hi-lo) * 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
if (res == MAP_FAILED)
die("asharing: mmap failed");
} else {
// Unmap
int res = munmap(base + lo * 4096, (hi-lo) * 4096);
if (res < 0)
die("asharing: munmap failed");
}
round++;
}
}
void* void*
fssharing(void* arg) fssharing(void* arg)
{ {
...@@ -84,6 +135,8 @@ main(int ac, char **av) ...@@ -84,6 +135,8 @@ main(int ac, char **av)
void* (*op)(void*) = 0; void* (*op)(void*) = 0;
if (ac == 2 && strcmp(av[1], "vm") == 0) if (ac == 2 && strcmp(av[1], "vm") == 0)
op = vmsharing; op = vmsharing;
else if (ac == 2 && strcmp(av[1], "vm2") == 0)
op = vm2sharing;
else if (ac == 2 && strcmp(av[1], "fs") == 0) else if (ac == 2 && strcmp(av[1], "fs") == 0)
op = fssharing; op = fssharing;
else else
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论