From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEVWL-0002zT-7t for qemu-devel@nongnu.org; Mon, 04 Aug 2014 23:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEVWF-0001YZ-1W for qemu-devel@nongnu.org; Mon, 04 Aug 2014 23:34:41 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:43548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEVWE-0001YU-SN for qemu-devel@nongnu.org; Mon, 04 Aug 2014 23:34:34 -0400 Received: by mail-pd0-f180.google.com with SMTP id y13so503710pdi.25 for ; Mon, 04 Aug 2014 20:34:34 -0700 (PDT) From: Ming Lei Date: Tue, 5 Aug 2014 11:33:07 +0800 Message-Id: <1407209598-2572-7-git-send-email-ming.lei@canonical.com> In-Reply-To: <1407209598-2572-1-git-send-email-ming.lei@canonical.com> References: <1407209598-2572-1-git-send-email-ming.lei@canonical.com> Subject: [Qemu-devel] [PATCH v1 06/17] block: introduce bdrv_co_can_bypass_co List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Peter Maydell , Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , Ming Lei , Fam Zheng , "Michael S. Tsirkin" This function is introduced to check if the current block I/O can be allowed to run without coroutine for sake of performance. Signed-off-by: Ming Lei --- block.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/block.c b/block.c index ac184ef..2326dab 100644 --- a/block.c +++ b/block.c @@ -4718,6 +4718,44 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque) qemu_bh_schedule(acb->bh); } +static bool bdrv_rw_aligned(BlockDriverState *bs, + int64_t offset, + int bytes) +{ + uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment); + + if ((offset & (align - 1)) || ((offset + bytes) & (align - 1))) { + return false; + } else { + return true; + } +} + +static bool bdrv_co_can_bypass_co(BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, + BdrvRequestFlags flags, + bool is_write) +{ + if (flags || bs->copy_on_read || bs->io_limits_enabled) { + return false; + } + + /* unaligned read is safe */ + if (!is_write) { + return true; + } + + if (!bs->enable_write_cache || + bs->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF || + !QLIST_EMPTY(&bs->before_write_notifiers.notifiers)) { + return false; + } else { + return bdrv_rw_aligned(bs, sector_num << BDRV_SECTOR_BITS, + nb_sectors << BDRV_SECTOR_BITS); + } +} + static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, -- 1.7.9.5