[SeaBIOS] [PATCH] virtio page align and usleep changes

Kevin O'Connor kevin at koconnor.net
Sat May 15 19:29:39 CEST 2010


Hi Gleb,

Is it okay for irqs to trigger during the wait for a read to complete?
I would think a read could take some time for the host to complete and
allowing the guest to handle irqs would be useful.

Also, the code looks to be manually obtaining a page aligned buffer -
seabios can do this natively.  Using the aligned allocation functions
reduces the memory pressure on the permanent low memory area.

-Kevin


diff --git a/src/virtio-blk.c b/src/virtio-blk.c
index 6c3f8a5..7cc2edb 100644
--- a/src/virtio-blk.c
+++ b/src/virtio-blk.c
@@ -58,7 +58,7 @@ virtio_blk_read(struct disk_op_s *op)
 
     /* Wait for reply */
     while (!vring_more_used(vq))
-        udelay(5);
+        usleep(5);
 
     /* Reclaim virtqueue element */
     vring_get_buf(vq, NULL);
@@ -104,7 +104,7 @@ virtio_blk_setup(void)
                 pci_bdf_to_dev(bdf));
         char *desc = malloc_tmphigh(MAXDESCSIZE);
         struct virtiodrive_s *vdrive_g = malloc_fseg(sizeof(*vdrive_g));
-        struct vring_virtqueue *vq = malloc_low(sizeof(*vq));
+        struct vring_virtqueue *vq = memalign_low(PAGE_SIZE, sizeof(*vq));
         if (!vdrive_g || !desc || !vq) {
             free(vdrive_g);
             free(desc);
diff --git a/src/virtio-ring.h b/src/virtio-ring.h
index 95ae85b..3fb86fe 100644
--- a/src/virtio-ring.h
+++ b/src/virtio-ring.h
@@ -72,7 +72,7 @@ struct vring {
          + PAGE_MASK) & ~PAGE_MASK) + \
          (sizeof(struct vring_used) + sizeof(struct vring_used_elem) * num))
 
-typedef unsigned char virtio_queue_t[PAGE_MASK + vring_size(MAX_QUEUE_NUM)];
+typedef unsigned char virtio_queue_t[vring_size(MAX_QUEUE_NUM)];
 
 struct vring_virtqueue {
    virtio_queue_t queue;



More information about the SeaBIOS mailing list