Start of some code to be smarter (dumber?) about communicating

kernel stacks to mtrace.
上级 b06ac8cf
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "condvar.h" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.h"
#include "xv6-mtrace.h" #include "xv6-kmtrace.h"
int __attribute__ ((aligned (CACHELINE))) idle[NCPU]; int __attribute__ ((aligned (CACHELINE))) idle[NCPU];
struct ns *nspid __attribute__ ((aligned (CACHELINE))); struct ns *nspid __attribute__ ((aligned (CACHELINE)));
...@@ -524,8 +524,7 @@ scheduler(void) ...@@ -524,8 +524,7 @@ scheduler(void)
// Enabling mtrace calls in scheduler generates many mtrace_call_entrys. // Enabling mtrace calls in scheduler generates many mtrace_call_entrys.
// mtrace_call_set(1, cpu->id); // mtrace_call_set(1, cpu->id);
mtrace_fcall_register(schedp->pid, (unsigned long)scheduler, mtrace_kstack_register(scheduler, mtrace_start, schedp->pid);
schedp->pid, 0, mtrace_start);
for(;;){ for(;;){
// Enable interrupts on this processor. // Enable interrupts on this processor.
...@@ -548,11 +547,15 @@ scheduler(void) ...@@ -548,11 +547,15 @@ scheduler(void)
p->state = RUNNING; p->state = RUNNING;
p->tsc = rdtsc(); p->tsc = rdtsc();
mtrace_fcall_register(schedp->pid, 0, schedp->pid, 0, mtrace_pause); mtrace_kstack_register(NULL, mtrace_pause, schedp->pid);
mtrace_fcall_register(proc->pid, 0, proc->pid, 0, mtrace_resume); if (p->context->eip != (uint)forkret &&
p->context->eip != (uint)rcu_gc_worker)
{
mtrace_kstack_register(NULL, mtrace_resume, 0);
}
mtrace_call_set(1, cpu->id); mtrace_call_set(1, cpu->id);
swtch(&cpu->scheduler, proc->context); swtch(&cpu->scheduler, proc->context);
mtrace_fcall_register(schedp->pid, 0, schedp->pid, 0, mtrace_resume); mtrace_kstack_register(NULL, mtrace_resume, schedp->pid);
mtrace_call_set(0, cpu->id); mtrace_call_set(0, cpu->id);
switchkvm(); switchkvm();
...@@ -605,7 +608,10 @@ sched(void) ...@@ -605,7 +608,10 @@ sched(void)
panic("sched interruptible"); panic("sched interruptible");
intena = cpu->intena; intena = cpu->intena;
proc->curcycles += rdtsc() - proc->tsc; proc->curcycles += rdtsc() - proc->tsc;
mtrace_fcall_register(proc->pid, 0, proc->pid, 0, mtrace_pause); if (proc->state == ZOMBIE)
mtrace_kstack_register(NULL, mtrace_done, 0);
else
mtrace_kstack_register(NULL, mtrace_pause, 0);
mtrace_call_set(0, cpu->id); mtrace_call_set(0, cpu->id);
swtch(&proc->context, cpu->scheduler); swtch(&proc->context, cpu->scheduler);
...@@ -633,8 +639,11 @@ forkret(void) ...@@ -633,8 +639,11 @@ forkret(void)
// just for the first process. can't do it earlier // just for the first process. can't do it earlier
// b/c file system code needs a process context // b/c file system code needs a process context
// in which to call cv_sleep(). // in which to call cv_sleep().
if(proc->cwd == 0) if(proc->cwd == 0) {
mtrace_kstack_register(forkret, mtrace_start, 0);
proc->cwd = namei("/"); proc->cwd = namei("/");
mtrace_kstack_register(NULL, mtrace_done, 0);
}
// Return to "caller", actually trapret (see allocproc). // Return to "caller", actually trapret (see allocproc).
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "condvar.h" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.h"
#include "xv6-kmtrace.h"
struct rcu { struct rcu {
unsigned long epoch; unsigned long epoch;
...@@ -115,6 +116,8 @@ rcu_gc_worker(void) ...@@ -115,6 +116,8 @@ rcu_gc_worker(void)
{ {
release(&proc->lock); // initially held by scheduler release(&proc->lock); // initially held by scheduler
mtrace_kstack_register(rcu_gc_worker, mtrace_start, 0);
struct spinlock wl; struct spinlock wl;
initlock(&wl, "rcu_gc_worker"); // dummy lock initlock(&wl, "rcu_gc_worker"); // dummy lock
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "proc.h" #include "proc.h"
#include "x86.h" #include "x86.h"
#include "syscall.h" #include "syscall.h"
#include "xv6-mtrace.h" #include "xv6-kmtrace.h"
// User code makes a system call with INT T_SYSCALL. // User code makes a system call with INT T_SYSCALL.
// System call number in %eax. // System call number in %eax.
...@@ -145,12 +145,10 @@ syscall(void) ...@@ -145,12 +145,10 @@ syscall(void)
num = proc->tf->eax; num = proc->tf->eax;
if(num >= 0 && num < NELEM(syscalls) && syscalls[num]) { if(num >= 0 && num < NELEM(syscalls) && syscalls[num]) {
mtrace_fcall_register(proc->pid, (unsigned long)syscalls[num], mtrace_kstack_register(syscalls[num], mtrace_start, 0);
proc->pid, 0,mtrace_start);
mtrace_call_set(1, cpunum()); mtrace_call_set(1, cpunum());
proc->tf->eax = syscalls[num](); proc->tf->eax = syscalls[num]();
mtrace_fcall_register(proc->pid, (unsigned long)syscalls[num], mtrace_kstack_register(NULL, mtrace_done, 0);
proc->pid, 0, mtrace_done);
mtrace_call_set(0, cpunum()); mtrace_call_set(0, cpunum());
} else { } else {
cprintf("%d %s: unknown sys call %d\n", cprintf("%d %s: unknown sys call %d\n",
......
#include "xv6-mtrace.h"
static inline void mtrace_kstack_register(void *eip,
mtrace_call_state_t state,
int pid)
{
if (pid == 0)
pid = proc->pid;
mtrace_fcall_register(pid, (unsigned long)eip, pid, 0, state);
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论