[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 13/22] block: Use QEMU_CLOCK_VIRTUAL for the acco
From: |
Alberto Garcia |
Subject: |
[Qemu-block] [PATCH v2 13/22] block: Use QEMU_CLOCK_VIRTUAL for the accounting code in qtest mode |
Date: |
Fri, 2 Oct 2015 17:26:23 +0300 |
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 <address@hidden>
---
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;
--
2.5.3
- [Qemu-block] [PATCH v2 12/22] qemu-io: Account for failed, invalid and flush operations, (continued)
- [Qemu-block] [PATCH v2 12/22] qemu-io: Account for failed, invalid and flush operations, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 05/22] block: Add idle_time_ns to BlockDeviceStats, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 08/22] block: Allow configuring whether to account failed and invalid ops, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 10/22] block: Add average I/O queue depth to BlockDeviceTimedStats, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 03/22] block: define 'clock_type' for the accounting code, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 14/22] iotests: Add test for the block device statistics, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 20/22] macio: Account for failed operations, Alberto Garcia, 2015/10/08
- [Qemu-block] [PATCH v2 13/22] block: Use QEMU_CLOCK_VIRTUAL for the accounting code in qtest mode,
Alberto Garcia <=