From patchwork Wed Mar 25 07:27:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 454250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3E6711400B7 for ; Wed, 25 Mar 2015 18:28:38 +1100 (AEDT) Received: from localhost ([::1]:36604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yafjv-0003jp-Uh for incoming@patchwork.ozlabs.org; Wed, 25 Mar 2015 03:28:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yafjf-0003T8-A5 for qemu-devel@nongnu.org; Wed, 25 Mar 2015 03:28:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yafja-0007WF-Al for qemu-devel@nongnu.org; Wed, 25 Mar 2015 03:28:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yafja-0007W9-27 for qemu-devel@nongnu.org; Wed, 25 Mar 2015 03:28:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2P7RXI8006479 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 25 Mar 2015 03:27:33 -0400 Received: from ad.nay.redhat.com (dhcp-14-137.nay.redhat.com [10.66.14.137]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2P7RUPF006976; Wed, 25 Mar 2015 03:27:31 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 25 Mar 2015 15:27:26 +0800 Message-Id: <1427268446-6426-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , pbonzini@redhat.com, berto@igalia.com, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v4] block: Switch to host monotonic clock for IO throttling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently, throttle timers won't make any progress when VCPU is not running, which would stall the request queue in utils, qtest, vm suspending, and live migration, without special handling. Block jobs are confusingly inconsistent between with and without throttling: if user sets a bps limit, stops the vm, then start a block job, the block job will not make any progress; in contrary, if user unsets the bps limit, or if it's not set, the block job will run normally. After this patch, with the host clock, even if the VCPUs are stopped, the throttle queues will be processed. This patch also enables potential to add throttle to bdrv_drain_all. Currently all requests are drained immediately. In other words whenever it is called, IO throttling goes ineffective (examples: system reset, migration and many block job operations.). This is a loophole that guest could exploit. If we use the host clock, we can later just trust the nested poll. This could be done on top. Note that for qemu-iotests case 093, which uses qtest, we still keep vm clock so the script can control the clock stepping in order to be deterministic. Reviewed-by: Paolo Bonzini Reviewed-by: Alberto Garcia Signed-off-by: Fam Zheng --- v4: Fix the description. [Alberto] v3: More justification in commit message. [Stefan] Add Paolo's and Alberto's rev-bys. v2: Don't break qemu-iotests 093. --- block.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 0fe97de..89a1d5b 100644 --- a/block.c +++ b/block.c @@ -30,6 +30,7 @@ #include "qapi/qmp/qjson.h" #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" +#include "sysemu/qtest.h" #include "qemu/notify.h" #include "block/coroutine.h" #include "block/qapi.h" @@ -181,10 +182,16 @@ static void bdrv_throttle_write_timer_cb(void *opaque) /* should be called before bdrv_set_io_limits if a limit is set */ void bdrv_io_limits_enable(BlockDriverState *bs) { + int clock_type = QEMU_CLOCK_REALTIME; + + if (qtest_enabled()) { + /* For testing block IO throttling only */ + clock_type = QEMU_CLOCK_VIRTUAL; + } assert(!bs->io_limits_enabled); throttle_init(&bs->throttle_state, bdrv_get_aio_context(bs), - QEMU_CLOCK_VIRTUAL, + clock_type, bdrv_throttle_read_timer_cb, bdrv_throttle_write_timer_cb, bs);