提交 2e4345d8 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Build forktree, mtrace seems to work again.

上级 22a3a4f0
......@@ -61,6 +61,7 @@ ULIB = ulib.o usys.o printf.o umalloc.o
UPROGS= \
_cat \
_init \
_forktree \
_ls \
_sh \
......@@ -95,13 +96,16 @@ fs.img: mkfs README $(UPROGS)
mscan.syms: kernel
$(NM) -S $< > $@
mscan.kernel: kernel
mscan.kern: kernel
cp $< $@
-include *.d
.PHONY: clean qemu gdb ud0
.PHONY: clean qemu gdb mtrace ud0
##
## qemu
##
QEMUOPTS = -smp $(QEMUSMP) -m 512 -serial mon:stdio -nographic
qemu: kernel
......@@ -114,8 +118,8 @@ gdb: kernel
##
MTRACEOPTS = -rtc clock=vm -mtrace-enable -mtrace-file mtrace.out \
-mtrace-quantum 100
mtrace: mscan.kernel mscan.syms
$(MTRACE) $(QEMUOPTS) $(MTRACEOPTS) -kernel kernel
mtrace: mscan.kern mscan.syms
$(MTRACE) $(QEMUOPTS) $(MTRACEOPTS) -kernel mscan.kern
mscan.out: mtrace.out $(QEMUSRC)/mtrace-tools/mscan
$(QEMUSRC)/mtrace-tools/mscan > $@ || (rm -f $@; exit 2)
......
......@@ -9,17 +9,17 @@
void
forktree(void)
{
uint depth = 0;
int depth = 0;
printf(1, "%d: fork tree\n", getpid());
mtrace_enable_set(1, "xv6-forktree");
mtenable("xv6-forktree");
next_level:
//printf(1, "pid %d, depth %d\n", getpid(), depth);
if (depth >= NDEPTH)
exit();
for (uint i = 0; i < NCHILD; i++) {
for (int i = 0; i < NCHILD; i++) {
int pid = fork(0);
if (pid < 0) {
printf(1, "fork error\n");
......@@ -32,7 +32,7 @@ forktree(void)
}
}
for (uint i = 0; i < NCHILD; i++) {
for (int i = 0; i < NCHILD; i++) {
if (wait() < 0) {
printf(1, "wait stopped early\n");
exit();
......@@ -47,10 +47,8 @@ forktree(void)
if (depth > 0)
exit();
struct mtrace_appdata_entry entry;
entry.u64 = 0;
mtrace_appdata_register(&entry);
mtrace_enable_set(0, "xv6-forktree");
mtops(0);
mtdisable("xv6-forktree");
printf(1, "%d: fork tree OK\n", getpid());
halt();
......
......@@ -6,6 +6,7 @@ struct kstack_tag {
};
extern struct kstack_tag kstack_tag[NCPU];
// Tell mtrace about switching threads/processes
static inline void mtstart(void *ip, struct proc *p)
{
unsigned long new_tag;
......@@ -54,9 +55,18 @@ static inline void mtresume(struct proc *p)
panic("mtrace_kstack_resume: bad stack");
mtrace_fcall_register(p->pid, 0, p->mtrace_stacks.tag[i], i, mtrace_resume);
}
// Tell mtrace to start/stop recording call and ret
#define mtrec() mtrace_call_set(1, ~0ull)
#define mtign() mtrace_call_set(0, ~0ull)
#else
#define mtstart(ip, p) do { } while (0)
#define mtstop(p) do { } while (0)
#define mtpause(p) do { } while (0)
#define mtresume(p) do { } while (0)
#define mtrec(cpu) do { } while (0)
#define mtign(cpu) do { } while (0)
#define mtrec(cpu) do { } while (0)
#define mtign(cpu) do { } while (0)
#endif
#include "param.h"
#if MTRACE
typedef __signed char int8_t;
typedef unsigned char uint8_t;
......@@ -32,9 +33,17 @@ char* strncpy(char *s, const char *t, int n);
#define mtunlock(ptr) \
mtrace_lock_register(RET_IP(), ptr, lockname(ptr), mtrace_lockop_release, 0)
// Tell mtrace to start/stop recording call and ret
#define mtrec(cpu) mtrace_call_set(1, cpu)
#define mtign(cpu) mtrace_call_set(0, cpu)
// Enable/disable all mtrace logging
#define mtenable(name) mtrace_enable_set(1, name)
#define mtdisable(name) mtrace_enable_set(0, name)
// Log the number of operations
static inline void mtops(u64 n)
{
struct mtrace_appdata_entry entry;
entry.u64 = 0;
mtrace_appdata_register(&entry);
}
#include "mtrace-magic.h"
#else
......@@ -45,4 +54,7 @@ char* strncpy(char *s, const char *t, int n);
#define mtunlock(ptr) do { } while (0)
#define mtrec(cpu) do { } while (0)
#define mtign(cpu) do { } while (0)
#define mtenable(name) do { } while (0)
#define mtdisable(name) do { } while (0)
#define mtops(n) do { } while (0)
#endif
#pragma once
#define NPROC 64 // maximum number of processes
#define KSTACKSIZE 8192 // size of per-process kernel stack
#define NCPU 4 // maximum number of CPUs
......
......@@ -44,7 +44,7 @@ sched(void)
mtstop(myproc());
else
mtpause(myproc());
mtign(mycpu()->id);
mtign();
swtch(&myproc()->context, mycpu()->scheduler);
mycpu()->intena = intena;
......@@ -426,11 +426,11 @@ scheduler(void)
{
mtresume(p);
}
mtrec(mycpu()->id);
mtrec();
swtch(&mycpu()->scheduler, myproc()->context);
mtresume(schedp);
mtign(mycpu()->id);
mtign();
switchkvm();
// Process is done running for now.
......
......@@ -170,10 +170,10 @@ syscall(void)
num = myproc()->tf->rax;
if(num >= 0 && num < NELEM(syscalls) && syscalls[num]) {
mtstart(syscalls[num], myproc());
mtrec(cpunum());
mtrec();
myproc()->tf->rax = syscalls[num]();
mtstop(myproc());
mtign(cpunum());
mtign();
} else {
cprintf("%d %s: unknown sys call %d\n",
myproc()->pid, myproc()->name, num);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论