qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org, avi@redhat.com
Cc: chrisw@redhat.com, mst@redhat.com, qemu-devel@nongnu.org,
	alex.williamson@redhat.com, ddutile@redhat.com
Subject: [Qemu-devel] [RFC PATCH] kvm: KVM_EOI_EVENTFD support for eoi_client
Date: Fri, 29 Oct 2010 12:05:52 -0600	[thread overview]
Message-ID: <20101029180511.26801.99926.stgit@s20.home> (raw)
In-Reply-To: <20101029175434.25281.70647.stgit@s20.home>

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@redhat.com>
---

 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);
 }
 

  reply	other threads:[~2010-10-29 18:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-29 17:56 [Qemu-devel] [PATCH] APIC/IOAPIC EOI callback Alex Williamson
2010-10-29 18:05 ` Alex Williamson [this message]
2010-10-29 19:19 ` [Qemu-devel] " Anthony Liguori
2010-11-01  3:54   ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101029180511.26801.99926.stgit@s20.home \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=chrisw@redhat.com \
    --cc=ddutile@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).