System call hacking stuff

上级 8160fa28
......@@ -14,12 +14,20 @@
#define BSIZE 4096
#define PSIZE (4*BSIZE)
static int usekernlet;
static int use_async;
static char buf[BSIZE];
struct ipcctl *ipcctl = (struct ipcctl*)KSHARED;
struct {
u64 acount;
u64 atot;
u64 pcount;
u64 ptot;
} stats;
static msgid_t
ipc_msg_alloc(void)
{
......@@ -70,7 +78,12 @@ kernlet_pread(int fd, size_t count, off_t off)
struct ipcmsg *msg;
msgid_t msgid;
pageid_t pageid;
u64 t0, t1;
if (!use_async)
return;
t0 = rdtsc();
msgid = ipc_msg_alloc();
if (msgid == NULL_MSGID) {
fprintf(2, "kernlet_pread: ipc_alloc_msg failed");
......@@ -91,14 +104,20 @@ kernlet_pread(int fd, size_t count, off_t off)
if (async(fd, count, off, msgid, pageid) != 0)
die("kernlet");
t1 = rdtsc();
stats.acount++;
stats.atot += t1 - t0;
}
static ssize_t
xpread(int fd, void *buf, size_t count, off_t off)
{
struct ipcmsg *msg;
u64 t0, t1;
int msgid;
t0 = rdtsc();
msgid = ipcctl->msgtail % IPC_NMSG;
msg = &ipcctl->msg[msgid];
......@@ -108,7 +127,7 @@ xpread(int fd, void *buf, size_t count, off_t off)
if (msg->result == -1)
die("xpread: result oops");
if (msg->off != off)
die("xpread: off oops");
die("xpread: off oops %lu", off);
char *kbuf = (char*) (KSHARED+PGSIZE+(msg->pageid*PGSIZE));
off_t kbufoff = off - msg->off;
......@@ -117,10 +136,17 @@ xpread(int fd, void *buf, size_t count, off_t off)
memmove(buf, kbuf+kbufoff, kbufcount);
ipc_msg_free(msgid);
ipc_page_free(msg->pageid);
t1 = rdtsc();
stats.pcount++;
stats.ptot += t1 - t0;
return kbufcount;
}
return pread(fd, buf, count, off);
ssize_t r = pread(fd, buf, count, off);
t1 = rdtsc();
stats.pcount++;
stats.ptot += t1 - t0;
return r;
}
int
......@@ -133,7 +159,7 @@ main(int ac, char **av)
memset(ipcctl, 0, sizeof(*ipcctl));
if (ac > 1)
usekernlet = av[1][0] == 'k';
use_async = av[1][0] == 'a';
fd = open("preadtest.x", O_CREATE|O_RDWR);
if (fd < 0)
......@@ -144,16 +170,26 @@ main(int ac, char **av)
die("write failed");
t0 = rdtsc();
kernlet_pread(fd, BSIZE, 0);
kernlet_pread(fd, BSIZE, 0*BSIZE);
kernlet_pread(fd, BSIZE, 1*BSIZE);
kernlet_pread(fd, BSIZE, 2*BSIZE);
kernlet_pread(fd, BSIZE, 3*BSIZE);
kernlet_pread(fd, BSIZE, 4*BSIZE);
for (i = 0; i < FSIZE; i+=BSIZE) {
if (xpread(fd, buf, BSIZE, i) != BSIZE)
die("pread failed");
kernlet_pread(fd, BSIZE, i+BSIZE);
if (i+BSIZE+3*BSIZE < FSIZE)
kernlet_pread(fd, BSIZE, i+BSIZE+4*BSIZE);
}
t1 = rdtsc();
fprintf(1, "usekernlet %u\n", usekernlet);
fprintf(1, "cycles %lu\n", t1 - t0);
printf("use_async %u\n", use_async);
printf("pread: count %lu total %lu ave %lu\n",
stats.pcount, stats.ptot, stats.ptot / stats.pcount);
if (use_async)
printf("async: count %lu total %lu ave %lu\n",
stats.acount, stats.atot, stats.atot / stats.acount);
printf("total %lu\n", t1 - t0);
exit();
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论