schedbench tweaks

上级 4a23dff8
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
#include "futex.h" #include "futex.h"
#include "errno.h" #include "errno.h"
#include "atomic.hh" #include "atomic.hh"
#include "mtrace.h"
static volatile std::atomic<u64> waiting; static volatile std::atomic<u64> waiting;
static volatile std::atomic<u64> waking; static volatile std::atomic<u64> waking;
static int iters; static int iters;
static int nworkers; static int nworkers;
static volatile int go;
static struct { static struct {
u64 mem; u64 mem;
...@@ -24,6 +26,11 @@ void* worker0(void* x) ...@@ -24,6 +26,11 @@ void* worker0(void* x)
u64* f = &(ftx[id>>1].mem); u64* f = &(ftx[id>>1].mem);
long r; long r;
setaffinity(id);
while (go == 0)
yield();
if (id & 0x1) { if (id & 0x1) {
for (u64 i = 0; i < iters; i++) { for (u64 i = 0; i < iters; i++) {
r = futex(f, FUTEX_WAIT, (u64)(i<<1), 0); r = futex(f, FUTEX_WAIT, (u64)(i<<1), 0);
...@@ -50,6 +57,7 @@ void* worker0(void* x) ...@@ -50,6 +57,7 @@ void* worker0(void* x)
static static
void master0(void) void master0(void)
{ {
go = 1;
for (int i = 0; i < nworkers; i++) for (int i = 0; i < nworkers; i++)
wait(); wait();
} }
...@@ -75,9 +83,11 @@ main(int ac, char** av) ...@@ -75,9 +83,11 @@ main(int ac, char** av)
} }
nsleep(1000*1000); nsleep(1000*1000);
mtenable("xv6-schedbench");
u64 t0 = rdtsc(); u64 t0 = rdtsc();
master0(); master0();
u64 t1 = rdtsc(); u64 t1 = rdtsc();
mtdisable("xv6-schedbench");
printf("%lu\n", (t1-t0)/iters); printf("%lu\n", (t1-t0)/iters);
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论