Instrument syscall and schedule.

上级 1bdda0cc
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "x86.h" #include "x86.h"
#include "proc.h" #include "proc.h"
#include "spinlock.h" #include "spinlock.h"
#include "xv6-mtrace.h"
struct { struct {
struct spinlock lock; struct spinlock lock;
...@@ -257,6 +258,13 @@ void ...@@ -257,6 +258,13 @@ void
scheduler(void) scheduler(void)
{ {
struct proc *p; struct proc *p;
int pid;
acquire(&ptable.lock);
pid = nextpid++;
release(&ptable.lock);
mtrace_fcall_register(pid, (unsigned long)scheduler, 0, mtrace_start);
for(;;){ for(;;){
// Enable interrupts on this processor. // Enable interrupts on this processor.
...@@ -274,7 +282,11 @@ scheduler(void) ...@@ -274,7 +282,11 @@ scheduler(void)
proc = p; proc = p;
switchuvm(p); switchuvm(p);
p->state = RUNNING; p->state = RUNNING;
mtrace_fcall_register(pid, 0, 0, mtrace_pause);
mtrace_fcall_register(proc->pid, 0, 0, mtrace_resume);
swtch(&cpu->scheduler, proc->context); swtch(&cpu->scheduler, proc->context);
mtrace_fcall_register(pid, 0, 0, mtrace_resume);
switchkvm(); switchkvm();
// Process is done running for now. // Process is done running for now.
...@@ -302,6 +314,8 @@ sched(void) ...@@ -302,6 +314,8 @@ sched(void)
if(readeflags()&FL_IF) if(readeflags()&FL_IF)
panic("sched interruptible"); panic("sched interruptible");
intena = cpu->intena; intena = cpu->intena;
mtrace_fcall_register(proc->pid, 0, 0, mtrace_pause);
swtch(&proc->context, cpu->scheduler); swtch(&proc->context, cpu->scheduler);
cpu->intena = intena; cpu->intena = intena;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "proc.h" #include "proc.h"
#include "x86.h" #include "x86.h"
#include "syscall.h" #include "syscall.h"
#include "xv6-mtrace.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.
...@@ -128,9 +129,15 @@ syscall(void) ...@@ -128,9 +129,15 @@ syscall(void)
int num; int num;
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],
0,
mtrace_start);
proc->tf->eax = syscalls[num](); proc->tf->eax = syscalls[num]();
else { mtrace_fcall_register(proc->pid, (unsigned long)syscalls[num],
0,
mtrace_done);
} else {
cprintf("%d %s: unknown sys call %d\n", cprintf("%d %s: unknown sys call %d\n",
proc->pid, proc->name, num); proc->pid, proc->name, num);
proc->tf->eax = -1; proc->tf->eax = -1;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论