提交 3e89a345 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Some forkexec stuff.

上级 d9f0899f
...@@ -64,6 +64,8 @@ ULIB = ulib.o usys.o printf.o umalloc.o uthread.o ...@@ -64,6 +64,8 @@ ULIB = ulib.o usys.o printf.o umalloc.o uthread.o
UPROGS= \ UPROGS= \
_cat \ _cat \
_init \ _init \
_forkexectree \
_forkexecbench \
_forktree \ _forktree \
_ls \ _ls \
_mapbench \ _mapbench \
......
#include "types.h"
#include "stat.h"
#include "user.h"
#include "mtrace.h"
#include "amd64.h"
#define NITERS 64
static void
execbench(void)
{
u64 s = rdtsc();
for (int i = 0; i < NITERS; i++) {
int pid = fork(0);
if (pid < 0) {
printf(1, "fork error\n");
exit();
}
if (pid == 0) {
char *av[] = { "forkexecbench", "x", 0 };
exec("forkexecbench", av);
printf(1, "exec failed\n");
exit();
} else {
wait();
}
}
u64 e = rdtsc();
printf(1, "%lu\n", (e-s) / NITERS);
}
int
main(int ac, char **av)
{
if (ac == 2)
exit();
execbench();
exit();
}
...@@ -7,17 +7,17 @@ ...@@ -7,17 +7,17 @@
#define NDEPTH 7 #define NDEPTH 7
void void
forktree(uint depth) forktree(int depth)
{ {
if (depth == 0) { if (depth == 0) {
printf(1, "%d: forkexectree\n", getpid()); printf(1, "%d: forkexectree\n", getpid());
mtrace_enable_set(1, "xv6-forktree"); mtenable("xv6-forkexectree");
} }
if (depth >= NDEPTH) if (depth >= NDEPTH)
exit(); exit();
for (uint i = 0; i < NCHILD; i++) { for (int i = 0; i < NCHILD; i++) {
int pid = fork(0); int pid = fork(0);
if (pid < 0) { if (pid < 0) {
printf(1, "fork error\n"); printf(1, "fork error\n");
...@@ -33,7 +33,7 @@ forktree(uint depth) ...@@ -33,7 +33,7 @@ forktree(uint depth)
} }
} }
for (uint i = 0; i < NCHILD; i++) { for (int i = 0; i < NCHILD; i++) {
if (wait() < 0) { if (wait() < 0) {
printf(1, "wait stopped early\n"); printf(1, "wait stopped early\n");
exit(); exit();
...@@ -48,10 +48,8 @@ forktree(uint depth) ...@@ -48,10 +48,8 @@ forktree(uint depth)
if (depth > 0) if (depth > 0)
exit(); exit();
struct mtrace_appdata_entry entry; mtops(0);
entry.u64 = 0; mtdisable("xv6-forkexectree");
mtrace_appdata_register(&entry);
mtrace_enable_set(0, "xv6-forktree");
printf(1, "%d: forkexectree OK\n", getpid()); printf(1, "%d: forkexectree OK\n", getpid());
halt(); halt();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论