From patchwork Thu Mar 31 20:30:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Riteau X-Patchwork-Id: 89127 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 EE407B6F01 for ; Fri, 1 Apr 2011 07:32:25 +1100 (EST) Received: from localhost ([127.0.0.1]:54971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5OXW-000258-3U for incoming@patchwork.ozlabs.org; Thu, 31 Mar 2011 16:32:22 -0400 Received: from [140.186.70.92] (port=53696 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5OWs-00024P-O8 for qemu-devel@nongnu.org; Thu, 31 Mar 2011 16:31:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q5OWr-0001Sd-Ib for qemu-devel@nongnu.org; Thu, 31 Mar 2011 16:31:42 -0400 Received: from mail1-relais-roc.national.inria.fr ([192.134.164.82]:62270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q5OWr-0001SX-E4 for qemu-devel@nongnu.org; Thu, 31 Mar 2011 16:31:41 -0400 X-IronPort-AV: E=Sophos;i="4.63,278,1299452400"; d="scan'208";a="104168204" Received: from cse35-1-82-236-142-224.fbx.proxad.net (HELO localhost.localdomain) ([82.236.142.224]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 31 Mar 2011 22:31:38 +0200 From: Pierre Riteau To: qemu-devel@nongnu.org Date: Thu, 31 Mar 2011 22:30:56 +0200 Message-Id: <1301603456-39324-1-git-send-email-Pierre.Riteau@irisa.fr> X-Mailer: git-send-email 1.7.4.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.134.164.82 Cc: Pierre Riteau Subject: [Qemu-devel] [PATCH] migration: Improve bandwidth estimation 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 In the current migration code, bandwidth is estimated by measuring the time spent in the ram_save_block loop and dividing by the number of sent bytes. However, because of buffering, the time spent in this loop is usually much less than the actual time required to send data on the wire. Try to improve this by measuring the time spent between two calls to ram_save_live instead. Signed-off-by: Pierre Riteau --- arch_init.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch_init.c b/arch_init.c index 0c09f91..7b822fe 100644 --- a/arch_init.c +++ b/arch_init.c @@ -175,6 +175,7 @@ static int ram_save_block(QEMUFile *f) } static uint64_t bytes_transferred; +static int64_t prev_time; static ram_addr_t ram_save_remaining(void) { @@ -254,6 +255,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) uint64_t bytes_transferred_last; double bwidth = 0; uint64_t expected_time = 0; + int64_t current_time; if (stage < 0) { cpu_physical_memory_set_dirty_tracking(0); @@ -286,6 +288,8 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) /* Enable dirty memory tracking */ cpu_physical_memory_set_dirty_tracking(1); + prev_time = qemu_get_clock_ns(rt_clock); + qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); QLIST_FOREACH(block, &ram_list.blocks, next) { @@ -296,7 +300,6 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) } bytes_transferred_last = bytes_transferred; - bwidth = qemu_get_clock_ns(rt_clock); while (!qemu_file_rate_limit(f)) { int bytes_sent; @@ -308,8 +311,10 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) } } - bwidth = qemu_get_clock_ns(rt_clock) - bwidth; + current_time = qemu_get_clock_ns(rt_clock); + bwidth = current_time - prev_time; bwidth = (bytes_transferred - bytes_transferred_last) / bwidth; + prev_time = current_time; /* if we haven't transferred anything this round, force expected_time to a * a very high value, but without crashing */