Dust off dirbench

上级 75de4440
......@@ -5,41 +5,44 @@
#include "amd64.h"
#include "fcntl.h"
enum { nthread = 2 };
static const bool pinit = true;
enum { nloop = 100 };
enum { nfile = 10 };
enum { nlookup = 100 };
char dirs[nthread][MAXNAME];
void
bench(u32 tid)
{
char pn[MAXNAME];
if (pinit)
setaffinity(tid);
for (u32 x = 0; x < nloop; x++) {
for (u32 i = 0; i < nfile; i++) {
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, i);
snprintf(pn, sizeof(pn), "/dbx/f:%d:%d", tid, i);
int fd = open(pn, O_CREATE | O_RDWR);
if (fd < 0)
fprintf(1, "create failed\n");
die("create failed\n");
close(fd);
}
for (u32 i = 0; i < nlookup; i++) {
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, (i % nfile));
snprintf(pn, sizeof(pn), "/dbx/f:%d:%d", tid, (i % nfile));
int fd = open(pn, O_RDWR);
if (fd < 0)
fprintf(1, "open failed\n");
die("open failed\n");
close(fd);
}
for (u32 i = 0; i < nfile; i++) {
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, i);
snprintf(pn, sizeof(pn), "/dbx/f:%d:%d", tid, i);
if (unlink(pn) < 0)
fprintf(1, "unlink failed\n");
die("unlink failed\n");
}
}
......@@ -47,29 +50,31 @@ bench(u32 tid)
}
int
main(void)
main(int ac, char** av)
{
for (u32 i = 0; i < nthread; i++) {
//snprintf(dirs[i], sizeof(dirs[i]), "/db%d", i);
snprintf(dirs[i], sizeof(dirs[i]), "/dbx");
if (mkdir(dirs[i]) < 0)
fprintf(1, "mkdir failed\n");
}
int nthread;
// mtrace_enable_set(1, "xv6-dirbench");
if (ac < 2)
die("usage: %s nthreads", av[0]);
fprintf(1, "dirbench[%d]: start\n", getpid());
nthread = atoi(av[1]);
if (mkdir("/dbx") < 0)
fprintf(1, "mkdir failed\n");
u64 t0 = rdtsc();
for(u32 i = 0; i < nthread; i++) {
int pid = fork(0);
if (pid == 0)
bench(i);
else if (pid < 0)
die("fork");
}
for (u32 i = 0; i < nthread; i++)
wait();
u64 t1 = rdtsc();
// mtrace_enable_set(0, "xv6-dirbench");
fprintf(1, "dirbench[%d]: done\n", getpid());
// halt();
exit();
printf("dirbench: %lu\n", t1-t0);
return 0;
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论