From 67702cf706bce7adef472f0caa48d81ddfaeb33a Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 2 Jul 2019 09:14:47 -0400 Subject: Checkpoint switching to per-process locks, in attempt clarify xv6's locking plan, which is a difficult to understand because ptable lock protects many invariants. This implementation has a bug: once in a while xv6 unlocks a proc lock that is locked by another core. --- kernel/spinlock.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'kernel/spinlock.c') diff --git a/kernel/spinlock.c b/kernel/spinlock.c index 5a44a46..c238091 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 +void //__attribute__ ((noinline)) acquire(struct spinlock *lk) { push_off(); // disable interrupts to avoid deadlock. @@ -44,11 +44,13 @@ acquire(struct spinlock *lk) } // Release the lock. -void +void //__attribute__ ((noinline)) release(struct spinlock *lk) { - if(!holding(lk)) + if(!holding(lk)) { + printf("%p: !holding %s %p\n", mycpu(), lk->name, lk->cpu); panic("release"); + } lk->cpu = 0; -- cgit v1.2.3