[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 2/2] bdrv_aio_readv/writev_em
From: |
Andrea Arcangeli |
Subject: |
[Qemu-devel] [RFC 2/2] bdrv_aio_readv/writev_em |
Date: |
Thu, 27 Nov 2008 13:43:51 +0100 |
Hello,
this is the emulated bdrv_aio_readv/writev pure hack to be able to
test the dma api in previous patch.
About the real thing there are two ways to go:
pthread_create() and do aio with pthreads by calling writev by hand.
Use kernel based linux aio (I think it's much better as it won't
screwup with contiguous I/O, and it handles o_direct random writes and
random reads by keeping the lowlevel I/O pipeline full without threads
but by just queuing _in_order_ [in order only from the point of view
of the I/O scheduler of course] and asynchronously the commands of
every different direct-io aio_readv/writev in the lowlevel storage
queue without needing any scheduler and thread synchronization
involvement).
So who's going to add bdrv_aio_readv/writev instead of the below
aberration that breaks on backend not supporting aio and breaks with
bdrv_aio_cancel too, besides being horribly slow and making direct
path slower than the bounce path?
Signed-off-by: Andrea Arcangeli <address@hidden>
Index: block.c
===================================================================
--- block.c (revision 5799)
+++ block.c (working copy)
@@ -53,6 +53,20 @@
uint8_t *buf, int nb_sectors);
static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
+static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
+ int64_t sector_num,
+ struct iovec *iov,
+ int iovnct,
+ size_t len,
+ BlockDriverCompletionFunc *cb,
+ void *opaque);
+static BlockDriverAIOCB *bdrv_aio_writev_em(BlockDriverState *bs,
+ int64_t sector_num,
+ struct iovec *iov,
+ int iovnct,
+ size_t len,
+ BlockDriverCompletionFunc *cb,
+ void *opaque);
BlockDriverState *bdrv_first;
@@ -135,6 +149,8 @@
/* add synchronous IO emulation layer */
bdrv->bdrv_read = bdrv_read_em;
bdrv->bdrv_write = bdrv_write_em;
+ bdrv->bdrv_aio_readv = bdrv_aio_readv_em;
+ bdrv->bdrv_aio_writev = bdrv_aio_writev_em;
}
bdrv->next = first_drv;
first_drv = bdrv;
@@ -1341,6 +1401,74 @@
qemu_aio_release(acb);
}
+static void bdrv_aio_iov_bh_cb(void *opaque)
+{
+ BlockDriverAIOCBSync *acb = opaque;
+ acb->common.cb(acb->common.opaque, acb->ret);
+ qemu_bh_delete(acb->bh);
+ qemu_free(acb);
+}
+
+static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
+ int64_t sector_num,
+ struct iovec *iov,
+ int iovcnt,
+ size_t len,
+ BlockDriverCompletionFunc *cb,
+ void *opaque)
+{
+ BlockDriverAIOCBSync *acb;
+ int ret = -1, idx;
+
+ for (idx = 0; idx < iovcnt; idx++) {
+ size_t sectors = iov[idx].iov_len >> SECTOR_BITS;
+ ret = bdrv_read(bs, sector_num, iov[idx].iov_base, sectors);
+ if (ret)
+ break;
+ sector_num += sectors;
+ }
+ acb = qemu_mallocz(sizeof(BlockDriverAIOCBSync));
+ if (!acb)
+ return NULL;
+ acb->common.bs = bs;
+ acb->common.cb = cb;
+ acb->common.opaque = opaque;
+ acb->bh = qemu_bh_new(bdrv_aio_iov_bh_cb, acb);
+ acb->ret = ret;
+ qemu_bh_schedule(acb->bh);
+ return &acb->common;
+}
+
+static BlockDriverAIOCB *bdrv_aio_writev_em(BlockDriverState *bs,
+ int64_t sector_num,
+ struct iovec *iov,
+ int iovcnt,
+ size_t len,
+ BlockDriverCompletionFunc *cb,
+ void *opaque)
+{
+ BlockDriverAIOCBSync *acb;
+ int ret = -1, idx;
+
+ for (idx = 0; idx < iovcnt; idx++) {
+ size_t sectors = iov[idx].iov_len >> SECTOR_BITS;
+ ret = bdrv_write(bs, sector_num, iov[idx].iov_base, sectors);
+ if (ret)
+ break;
+ sector_num += sectors;
+ }
+ acb = qemu_mallocz(sizeof(BlockDriverAIOCBSync));
+ if (!acb)
+ return NULL;
+ acb->common.bs = bs;
+ acb->common.cb = cb;
+ acb->common.opaque = opaque;
+ acb->bh = qemu_bh_new(bdrv_aio_iov_bh_cb, acb);
+ acb->ret = ret;
+ qemu_bh_schedule(acb->bh);
+ return &acb->common;
+}
+
/**************************************************************/
/* sync block device emulation */
- [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Andrea Arcangeli, 2008/11/27
- [Qemu-devel] [RFC 2/2] bdrv_aio_readv/writev_em,
Andrea Arcangeli <=
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Blue Swirl, 2008/11/27
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Andrea Arcangeli, 2008/11/27
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Blue Swirl, 2008/11/28
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Andrea Arcangeli, 2008/11/28
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Blue Swirl, 2008/11/28
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Jamie Lokier, 2008/11/28
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Avi Kivity, 2008/11/29
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Andrea Arcangeli, 2008/11/30
- Re: [Qemu-devel] [RFC 1/2] pci-dma-api-v1, Anthony Liguori, 2008/11/30