Add mtrace hooks to spinlock and kalloc.

上级 f70ef994
...@@ -49,6 +49,12 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d ...@@ -49,6 +49,12 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d
echo "***" 1>&2; exit 1; fi) echo "***" 1>&2; exit 1; fi)
endif endif
QEMUSRC ?=
ifeq ($(QEMUSRC),)
$(error You need to set QEMUSRC (e.g. make QEMUSRC=~/qemu))
endif
# If the makefile can't find QEMU, specify its path here # If the makefile can't find QEMU, specify its path here
#QEMU = #QEMU =
...@@ -71,7 +77,7 @@ AS = $(TOOLPREFIX)gas ...@@ -71,7 +77,7 @@ AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -I$(QEMUSRC)
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m32 -gdwarf-2 ASFLAGS = -m32 -gdwarf-2
# FreeBSD ld wants ``elf_i386_fbsd'' # FreeBSD ld wants ``elf_i386_fbsd''
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "param.h" #include "param.h"
#include "mmu.h" #include "mmu.h"
#include "spinlock.h" #include "spinlock.h"
#include "xv6-mtrace.h"
struct run { struct run {
struct run *next; struct run *next;
...@@ -51,6 +52,14 @@ kfree(char *v) ...@@ -51,6 +52,14 @@ kfree(char *v)
r = (struct run*)v; r = (struct run*)v;
r->next = kmem.freelist; r->next = kmem.freelist;
kmem.freelist = r; kmem.freelist = r;
mtrace_label_register(mtrace_label_block,
r,
0,
0,
0,
RET_EIP());
release(&kmem.lock); release(&kmem.lock);
} }
...@@ -66,6 +75,14 @@ kalloc(void) ...@@ -66,6 +75,14 @@ kalloc(void)
r = kmem.freelist; r = kmem.freelist;
if(r) if(r)
kmem.freelist = r->next; kmem.freelist = r->next;
mtrace_label_register(mtrace_label_block,
r,
4096,
"kalloc",
sizeof("kalloc"),
RET_EIP());
release(&kmem.lock); release(&kmem.lock);
return (char*)r; return (char*)r;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "mmu.h" #include "mmu.h"
#include "proc.h" #include "proc.h"
#include "spinlock.h" #include "spinlock.h"
#include "xv6-mtrace.h"
void void
initlock(struct spinlock *lk, char *name) initlock(struct spinlock *lk, char *name)
...@@ -27,12 +28,24 @@ acquire(struct spinlock *lk) ...@@ -27,12 +28,24 @@ acquire(struct spinlock *lk)
if(holding(lk)) if(holding(lk))
panic("acquire"); panic("acquire");
mtrace_lock_register(RET_EIP(),
lk,
lk->name,
mtrace_lockop_acquire,
0);
// The xchg is atomic. // The xchg is atomic.
// It also serializes, so that reads after acquire are not // It also serializes, so that reads after acquire are not
// reordered before it. // reordered before it.
while(xchg(&lk->locked, 1) != 0) while(xchg(&lk->locked, 1) != 0)
; ;
mtrace_lock_register(RET_EIP(),
lk,
lk->name,
mtrace_lockop_acquired,
0);
// Record info about lock acquisition for debugging. // Record info about lock acquisition for debugging.
lk->cpu = cpu; lk->cpu = cpu;
getcallerpcs(&lk, lk->pcs); getcallerpcs(&lk, lk->pcs);
...@@ -45,6 +58,12 @@ release(struct spinlock *lk) ...@@ -45,6 +58,12 @@ release(struct spinlock *lk)
if(!holding(lk)) if(!holding(lk))
panic("release"); panic("release");
mtrace_lock_register(RET_EIP(),
lk,
lk->name,
mtrace_lockop_release,
0);
lk->pcs[0] = 0; lk->pcs[0] = 0;
lk->cpu = 0; lk->cpu = 0;
......
#include <stdint.h>
void* memcpy(void *dst, const void *src, uint n);
#define RET_EIP() ((unsigned long)__builtin_return_address(0))
#include "mtrace-magic.h"
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论