[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/38] ide: convert ide_sector_read() to asynchronou
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 07/38] ide: convert ide_sector_read() to asynchronous I/O |
Date: |
Fri, 20 Apr 2012 19:01:13 +0200 |
From: Stefan Hajnoczi <address@hidden>
The IDE PIO interface currently uses bdrv_read() to perform reads
synchronously. Synchronous I/O in the vcpu thread is bad because it
prevents the guest from executing code - it makes the guest
unresponsive.
This patch converts IDE PIO to use bdrv_aio_readv(). We simply need to
use the BUSY_STAT status so the guest knows to wait while we are busy.
The only external user of ide_sector_read() is restart behavior on I/O
errors and it is not affected by this change. We still need to restart
I/O in the same way.
Migration is also unaffected if I understand the code correctly. We
continue to use the same transfer function and the BUSY_STAT status
should never be migrated since we flush I/O before migrating device
state.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Reviewed-by: Zhi Yong Wu <address@hidden>
Tested-by: Richard Davies <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
hw/ide/core.c | 76 ++++++++++++++++++++++++++++++++++++++--------------
hw/ide/internal.h | 3 ++
2 files changed, 58 insertions(+), 21 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 35723fd..9894b3b 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -471,40 +471,68 @@ static void ide_rw_error(IDEState *s) {
ide_set_irq(s->bus);
}
+static void ide_sector_read_cb(void *opaque, int ret)
+{
+ IDEState *s = opaque;
+ int n;
+
+ s->pio_aiocb = NULL;
+ s->status &= ~BUSY_STAT;
+
+ bdrv_acct_done(s->bs, &s->acct);
+ if (ret != 0) {
+ if (ide_handle_rw_error(s, -ret, BM_STATUS_PIO_RETRY |
+ BM_STATUS_RETRY_READ)) {
+ return;
+ }
+ }
+
+ n = s->nsector;
+ if (n > s->req_nb_sectors) {
+ n = s->req_nb_sectors;
+ }
+
+ /* Allow the guest to read the io_buffer */
+ ide_transfer_start(s, s->io_buffer, n * BDRV_SECTOR_SIZE, ide_sector_read);
+
+ ide_set_irq(s->bus);
+
+ ide_set_sector(s, ide_get_sector(s) + n);
+ s->nsector -= n;
+}
+
void ide_sector_read(IDEState *s)
{
int64_t sector_num;
- int ret, n;
+ int n;
s->status = READY_STAT | SEEK_STAT;
s->error = 0; /* not needed by IDE spec, but needed by Windows */
sector_num = ide_get_sector(s);
n = s->nsector;
+
if (n == 0) {
- /* no more sector to read from disk */
ide_transfer_stop(s);
- } else {
+ return;
+ }
+
+ s->status |= BUSY_STAT;
+
+ if (n > s->req_nb_sectors) {
+ n = s->req_nb_sectors;
+ }
+
#if defined(DEBUG_IDE)
- printf("read sector=%" PRId64 "\n", sector_num);
+ printf("sector=%" PRId64 "\n", sector_num);
#endif
- if (n > s->req_nb_sectors)
- n = s->req_nb_sectors;
- bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
- ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);
- bdrv_acct_done(s->bs, &s->acct);
- if (ret != 0) {
- if (ide_handle_rw_error(s, -ret,
- BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))
- {
- return;
- }
- }
- ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);
- ide_set_irq(s->bus);
- ide_set_sector(s, sector_num + n);
- s->nsector -= n;
- }
+ s->iov.iov_base = s->io_buffer;
+ s->iov.iov_len = n * BDRV_SECTOR_SIZE;
+ qemu_iovec_init_external(&s->qiov, &s->iov, 1);
+
+ bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ s->pio_aiocb = bdrv_aio_readv(s->bs, sector_num, &s->qiov, n,
+ ide_sector_read_cb, s);
}
static void dma_buf_commit(IDEState *s)
@@ -1765,6 +1793,12 @@ static void ide_reset(IDEState *s)
#ifdef DEBUG_IDE
printf("ide: reset\n");
#endif
+
+ if (s->pio_aiocb) {
+ bdrv_aio_cancel(s->pio_aiocb);
+ s->pio_aiocb = NULL;
+ }
+
if (s->drive_kind == IDE_CFATA)
s->mult_sectors = 0;
else
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 100efd3..f8a027d 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -385,6 +385,9 @@ struct IDEState {
int cd_sector_size;
int atapi_dma; /* true if dma is requested for the packet cmd */
BlockAcctCookie acct;
+ BlockDriverAIOCB *pio_aiocb;
+ struct iovec iov;
+ QEMUIOVector qiov;
/* ATA DMA state */
int io_buffer_size;
QEMUSGList sg;
--
1.7.6.5
- [Qemu-devel] [PULL 00/38] Block patches, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 03/38] block: Drain requests in bdrv_close, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 02/38] qemu-iotests: Test bdrv_close while AIO is in flight, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 01/38] qemu-iotests: Always filter cluster_size out in _make_test_img, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 06/38] qemu-io: Add command line switch for cache mode, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 05/38] block: Fix spelling in comment (ineffcient -> inefficient), Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 04/38] iotests: fix error in 005, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 07/38] ide: convert ide_sector_read() to asynchronous I/O,
Kevin Wolf <=
- [Qemu-devel] [PATCH 10/38] qcow2: Fix return value of alloc_refcount_block, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 09/38] qcow2: Fix error handling in qcow2_alloc_cluster_offset, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 08/38] ide: convert ide_sector_write() to asynchronous I/O, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 12/38] qemu-io: use main_loop_wait, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 13/38] qemu-tool: map vm_clock to rt_clock, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 11/38] block: allow interrupting a co_sleep_ns, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 17/38] aio: simplify qemu_aio_wait, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 14/38] posix-aio: merge posix_aio_process_queue and posix_aio_read, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 16/38] aio: return "AIO in progress" state from qemu_aio_wait, Kevin Wolf, 2012/04/20
- [Qemu-devel] [PATCH 18/38] qemu-img: let 'qemu-img convert' flush data, Kevin Wolf, 2012/04/20