From patchwork Fri May 27 16:18:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 824812 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 p4RGKP62032292 for ; Fri, 27 May 2011 16:20:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754725Ab1E0QUR (ORCPT ); Fri, 27 May 2011 12:20:17 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:51264 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754133Ab1E0QUQ (ORCPT ); Fri, 27 May 2011 12:20:16 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so2028484wwa.1 for ; Fri, 27 May 2011 09:20:15 -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=Vs9tH1hYHlVx2GMk1WEuwlQtyBYh6Kh/Wq7PVZWZfSI=; b=hubGorpjGZR1MesrHrWgQwGnUqwF26TH/5XAA6uwNJ+A/FSVnVCDEdz6JqbONr4Vl/ 6KDPymRI7i1vzBIBGnLjqF39KK8LNx3DOeJtKFzjdSxaLwsxDRT/Sgp1ZiO3XRiohL4x vksKN4GnF4tSUbJ2zLQ57Ydxy7oxI5TfDakTQ= 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=DnSWJxDPPZarZQQhAQeEgD92JhfBmlxTd6QnmBTG55UdjXn/DaZxG3BGFBIZRe6iEA Zeigv8AIO5mwTsT3JLM+ZcifBUgr/0/escvAqzi47+F1zlkevmXBpoi3fDB/BmWoAYWT NF2f3Zc6ZFQsRpgB+J0+dpfCEEMV3jDAmPq0Q= Received: by 10.216.15.137 with SMTP id f9mr2168254wef.62.1306513214872; Fri, 27 May 2011 09:20:14 -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.13 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 May 2011 09:20:14 -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 2/4] kvm tools: Use ioeventfd in virtio-blk Date: Fri, 27 May 2011 19:18:38 +0300 Message-Id: <1306513120-28794-2-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-blk. Doing so prevents an exit every time we read/write from/to the virtio disk. Signed-off-by: Sasha Levin --- tools/kvm/virtio/blk.c | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-) diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c index a8f9d8c..8d54f5a 100644 --- a/tools/kvm/virtio/blk.c +++ b/tools/kvm/virtio/blk.c @@ -10,6 +10,7 @@ #include "kvm/kvm.h" #include "kvm/pci.h" #include "kvm/threadpool.h" +#include "kvm/ioeventfd.h" #include #include @@ -243,11 +244,19 @@ static struct ioport_operations virtio_blk_io_ops = { .io_out = virtio_blk_pci_io_out, }; +static void ioevent_callback(struct kvm *kvm, void *param) +{ + struct blk_dev_job *job = param; + + thread_pool__do_job(job->job_id); +} + void virtio_blk__init(struct kvm *kvm, struct disk_image *disk) { u16 blk_dev_base_addr; - u8 dev, pin, line; + u8 dev, pin, line, i; struct blk_dev *bdev; + struct ioevent ioevent; if (!disk) return; @@ -293,6 +302,20 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk) bdev->pci_hdr.irq_line = line; pci__register(&bdev->pci_hdr, dev); + + for (i = 0; i < NUM_VIRT_QUEUES; i++) { + ioevent = (struct ioevent) { + .io_addr = blk_dev_base_addr + VIRTIO_PCI_QUEUE_NOTIFY, + .io_len = sizeof(u16), + .fn = ioevent_callback, + .datamatch = i, + .fn_ptr = &bdev->jobs[i], + .fn_kvm = kvm, + .fd = eventfd(0, 0), + }; + + ioeventfd__add_event(&ioevent); + } } void virtio_blk__init_all(struct kvm *kvm) @@ -309,6 +332,7 @@ void virtio_blk__delete_all(struct kvm *kvm) struct blk_dev *bdev; bdev = list_first_entry(&bdevs, struct blk_dev, list); + ioeventfd__del_event(bdev->base_addr + VIRTIO_PCI_QUEUE_NOTIFY, 0); list_del(&bdev->list); free(bdev); }