1. Assignment: In this assignment we will explore some of the interaction between
interrupts and locking.
Make sure you understand what would happen if the kernel executed the following code
snippet:
struct spinlock lk;
initlock(&lk, "test lock");
acquire(&lk);
acquire(&lk);
a. If sti() in spin_lock() and try to acquire spin lock twice, the result is the same even without sti().
cpu0: starting xv6
mem = 1048576
unexpected trap 6 from cpu 0 eip 3
panic (0): trap
104170(cpu) 103FE2(alltraps) 0 0 0 0 0 0 0 0
Why? I think should happen in acquire, cause it's already holding the lock...
b. if just sti() in spin_lock().
cpu0: starting xv6
mem = 1048576
panic (0): acquire
102CA4(ide_intr) 100C32(lapic_eoi) 1041F5(alltraps) 103FB2(ide_start_request) 100D4A(ide_rw) 104E16(bread) 1051E8(iget) 101788(process0) 0 0
c. Try to acquire spin lock twice on jos(not xv6) to make a dead lock
Test code:
55 struct spinlock lk;
56 spin_initlock(&lk);
57 spin_lock(&lk);
58 spin_lock(&lk);
Result:
SMP: CPU 0 found 1 CPU(s)
EAX=00000010 EBX=00010094 ECX=000003d4 EDX=ef800000
ESI=f0104c05 EDI=00000000 EBP=f0104bf8 ESP=efff8000
EIP=f0104b44 EFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0023 00000000 ffffffff 00cff300 DPL=3 DS [-WA]
GS =0023 00000000 ffffffff 00cff300 DPL=3 DS [-WA]
LDT=0000 00000000 00000000 00008200 DPL=0 LDT
TR =0028 f025ea80 00000068 00408900 DPL=0 TSS32-avl
GDT= f0121300 00000067
IDT= f025e260 000007ff
CR0=80050033 CR2=efff7ffc CR3=002a1000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
EFER=0000000000000000
Triple fault. Halting for inspection via QEMU monitor.
2. Turn in: explain in a few sentences why the kernel didn't panic. What is different about
kalloc_lock as compared to ide_lock?
A: Because the kalloc_lock don't need to response to interrupt, but ide_lock did.