From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LDMc6-0006mm-Q4 for qemu-devel@nongnu.org; Thu, 18 Dec 2008 12:24:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LDMc5-0006k0-E9 for qemu-devel@nongnu.org; Thu, 18 Dec 2008 12:24:41 -0500 Received: from [199.232.76.173] (port=51155 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LDMc5-0006jm-4x for qemu-devel@nongnu.org; Thu, 18 Dec 2008 12:24:41 -0500 Received: from mail14.svc.cra.dublin.eircom.net ([159.134.118.30]:42094) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LDMc4-0003Is-NZ for qemu-devel@nongnu.org; Thu, 18 Dec 2008 12:24:40 -0500 From: Mark McLoughlin Date: Thu, 18 Dec 2008 17:24:38 +0000 Message-Id: <1229621078-25563-3-git-send-email-markmc@redhat.com> In-Reply-To: <1229621078-25563-2-git-send-email-markmc@redhat.com> References: <1229621078-25563-1-git-send-email-markmc@redhat.com> <1229621078-25563-2-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] virtio: add support for indirect ring entries Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mark McLoughlin Support a new feature flag for indirect ring entries. These are ring entries which point to a table of buffer descriptors. The idea here is to increase the ring capacity by allowing a larger effective ring size whereby the ring size dictates the number of requests that may be outstanding, rather than the size of those requests. This should be most effective in the case of block I/O where we can potentially benefit by concurrently dispatching a large number of large requests. Even in the simple case of single segment block requests, this results in a threefold increase in ring capacity. Signed-off-by: Mark McLoughlin --- hw/virtio.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- hw/virtio.h | 4 ++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/hw/virtio.c b/hw/virtio.c index e997a5e..1f0f3eb 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -380,18 +380,41 @@ static unsigned virtqueue_next_desc(target_phys_addr_t desc_pa, int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes) { - target_phys_addr_t desc_pa = vq->vring.desc; - unsigned int idx, max; - int num_bufs, in_total, out_total; + unsigned int idx; + int total_bufs, in_total, out_total; idx = vq->last_avail_idx; - max = vq->vring.num; - num_bufs = in_total = out_total = 0; + total_bufs = in_total = out_total = 0; while (virtqueue_num_heads(vq, idx)) { + unsigned int max, num_bufs, indirect = 0; + target_phys_addr_t desc_pa; int i; + max = vq->vring.num; + num_bufs = total_bufs; i = virtqueue_get_head(vq, idx++); + desc_pa = vq->vring.desc; + + if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) { + if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) { + fprintf(stderr, "Invalid size for indirect buffer table\n"); + exit(1); + } + + /* If we've got too many, that implies a descriptor loop. */ + if (num_bufs >= max) { + fprintf(stderr, "Looped descriptor"); + exit(1); + } + + /* loop over the indirect descriptor table */ + indirect = 1; + max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); + num_bufs = i = 0; + desc_pa = vring_desc_addr(desc_pa, i); + } + do { /* If we've got too many, that implies a descriptor loop. */ if (++num_bufs > max) { @@ -409,6 +432,11 @@ int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes) return 1; } } while ((i = virtqueue_next_desc(desc_pa, i, max)) != max); + + if (!indirect) + total_bufs = num_bufs; + else + total_bufs++; } return 0; @@ -428,6 +456,19 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) max = vq->vring.num; i = head = virtqueue_get_head(vq, vq->last_avail_idx++); + + if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) { + if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) { + fprintf(stderr, "Invalid size for indirect buffer table\n"); + exit(1); + } + + /* loop over the indirect descriptor table */ + max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); + desc_pa = vring_desc_addr(desc_pa, i); + i = 0; + } + do { struct iovec *sg; @@ -563,6 +604,7 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr) case VIRTIO_PCI_HOST_FEATURES: ret = vdev->get_features(vdev); ret |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY); + ret |= (1 << VIRTIO_RING_F_INDIRECT_DESC); break; case VIRTIO_PCI_GUEST_FEATURES: ret = vdev->features; diff --git a/hw/virtio.h b/hw/virtio.h index 83511e2..52252fc 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -32,6 +32,8 @@ /* We notify when the ring is completely used, even if the guest is supressing * callbacks */ #define VIRTIO_F_NOTIFY_ON_EMPTY 24 +/* We support indirect buffer descriptors */ +#define VIRTIO_RING_F_INDIRECT_DESC 28 /* from Linux's linux/virtio_ring.h */ @@ -39,6 +41,8 @@ #define VRING_DESC_F_NEXT 1 /* This marks a buffer as write-only (otherwise read-only). */ #define VRING_DESC_F_WRITE 2 +/* This means the buffer contains a list of buffer descriptors. */ +#define VRING_DESC_F_INDIRECT 4 /* This means don't notify other side when buffer added. */ #define VRING_USED_F_NO_NOTIFY 1 -- 1.6.0.5