From patchwork Fri Feb 13 16:06:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 439530 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 663F81402F8 for ; Sat, 14 Feb 2015 03:10:21 +1100 (AEDT) Received: from localhost ([::1]:56104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMIot-00033S-Ha for incoming@patchwork.ozlabs.org; Fri, 13 Feb 2015 11:10:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMIm7-0006d5-Dg for qemu-devel@nongnu.org; Fri, 13 Feb 2015 11:07:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMIm3-00029b-FR for qemu-devel@nongnu.org; Fri, 13 Feb 2015 11:07:27 -0500 Received: from smtp3.mundo-r.com ([212.51.32.191]:27955 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMIm3-0001YT-8o for qemu-devel@nongnu.org; Fri, 13 Feb 2015 11:07:23 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlcHAMQf3lRbdWOb/2dsb2JhbABbgwaBLIMCrFYBAQEBAQEFAXWCcpRUAoEUQwEBAQEBAXyEDQEFIwQLAUYQIAUCGA4CAjwbGYgxAb4GlxQBAQEBBgIBH4EhhGOJdQcWglKBQgWYaYEYhVCMHSKCAhyBUm2CQwEBAQ X-IPAS-Result: AlcHAMQf3lRbdWOb/2dsb2JhbABbgwaBLIMCrFYBAQEBAQEFAXWCcpRUAoEUQwEBAQEBAXyEDQEFIwQLAUYQIAUCGA4CAjwbGYgxAb4GlxQBAQEBBgIBH4EhhGOJdQcWglKBQgWYaYEYhVCMHSKCAhyBUm2CQwEBAQ X-IronPort-AV: E=Sophos;i="5.09,571,1418079600"; d="scan'208";a="316286329" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 13 Feb 2015 17:06:48 +0100 Received: from dsl-hkibrasgw4-50df50-128.dhcp.inet.fi ([80.223.80.128] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1YMIlU-0007Fn-7J; Fri, 13 Feb 2015 17:06:48 +0100 Received: from berto by perseus.local with local (Exim 4.84) (envelope-from ) id 1YMIlH-0006NP-0R; Fri, 13 Feb 2015 18:06:35 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 13 Feb 2015 18:06:12 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Cc: Kevin Wolf , Alberto Garcia , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 4/9] throttle: Prepare to have multiple timers for one ThrottleState 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 From: BenoƮt Canet This patch transform the timer_pending call into two boolean values in the ThrottleState structure. This way we are sure that when multiple timers will be used only one can be armed at a time. Signed-off-by: Benoit Canet Signed-off-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi --- block.c | 2 ++ include/qemu/throttle.h | 3 +++ util/throttle.c | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index b7469a7..fb45c6e 100644 --- a/block.c +++ b/block.c @@ -169,12 +169,14 @@ void bdrv_io_limits_disable(BlockDriverState *bs) static void bdrv_throttle_read_timer_cb(void *opaque) { BlockDriverState *bs = opaque; + throttle_timer_fired(&bs->throttle_state, false); qemu_co_enter_next(&bs->throttled_reqs[0]); } static void bdrv_throttle_write_timer_cb(void *opaque) { BlockDriverState *bs = opaque; + throttle_timer_fired(&bs->throttle_state, true); qemu_co_enter_next(&bs->throttled_reqs[1]); } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 2c560db..546ba12 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -65,6 +65,7 @@ typedef struct ThrottleConfig { typedef struct ThrottleState { ThrottleConfig cfg; /* configuration */ int64_t previous_leak; /* timestamp of the last leak done */ + bool any_timer_armed[2]; /* is any timer armed for this throttle state */ } ThrottleState; typedef struct ThrottleTimers { @@ -125,6 +126,8 @@ bool throttle_schedule_timer(ThrottleState *ts, ThrottleTimers *tt, bool is_write); +void throttle_timer_fired(ThrottleState *ts, bool is_write); + void throttle_account(ThrottleState *ts, bool is_write, uint64_t size); #endif diff --git a/util/throttle.c b/util/throttle.c index d76a48e..71770d3 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -390,16 +390,26 @@ bool throttle_schedule_timer(ThrottleState *ts, return false; } - /* request throttled and timer pending -> do nothing */ - if (timer_pending(tt->timers[is_write])) { + /* request throttled and any timer pending -> do nothing */ + if (ts->any_timer_armed[is_write]) { return true; } - /* request throttled and timer not pending -> arm timer */ + ts->any_timer_armed[is_write] = true; timer_mod(tt->timers[is_write], next_timestamp); return true; } +/* Remember that now timers are currently armed + * + * @ts: the throttle state we are working on + * @is_write: the type of operation (read/write) + */ +void throttle_timer_fired(ThrottleState *ts, bool is_write) +{ + ts->any_timer_armed[is_write] = false; +} + /* do the accounting for this operation * * @is_write: the type of operation (read/write)