public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
To: carsteno-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org
Cc: Jimi Xenidis <jimix-aZOuKsOsJu3MbYB6QlFGEg@public.gmane.org>,
	Stephen Rothwell <sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>,
	Xen Mailing List
	<xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR@public.gmane.org>,
	"jmk-zzFmDc4TPjtKvsKVC3L/VUEOCMrvLtNR@public.gmane.org"
	<jmk-zzFmDc4TPjtKvsKVC3L/VUEOCMrvLtNR@public.gmane.org>,
	Herbert Xu
	<herbert-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>,
	kvm-devel
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	mschwid2-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
	virtualization
	<virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	Christian Borntraeger
	<cborntra-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>,
	Suzanne McIntosh
	<skranjac-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
	Jens Axboe <jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH RFC 3/3] virtio infrastructure: example	block driver
Date: Sat, 02 Jun 2007 19:28:02 +1000	[thread overview]
Message-ID: <1180776482.9228.22.camel@localhost.localdomain> (raw)
In-Reply-To: <465FC65C.6020905-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>

On Fri, 2007-06-01 at 09:10 +0200, Carsten Otte wrote:
> Rusty Russell wrote:
> > What's the overhead in doing both?
> With regard to compute power needed, almost none. The penalty is 
> latency, not overhead: A small request may sit on the request queue to 
> wait for other work to arrive until the queue gets unplugged. This 
> penality is compensated by the benefit of a good chance that more 
> requests will be merged during this time period.
> If we have this method both in host and guest, we have twice the 
> penalty with no added benefit.

Indeed, but as it turns out that the draft block driver is appealingly
naive in this respect: the caller can invoke "elevator_init(disk->queue,
"noop")".  See the extract from the lguest implementation below (which
doesn't do this, but could).

Is the noop scheduler significantly worse than hooking directly into
q->make_request_fn?

> A third way out of that situation is to do queueing between guest and 
> host: on the first bio, guest does a hypercall. When the next bio 
> arrives, guest sees that the host has not finished processing the 
> queue yet and pushes another buffer without doing a notification. 
> We've also implemented this, with the result that our host stack was 
> quick enough to practically always process the bio before the guest 
> had the chance to submit another one. Performance was a nightmare, so 
> we discontinued pursuing that idea.

Interesting!  This kind of implementation becomes quite natural with
shared memory so the guest can see an "ack" from the host: if the
previous notification hasn't been acked, it doesn't send another one.

Such a scheme has application beyond block devices and (this is what I'm
really interested in): should be easy to implement under virtio_ops.

Thanks!
Rusty.

+/* Example block driver code. */
+#include <linux/virtio_blk.h>
+#include <linux/genhd.h>
+#include <linux/blkdev.h>
+static irqreturn_t lguest_virtblk_interrupt(int irq, void *_lgv)
+{
+	struct lguest_virtio_device *lgv = _lgv;
+
+	return virtblk_interrupt(lgv->priv);
+}
+
+static int lguest_virtblk_probe(struct lguest_device *lgdev)
+{
+	struct lguest_virtio_device *lgv;
+	struct gendisk *disk;
+	unsigned long sectors;
+	int err, irqf, i;
+
+	lgv = kmalloc(sizeof(*lgv), GFP_KERNEL);
+	if (!lgv)
+		return -ENOMEM;
+
+	memset(lgv, 0, sizeof(*lgv));
+
+	lgdev->private = lgv;
+	lgv->lg = lgdev;
+
+	/* Map is input page followed by output page */
+	lgv->in.p = lguest_map(lguest_devices[lgdev->index].pfn<<PAGE_SHIFT,2);
+	if (!lgv->in.p) {
+		err = -ENOMEM;
+		goto free_lgv;
+	}
+	lgv->out.p = lgv->in.p + 1;
+	/* Page is initially used to pass capacity. */
+	sectors = *(unsigned long *)lgv->in.p;
+	*(unsigned long *)lgv->in.p = 0;
+
+	/* Put everything in free lists. */
+	lgv->in.avail = lgv->out.avail = NUM_DESCS;
+	for (i = 0; i < NUM_DESCS-1; i++) {
+		lgv->in.p->desc[i].next = i+1;
+		lgv->out.p->desc[i].next = i+1;
+	}
+
+	lgv->vdev.ops = &lguest_virtio_ops;
+	lgv->vdev.dev = &lgdev->dev;
+
+	lgv->priv = disk = virtblk_probe(&lgv->vdev);
+	if (IS_ERR(lgv->priv)) {
+		err = PTR_ERR(lgv->priv);
+		goto unmap;
+	}
+	set_capacity(disk, sectors);
+	blk_queue_max_hw_segments(disk->queue, NUM_DESCS-1);
+
+	if (lguest_devices[lgv->lg->index].features&LGUEST_DEVICE_F_RANDOMNESS)
+		irqf = IRQF_SAMPLE_RANDOM;
+	else
+		irqf = 0;
+
+	err = request_irq(lgdev_irq(lgv->lg), lguest_virtblk_interrupt, irqf,
+			  disk->disk_name, lgv);
+	if (err)
+		goto remove;
+
+	add_disk(disk);
+	printk("Virtblk device %s registered\n", disk->disk_name);
+	return 0;
+
+remove:
+	virtblk_remove(disk);
+unmap:
+	lguest_unmap(lgv->in.p);
+free_lgv:
+	kfree(lgv);
+	return err;
+}
+
+static struct lguest_driver lguest_virtblk_drv = {
+	.name = "lguestvirtblk",
+	.owner = THIS_MODULE,
+	.device_type = LGUEST_DEVICE_T_VIRTBLK,
+	.probe = lguest_virtblk_probe,
+};
+
+static __init int lguest_virtblk_init(void)
+{
+	return register_lguest_driver(&lguest_virtblk_drv);
+}
+device_initcall(lguest_virtblk_init);
+
+MODULE_LICENSE("GPL");


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

  parent reply	other threads:[~2007-06-02  9:28 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-31 12:19 [PATCH RFC 1/3] virtio infrastructure Rusty Russell
2007-06-01 23:35 ` Santos, Jose Renato G
2007-06-02 10:12   ` Rusty Russell
     [not found]     ` <1180779167.9228.66.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-04 21:14       ` [Xen-devel] " Santos, Jose Renato G
     [not found]         ` <08CA2245AFCF444DB3AC415E47CC40AFBD2FD4-VylnnfFjWmASZAcGdq5asR6epYMZPwEe5NbjCUgZEJk@public.gmane.org>
2007-06-04 21:19           ` Jeremy Fitzhardinge
     [not found]             ` <466481ED.8050209-TSDbQ3PG+2Y@public.gmane.org>
2007-06-05  2:05               ` Santos, Jose Renato G
     [not found]                 ` <08CA2245AFCF444DB3AC415E47CC40AFBD30B4-VylnnfFjWmASZAcGdq5asR6epYMZPwEe5NbjCUgZEJk@public.gmane.org>
2007-06-05  2:27                   ` Rusty Russell
2007-06-05  2:49                     ` Santos, Jose Renato G
2007-06-05  1:44           ` [Xen-devel] " Rusty Russell
     [not found]             ` <1181007892.25878.112.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-05  2:39               ` Santos, Jose Renato G
     [not found] ` <1180613947.11133.58.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-05-31 12:20   ` [PATCH RFC 2/3] virtio infrastructure: example net driver Rusty Russell
     [not found]     ` <1180614044.11133.61.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-05-31 12:21       ` [PATCH RFC 3/3] virtio infrastructure: example block driver Rusty Russell
     [not found]         ` <1180614091.11133.63.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-05-31 12:57           ` Carsten Otte
     [not found]             ` <465EC637.7020504-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-05-31 15:02               ` Troy Benjegerdes
     [not found]                 ` <20070531150206.GB6474-na1kE3HDu0idQnJuSAr7PQ@public.gmane.org>
2007-05-31 17:01                   ` Carsten Otte
     [not found]                     ` <465EFF72.5070100-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-05-31 17:36                       ` Avi Kivity
2007-05-31 23:39               ` Rusty Russell
     [not found]                 ` <1180654765.10999.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-01  7:10                   ` Carsten Otte
     [not found]                     ` <465FC65C.6020905-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-06-01 13:13                       ` Jens Axboe
     [not found]                         ` <20070601131315.GW32105-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2007-06-04 13:40                           ` Carsten Otte
     [not found]                             ` <4664164A.40604-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-06-04 13:43                               ` Jens Axboe
     [not found]                                 ` <20070604134322.GC32105-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2007-06-04 13:52                                   ` Rusty Russell
     [not found]                                     ` <1180965161.25878.47.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-04 13:54                                       ` Jens Axboe
     [not found]                                         ` <20070604135433.GG32105-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2007-06-04 14:12                                           ` Carsten Otte
     [not found]                                             ` <46641DC9.5050600-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-06-04 14:31                                               ` Jens Axboe
2007-06-02  9:28                       ` Rusty Russell [this message]
     [not found]                         ` <1180776482.9228.22.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-04 12:53                           ` Carsten Otte
2007-05-31 12:53   ` [PATCH RFC 1/3] virtio infrastructure Carsten Otte
2007-05-31 13:01   ` Dor Laor
2007-06-02  6:30   ` Avi Kivity
     [not found]     ` <46610E8D.10706-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-06-02  9:50       ` Rusty Russell
     [not found]         ` <1180777836.9228.44.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-03  5:28           ` Avi Kivity
     [not found]             ` <46625192.5020108-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-06-03 10:29               ` Rusty Russell
     [not found]                 ` <1180866540.17442.74.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-03 11:39                   ` [Xen-devel] " Avi Kivity
     [not found]                     ` <4662A86A.7010706-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-06-03 23:53                       ` Rusty Russell
     [not found]                         ` <1180914836.17442.104.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-04  9:55                           ` Avi Kivity
     [not found]                             ` <4663E18D.4030007-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-06-04 10:32                               ` Herbert Xu
2007-06-04 11:19                               ` Rusty Russell
     [not found]                                 ` <1180955964.25878.27.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-06-04 11:25                                   ` Avi Kivity
     [not found]                                     ` <4663F6AC.7070100-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-06-04 11:40                                       ` Rusty Russell
2007-06-04 12:17                                       ` Herbert Xu

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=1180776482.9228.22.camel@localhost.localdomain \
    --to=rusty-8n+1lvoiyb80n/f98k4iww@public.gmane.org \
    --cc=carsteno-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
    --cc=cborntra-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
    --cc=herbert-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org \
    --cc=jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
    --cc=jimix-aZOuKsOsJu3MbYB6QlFGEg@public.gmane.org \
    --cc=jmk-zzFmDc4TPjtKvsKVC3L/VUEOCMrvLtNR@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=mschwid2-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    --cc=sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org \
    --cc=skranjac-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    --cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR@public.gmane.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