From patchwork Thu Mar 31 14:13:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avishay Traeger1 X-Patchwork-Id: 89080 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 8E5F6B6EFF for ; Fri, 1 Apr 2011 01:14:51 +1100 (EST) Received: from localhost ([127.0.0.1]:40641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5Ie6-0000mF-VG for incoming@patchwork.ozlabs.org; Thu, 31 Mar 2011 10:14:47 -0400 Received: from [140.186.70.92] (port=45310 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5IdR-0000m4-GO for qemu-devel@nongnu.org; Thu, 31 Mar 2011 10:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q5IdP-0007oX-VH for qemu-devel@nongnu.org; Thu, 31 Mar 2011 10:14:05 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:51808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q5IdP-0007ne-OD for qemu-devel@nongnu.org; Thu, 31 Mar 2011 10:14:03 -0400 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p2VEDulC014796 for ; Thu, 31 Mar 2011 14:13:56 GMT Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2VEEUFR1736840 for ; Thu, 31 Mar 2011 15:14:32 +0100 Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2VEDsCD002623 for ; Thu, 31 Mar 2011 08:13:54 -0600 Received: from d12mc102.megacenter.de.ibm.com (d12nrml1506.megacenter.de.ibm.com [9.149.164.56] (may be forged)) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p2VEDsFt002618 for ; Thu, 31 Mar 2011 08:13:54 -0600 X-KeepSent: 532A7D77:B17230EE-C2257864:004CFAD7; 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: Thu, 31 Mar 2011 16:13:59 +0200 X-MIMETrack: Serialize by Router on D12MC102/12/M/IBM(Release 8.5.1FP4|July 25, 2010) at 31/03/2011 16:13:59 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: Liran Schour Subject: [Qemu-devel] [PATCH] 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 The current bandwidth calculation looks like this: (block_mig_state.reads * BLOCK_SIZE)/ block_mig_state.total_time "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. So my solution is to use the total wall-clock time when I/Os are actually in flight. I hope my explanation was clear :) Signed-off-by: Avishay Traeger --- block-migration.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) bmds_set_aio_inflight(blk->bmds, blk->sector, blk->nr_sectors, 0); @@ -250,7 +248,9 @@ 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 there are no outstanding requests, start an interval */ + if (block_mig_state.submitted == 0) + block_mig_state.interval_start_time = 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 +409,9 @@ 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 there are no outstanding requests, start an interval */ + if (block_mig_state.submitted == 0) + block_mig_state.interval_start_time = 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..833d25a 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; @@ -77,6 +76,7 @@ typedef struct BlkMigState { int64_t total_sector_sum; int prev_progress; int bulk_completed; + int64_t interval_start_time; long double total_time; 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); @@ -195,9 +189,13 @@ static void blk_mig_read_cb(void *opaque, int ret) blk->ret = ret; - blk->time = qemu_get_clock_ns(rt_clock) - blk->time; + /* If this is the last outstanding callback, we end the interval */ + if (block_mig_state.submitted == 1) { + block_mig_state.total_time += + (qemu_get_clock_ns(rt_clock) - block_mig_state.interval_start_time); + } - add_avg_read_time(blk->time); + block_mig_state.reads++; QSIMPLEQ_INSERT_TAIL(&block_mig_state.blk_list, blk, entry);