From 65bd8e139a8368e987455a10ec59dd7b079b3af1 Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 16 Jul 2006 01:15:28 +0000 Subject: New scheduler. Removed cli and sti stack in favor of tracking number of locks held on each CPU and explicit conditionals in spinlock.c. --- spinlock.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'spinlock.c') diff --git a/spinlock.c b/spinlock.c index 4c11064..aa11ad5 100644 --- a/spinlock.c +++ b/spinlock.c @@ -6,53 +6,47 @@ #include "proc.h" #include "spinlock.h" -#define DEBUG 0 +// Can't call cprintf from inside these routines, +// because cprintf uses them itself. +#define cprintf dont_use_cprintf extern int use_console_lock; -int getcallerpc(void *v) { - return ((int*)v)[-1]; +int +getcallerpc(void *v) +{ + return ((int*)v)[-1]; } void acquire1(struct spinlock * lock, struct proc *cp) { - if(DEBUG) cprintf("cpu%d: acquiring at %x\n", cpu(), getcallerpc(&lock)); - - cli(); - while ( cmpxchg(0, 1, &lock->locked) == 1 ) { ; } - lock->locker_pc = getcallerpc(&lock); - - if(cp) - cp->locks += 1; - - if(DEBUG) cprintf("cpu%d: acquired at %x\n", cpu(), getcallerpc(&lock)); + if(cpus[cpu()].nlock++ == 0) + cli(); + while(cmpxchg(0, 1, &lock->locked) == 1) + ; + cpuid(0, 0, 0, 0, 0); // memory barrier + lock->locker_pc = getcallerpc(&lock); } void release1(struct spinlock * lock, struct proc *cp) { - - if(DEBUG) cprintf ("cpu%d: releasing at %x\n", cpu(), getcallerpc(&lock)); - - if(lock->locked != 1) - panic("release"); - - if(cp) - cp->locks -= 1; - - cmpxchg(1, 0, &lock->locked); - sti(); + cpuid(0, 0, 0, 0, 0); // memory barrier + lock->locked = 0; + if(--cpus[cpu()].nlock == 0) + sti(); } void acquire(struct spinlock *lock) { - acquire1(lock, curproc[cpu()]); + acquire1(lock, curproc[cpu()]); } void release(struct spinlock *lock) { - release1(lock, curproc[cpu()]); + release1(lock, curproc[cpu()]); } + -- cgit v1.2.3