From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KlsmS-0002r6-10 for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KlsmQ-0002qE-5T for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:46 -0400 Received: from [199.232.76.173] (port=51476 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KlsmP-0002qA-Pe for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:45 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:35524) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KlsmP-0007NO-4p for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:45 -0400 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e34.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id m93M5heJ018418 for ; Fri, 3 Oct 2008 18:05:43 -0400 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id m93M5ggW222860 for ; Fri, 3 Oct 2008 16:05:42 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m93M5gnX001474 for ; Fri, 3 Oct 2008 16:05:42 -0600 From: Ryan Harper Date: Fri, 3 Oct 2008 17:05:31 -0500 Message-Id: <1223071531-31817-5-git-send-email-ryanh@us.ibm.com> In-Reply-To: <1223071531-31817-1-git-send-email-ryanh@us.ibm.com> References: <1223071531-31817-1-git-send-email-ryanh@us.ibm.com> Subject: [Qemu-devel] [PATCH 4/4] Reallocate dma buffers in read/write path if needed Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Ryan Harper , kvm@vger.kernel.org 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 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;