How the Sstc timer and the PLIC raise interrupts, which hart takes them and when, how devintr tells them apart, and how claim, complete and stimecmp acknowledge them.
1warm-upChoose one
A supervisor timer interrupt is pending on hart 1. In this kernel, what makes it stop
being pending?
The machine has three harts, and QEMU’s time counter runs at 10,000,000 per second.
Approximately how many times per second does the kernel’s global ticks counter increase?
(Give the nearest whole number.)
A hart is running kernel code in supervisor mode. Which of these does the hardware
check before it takes a supervisor timer interrupt?
7warm-upDecode the bits
kerneltrap reads scause = 0x8000000000000009. Decode it.
Value: 0x8000000000000009
8solidDecode the bits
Under gdb, hart 0 at the first instruction of scheduler shows sie = 0x220. Decode
it.
Value: 0x220
9solidPut in order
Hart 2 is idle in its scheduler when the disk finishes a read. Put the events in order,
from the device to the moment the PLIC may forward the disk’s interrupts again.
Hart 2 executes intr_on() in its scheduler and takes the trap at stvec, which is kernelvec
plic_claim reads hart 2’s claim register and gets 1
virtio_disk_intr acknowledges the device, sets b->disk = 0 and calls wakeup
kerneltrap calls devintr, which sees scause 0x8000000000000009
plic_complete(1) writes 1 back to the claim register
The disk raises interrupt source 1; the PLIC marks it pending and signals the harts (SEIP)
10warm-upClick the line
In clockintr, click the line that acknowledges the timer interrupt, so that it stops
being pending.
Two harts trap for the same disk interrupt. Hart 2 claims it; hart 1’s claim returns 0.
In devintr, click the line that keeps hart 1 from sending a completion to the PLIC.
Hart 1 is idle in its scheduler and traps for a disk interrupt that hart 2 has already
claimed, so hart 1’s plic_claim returns 0. What happens next on hart 1?
True or false: while a hart is executing user code, a pending supervisor timer interrupt
(with sie.STIE set) is taken even if sstatus.SIE happened to be 0.
Why?
14warm-upChoose one
clockintr increments ticks only when cpuid() == 0. What is the reason?
Suppose clockintr were changed so that only hart 0 executes line 179
(w_stimecmp(...)), on the theory that only hart 0’s ticks matter. What happens to
hart 1 after its first timer interrupt?
Hart 2 was idle in its scheduler when a disk interrupt arrived. It is now in
virtio_disk_intr and has just executed line 303, acquire(&disk.vdisk_lock).
What is the state of hart 2?
Match each register with its role in taking an interrupt.
18solidChoose one
When its scan finds nothing to run, the scheduler executes wfi at line 467 with
interrupts off (line 442 turned them off). Why doesn’t the hart sleep through the
interrupt that should wake it?
The scheduler turns interrupts on at line 441 and straight back off at line 442, and then
scans the table and possibly executes wfi with interrupts off. What would go wrong if
line 442 were removed, so interrupts stayed on during the scan and wfi?
A process calls pause(5) just after a tick. Assume nothing else wakes or kills it, and
that after each wakeup some scheduler runs it again before the next tick. How many times
does sys_pause call sleep() (line 85)?
Hart 0 started a disk read and its process went to sleep. When the disk finishes, which
hart runs virtio_disk_intr?
22solidChoose one
virtio_disk_intr writes the device’s INTERRUPT_ACK register (line 311), and later
devintr calls plic_complete. What would happen if xv6 called plic_complete
without acknowledging the device?
True or false: if hart 1 has interrupts off when its timer fires, hart 0 may handle that
timer interrupt instead.
Why?
24deepChoose all that apply
Which of these always run with interrupts off (sstatus.SIE = 0) on the hart executing
them?
25deepChoose all that apply
Hypothetically, hart 0 runs for 0.35 seconds with interrupts off (say, a buggy driver
spinning). Harts 1 and 2 run normally. Which statements are true?