From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3eRd-0003X8-FD for qemu-devel@nongnu.org; Thu, 27 Apr 2017 04:06:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3eRc-00007Q-IB for qemu-devel@nongnu.org; Thu, 27 Apr 2017 04:06:33 -0400 From: Ashijeet Acharya Date: Thu, 27 Apr 2017 13:36:36 +0530 Message-Id: <1493280397-9622-7-git-send-email-ashijeetacharya@gmail.com> In-Reply-To: <1493280397-9622-1-git-send-email-ashijeetacharya@gmail.com> References: <1493280397-9622-1-git-send-email-ashijeetacharya@gmail.com> Subject: [Qemu-devel] [PATCH v2 6/7] dmg: Refactor dmg_co_preadv() to start reading multiple sectors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stefanha@gmail.com Cc: kwolf@redhat.com, jsnow@redhat.com, mreitz@redhat.com, famz@redhat.com, peter@lekensteyn.nl, qemu-devel@nongnu.org, qemu-block@nongnu.org, Ashijeet Acharya At the moment, dmg_co_preadv() reads one sector at a time. Make it read multiple sectors at a time depending on the number of sectors stored in "drs->sectors_read". This does not provide any significant optimization in the I/O process of DMG but is still a nicer way. Adjust the 'data' variable depending on our cached access point situation to align our read requests appropriately. Signed-off-by: Ashijeet Acharya --- block/dmg.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index f9045f9..8b7460c 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -718,7 +718,7 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, BDRVDMGState *s = bs->opaque; uint64_t sector_num = offset >> BDRV_SECTOR_BITS; int nb_sectors = bytes >> BDRV_SECTOR_BITS; - int ret, i; + int ret, i = 0; DMGReadState *drs = s->drs; assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); @@ -726,8 +726,7 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, qemu_co_mutex_lock(&s->lock); - for (i = 0; i < nb_sectors; i++) { - uint32_t sector_offset_in_chunk; + while (i < nb_sectors) { void *data; if (dmg_read_chunk(bs, sector_num + i, drs) != 0) { @@ -738,12 +737,20 @@ dmg_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, * s->uncompressed_chunk may be too small to cover the large all-zeroes * section. dmg_read_chunk is called to find s->current_chunk */ if (s->types[s->current_chunk] == 2) { /* all zeroes block entry */ - qemu_iovec_memset(qiov, i * 512, 0, 512); - continue; + qemu_iovec_memset(qiov, i * 512, 0, + 512 * drs->sectors_read); + goto increment; + } + + if (drs->saved_next_in == NULL) { + data = s->uncompressed_chunk + drs->sector_offset_in_chunk * 512; + } else { + data = s->uncompressed_chunk; } - sector_offset_in_chunk = sector_num + i - s->sectors[s->current_chunk]; - data = s->uncompressed_chunk + sector_offset_in_chunk * 512; - qemu_iovec_from_buf(qiov, i * 512, data, 512); + qemu_iovec_from_buf(qiov, i * 512, data, drs->sectors_read * 512); + +increment: + i += drs->sectors_read; } ret = 0; -- 2.6.2