From patchwork Fri May 27 10:37:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 823452 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 p4RAbbH1030404 for ; Fri, 27 May 2011 10:37:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758826Ab1E0Khf (ORCPT ); Fri, 27 May 2011 06:37:35 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:47954 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753732Ab1E0Khd (ORCPT ); Fri, 27 May 2011 06:37:33 -0400 Received: by mail-wy0-f174.google.com with SMTP id 21so1139656wya.19 for ; Fri, 27 May 2011 03:37:32 -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=RAkZ7JpmvCkaNtzRuZ3fV6+tmmc01AX9wonCdKQ6X+o=; b=UygdQ49Hp4Dg33a/Lv5AHvkcublf5r85vOJRu0NJHX9lnNBw+Nk18kp0wsWoOuRLDO 35GTJRYQcXtCjpGK75tzjyLZ+qSW26h6M9ZzuyWJKvGGX7S308jK1jBbuPxi6sBiHcb1 hdE45hv0dqzU8EeXP0hJBIhwQsup9EJGqWlbc= 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=W3jXXArRfyerHl1Cw4oXhKNZuoCojICpEQbpCyVnGcx97aDop3NgH9RCCJMOEMVySC Tz1XS3I8PiIRKDrmhNDCr/8ivse40jNNIMfgOfnMI5nZ6xR+1YQEs2XppIYGa8pS5ZG5 z7wVM38dsBraHFkzLz6rXGZLuG9c78AeftnSo= Received: by 10.227.178.135 with SMTP id bm7mr1886382wbb.52.1306492652508; Fri, 27 May 2011 03:37:32 -0700 (PDT) Received: from localhost.localdomain ([109.66.201.145]) by mx.google.com with ESMTPS id gb6sm1084635wbb.51.2011.05.27.03.37.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 May 2011 03:37:32 -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 3/4] kvm tools: Use ioeventfd in virtio-net Date: Fri, 27 May 2011 13:37:00 +0300 Message-Id: <1306492621-10208-3-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1306492621-10208-1-git-send-email-levinsasha928@gmail.com> References: <1306492621-10208-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 10:37:37 +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..0e47be5 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) { + .start = net_base_addr + VIRTIO_PCI_QUEUE_NOTIFY, + .len = sizeof(u16), + .ioevent_callback_fn = ioevent_callback, + .datamatch = i, + .ptr = (void *)i, + .kvm = params->kvm, + .event_fd = eventfd(0, 0), + }; + + ioeventfd__add_event(params->kvm, &ioevent); + } } }