summaryrefslogtreecommitdiff
path: root/kernel/spinlock.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2019-07-02 13:40:33 -0400
committerFrans Kaashoek <[email protected]>2019-07-02 13:40:33 -0400
commitda51735980e500922bc108a3444b64ac9450032e (patch)
tree76ad738ff42f56a36ea2300b2d90946e64d5040e /kernel/spinlock.c
parent67702cf706bce7adef472f0caa48d81ddfaeb33a (diff)
downloadxv6-labs-da51735980e500922bc108a3444b64ac9450032e.tar.gz
xv6-labs-da51735980e500922bc108a3444b64ac9450032e.tar.bz2
xv6-labs-da51735980e500922bc108a3444b64ac9450032e.zip
Avoid two cores selecting the same process to run
Diffstat (limited to 'kernel/spinlock.c')
-rw-r--r--kernel/spinlock.c11
1 files changed, 8 insertions, 3 deletions
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