summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/trap.c20
-rw-r--r--kernel/virtio_disk.c16
2 files changed, 22 insertions, 14 deletions
diff --git a/kernel/trap.c b/kernel/trap.c
index eb7f6cf..ea5799f 100644
--- a/kernel/trap.c
+++ b/kernel/trap.c
@@ -158,6 +158,15 @@ kerneltrap()
w_sstatus(sstatus);
}
+void
+clockintr()
+{
+ acquire(&tickslock);
+ ticks++;
+ wakeup(&ticks);
+ release(&tickslock);
+}
+
// check if it's an external interrupt or software interrupt,
// and handle it.
// returns 2 if timer interrupt,
@@ -182,16 +191,15 @@ devintr()
plic_complete(irq);
return 1;
} else if(scause == 0x8000000000000001){
- // software interrupt from a machine-mode timer interrupt.
+ // software interrupt from a machine-mode timer interrupt,
+ // forwarded by machinevec in kernelvec.S.
if(cpuid() == 0){
- acquire(&tickslock);
- ticks++;
- wakeup(&ticks);
- release(&tickslock);
+ clockintr();
}
- // acknowledge.
+ // acknowledge the software interrupt by clearing
+ // the SSIP bit in sip.
w_sip(r_sip() & ~2);
return 2;
diff --git a/kernel/virtio_disk.c b/kernel/virtio_disk.c
index 8637b56..1a29ce7 100644
--- a/kernel/virtio_disk.c
+++ b/kernel/virtio_disk.c
@@ -20,7 +20,7 @@
// the address of virtio mmio register r.
#define R(r) ((volatile uint32 *)(VIRTIO0 + (r)))
-struct spinlock virtio_disk_lock;
+struct spinlock vdisk_lock;
// memory for virtio descriptors &c for queue 0.
// this is a global instead of allocated because it has
@@ -49,7 +49,7 @@ virtio_disk_init(void)
{
uint32 status = 0;
- initlock(&virtio_disk_lock, "virtio_disk");
+ initlock(&vdisk_lock, "virtio_disk");
if(*R(VIRTIO_MMIO_MAGIC_VALUE) != 0x74726976 ||
*R(VIRTIO_MMIO_VERSION) != 1 ||
@@ -168,7 +168,7 @@ virtio_disk_rw(struct buf *b)
{
uint64 sector = b->blockno * (BSIZE / 512);
- acquire(&virtio_disk_lock);
+ acquire(&vdisk_lock);
// the spec says that legacy block operations use three
// descriptors: one for type/reserved/sector, one for
@@ -180,7 +180,7 @@ virtio_disk_rw(struct buf *b)
if(alloc3_desc(idx) == 0) {
break;
}
- sleep(&free[0], &virtio_disk_lock);
+ sleep(&free[0], &vdisk_lock);
}
// format the three descriptors.
@@ -234,16 +234,16 @@ virtio_disk_rw(struct buf *b)
// Wait for virtio_disk_intr() to say request has finished.
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID){
- sleep(b, &virtio_disk_lock);
+ sleep(b, &vdisk_lock);
}
- release(&virtio_disk_lock);
+ release(&vdisk_lock);
}
void
virtio_disk_intr()
{
- acquire(&virtio_disk_lock);
+ acquire(&vdisk_lock);
while((used_idx % NUM) != (used->id % NUM)){
int id = used->elems[used_idx].id;
@@ -262,5 +262,5 @@ virtio_disk_intr()
used_idx = (used_idx + 1) % NUM;
}
- release(&virtio_disk_lock);
+ release(&vdisk_lock);
}