From patchwork Fri Oct 2 14:26:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 525624 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 D94C01402F0 for ; Sat, 3 Oct 2015 02:09:17 +1000 (AEST) Received: from localhost ([::1]:32845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi2tX-0005Pf-Li for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 12:09:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi1JI-0001qS-0h for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:27:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi1JG-0005R0-DO for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:27:43 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:19591 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi1JG-0004y4-3u; Fri, 02 Oct 2015 10:27:42 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BCBgCRkw5W/5tjdVteHAEBAYMIgUKpKgEBAQEBAQUBgQ0BjxyMIwKBNDsRAQEBAQEBAYEKhCUBAQQnUhA/EjwbGYgyAct3ASuGLIpSBxeEFQWNd4gFjRePEoxRNyyBSkQDHRaBQW6JeAEBAQ X-IPAS-Result: A2BCBgCRkw5W/5tjdVteHAEBAYMIgUKpKgEBAQEBAQUBgQ0BjxyMIwKBNDsRAQEBAQEBAYEKhCUBAQQnUhA/EjwbGYgyAct3ASuGLIpSBxeEFQWNd4gFjRePEoxRNyyBSkQDHRaBQW6JeAEBAQ X-IronPort-AV: E=Sophos;i="5.17,623,1437429600"; d="scan'208";a="29069641" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 02 Oct 2015 16:27:06 +0200 Received: from dsl-hkibrasgw4-50df50-201.dhcp.inet.fi ([80.223.80.201] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1Zi1Ie-0006yq-CU; Fri, 02 Oct 2015 16:27:04 +0200 Received: from berto by perseus.local with local (Exim 4.86) (envelope-from ) id 1Zi1IG-00070r-NK; Fri, 02 Oct 2015 17:26:40 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 17:26:23 +0300 Message-Id: <562ef871d4209a762c8b20e5184e4ccfdd64f04c.1443793122.git.berto@igalia.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: References: In-Reply-To: References: 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 , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 13/22] block: Use QEMU_CLOCK_VIRTUAL for the accounting code in qtest mode 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 This patch switches to QEMU_CLOCK_VIRTUAL for the accounting code in qtest mode, and makes the latency of the operation constant. This way we can perform tests on the accounting code with reproducible results. Signed-off-by: Alberto Garcia --- block/accounting.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/accounting.c b/block/accounting.c index d94ebed..8eb59fc 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -25,14 +25,20 @@ #include "block/accounting.h" #include "block/block_int.h" #include "qemu/timer.h" +#include "sysemu/qtest.h" static QEMUClockType clock_type = QEMU_CLOCK_REALTIME; +static const int qtest_latency_ns = NANOSECONDS_PER_SECOND / 1000; void block_acct_init(BlockAcctStats *stats, bool account_invalid, bool account_failed) { stats->account_invalid = account_invalid; stats->account_failed = account_failed; + + if (qtest_enabled()) { + clock_type = QEMU_CLOCK_VIRTUAL; + } } void block_acct_cleanup(BlockAcctStats *stats) @@ -84,6 +90,10 @@ void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) int64_t time_ns = qemu_clock_get_ns(clock_type); int64_t latency_ns = time_ns - cookie->start_time_ns; + if (qtest_enabled()) { + latency_ns = qtest_latency_ns; + } + assert(cookie->type < BLOCK_MAX_IOTYPE); stats->nr_bytes[cookie->type] += cookie->bytes; @@ -107,6 +117,10 @@ void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie) int64_t time_ns = qemu_clock_get_ns(clock_type); int64_t latency_ns = time_ns - cookie->start_time_ns; + if (qtest_enabled()) { + latency_ns = qtest_latency_ns; + } + stats->total_time_ns[cookie->type] += latency_ns; stats->last_access_time_ns = time_ns;