From patchwork Thu Apr 5 10:59:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 151165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 70E68B7086 for ; Fri, 6 Apr 2012 21:09:57 +1000 (EST) Received: from localhost ([::1]:45431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkUb-0003fM-Ud for incoming@patchwork.ozlabs.org; Thu, 05 Apr 2012 07:04:41 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkR2-0007kN-Cg for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:03:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFkPR-00075W-Qd for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:00:59 -0400 Received: from david.siemens.de ([192.35.17.14]:29892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkPR-000746-Gs for qemu-devel@nongnu.org; Thu, 05 Apr 2012 06:59:21 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by david.siemens.de (8.13.6/8.13.6) with ESMTP id q35AxIS8000363; Thu, 5 Apr 2012 12:59:18 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id q35AxIcF027596; Thu, 5 Apr 2012 12:59:18 +0200 From: Jan Kiszka To: Anthony Liguori , qemu-devel@nongnu.org Date: Thu, 5 Apr 2012 12:59:16 +0200 Message-Id: X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.14 Cc: Kevin Wolf , Paolo Bonzini , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v3 09/10] virtio: Switch to QemuEvent X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Replace EventNotifier with the new generic QemuEvent service. CC: Michael S. Tsirkin Signed-off-by: Jan Kiszka --- hw/vhost.c | 4 +- hw/virtio-pci.c | 61 ++++++++++++++++++++++-------------------------------- hw/virtio.c | 12 +++++----- hw/virtio.h | 6 ++-- 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/hw/vhost.c b/hw/vhost.c index 8d3ba5b..c7bd8b7 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -673,14 +673,14 @@ static int vhost_virtqueue_init(struct vhost_dev *dev, r = -errno; goto fail_alloc; } - file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); + file.fd = qemu_event_get_signal_fd(virtio_queue_get_host_event(vvq)); r = ioctl(dev->control, VHOST_SET_VRING_KICK, &file); if (r) { r = -errno; goto fail_kick; } - file.fd = event_notifier_get_fd(virtio_queue_get_guest_notifier(vvq)); + file.fd = qemu_event_get_signal_fd(virtio_queue_get_guest_event(vvq)); r = ioctl(dev->control, VHOST_SET_VRING_CALL, &file); if (r) { r = -errno; diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index a0fb7c1..9b9e69a 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -162,53 +162,47 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy, int n, bool assign) { VirtQueue *vq = virtio_get_queue(proxy->vdev, n); - EventNotifier *notifier = virtio_queue_get_host_notifier(vq); + QemuEvent *event = virtio_queue_get_host_event(vq); int r = 0; if (assign) { - r = event_notifier_init(notifier, 1); - if (r < 0) { - error_report("%s: unable to init event notifier: %d", - __func__, r); - return r; - } + qemu_event_init(event, true); memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2, - true, n, event_notifier_get_fd(notifier)); + true, n, qemu_event_get_signal_fd(event)); } else { memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2, - true, n, event_notifier_get_fd(notifier)); + true, n, qemu_event_get_signal_fd(event)); /* Handle the race condition where the guest kicked and we deassigned * before we got around to handling the kick. */ - if (event_notifier_test_and_clear(notifier)) { + if (qemu_event_consume(event)) { virtio_queue_notify_vq(vq); } - event_notifier_cleanup(notifier); + qemu_event_destroy(event); } return r; } -static void virtio_pci_host_notifier_read(void *opaque) +static void virtio_pci_host_event(void *opaque) { VirtQueue *vq = opaque; - EventNotifier *n = virtio_queue_get_host_notifier(vq); - if (event_notifier_test_and_clear(n)) { - virtio_queue_notify_vq(vq); - } + QemuEvent *event = virtio_queue_get_host_event(vq); + + qemu_event_consume(event); + virtio_queue_notify_vq(vq); } static void virtio_pci_set_host_notifier_fd_handler(VirtIOPCIProxy *proxy, int n, bool assign) { VirtQueue *vq = virtio_get_queue(proxy->vdev, n); - EventNotifier *notifier = virtio_queue_get_host_notifier(vq); + QemuEvent *event = virtio_queue_get_host_event(vq); + if (assign) { - qemu_set_fd_handler(event_notifier_get_fd(notifier), - virtio_pci_host_notifier_read, NULL, vq); + qemu_event_set_handler(event, virtio_pci_host_event, vq); } else { - qemu_set_fd_handler(event_notifier_get_fd(notifier), - NULL, NULL, NULL); + qemu_event_set_handler(event, NULL, NULL); } } @@ -530,32 +524,27 @@ static unsigned virtio_pci_get_features(void *opaque) return proxy->host_features; } -static void virtio_pci_guest_notifier_read(void *opaque) +static void virtio_pci_guest_event(void *opaque) { VirtQueue *vq = opaque; - EventNotifier *n = virtio_queue_get_guest_notifier(vq); - if (event_notifier_test_and_clear(n)) { - virtio_irq(vq); - } + QemuEvent *event = virtio_queue_get_guest_event(vq); + + qemu_event_consume(event); + virtio_irq(vq); } static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign) { VirtIOPCIProxy *proxy = opaque; VirtQueue *vq = virtio_get_queue(proxy->vdev, n); - EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); + QemuEvent *event = virtio_queue_get_guest_event(vq); if (assign) { - int r = event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - qemu_set_fd_handler(event_notifier_get_fd(notifier), - virtio_pci_guest_notifier_read, NULL, vq); + qemu_event_init(event, false); + qemu_event_set_handler(event, virtio_pci_guest_event, vq); } else { - qemu_set_fd_handler(event_notifier_get_fd(notifier), - NULL, NULL, NULL); - event_notifier_cleanup(notifier); + qemu_event_set_handler(event, NULL, NULL); + qemu_event_destroy(event); } return 0; diff --git a/hw/virtio.c b/hw/virtio.c index 064aecf..7f43663 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -76,9 +76,9 @@ struct VirtQueue uint16_t vector; void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq); + QemuEvent guest_event; + QemuEvent host_event; VirtIODevice *vdev; - EventNotifier guest_notifier; - EventNotifier host_notifier; }; /* virt queue functions */ @@ -966,11 +966,11 @@ VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n) return vdev->vq + n; } -EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) +QemuEvent *virtio_queue_get_guest_event(VirtQueue *vq) { - return &vq->guest_notifier; + return &vq->guest_event; } -EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq) +QemuEvent *virtio_queue_get_host_event(VirtQueue *vq) { - return &vq->host_notifier; + return &vq->host_event; } diff --git a/hw/virtio.h b/hw/virtio.h index 400c092..199b0d8 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -19,7 +19,7 @@ #include "qdev.h" #include "sysemu.h" #include "block.h" -#include "event_notifier.h" +#include "qemu-thread.h" #ifdef CONFIG_LINUX #include "9p.h" #endif @@ -229,8 +229,8 @@ target_phys_addr_t virtio_queue_get_ring_size(VirtIODevice *vdev, int n); uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n); -EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq); -EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); +QemuEvent *virtio_queue_get_guest_event(VirtQueue *vq); +QemuEvent *virtio_queue_get_host_event(VirtQueue *vq); void virtio_queue_notify_vq(VirtQueue *vq); void virtio_irq(VirtQueue *vq); #endif