From da51735980e500922bc108a3444b64ac9450032e Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 2 Jul 2019 13:40:33 -0400 Subject: Avoid two cores selecting the same process to run --- kernel/spinlock.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'kernel/spinlock.c') diff --git a/kernel/spinlock.c b/kernel/spinlock.c index c238091..1d0b16a 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c @@ -20,7 +20,7 @@ initlock(struct spinlock *lk, char *name) // Loops (spins) until the lock is acquired. // Holding a lock for a long time may cause // other CPUs to waste time spinning to acquire it. -void //__attribute__ ((noinline)) +void acquire(struct spinlock *lk) { push_off(); // disable interrupts to avoid deadlock. @@ -44,14 +44,19 @@ acquire(struct spinlock *lk) } // Release the lock. -void //__attribute__ ((noinline)) +void release(struct spinlock *lk) { + uint64 x; + asm volatile("mv %0, ra" : "=r" (x) ); if(!holding(lk)) { - printf("%p: !holding %s %p\n", mycpu(), lk->name, lk->cpu); + printf("%p: !holding %d %s %p %p %p %p\n", mycpu(), lk->locked, lk->name, lk->cpu, + lk->last_release, lk->last_pc, x); panic("release"); } + lk->last_release = lk->cpu; + lk->last_pc = x; lk->cpu = 0; // Tell the C compiler and the CPU to not move loads or stores -- cgit v1.2.3