提交 4c97b4dd 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Merge branch 'old-types' into scale-amd64

#if defined(LINUX)
#include "user/util.h"
#include "types.h"
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>
#define O_CREATE O_CREAT
#define xfork() fork()
#define xexit() exit(EXIT_SUCCESS)
#define xmkdir(pathname) mkdir((pathname), S_IWUSR|S_IRUSR);
#define mtenable(x) do { } while(0)
#define mtdisable(x) do { } while(0)
#else
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
#include "mtrace.h" #include "mtrace.h"
#include "amd64.h" #include "amd64.h"
#include "fcntl.h" #include "fcntl.h"
#define xfork() fork(0)
#define xexit() exit()
#define xmkdir(pathname) mkdir((pathname))
#endif
static const bool pinit = true; static const bool pinit = true;
...@@ -11,7 +29,7 @@ enum { nfile = 10 }; ...@@ -11,7 +29,7 @@ enum { nfile = 10 };
enum { nlookup = 100 }; enum { nlookup = 100 };
void void
bench(u32 tid, int nloop) bench(u32 tid, int nloop, const char* path)
{ {
char pn[MAXNAME]; char pn[MAXNAME];
...@@ -20,7 +38,7 @@ bench(u32 tid, int nloop) ...@@ -20,7 +38,7 @@ bench(u32 tid, int nloop)
for (u32 x = 0; x < nloop; x++) { for (u32 x = 0; x < nloop; x++) {
for (u32 i = 0; i < nfile; i++) { for (u32 i = 0; i < nfile; i++) {
snprintf(pn, sizeof(pn), "/dbx/f:%d:%d", tid, i); snprintf(pn, sizeof(pn), "%s/f:%d:%d", path, tid, i);
int fd = open(pn, O_CREATE | O_RDWR); int fd = open(pn, O_CREATE | O_RDWR);
if (fd < 0) if (fd < 0)
...@@ -30,7 +48,7 @@ bench(u32 tid, int nloop) ...@@ -30,7 +48,7 @@ bench(u32 tid, int nloop)
} }
for (u32 i = 0; i < nlookup; i++) { for (u32 i = 0; i < nlookup; i++) {
snprintf(pn, sizeof(pn), "/dbx/f:%d:%d", tid, (i % nfile)); snprintf(pn, sizeof(pn), "%s/f:%d:%d", path, tid, (i % nfile));
int fd = open(pn, O_RDWR); int fd = open(pn, O_RDWR);
if (fd < 0) if (fd < 0)
die("open failed\n"); die("open failed\n");
...@@ -39,18 +57,19 @@ bench(u32 tid, int nloop) ...@@ -39,18 +57,19 @@ bench(u32 tid, int nloop)
} }
for (u32 i = 0; i < nfile; i++) { for (u32 i = 0; i < nfile; i++) {
snprintf(pn, sizeof(pn), "/dbx/f:%d:%d", tid, i); snprintf(pn, sizeof(pn), "%s/f:%d:%d", path, tid, i);
if (unlink(pn) < 0) if (unlink(pn) < 0)
die("unlink failed\n"); die("unlink failed\n");
} }
} }
exit(); xexit();
} }
int int
main(int ac, char** av) main(int ac, char** av)
{ {
const char* path;
int nthread; int nthread;
int nloop; int nloop;
...@@ -59,22 +78,25 @@ main(int ac, char** av) ...@@ -59,22 +78,25 @@ main(int ac, char** av)
#else #else
nloop = 1000; nloop = 1000;
#endif #endif
path = "/dbx";
if (ac < 2) if (ac < 2)
die("usage: %s nthreads [nloop]", av[0]); die("usage: %s nthreads [nloop] [path]", av[0]);
nthread = atoi(av[1]); nthread = atoi(av[1]);
if (ac > 2) if (ac > 2)
nloop = atoi(av[2]); nloop = atoi(av[2]);
if (ac > 3)
path = av[3];
mkdir("/dbx"); xmkdir(path);
mtenable("xv6-dirbench"); mtenable("xv6-dirbench");
u64 t0 = rdtsc(); u64 t0 = rdtsc();
for(u32 i = 0; i < nthread; i++) { for(u32 i = 0; i < nthread; i++) {
int pid = fork(0); int pid = xfork();
if (pid == 0) if (pid == 0)
bench(i, nloop); bench(i, nloop, path);
else if (pid < 0) else if (pid < 0)
die("fork"); die("fork");
} }
......
#if defined(LINUX) #if defined(LINUX)
#include "user/util.h" #include "user/util.h"
#include "types.h"
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
...@@ -9,7 +10,6 @@ ...@@ -9,7 +10,6 @@
#define xcreat(name) open((name), O_CREATE|O_WRONLY, S_IRUSR|S_IWUSR) #define xcreat(name) open((name), O_CREATE|O_WRONLY, S_IRUSR|S_IWUSR)
#define mtenable(x) do { } while(0) #define mtenable(x) do { } while(0)
#define mtdisable(x) do { } while(0) #define mtdisable(x) do { } while(0)
typedef uint64_t u64;
#else #else
#include "types.h" #include "types.h"
#include "user.h" #include "user.h"
......
...@@ -23,4 +23,4 @@ $(O)/%: $(O)/user/%.o ...@@ -23,4 +23,4 @@ $(O)/%: $(O)/user/%.o
.PRECIOUS: $(O)/user/%.o .PRECIOUS: $(O)/user/%.o
-include $(O)/user/*.d -include $(O)/user/*.d
ALL := $(O)/filebench ALL := $(O)/filebench $(O)/dirbench
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论