From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwAXC-0002aD-RJ for qemu-devel@nongnu.org; Tue, 10 Nov 2015 10:08:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwAX8-0003aQ-UT for qemu-devel@nongnu.org; Tue, 10 Nov 2015 10:08:34 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:33402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwAX8-0003aM-OC for qemu-devel@nongnu.org; Tue, 10 Nov 2015 10:08:30 -0500 Received: by wmec201 with SMTP id c201so138275281wme.0 for ; Tue, 10 Nov 2015 07:08:30 -0800 (PST) Sender: Paolo Bonzini References: <1447164879-6756-1-git-send-email-stefanha@redhat.com> <1447164879-6756-36-git-send-email-stefanha@redhat.com> From: Paolo Bonzini Message-ID: <5642086A.2040700@redhat.com> Date: Tue, 10 Nov 2015 16:08:26 +0100 MIME-Version: 1.0 In-Reply-To: <1447164879-6756-36-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [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: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Peter Maydell , Alberto Garcia On 10/11/2015 15:14, Stefan Hajnoczi wrote: > 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; > > Using QEMU_CLOCK_VIRTUAL makes sense but for the other part, could the test instead use the null backend? Paolo