From: Ryan Harper <ryanh@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Ryan Harper <ryanh@us.ibm.com>,
kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 4/4] Reallocate dma buffers in read/write path if needed
Date: Fri, 3 Oct 2008 17:05:31 -0500 [thread overview]
Message-ID: <1223071531-31817-5-git-send-email-ryanh@us.ibm.com> (raw)
In-Reply-To: <1223071531-31817-1-git-send-email-ryanh@us.ibm.com>
The default buffer size breaks up larger read/write requests unnecessarily.
When we encounter requests larger than the default dma buffer, reallocate the
buffer to support the request.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f2b4814..a94f10a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -192,10 +192,14 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
}
n = r->sector_count;
- if (n > SCSI_DMA_BUF_SIZE / 512)
- n = SCSI_DMA_BUF_SIZE / 512;
-
r->buf_len = n * 512;
+
+ /* if the request is larger than the default, allocate a larger buffer */
+ if (r->buf_len > SCSI_DMA_BUF_SIZE) {
+ qemu_free(r->dma_buf);
+ r->dma_buf = qemu_memalign(512, r->buf_len);
+ }
+
r->aiocb = bdrv_aio_read(s->bdrv, r->sector, r->dma_buf, n,
scsi_read_complete, r);
if (r->aiocb == NULL)
@@ -224,7 +228,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
{
SCSIDeviceState *s = d->state;
SCSIRequest *r;
- uint32_t n, len;
+ uint32_t n;
DPRINTF("Write data tag=0x%x\n", tag);
r = scsi_find_request(s, tag);
@@ -243,10 +247,13 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
/* we know the len of the request and with the max size of the scsi buffer,
* we can calculate buf_len needed */
- len = r->sector_count * 512;
- if (len > SCSI_DMA_BUF_SIZE)
- len = SCSI_DMA_BUF_SIZE;
- r->buf_len = len;
+ r->buf_len = r->sector_count * 512;
+
+ /* if the request is larger than the default, allocate a larger buffer */
+ if (r->buf_len > SCSI_DMA_BUF_SIZE) {
+ qemu_free(r->dma_buf);
+ r->dma_buf = qemu_memalign(512, r->buf_len);
+ }
/* number of sectors to submit */
n = r->buf_len / 512;
next prev parent reply other threads:[~2008-10-03 22:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-03 22:05 [Qemu-devel] [PATCH 0/4] Improve emulated scsi write performance Ryan Harper
2008-10-03 22:05 ` [Qemu-devel] [PATCH 1/4] lsi_queue_command: add dma direction parameter Ryan Harper
2008-10-03 22:05 ` [Qemu-devel] [PATCH 2/4] Refactor lsi_do_command to queue read and write ops Ryan Harper
2008-10-03 22:05 ` [Qemu-devel] [PATCH 3/4] Refactor scsi-disk layer for queue'ing writes Ryan Harper
2008-10-03 22:05 ` Ryan Harper [this message]
2008-10-03 23:17 ` [Qemu-devel] [PATCH 4/4] Reallocate dma buffers in read/write path if needed Paul Brook
2008-10-03 23:35 ` Anthony Liguori
2008-10-04 0:00 ` Paul Brook
2008-10-04 10:00 ` Avi Kivity
[not found] ` <20081004135749.pphehrhuw9w4gwsc@imap.linux.ibm.com>
2008-10-04 21:47 ` Ryan Harper
2008-10-04 22:22 ` Anthony Liguori
2008-10-05 5:23 ` Avi Kivity
2008-10-05 23:06 ` Ryan Harper
2008-10-06 7:27 ` Avi Kivity
2008-10-04 23:00 ` Paul Brook
2008-10-05 5:29 ` Avi Kivity
2008-10-05 23:08 ` [Qemu-devel] [PATCH 0/4] Improve emulated scsi write performance Ryan Harper
2008-10-13 16:15 ` Ryan Harper
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=1223071531-31817-5-git-send-email-ryanh@us.ibm.com \
--to=ryanh@us.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).