From patchwork Fri May 27 16:18:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 824822 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4RGKP63032292 for ; Fri, 27 May 2011 16:20:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755298Ab1E0QUU (ORCPT ); Fri, 27 May 2011 12:20:20 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:63870 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753931Ab1E0QUT (ORCPT ); Fri, 27 May 2011 12:20:19 -0400 Received: by wwk4 with SMTP id 4so5563799wwk.1 for ; Fri, 27 May 2011 09:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=F3M0E4EzGAMsw3qkH3PO+zJ7tBmuuZmIX53Hbjn5cqE=; b=asiPOifqXYYgK3VLJ3JDQB1aqX7dJ8aXgSv3LrschcTil0sQak54ZMfuOLOkbu1i1Y HzPPHBVkegx/hUoSmIbq/hyz0j22Yb3wjFhL84kcJJLiQGugRcsBO9uqXM1xeUTqUfCe N0bTDPJUpQtL+N/HUSLa/aucfaFLO3Z2HtdV4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=eQRsWgX6NZD1KlzC2XRoAExoMrZuIitFUU7VcsI4buf+4xc9zxbvRpwG2UqJT06Tnj ZVnwV1qR23qw8lbKjG1JKvrSl3UoGS8YIXEft/mRDHVOFzSbZXzGt2kLcJhMzSw9UlwF c3ZQe30QSTBUAe23m3IlFruEPDUWdjyVfbOWA= Received: by 10.216.229.3 with SMTP id g3mr7132439weq.91.1306513217769; Fri, 27 May 2011 09:20:17 -0700 (PDT) Received: from localhost.localdomain (bzq-79-176-208-154.red.bezeqint.net [79.176.208.154]) by mx.google.com with ESMTPS id w58sm1063873weq.1.2011.05.27.09.20.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 May 2011 09:20:17 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: john@jfloren.net, kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH v2 3/4] kvm tools: Use ioeventfd in virtio-net Date: Fri, 27 May 2011 19:18:39 +0300 Message-Id: <1306513120-28794-3-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1306513120-28794-1-git-send-email-levinsasha928@gmail.com> References: <1306513120-28794-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 27 May 2011 16:20:25 +0000 (UTC) Use ioeventfds to receive notifications of IO events in virtio-net. Doing so prevents an exit every time we receive/send a packet. Signed-off-by: Sasha Levin --- tools/kvm/virtio/net.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 3064da6..5c39c43 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -8,6 +8,7 @@ #include "kvm/kvm.h" #include "kvm/pci.h" #include "kvm/irq.h" +#include "kvm/ioeventfd.h" #include #include @@ -280,6 +281,11 @@ static bool virtio_net_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po return ret; } +static void ioevent_callback(struct kvm *kvm, void *param) +{ + virtio_net_handle_callback(kvm, (u64)param); +} + static struct ioport_operations virtio_net_io_ops = { .io_in = virtio_net_pci_io_in, .io_out = virtio_net_pci_io_out, @@ -388,6 +394,8 @@ void virtio_net__init(const struct virtio_net_parameters *params) if (virtio_net__tap_init(params)) { u8 dev, line, pin; u16 net_base_addr; + u64 i; + struct ioevent ioevent; if (irq__register_device(VIRTIO_ID_NET, &dev, &pin, &line) < 0) return; @@ -401,5 +409,19 @@ void virtio_net__init(const struct virtio_net_parameters *params) pci__register(&pci_header, dev); virtio_net__io_thread_init(params->kvm); + + for (i = 0; i < VIRTIO_NET_NUM_QUEUES; i++) { + ioevent = (struct ioevent) { + .io_addr = net_base_addr + VIRTIO_PCI_QUEUE_NOTIFY, + .io_len = sizeof(u16), + .fn = ioevent_callback, + .datamatch = i, + .fn_ptr = (void *)i, + .fn_kvm = params->kvm, + .fd = eventfd(0, 0), + }; + + ioeventfd__add_event(&ioevent); + } } }