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