From patchwork Sun Apr 3 08:31:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avishay Traeger1 X-Patchwork-Id: 89470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CA0A3B6F75 for ; Sun, 3 Apr 2011 18:32:54 +1000 (EST) Received: from localhost ([127.0.0.1]:58826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6Ijo-0007PA-Fd for incoming@patchwork.ozlabs.org; Sun, 03 Apr 2011 04:32:48 -0400 Received: from [140.186.70.92] (port=49920 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6Ij3-0007Ni-Be for qemu-devel@nongnu.org; Sun, 03 Apr 2011 04:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6Iix-0006iy-LG for qemu-devel@nongnu.org; Sun, 03 Apr 2011 04:32:00 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:60198) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q6Iix-0006iM-Dk for qemu-devel@nongnu.org; Sun, 03 Apr 2011 04:31:55 -0400 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p338Vnb1018392 for ; Sun, 3 Apr 2011 08:31:49 GMT Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p338WK0N1822952 for ; Sun, 3 Apr 2011 09:32:28 +0100 Received: from d06av11.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p338VeZl007232 for ; Sun, 3 Apr 2011 02:31:41 -0600 Received: from d12mc102.megacenter.de.ibm.com (d12nrml1506.megacenter.de.ibm.com [9.149.164.56] (may be forged)) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p338VeDX007228; Sun, 3 Apr 2011 02:31:40 -0600 X-KeepSent: B6BB9DCC:7838F587-C2257867:002AF477; type=4; name=$KeepSent To: qemu-devel@nongnu.org X-Mailer: Lotus Notes Build V852_06012010 June 01, 2010 Message-ID: From: Avishay Traeger Date: Sun, 3 Apr 2011 11:31:45 +0300 X-MIMETrack: Serialize by Router on D12MC102/12/M/IBM(Release 8.5.1FP4|July 25, 2010) at 03/04/2011 11:31:45 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.163 Cc: Michael Roth , Liran Schour Subject: [Qemu-devel] [PATCH v2] Improve accuracy of block migration bandwidth calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Revised patch for improving the accuracy of the block migration bandwidth calculation. Thanks a lot to Michael Roth for the input. For those that missed the original patch, here is the description: block_mig_state.total_time is currently the sum of the read request latencies. This is not very accurate because block migration uses aio and so several requests can be submitted at once. Bandwidth should be computed with wall-clock time, not by adding the latencies. In this case, "total_time" has a higher value than it should, and so the computed bandwidth is lower than it is in reality. This means that migration can take longer than it needs to. However, we don't want to use pure wall-clock time here. We are computing bandwidth in the asynchronous phase, where the migration repeatedly wakes up and sends some aio requests. The computed bandwidth will be used for synchronous transfer. Avishay Signed-off-by: Avishay Traeger Reviewed-by: Michael Roth --- block-migration.c | 21 +++++++++------------ 1 files changed, 9 insertions(+), 12 deletions(-) bmds_set_aio_inflight(blk->bmds, blk->sector, blk->nr_sectors, 0); @@ -250,7 +245,8 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f, blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&blk->qiov, &blk->iov, 1); - blk->time = qemu_get_clock_ns(rt_clock); + if (block_mig_state.submitted == 0) + block_mig_state.prev_time_offset = qemu_get_clock_ns(rt_clock); blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov, nr_sectors, blk_mig_read_cb, blk); @@ -409,7 +405,8 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f, blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&blk->qiov, &blk->iov, 1); - blk->time = qemu_get_clock_ns(rt_clock); + if (block_mig_state.submitted == 0) + block_mig_state.prev_time_offset = qemu_get_clock_ns (rt_clock); blk->aiocb = bdrv_aio_readv(bmds->bs, sector, &blk->qiov, nr_sectors, blk_mig_read_cb, blk); -- 1.7.0.4 diff --git a/block-migration.c b/block-migration.c index 8218bac..47296ca 100644 --- a/block-migration.c +++ b/block-migration.c @@ -62,7 +62,6 @@ typedef struct BlkMigBlock { QEMUIOVector qiov; BlockDriverAIOCB *aiocb; int ret; - int64_t time; QSIMPLEQ_ENTRY(BlkMigBlock) entry; } BlkMigBlock; @@ -78,6 +77,7 @@ typedef struct BlkMigState { int prev_progress; int bulk_completed; long double total_time; + long double prev_time_offset; int reads; } BlkMigState; @@ -131,12 +131,6 @@ uint64_t blk_mig_bytes_total(void) return sum << BDRV_SECTOR_BITS; } -static inline void add_avg_read_time(int64_t time) -{ - block_mig_state.reads++; - block_mig_state.total_time += time; -} - static inline long double compute_read_bwidth(void) { assert(block_mig_state.total_time != 0); @@ -191,13 +185,14 @@ static void alloc_aio_bitmap(BlkMigDevState *bmds) static void blk_mig_read_cb(void *opaque, int ret) { + long double curr_time = qemu_get_clock_ns(rt_clock); BlkMigBlock *blk = opaque; blk->ret = ret; - blk->time = qemu_get_clock_ns(rt_clock) - blk->time; - - add_avg_read_time(blk->time); + block_mig_state.reads++; + block_mig_state.total_time += (curr_time - block_mig_state.prev_time_offset); + block_mig_state.prev_time_offset = curr_time; QSIMPLEQ_INSERT_TAIL(&block_mig_state.blk_list, blk, entry);