From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zw9iT-0002sR-DA for qemu-devel@nongnu.org; Tue, 10 Nov 2015 09:16:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zw9iO-00064L-Ml for qemu-devel@nongnu.org; Tue, 10 Nov 2015 09:16:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zw9iO-00064G-IM for qemu-devel@nongnu.org; Tue, 10 Nov 2015 09:16:04 -0500 From: Stefan Hajnoczi Date: Tue, 10 Nov 2015 14:14:30 +0000 Message-Id: <1447164879-6756-36-git-send-email-stefanha@redhat.com> In-Reply-To: <1447164879-6756-1-git-send-email-stefanha@redhat.com> References: <1447164879-6756-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 35/44] block: Use QEMU_CLOCK_VIRTUAL for the accounting code in qtest mode List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Alberto Garcia , Stefan Hajnoczi From: Alberto Garcia 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 Message-id: 35ed0501450fa572684e9b5e92c361ab6cce565b.1446044838.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi --- block/accounting.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/accounting.c b/block/accounting.c index a941931..05a5c5f 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; -- 2.5.0