[RFC PATCH] kvm: KVM_EOI_EVENTFD support for eoi_client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



With the KVM irqchip, we need to get the EOI via an eventfd.  This
adds support for that, abstracting the details to the caller.

The get_fd function allows drivers to make further optimizations
in handling the EOI.  For instance with VFIO, we can make use of
an irqfd-like mechanism to have the VFIO kernel module consume
the EOI directly, bypassing qemu userspace.

Signed-off-by: Alex Williamson <alex.williamson@xxxxxxxxxx>
---

 hw/ioapic.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/hw/ioapic.c b/hw/ioapic.c
index c43be3a..707f2a2 100644
--- a/hw/ioapic.c
+++ b/hw/ioapic.c
@@ -72,14 +72,66 @@ static QLIST_HEAD(ioapic_eoi_client_list,
                   ioapic_eoi_client) ioapic_eoi_client_list =
                   QLIST_HEAD_INITIALIZER(ioapic_eoi_client_list);
 
+#ifdef KVM_EOI_EVENTFD
+static void ioapic_eoi_callback(void *opaque)
+{
+    ioapic_eoi_client *client = opaque;
+
+    if (!event_notifier_test_and_clear(&client->notifier)) {
+        return;
+    }
+
+    client->eoi(client);
+}
+#endif
+
 int ioapic_register_eoi_client(ioapic_eoi_client *client)
 {
     QLIST_INSERT_HEAD(&ioapic_eoi_client_list, client, list);
+
+#ifdef KVM_EOI_EVENTFD
+    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
+        int ret, fd;
+
+        ret = event_notifier_init(&client->notifier, 0);
+        if (ret) {
+            fprintf(stderr, "%s notifier init failed %d\n", __FUNCTION__, ret);
+            return ret;
+        }
+
+        fd = event_notifier_get_fd(&client->notifier);
+        qemu_set_fd_handler(fd, ioapic_eoi_callback, NULL, client);
+
+        ret = kvm_eoi_eventfd(client->irq, fd, KVM_EOI_EVENTFD_FLAG_DEASSERT);
+        if (ret) {
+            fprintf(stderr, "%s eoi eventfd failed %d\n", __FUNCTION__, ret);
+            return ret;
+        }
+        client->notifier_enabled = true;
+    }
+#endif
     return 0;
 }
 
 void ioapic_unregister_eoi_client(ioapic_eoi_client *client)
 {
+#ifdef KVM_EOI_EVENTFD
+    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
+        int ret, fd;
+
+        fd = event_notifier_get_fd(&client->notifier);
+
+        ret = kvm_eoi_eventfd(client->irq, fd, KVM_EOI_EVENTFD_FLAG_DEASSIGN);
+        if (ret) {
+            fprintf(stderr, "%s eoi eventfd failed %d\n", __FUNCTION__, ret);
+        }
+
+        qemu_set_fd_handler(fd, NULL, NULL, NULL);
+
+        event_notifier_cleanup(&client->notifier);
+        client->notifier_enabled = false;
+    }
+#endif
     QLIST_REMOVE(client, list);
 }
 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux