[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 37/55] virtio: Introduce virtio_add_queue_aio
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL v2 37/55] virtio: Introduce virtio_add_queue_aio |
Date: |
Tue, 19 Jul 2016 20:54:10 +0300 |
From: Fam Zheng <address@hidden>
Using this function instead of virtio_add_queue marks the vq as aio
based. This differentiation will be useful in later patches.
Distinguish between virtqueue processing in the iohandler context and main loop
AioContext. iohandler context is isolated from AioContexts and therefore does
not run during aio_poll().
Signed-off-by: Fam Zheng <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Cornelia Huck <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Acked-by: Paolo Bonzini <address@hidden>
---
include/hw/virtio/virtio.h | 3 +++
hw/virtio/virtio.c | 38 ++++++++++++++++++++++++++++++++++----
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 3670829..7a82f79 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -143,6 +143,9 @@ typedef void (*VirtIOHandleOutput)(VirtIODevice *,
VirtQueue *);
VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
VirtIOHandleOutput handle_output);
+VirtQueue *virtio_add_queue_aio(VirtIODevice *vdev, int queue_size,
+ VirtIOHandleOutput handle_output);
+
void virtio_del_queue(VirtIODevice *vdev, int n);
void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 2cc68d24..2fbed0c 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -97,6 +97,7 @@ struct VirtQueue
uint16_t vector;
VirtIOHandleOutput handle_output;
VirtIOHandleOutput handle_aio_output;
+ bool use_aio;
VirtIODevice *vdev;
EventNotifier guest_notifier;
EventNotifier host_notifier;
@@ -1130,8 +1131,9 @@ void virtio_queue_set_vector(VirtIODevice *vdev, int n,
uint16_t vector)
}
}
-VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
- VirtIOHandleOutput handle_output)
+static VirtQueue *virtio_add_queue_internal(VirtIODevice *vdev, int queue_size,
+ VirtIOHandleOutput handle_output,
+ bool use_aio)
{
int i;
@@ -1148,10 +1150,28 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int
queue_size,
vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN;
vdev->vq[i].handle_output = handle_output;
vdev->vq[i].handle_aio_output = NULL;
+ vdev->vq[i].use_aio = use_aio;
return &vdev->vq[i];
}
+/* Add a virt queue and mark AIO.
+ * An AIO queue will use the AioContext based event interface instead of the
+ * default IOHandler and EventNotifier interface.
+ */
+VirtQueue *virtio_add_queue_aio(VirtIODevice *vdev, int queue_size,
+ VirtIOHandleOutput handle_output)
+{
+ return virtio_add_queue_internal(vdev, queue_size, handle_output, true);
+}
+
+/* Add a normal virt queue (on the contrary to the AIO version above. */
+VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
+ VirtIOHandleOutput handle_output)
+{
+ return virtio_add_queue_internal(vdev, queue_size, handle_output, false);
+}
+
void virtio_del_queue(VirtIODevice *vdev, int n)
{
if (n < 0 || n >= VIRTIO_QUEUE_MAX) {
@@ -1830,11 +1850,21 @@ static void
virtio_queue_host_notifier_read(EventNotifier *n)
void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
bool set_handler)
{
+ AioContext *ctx = qemu_get_aio_context();
if (assign && set_handler) {
- event_notifier_set_handler(&vq->host_notifier, true,
+ if (vq->use_aio) {
+ aio_set_event_notifier(ctx, &vq->host_notifier, true,
virtio_queue_host_notifier_read);
+ } else {
+ event_notifier_set_handler(&vq->host_notifier, true,
+ virtio_queue_host_notifier_read);
+ }
} else {
- event_notifier_set_handler(&vq->host_notifier, true, NULL);
+ if (vq->use_aio) {
+ aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL);
+ } else {
+ event_notifier_set_handler(&vq->host_notifier, true, NULL);
+ }
}
if (!assign) {
/* Test and clear notifier before after disabling event,
--
MST
- [Qemu-devel] [PULL v2 27/55] intel_iommu: Add support for Extended Interrupt Mode, (continued)
- [Qemu-devel] [PULL v2 27/55] intel_iommu: Add support for Extended Interrupt Mode, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 28/55] intel_iommu: add SID validation for IR, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 29/55] kvm-irqchip: simplify kvm_irqchip_add_msi_route, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 30/55] kvm-irqchip: i386: add hook for add/remove virq, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 31/55] kvm-irqchip: x86: add msi route notify fn, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 32/55] kvm-irqchip: do explicit commit when update irq, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 33/55] intel_iommu: support all masks in interrupt entry cache invalidation, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 34/55] kvm-all: add trace events for kvm irqchip ops, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 35/55] intel_iommu: disallow kernel-irqchip=on with IR, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 36/55] virtio: Add typedef for handle_output, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 37/55] virtio: Introduce virtio_add_queue_aio,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL v2 38/55] virtio-blk: Call virtio_add_queue_aio, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 39/55] virtio-scsi: Call virtio_add_queue_aio, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 40/55] Revert "mirror: Workaround for unexpected iohandler events during completion", Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 41/55] virtio-scsi: Replace HandleOutput typedef, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 42/55] virtio-net: Remove old migration version support, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 43/55] virtio-serial: Remove old migration version support, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 44/55] virtio: Migration helper function and macro, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 45/55] virtio-scsi: Wrap in vmstate, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 47/55] virtio-rng: Wrap in vmstate, Michael S. Tsirkin, 2016/07/19
- [Qemu-devel] [PULL v2 46/55] virtio-blk: Wrap in vmstate, Michael S. Tsirkin, 2016/07/19