* [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module
@ 2014-09-05 13:46 Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 1/4] block: Extract the BlockAcctStats structure Benoît Canet
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Benoît Canet @ 2014-09-05 13:46 UTC (permalink / raw)
To: qemu-devel; +Cc: Benoît Canet
With the need to add new statistics it's better to modularize asap the I/O
block accounting code.
This series takes care of extracting this code and making it independant of the
BlockDriverState structure.
Compile tested and basically runtime tested excepted for the xen_disk.c backend.
Best regards
Benoît
Benoît Canet (4):
block: Extract the BlockAcctStats structure
block: Extract the block accounting code
block: rename BlockAcctType members to start with BLOCK_ instead of
BDRV_
block: Make the block accounting functions operate on BlockAcctStats
block.c | 37 ++++++++++-----------------
block/Makefile.objs | 1 +
block/accounting.c | 54 +++++++++++++++++++++++++++++++++++++++
block/qapi.c | 19 +++++++-------
dma-helpers.c | 2 +-
hw/block/nvme.c | 4 +--
hw/block/virtio-blk.c | 15 ++++++-----
hw/block/xen_disk.c | 8 +++---
hw/ide/ahci.c | 7 +++---
hw/ide/atapi.c | 18 +++++++------
hw/ide/core.c | 24 ++++++++++--------
hw/ide/macio.c | 19 ++++++++------
hw/scsi/scsi-disk.c | 45 ++++++++++++++++++++-------------
include/block/accounting.h | 57 ++++++++++++++++++++++++++++++++++++++++++
include/block/block.h | 20 +++------------
include/block/block_int.h | 6 ++---
include/hw/virtio/virtio-blk.h | 1 +
include/sysemu/dma.h | 1 +
18 files changed, 225 insertions(+), 113 deletions(-)
create mode 100644 block/accounting.c
create mode 100644 include/block/accounting.h
--
2.1.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 1/4] block: Extract the BlockAcctStats structure
2014-09-05 13:46 [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Benoît Canet
@ 2014-09-05 13:46 ` Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 2/4] block: Extract the block accounting code Benoît Canet
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Benoît Canet @ 2014-09-05 13:46 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Benoît Canet, Max Reitz
Extract the block accounting statistics into a structure so the block device
models can hold them in the future.
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Max Reitz <mreitz@redhat.com>
CC: Eric Blake <eblake@redhat.com>
Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
---
block.c | 11 ++++++-----
block/qapi.c | 19 ++++++++++---------
include/block/block.h | 7 +++++++
include/block/block_int.h | 5 +----
4 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/block.c b/block.c
index cb670fd..f7f559c 100644
--- a/block.c
+++ b/block.c
@@ -3363,8 +3363,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
bdrv_set_dirty(bs, sector_num, nb_sectors);
- if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
- bs->wr_highest_sector = sector_num + nb_sectors - 1;
+ if (bs->stats.wr_highest_sector < sector_num + nb_sectors - 1) {
+ bs->stats.wr_highest_sector = sector_num + nb_sectors - 1;
}
if (bs->growable && ret >= 0) {
bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
@@ -5582,9 +5582,10 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
{
assert(cookie->type < BDRV_MAX_IOTYPE);
- bs->nr_bytes[cookie->type] += cookie->bytes;
- bs->nr_ops[cookie->type]++;
- bs->total_time_ns[cookie->type] += get_clock() - cookie->start_time_ns;
+ bs->stats.nr_bytes[cookie->type] += cookie->bytes;
+ bs->stats.nr_ops[cookie->type]++;
+ bs->stats.total_time_ns[cookie->type] += get_clock() -
+ cookie->start_time_ns;
}
void bdrv_img_create(const char *filename, const char *fmt,
diff --git a/block/qapi.c b/block/qapi.c
index 79d1e6a..3d3d30b 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -333,15 +333,16 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
}
s->stats = g_malloc0(sizeof(*s->stats));
- s->stats->rd_bytes = bs->nr_bytes[BDRV_ACCT_READ];
- s->stats->wr_bytes = bs->nr_bytes[BDRV_ACCT_WRITE];
- s->stats->rd_operations = bs->nr_ops[BDRV_ACCT_READ];
- s->stats->wr_operations = bs->nr_ops[BDRV_ACCT_WRITE];
- s->stats->wr_highest_offset = bs->wr_highest_sector * BDRV_SECTOR_SIZE;
- s->stats->flush_operations = bs->nr_ops[BDRV_ACCT_FLUSH];
- s->stats->wr_total_time_ns = bs->total_time_ns[BDRV_ACCT_WRITE];
- s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ];
- s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH];
+ s->stats->rd_bytes = bs->stats.nr_bytes[BDRV_ACCT_READ];
+ s->stats->wr_bytes = bs->stats.nr_bytes[BDRV_ACCT_WRITE];
+ s->stats->rd_operations = bs->stats.nr_ops[BDRV_ACCT_READ];
+ s->stats->wr_operations = bs->stats.nr_ops[BDRV_ACCT_WRITE];
+ s->stats->wr_highest_offset =
+ bs->stats.wr_highest_sector * BDRV_SECTOR_SIZE;
+ s->stats->flush_operations = bs->stats.nr_ops[BDRV_ACCT_FLUSH];
+ s->stats->wr_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_WRITE];
+ s->stats->rd_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_READ];
+ s->stats->flush_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_FLUSH];
if (bs->file) {
s->has_parent = true;
diff --git a/include/block/block.h b/include/block/block.h
index 8f4ad16..f47d66f 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -492,6 +492,13 @@ enum BlockAcctType {
BDRV_MAX_IOTYPE,
};
+typedef struct BlockAcctStats {
+ uint64_t nr_bytes[BDRV_MAX_IOTYPE];
+ uint64_t nr_ops[BDRV_MAX_IOTYPE];
+ uint64_t total_time_ns[BDRV_MAX_IOTYPE];
+ uint64_t wr_highest_sector;
+} BlockAcctStats;
+
typedef struct BlockAcctCookie {
int64_t bytes;
int64_t start_time_ns;
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 8a61215..20954f3 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -359,10 +359,7 @@ struct BlockDriverState {
bool io_limits_enabled;
/* I/O stats (display with "info blockstats"). */
- uint64_t nr_bytes[BDRV_MAX_IOTYPE];
- uint64_t nr_ops[BDRV_MAX_IOTYPE];
- uint64_t total_time_ns[BDRV_MAX_IOTYPE];
- uint64_t wr_highest_sector;
+ BlockAcctStats stats;
/* I/O Limits */
BlockLimits bl;
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 2/4] block: Extract the block accounting code
2014-09-05 13:46 [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 1/4] block: Extract the BlockAcctStats structure Benoît Canet
@ 2014-09-05 13:46 ` Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 3/4] block: rename BlockAcctType members to start with BLOCK_ instead of BDRV_ Benoît Canet
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Benoît Canet @ 2014-09-05 13:46 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Crosthwaite, Fam Zheng, Benoit Canet, Max Reitz,
Stefan Hajnoczi, Paolo Bonzini, Benoît Canet
The plan is to add new accounting metrics (latency, invalid requests, failed
requests, queue depth) and block.c is overpopulated so it will be better to work
in a separate module.
Moreover the long term plan is to have statistics in each of the BDS of the graph
for metrology purpose; this means that the device model statistics must move from
the topmost BDS to the device model.
So we need to decouple the statistic code from BlockDriverState.
This is another argument for the extraction of the code in a separate module.
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Max Reitz <mreitz@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: Benoit Canet <benoit@irqsave.net>
CC: Fam Zheng <famz@redhat.com>
CC: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
---
block.c | 27 ++------------------
block/Makefile.objs | 1 +
block/accounting.c | 57 ++++++++++++++++++++++++++++++++++++++++++
include/block/accounting.h | 57 ++++++++++++++++++++++++++++++++++++++++++
include/block/block.h | 24 ------------------
include/block/block_int.h | 1 +
include/hw/virtio/virtio-blk.h | 1 +
include/sysemu/dma.h | 1 +
8 files changed, 120 insertions(+), 49 deletions(-)
create mode 100644 block/accounting.c
create mode 100644 include/block/accounting.h
diff --git a/block.c b/block.c
index f7f559c..1ae3e6b 100644
--- a/block.c
+++ b/block.c
@@ -3363,9 +3363,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
bdrv_set_dirty(bs, sector_num, nb_sectors);
- if (bs->stats.wr_highest_sector < sector_num + nb_sectors - 1) {
- bs->stats.wr_highest_sector = sector_num + nb_sectors - 1;
- }
+ bdrv_acct_highest_sector(bs, sector_num, nb_sectors);
+
if (bs->growable && ret >= 0) {
bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
}
@@ -5566,28 +5565,6 @@ void bdrv_iostatus_set_err(BlockDriverState *bs, int error)
}
}
-void
-bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes,
- enum BlockAcctType type)
-{
- assert(type < BDRV_MAX_IOTYPE);
-
- cookie->bytes = bytes;
- cookie->start_time_ns = get_clock();
- cookie->type = type;
-}
-
-void
-bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
-{
- assert(cookie->type < BDRV_MAX_IOTYPE);
-
- bs->stats.nr_bytes[cookie->type] += cookie->bytes;
- bs->stats.nr_ops[cookie->type]++;
- bs->stats.total_time_ns[cookie->type] += get_clock() -
- cookie->start_time_ns;
-}
-
void bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
char *options, uint64_t img_size, int flags,
diff --git a/block/Makefile.objs b/block/Makefile.objs
index f45f939..c9c8bbb 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -18,6 +18,7 @@ block-obj-$(CONFIG_RBD) += rbd.o
block-obj-$(CONFIG_GLUSTERFS) += gluster.o
block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o
block-obj-$(CONFIG_LIBSSH2) += ssh.o
+block-obj-y += accounting.o
common-obj-y += stream.o
common-obj-y += commit.o
diff --git a/block/accounting.c b/block/accounting.c
new file mode 100644
index 0000000..702542e
--- /dev/null
+++ b/block/accounting.c
@@ -0,0 +1,57 @@
+/*
+ * QEMU System Emulator block accounting
+ *
+ * Copyright (c) 2011 Christoph Hellwig
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "block/accounting.h"
+#include "block/block_int.h"
+
+void
+bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes,
+ enum BlockAcctType type)
+{
+ assert(type < BDRV_MAX_IOTYPE);
+
+ cookie->bytes = bytes;
+ cookie->start_time_ns = get_clock();
+ cookie->type = type;
+}
+
+void
+bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
+{
+ assert(cookie->type < BDRV_MAX_IOTYPE);
+
+ bs->stats.nr_bytes[cookie->type] += cookie->bytes;
+ bs->stats.nr_ops[cookie->type]++;
+ bs->stats.total_time_ns[cookie->type] += get_clock() -
+ cookie->start_time_ns;
+}
+
+
+void bdrv_acct_highest_sector(BlockDriverState *bs, int64_t sector_num,
+ unsigned int nb_sectors)
+{
+ if (bs->stats.wr_highest_sector < sector_num + nb_sectors - 1) {
+ bs->stats.wr_highest_sector = sector_num + nb_sectors - 1;
+ }
+}
diff --git a/include/block/accounting.h b/include/block/accounting.h
new file mode 100644
index 0000000..2b2d857
--- /dev/null
+++ b/include/block/accounting.h
@@ -0,0 +1,57 @@
+/*
+ * QEMU System Emulator block accounting
+ *
+ * Copyright (c) 2011 Christoph Hellwig
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef BLOCK_ACCOUNTING_H
+#define BLOCK_ACCOUNTING_H
+
+#include <stdint.h>
+
+#include "qemu/typedefs.h"
+
+enum BlockAcctType {
+ BDRV_ACCT_READ,
+ BDRV_ACCT_WRITE,
+ BDRV_ACCT_FLUSH,
+ BDRV_MAX_IOTYPE,
+};
+
+typedef struct BlockAcctStats {
+ uint64_t nr_bytes[BDRV_MAX_IOTYPE];
+ uint64_t nr_ops[BDRV_MAX_IOTYPE];
+ uint64_t total_time_ns[BDRV_MAX_IOTYPE];
+ uint64_t wr_highest_sector;
+} BlockAcctStats;
+
+typedef struct BlockAcctCookie {
+ int64_t bytes;
+ int64_t start_time_ns;
+ enum BlockAcctType type;
+} BlockAcctCookie;
+
+void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
+ int64_t bytes, enum BlockAcctType type);
+void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
+void bdrv_acct_highest_sector(BlockDriverState *bs, int64_t sector_num,
+ unsigned int nb_sectors);
+
+#endif
diff --git a/include/block/block.h b/include/block/block.h
index f47d66f..5fb36b1 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -485,30 +485,6 @@ void bdrv_op_block_all(BlockDriverState *bs, Error *reason);
void bdrv_op_unblock_all(BlockDriverState *bs, Error *reason);
bool bdrv_op_blocker_is_empty(BlockDriverState *bs);
-enum BlockAcctType {
- BDRV_ACCT_READ,
- BDRV_ACCT_WRITE,
- BDRV_ACCT_FLUSH,
- BDRV_MAX_IOTYPE,
-};
-
-typedef struct BlockAcctStats {
- uint64_t nr_bytes[BDRV_MAX_IOTYPE];
- uint64_t nr_ops[BDRV_MAX_IOTYPE];
- uint64_t total_time_ns[BDRV_MAX_IOTYPE];
- uint64_t wr_highest_sector;
-} BlockAcctStats;
-
-typedef struct BlockAcctCookie {
- int64_t bytes;
- int64_t start_time_ns;
- enum BlockAcctType type;
-} BlockAcctCookie;
-
-void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
- int64_t bytes, enum BlockAcctType type);
-void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
-
typedef enum {
BLKDBG_L1_UPDATE,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 20954f3..8d86a6c 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -24,6 +24,7 @@
#ifndef BLOCK_INT_H
#define BLOCK_INT_H
+#include "block/accounting.h"
#include "block/block.h"
#include "qemu/option.h"
#include "qemu/queue.h"
diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index afb7b8d..cf61154 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -18,6 +18,7 @@
#include "hw/block/block.h"
#include "sysemu/iothread.h"
#include "block/block.h"
+#include "block/accounting.h"
#define TYPE_VIRTIO_BLK "virtio-blk-device"
#define VIRTIO_BLK(obj) \
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index 00f21f3..73ff86d 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -15,6 +15,7 @@
#include "exec/address-spaces.h"
#include "hw/hw.h"
#include "block/block.h"
+#include "block/accounting.h"
#include "sysemu/kvm.h"
typedef struct ScatterGatherEntry ScatterGatherEntry;
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 3/4] block: rename BlockAcctType members to start with BLOCK_ instead of BDRV_
2014-09-05 13:46 [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 1/4] block: Extract the BlockAcctStats structure Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 2/4] block: Extract the block accounting code Benoît Canet
@ 2014-09-05 13:46 ` Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 4/4] block: Make the block accounting functions operate on BlockAcctStats Benoît Canet
2014-09-09 9:56 ` [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Kevin Wolf
4 siblings, 0 replies; 7+ messages in thread
From: Benoît Canet @ 2014-09-05 13:46 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Anthony Liguori, Michael S. Tsirkin,
Markus Armbruster, Alexander Graf, Keith Busch, Stefan Hajnoczi,
Paolo Bonzini, John Snow, Benoît Canet, Richard Henderson
The middle term goal is to move the BlockAcctStats structure in the device models.
(Capturing I/O accounting statistics in the device models is good for billing)
This patch make a small step in this direction by removing a reference to BDRV.
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Keith Busch <keith.busch@intel.com>
CC: Anthony Liguori <aliguori@amazon.com>
CC: "Michael S. Tsirkin" <mst@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: John Snow <jsnow@redhat.com>
CC: Richard Henderson <rth@twiddle.net>
CC: Markus Armbruster <armbru@redhat.com>
CC: Alexander Graf <agraf@suse.de>i
Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
---
block/accounting.c | 4 ++--
block/qapi.c | 16 ++++++++--------
hw/block/nvme.c | 2 +-
hw/block/virtio-blk.c | 6 +++---
hw/block/xen_disk.c | 6 ++++--
hw/ide/ahci.c | 4 ++--
hw/ide/atapi.c | 8 ++++----
hw/ide/core.c | 10 +++++-----
hw/ide/macio.c | 8 ++++----
hw/scsi/scsi-disk.c | 28 ++++++++++++++++------------
include/block/accounting.h | 14 +++++++-------
11 files changed, 56 insertions(+), 50 deletions(-)
diff --git a/block/accounting.c b/block/accounting.c
index 702542e..38932ca 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -29,7 +29,7 @@ void
bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes,
enum BlockAcctType type)
{
- assert(type < BDRV_MAX_IOTYPE);
+ assert(type < BLOCK_MAX_IOTYPE);
cookie->bytes = bytes;
cookie->start_time_ns = get_clock();
@@ -39,7 +39,7 @@ bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes,
void
bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
{
- assert(cookie->type < BDRV_MAX_IOTYPE);
+ assert(cookie->type < BLOCK_MAX_IOTYPE);
bs->stats.nr_bytes[cookie->type] += cookie->bytes;
bs->stats.nr_ops[cookie->type]++;
diff --git a/block/qapi.c b/block/qapi.c
index 3d3d30b..9733ebd 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -333,16 +333,16 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
}
s->stats = g_malloc0(sizeof(*s->stats));
- s->stats->rd_bytes = bs->stats.nr_bytes[BDRV_ACCT_READ];
- s->stats->wr_bytes = bs->stats.nr_bytes[BDRV_ACCT_WRITE];
- s->stats->rd_operations = bs->stats.nr_ops[BDRV_ACCT_READ];
- s->stats->wr_operations = bs->stats.nr_ops[BDRV_ACCT_WRITE];
+ s->stats->rd_bytes = bs->stats.nr_bytes[BLOCK_ACCT_READ];
+ s->stats->wr_bytes = bs->stats.nr_bytes[BLOCK_ACCT_WRITE];
+ s->stats->rd_operations = bs->stats.nr_ops[BLOCK_ACCT_READ];
+ s->stats->wr_operations = bs->stats.nr_ops[BLOCK_ACCT_WRITE];
s->stats->wr_highest_offset =
bs->stats.wr_highest_sector * BDRV_SECTOR_SIZE;
- s->stats->flush_operations = bs->stats.nr_ops[BDRV_ACCT_FLUSH];
- s->stats->wr_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_WRITE];
- s->stats->rd_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_READ];
- s->stats->flush_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_FLUSH];
+ s->stats->flush_operations = bs->stats.nr_ops[BLOCK_ACCT_FLUSH];
+ s->stats->wr_total_time_ns = bs->stats.total_time_ns[BLOCK_ACCT_WRITE];
+ s->stats->rd_total_time_ns = bs->stats.total_time_ns[BLOCK_ACCT_READ];
+ s->stats->flush_total_time_ns = bs->stats.total_time_ns[BLOCK_ACCT_FLUSH];
if (bs->file) {
s->has_parent = true;
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 04459e5..f9aec24 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -232,7 +232,7 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
assert((nlb << data_shift) == req->qsg.size);
dma_acct_start(n->conf.bs, &req->acct, &req->qsg, is_write ?
- BDRV_ACCT_WRITE : BDRV_ACCT_READ);
+ BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
req->aiocb = is_write ?
dma_bdrv_write(n->conf.bs, &req->qsg, aio_slba, nvme_rw_cb, req) :
dma_bdrv_read(n->conf.bs, &req->qsg, aio_slba, nvme_rw_cb, req);
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index a7f2827..c2cb815 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -279,7 +279,7 @@ void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
{
- bdrv_acct_start(req->dev->bs, &req->acct, 0, BDRV_ACCT_FLUSH);
+ bdrv_acct_start(req->dev->bs, &req->acct, 0, BLOCK_ACCT_FLUSH);
/*
* Make sure all outstanding writes are posted to the backing device.
@@ -322,7 +322,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
return;
}
- bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
+ bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BLOCK_ACCT_WRITE);
if (mrb->num_writes == 32) {
virtio_submit_multiwrite(req->dev->bs, mrb);
@@ -353,7 +353,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
return;
}
- bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
+ bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BLOCK_ACCT_READ);
bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
req->qiov.size / BDRV_SECTOR_SIZE,
virtio_blk_rw_complete, req);
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index a221d0b..74da7f7 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -518,7 +518,8 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
switch (ioreq->req.operation) {
case BLKIF_OP_READ:
- bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size, BDRV_ACCT_READ);
+ bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size,
+ BLOCK_ACCT_READ);
ioreq->aio_inflight++;
bdrv_aio_readv(blkdev->bs, ioreq->start / BLOCK_SIZE,
&ioreq->v, ioreq->v.size / BLOCK_SIZE,
@@ -530,7 +531,8 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
break;
}
- bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size, BDRV_ACCT_WRITE);
+ bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size,
+ BLOCK_ACCT_WRITE);
ioreq->aio_inflight++;
bdrv_aio_writev(blkdev->bs, ioreq->start / BLOCK_SIZE,
&ioreq->v, ioreq->v.size / BLOCK_SIZE,
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 0ee713b..9f434b1 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -860,7 +860,7 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
ncq_tfs->tag, ncq_tfs->lba);
dma_acct_start(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct,
- &ncq_tfs->sglist, BDRV_ACCT_READ);
+ &ncq_tfs->sglist, BLOCK_ACCT_READ);
ncq_tfs->aiocb = dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs,
&ncq_tfs->sglist, ncq_tfs->lba,
ncq_cb, ncq_tfs);
@@ -873,7 +873,7 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
ncq_tfs->tag, ncq_tfs->lba);
dma_acct_start(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct,
- &ncq_tfs->sglist, BDRV_ACCT_WRITE);
+ &ncq_tfs->sglist, BLOCK_ACCT_WRITE);
ncq_tfs->aiocb = dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs,
&ncq_tfs->sglist, ncq_tfs->lba,
ncq_cb, ncq_tfs);
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 3d92b52..4b15af1 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -110,12 +110,12 @@ static int cd_read_sector(IDEState *s, int lba, uint8_t *buf, int sector_size)
switch(sector_size) {
case 2048:
- bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
ret = bdrv_read(s->bs, (int64_t)lba << 2, buf, 4);
bdrv_acct_done(s->bs, &s->acct);
break;
case 2352:
- bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
ret = bdrv_read(s->bs, (int64_t)lba << 2, buf + 16, 4);
bdrv_acct_done(s->bs, &s->acct);
if (ret < 0)
@@ -253,7 +253,7 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int max_size)
s->io_buffer_index = 0;
if (s->atapi_dma) {
- bdrv_acct_start(s->bs, &s->acct, size, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, size, BLOCK_ACCT_READ);
s->status = READY_STAT | SEEK_STAT | DRQ_STAT;
ide_start_dma(s, ide_atapi_cmd_read_dma_cb);
} else {
@@ -369,7 +369,7 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
s->io_buffer_size = 0;
s->cd_sector_size = sector_size;
- bdrv_acct_start(s->bs, &s->acct, s->packet_transfer_size, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, s->packet_transfer_size, BLOCK_ACCT_READ);
/* XXX: check if BUSY_STAT should be set */
s->status = READY_STAT | SEEK_STAT | DRQ_STAT | BUSY_STAT;
diff --git a/hw/ide/core.c b/hw/ide/core.c
index b48127f..697feb4 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -586,7 +586,7 @@ void ide_sector_read(IDEState *s)
s->iov.iov_len = n * BDRV_SECTOR_SIZE;
qemu_iovec_init_external(&s->qiov, &s->iov, 1);
- bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
s->pio_aiocb = bdrv_aio_readv(s->bs, sector_num, &s->qiov, n,
ide_sector_read_cb, s);
}
@@ -733,11 +733,11 @@ static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
switch (dma_cmd) {
case IDE_DMA_READ:
bdrv_acct_start(s->bs, &s->acct, s->nsector * BDRV_SECTOR_SIZE,
- BDRV_ACCT_READ);
+ BLOCK_ACCT_READ);
break;
case IDE_DMA_WRITE:
bdrv_acct_start(s->bs, &s->acct, s->nsector * BDRV_SECTOR_SIZE,
- BDRV_ACCT_WRITE);
+ BLOCK_ACCT_WRITE);
break;
default:
break;
@@ -831,7 +831,7 @@ void ide_sector_write(IDEState *s)
s->iov.iov_len = n * BDRV_SECTOR_SIZE;
qemu_iovec_init_external(&s->qiov, &s->iov, 1);
- bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
s->pio_aiocb = bdrv_aio_writev(s->bs, sector_num, &s->qiov, n,
ide_sector_write_cb, s);
}
@@ -865,7 +865,7 @@ void ide_flush_cache(IDEState *s)
}
s->status |= BUSY_STAT;
- bdrv_acct_start(s->bs, &s->acct, 0, BDRV_ACCT_FLUSH);
+ bdrv_acct_start(s->bs, &s->acct, 0, BLOCK_ACCT_FLUSH);
s->pio_aiocb = bdrv_aio_flush(s->bs, ide_flush_cb, s);
}
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index b0c0d40..1b653ae 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -371,7 +371,7 @@ static void pmac_ide_transfer(DBDMA_io *io)
if (s->lba == -1) {
s->io_buffer_size = MIN(io->len, s->packet_transfer_size);
bdrv_acct_start(s->bs, &s->acct, s->io_buffer_size,
- BDRV_ACCT_READ);
+ BLOCK_ACCT_READ);
MACIO_DPRINTF("non-block ATAPI DMA transfer size: %d\n",
s->io_buffer_size);
@@ -387,17 +387,17 @@ static void pmac_ide_transfer(DBDMA_io *io)
return;
}
- bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, io->len, BLOCK_ACCT_READ);
pmac_ide_atapi_transfer_cb(io, 0);
return;
}
switch (s->dma_cmd) {
case IDE_DMA_READ:
- bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_READ);
+ bdrv_acct_start(s->bs, &s->acct, io->len, BLOCK_ACCT_READ);
break;
case IDE_DMA_WRITE:
- bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_WRITE);
+ bdrv_acct_start(s->bs, &s->acct, io->len, BLOCK_ACCT_WRITE);
break;
default:
break;
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index e34a544..14b535c 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -237,7 +237,7 @@ static void scsi_write_do_fua(SCSIDiskReq *r)
}
if (scsi_is_cmd_fua(&r->req.cmd)) {
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
return;
}
@@ -349,13 +349,14 @@ static void scsi_do_read(void *opaque, int ret)
scsi_req_ref(&r->req);
if (r->req.sg) {
- dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BDRV_ACCT_READ);
+ dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BLOCK_ACCT_READ);
r->req.resid -= r->req.sg->size;
r->req.aiocb = dma_bdrv_read(s->qdev.conf.bs, r->req.sg, r->sector,
scsi_dma_complete, r);
} else {
n = scsi_init_iovec(r, SCSI_DMA_BUF_SIZE);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE,
+ BLOCK_ACCT_READ);
r->req.aiocb = bdrv_aio_readv(s->qdev.conf.bs, r->sector, &r->qiov, n,
scsi_read_complete, r);
}
@@ -399,7 +400,7 @@ static void scsi_read_data(SCSIRequest *req)
first = !r->started;
r->started = true;
if (first && scsi_is_cmd_fua(&r->req.cmd)) {
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_do_read, r);
} else {
scsi_do_read(r, 0);
@@ -522,13 +523,14 @@ static void scsi_write_data(SCSIRequest *req)
}
if (r->req.sg) {
- dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BDRV_ACCT_WRITE);
+ dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BLOCK_ACCT_WRITE);
r->req.resid -= r->req.sg->size;
r->req.aiocb = dma_bdrv_write(s->qdev.conf.bs, r->req.sg, r->sector,
scsi_dma_complete, r);
} else {
n = r->qiov.size / 512;
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_WRITE);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE,
+ BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, r->sector, &r->qiov, n,
scsi_write_complete, r);
}
@@ -1496,7 +1498,7 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, uint8_t *inbuf)
if (!bdrv_enable_write_cache(s->qdev.conf.bs)) {
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
return;
}
@@ -1662,7 +1664,8 @@ static void scsi_write_same_complete(void *opaque, int ret)
data->sector += data->iov.iov_len / 512;
data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len);
if (data->iov.iov_len) {
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len, BDRV_ACCT_WRITE);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len,
+ BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
&data->qiov, data->iov.iov_len / 512,
scsi_write_same_complete, data);
@@ -1708,8 +1711,8 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, nb_sectors * s->qdev.blocksize,
- BDRV_ACCT_WRITE);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct,
+ nb_sectors * s->qdev.blocksize, BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_write_zeroes(s->qdev.conf.bs,
r->req.cmd.lba * (s->qdev.blocksize / 512),
nb_sectors * (s->qdev.blocksize / 512),
@@ -1730,7 +1733,8 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
}
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len, BDRV_ACCT_WRITE);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len,
+ BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
&data->qiov, data->iov.iov_len / 512,
scsi_write_same_complete, data);
@@ -1994,7 +1998,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
case SYNCHRONIZE_CACHE:
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH);
+ bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
return 0;
case SEEK_10:
diff --git a/include/block/accounting.h b/include/block/accounting.h
index 2b2d857..ea5998d 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -29,16 +29,16 @@
#include "qemu/typedefs.h"
enum BlockAcctType {
- BDRV_ACCT_READ,
- BDRV_ACCT_WRITE,
- BDRV_ACCT_FLUSH,
- BDRV_MAX_IOTYPE,
+ BLOCK_ACCT_READ,
+ BLOCK_ACCT_WRITE,
+ BLOCK_ACCT_FLUSH,
+ BLOCK_MAX_IOTYPE,
};
typedef struct BlockAcctStats {
- uint64_t nr_bytes[BDRV_MAX_IOTYPE];
- uint64_t nr_ops[BDRV_MAX_IOTYPE];
- uint64_t total_time_ns[BDRV_MAX_IOTYPE];
+ uint64_t nr_bytes[BLOCK_MAX_IOTYPE];
+ uint64_t nr_ops[BLOCK_MAX_IOTYPE];
+ uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
uint64_t wr_highest_sector;
} BlockAcctStats;
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 4/4] block: Make the block accounting functions operate on BlockAcctStats
2014-09-05 13:46 [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Benoît Canet
` (2 preceding siblings ...)
2014-09-05 13:46 ` [Qemu-devel] [PATCH 3/4] block: rename BlockAcctType members to start with BLOCK_ instead of BDRV_ Benoît Canet
@ 2014-09-05 13:46 ` Benoît Canet
2014-09-09 9:56 ` [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Kevin Wolf
4 siblings, 0 replies; 7+ messages in thread
From: Benoît Canet @ 2014-09-05 13:46 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Michael S. Tsirkin,
John Snow, Michael Tokarev, Markus Armbruster, Alexander Graf,
Keith Busch, Stefan Hajnoczi, Paolo Bonzini, Max Reitz,
Benoît Canet
This is the next step for decoupling block accounting functions from
BlockDriverState.
In a future commit the BlockAcctStats structure will be moved from
BlockDriverState to the device models structures.
Note that bdrv_get_stats was introduced so device models can retrieve the
BlockAcctStats structure of a BlockDriverState without being aware of it's
layout.
This function should go away when BlockAcctStats will be embedded in the device
models structures.
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Keith Busch <keith.busch@intel.com>
CC: Anthony Liguori <aliguori@amazon.com>
CC: "Michael S. Tsirkin" <mst@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: Peter Maydell <peter.maydell@linaro.org>
CC: Michael Tokarev <mjt@tls.msk.ru>
CC: John Snow <jsnow@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
CC: Alexander Graf <agraf@suse.de>
CC: Max Reitz <mreitz@redhat.com>
Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
---
block.c | 13 ++++++++++++-
block/accounting.c | 23 ++++++++++-------------
dma-helpers.c | 2 +-
hw/block/nvme.c | 2 +-
hw/block/virtio-blk.c | 15 +++++++++------
hw/block/xen_disk.c | 10 +++++-----
hw/ide/ahci.c | 3 ++-
hw/ide/atapi.c | 18 +++++++++++-------
hw/ide/core.c | 24 +++++++++++++-----------
hw/ide/macio.c | 19 +++++++++++--------
hw/scsi/scsi-disk.c | 45 +++++++++++++++++++++++++--------------------
include/block/accounting.h | 10 +++++-----
include/block/block.h | 3 +++
13 files changed, 108 insertions(+), 79 deletions(-)
diff --git a/block.c b/block.c
index 1ae3e6b..16499b2 100644
--- a/block.c
+++ b/block.c
@@ -3363,7 +3363,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
bdrv_set_dirty(bs, sector_num, nb_sectors);
- bdrv_acct_highest_sector(bs, sector_num, nb_sectors);
+ block_acct_highest_sector(&bs->stats, sector_num, nb_sectors);
if (bs->growable && ret >= 0) {
bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
@@ -6081,3 +6081,14 @@ void bdrv_refresh_filename(BlockDriverState *bs)
QDECREF(json);
}
}
+
+/* This accessor function purpose is to allow the device models to access the
+ * BlockAcctStats structure embedded inside a BlockDriverState without being
+ * aware of the BlockDriverState structure layout.
+ * It will go away when the BlockAcctStats structure will be moved inside
+ * the device models.
+ */
+BlockAcctStats *bdrv_get_stats(BlockDriverState *bs)
+{
+ return &bs->stats;
+}
diff --git a/block/accounting.c b/block/accounting.c
index 38932ca..edbb1cc 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -25,9 +25,8 @@
#include "block/accounting.h"
#include "block/block_int.h"
-void
-bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes,
- enum BlockAcctType type)
+void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
+ int64_t bytes, enum BlockAcctType type)
{
assert(type < BLOCK_MAX_IOTYPE);
@@ -36,22 +35,20 @@ bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes,
cookie->type = type;
}
-void
-bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
+void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie)
{
assert(cookie->type < BLOCK_MAX_IOTYPE);
- bs->stats.nr_bytes[cookie->type] += cookie->bytes;
- bs->stats.nr_ops[cookie->type]++;
- bs->stats.total_time_ns[cookie->type] += get_clock() -
- cookie->start_time_ns;
+ stats->nr_bytes[cookie->type] += cookie->bytes;
+ stats->nr_ops[cookie->type]++;
+ stats->total_time_ns[cookie->type] += get_clock() - cookie->start_time_ns;
}
-void bdrv_acct_highest_sector(BlockDriverState *bs, int64_t sector_num,
- unsigned int nb_sectors)
+void block_acct_highest_sector(BlockAcctStats *stats, int64_t sector_num,
+ unsigned int nb_sectors)
{
- if (bs->stats.wr_highest_sector < sector_num + nb_sectors - 1) {
- bs->stats.wr_highest_sector = sector_num + nb_sectors - 1;
+ if (stats->wr_highest_sector < sector_num + nb_sectors - 1) {
+ stats->wr_highest_sector = sector_num + nb_sectors - 1;
}
}
diff --git a/dma-helpers.c b/dma-helpers.c
index 499b52b..f6811fa 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -277,5 +277,5 @@ uint64_t dma_buf_write(uint8_t *ptr, int32_t len, QEMUSGList *sg)
void dma_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
QEMUSGList *sg, enum BlockAcctType type)
{
- bdrv_acct_start(bs, cookie, sg->size, type);
+ block_acct_start(bdrv_get_stats(bs), cookie, sg->size, type);
}
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index f9aec24..b010c9b 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -197,7 +197,7 @@ static void nvme_rw_cb(void *opaque, int ret)
NvmeCtrl *n = sq->ctrl;
NvmeCQueue *cq = n->cq[sq->cqid];
- bdrv_acct_done(n->conf.bs, &req->acct);
+ block_acct_done(bdrv_get_stats(n->conf.bs), &req->acct);
if (!ret) {
req->status = NVME_SUCCESS;
} else {
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index c2cb815..38ad38f 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -74,7 +74,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
s->rq = req;
} else if (action == BLOCK_ERROR_ACTION_REPORT) {
virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
- bdrv_acct_done(s->bs, &req->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &req->acct);
virtio_blk_free_request(req);
}
@@ -96,7 +96,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
}
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
- bdrv_acct_done(req->dev->bs, &req->acct);
+ block_acct_done(bdrv_get_stats(req->dev->bs), &req->acct);
virtio_blk_free_request(req);
}
@@ -111,7 +111,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
}
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
- bdrv_acct_done(req->dev->bs, &req->acct);
+ block_acct_done(bdrv_get_stats(req->dev->bs), &req->acct);
virtio_blk_free_request(req);
}
@@ -279,7 +279,8 @@ void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
{
- bdrv_acct_start(req->dev->bs, &req->acct, 0, BLOCK_ACCT_FLUSH);
+ block_acct_start(bdrv_get_stats(req->dev->bs), &req->acct, 0,
+ BLOCK_ACCT_FLUSH);
/*
* Make sure all outstanding writes are posted to the backing device.
@@ -322,7 +323,8 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
return;
}
- bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(req->dev->bs), &req->acct, req->qiov.size,
+ BLOCK_ACCT_WRITE);
if (mrb->num_writes == 32) {
virtio_submit_multiwrite(req->dev->bs, mrb);
@@ -353,7 +355,8 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
return;
}
- bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(req->dev->bs), &req->acct, req->qiov.size,
+ BLOCK_ACCT_READ);
bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
req->qiov.size / BDRV_SECTOR_SIZE,
virtio_blk_rw_complete, req);
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 74da7f7..053381b 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -493,7 +493,7 @@ static void qemu_aio_complete(void *opaque, int ret)
break;
}
case BLKIF_OP_READ:
- bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
+ block_acct_done(bdrv_get_stats(ioreq->blkdev->bs), &ioreq->acct);
break;
case BLKIF_OP_DISCARD:
default:
@@ -518,8 +518,8 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
switch (ioreq->req.operation) {
case BLKIF_OP_READ:
- bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size,
- BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(blkdev->bs), &ioreq->acct,
+ ioreq->v.size, BLOCK_ACCT_READ);
ioreq->aio_inflight++;
bdrv_aio_readv(blkdev->bs, ioreq->start / BLOCK_SIZE,
&ioreq->v, ioreq->v.size / BLOCK_SIZE,
@@ -531,8 +531,8 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
break;
}
- bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size,
- BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(blkdev->bs), &ioreq->acct,
+ ioreq->v.size, BLOCK_ACCT_WRITE);
ioreq->aio_inflight++;
bdrv_aio_writev(blkdev->bs, ioreq->start / BLOCK_SIZE,
&ioreq->v, ioreq->v.size / BLOCK_SIZE,
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 9f434b1..ba69de3 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -809,7 +809,8 @@ static void ncq_cb(void *opaque, int ret)
DPRINTF(ncq_tfs->drive->port_no, "NCQ transfer tag %d finished\n",
ncq_tfs->tag);
- bdrv_acct_done(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct);
+ block_acct_done(bdrv_get_stats(ncq_tfs->drive->port.ifs[0].bs),
+ &ncq_tfs->acct);
qemu_sglist_destroy(&ncq_tfs->sglist);
ncq_tfs->used = 0;
}
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 4b15af1..6d52cda 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -110,14 +110,16 @@ static int cd_read_sector(IDEState *s, int lba, uint8_t *buf, int sector_size)
switch(sector_size) {
case 2048:
- bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+ 4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
ret = bdrv_read(s->bs, (int64_t)lba << 2, buf, 4);
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
break;
case 2352:
- bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+ 4 * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
ret = bdrv_read(s->bs, (int64_t)lba << 2, buf + 16, 4);
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
if (ret < 0)
return ret;
cd_data_to_raw(buf, lba);
@@ -253,7 +255,8 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int max_size)
s->io_buffer_index = 0;
if (s->atapi_dma) {
- bdrv_acct_start(s->bs, &s->acct, size, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, size,
+ BLOCK_ACCT_READ);
s->status = READY_STAT | SEEK_STAT | DRQ_STAT;
ide_start_dma(s, ide_atapi_cmd_read_dma_cb);
} else {
@@ -354,7 +357,7 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
return;
eot:
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
ide_set_inactive(s, false);
}
@@ -369,7 +372,8 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
s->io_buffer_size = 0;
s->cd_sector_size = sector_size;
- bdrv_acct_start(s->bs, &s->acct, s->packet_transfer_size, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, s->packet_transfer_size,
+ BLOCK_ACCT_READ);
/* XXX: check if BUSY_STAT should be set */
s->status = READY_STAT | SEEK_STAT | DRQ_STAT | BUSY_STAT;
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 697feb4..6df5228 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -530,7 +530,7 @@ static void ide_sector_read_cb(void *opaque, int ret)
s->pio_aiocb = NULL;
s->status &= ~BUSY_STAT;
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
if (ret != 0) {
if (ide_handle_rw_error(s, -ret, IDE_RETRY_PIO |
IDE_RETRY_READ)) {
@@ -586,7 +586,8 @@ void ide_sector_read(IDEState *s)
s->iov.iov_len = n * BDRV_SECTOR_SIZE;
qemu_iovec_init_external(&s->qiov, &s->iov, 1);
- bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+ n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
s->pio_aiocb = bdrv_aio_readv(s->bs, sector_num, &s->qiov, n,
ide_sector_read_cb, s);
}
@@ -718,7 +719,7 @@ void ide_dma_cb(void *opaque, int ret)
eot:
if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
}
ide_set_inactive(s, stay_active);
}
@@ -732,12 +733,12 @@ static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
switch (dma_cmd) {
case IDE_DMA_READ:
- bdrv_acct_start(s->bs, &s->acct, s->nsector * BDRV_SECTOR_SIZE,
- BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+ s->nsector * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
break;
case IDE_DMA_WRITE:
- bdrv_acct_start(s->bs, &s->acct, s->nsector * BDRV_SECTOR_SIZE,
- BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+ s->nsector * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE);
break;
default:
break;
@@ -764,7 +765,7 @@ static void ide_sector_write_cb(void *opaque, int ret)
IDEState *s = opaque;
int n;
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
s->pio_aiocb = NULL;
s->status &= ~BUSY_STAT;
@@ -831,7 +832,8 @@ void ide_sector_write(IDEState *s)
s->iov.iov_len = n * BDRV_SECTOR_SIZE;
qemu_iovec_init_external(&s->qiov, &s->iov, 1);
- bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct,
+ n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
s->pio_aiocb = bdrv_aio_writev(s->bs, sector_num, &s->qiov, n,
ide_sector_write_cb, s);
}
@@ -850,7 +852,7 @@ static void ide_flush_cb(void *opaque, int ret)
}
if (s->bs) {
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
}
s->status = READY_STAT | SEEK_STAT;
ide_cmd_done(s);
@@ -865,7 +867,7 @@ void ide_flush_cache(IDEState *s)
}
s->status |= BUSY_STAT;
- bdrv_acct_start(s->bs, &s->acct, 0, BLOCK_ACCT_FLUSH);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, 0, BLOCK_ACCT_FLUSH);
s->pio_aiocb = bdrv_aio_flush(s->bs, ide_flush_cb, s);
}
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 1b653ae..cefc85c 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -171,7 +171,7 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
done:
MACIO_DPRINTF("done DMA\n");
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
io->dma_end(opaque);
}
@@ -352,7 +352,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
done:
if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
}
io->dma_end(io);
}
@@ -370,8 +370,8 @@ static void pmac_ide_transfer(DBDMA_io *io)
/* Handle non-block ATAPI DMA transfers */
if (s->lba == -1) {
s->io_buffer_size = MIN(io->len, s->packet_transfer_size);
- bdrv_acct_start(s->bs, &s->acct, s->io_buffer_size,
- BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, s->io_buffer_size,
+ BLOCK_ACCT_READ);
MACIO_DPRINTF("non-block ATAPI DMA transfer size: %d\n",
s->io_buffer_size);
@@ -382,22 +382,25 @@ static void pmac_ide_transfer(DBDMA_io *io)
m->dma_active = false;
MACIO_DPRINTF("end of non-block ATAPI DMA transfer\n");
- bdrv_acct_done(s->bs, &s->acct);
+ block_acct_done(bdrv_get_stats(s->bs), &s->acct);
io->dma_end(io);
return;
}
- bdrv_acct_start(s->bs, &s->acct, io->len, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, io->len,
+ BLOCK_ACCT_READ);
pmac_ide_atapi_transfer_cb(io, 0);
return;
}
switch (s->dma_cmd) {
case IDE_DMA_READ:
- bdrv_acct_start(s->bs, &s->acct, io->len, BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, io->len,
+ BLOCK_ACCT_READ);
break;
case IDE_DMA_WRITE:
- bdrv_acct_start(s->bs, &s->acct, io->len, BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(s->bs), &s->acct, io->len,
+ BLOCK_ACCT_WRITE);
break;
default:
break;
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 14b535c..9645d01 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -183,7 +183,7 @@ static void scsi_aio_complete(void *opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
- bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+ block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
if (r->req.io_canceled) {
goto done;
}
@@ -237,7 +237,8 @@ static void scsi_write_do_fua(SCSIDiskReq *r)
}
if (scsi_is_cmd_fua(&r->req.cmd)) {
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
return;
}
@@ -257,7 +258,7 @@ static void scsi_dma_complete_noio(void *opaque, int ret)
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
- bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+ block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
}
if (r->req.io_canceled) {
goto done;
@@ -300,7 +301,7 @@ static void scsi_read_complete(void * opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
- bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+ block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
if (r->req.io_canceled) {
goto done;
}
@@ -333,7 +334,7 @@ static void scsi_do_read(void *opaque, int ret)
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
- bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+ block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
}
if (r->req.io_canceled) {
goto done;
@@ -355,8 +356,8 @@ static void scsi_do_read(void *opaque, int ret)
scsi_dma_complete, r);
} else {
n = scsi_init_iovec(r, SCSI_DMA_BUF_SIZE);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE,
- BLOCK_ACCT_READ);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
r->req.aiocb = bdrv_aio_readv(s->qdev.conf.bs, r->sector, &r->qiov, n,
scsi_read_complete, r);
}
@@ -400,7 +401,8 @@ static void scsi_read_data(SCSIRequest *req)
first = !r->started;
r->started = true;
if (first && scsi_is_cmd_fua(&r->req.cmd)) {
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_do_read, r);
} else {
scsi_do_read(r, 0);
@@ -454,7 +456,7 @@ static void scsi_write_complete(void * opaque, int ret)
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
- bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+ block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
}
if (r->req.io_canceled) {
goto done;
@@ -529,8 +531,8 @@ static void scsi_write_data(SCSIRequest *req)
scsi_dma_complete, r);
} else {
n = r->qiov.size / 512;
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, n * BDRV_SECTOR_SIZE,
- BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ n * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, r->sector, &r->qiov, n,
scsi_write_complete, r);
}
@@ -1498,7 +1500,8 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, uint8_t *inbuf)
if (!bdrv_enable_write_cache(s->qdev.conf.bs)) {
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
return;
}
@@ -1649,7 +1652,7 @@ static void scsi_write_same_complete(void *opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
- bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+ block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
if (r->req.io_canceled) {
goto done;
}
@@ -1664,8 +1667,8 @@ static void scsi_write_same_complete(void *opaque, int ret)
data->sector += data->iov.iov_len / 512;
data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len);
if (data->iov.iov_len) {
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len,
- BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ data->iov.iov_len, BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
&data->qiov, data->iov.iov_len / 512,
scsi_write_same_complete, data);
@@ -1711,8 +1714,9 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct,
- nb_sectors * s->qdev.blocksize, BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ nb_sectors * s->qdev.blocksize,
+ BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_write_zeroes(s->qdev.conf.bs,
r->req.cmd.lba * (s->qdev.blocksize / 512),
nb_sectors * (s->qdev.blocksize / 512),
@@ -1733,8 +1737,8 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
}
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len,
- BLOCK_ACCT_WRITE);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ data->iov.iov_len, BLOCK_ACCT_WRITE);
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
&data->qiov, data->iov.iov_len / 512,
scsi_write_same_complete, data);
@@ -1998,7 +2002,8 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
case SYNCHRONIZE_CACHE:
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BLOCK_ACCT_FLUSH);
+ block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ BLOCK_ACCT_FLUSH);
r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
return 0;
case SEEK_10:
diff --git a/include/block/accounting.h b/include/block/accounting.h
index ea5998d..50b42b3 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -48,10 +48,10 @@ typedef struct BlockAcctCookie {
enum BlockAcctType type;
} BlockAcctCookie;
-void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
- int64_t bytes, enum BlockAcctType type);
-void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
-void bdrv_acct_highest_sector(BlockDriverState *bs, int64_t sector_num,
- unsigned int nb_sectors);
+void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
+ int64_t bytes, enum BlockAcctType type);
+void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
+void block_acct_highest_sector(BlockAcctStats *stats, int64_t sector_num,
+ unsigned int nb_sectors);
#endif
diff --git a/include/block/block.h b/include/block/block.h
index 5fb36b1..07d6d8e 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -5,6 +5,7 @@
#include "qemu-common.h"
#include "qemu/option.h"
#include "block/coroutine.h"
+#include "block/accounting.h"
#include "qapi/qmp/qobject.h"
#include "qapi-types.h"
@@ -574,4 +575,6 @@ void bdrv_io_plug(BlockDriverState *bs);
void bdrv_io_unplug(BlockDriverState *bs);
void bdrv_flush_io_queue(BlockDriverState *bs);
+BlockAcctStats *bdrv_get_stats(BlockDriverState *bs);
+
#endif
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module
2014-09-05 13:46 [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Benoît Canet
` (3 preceding siblings ...)
2014-09-05 13:46 ` [Qemu-devel] [PATCH 4/4] block: Make the block accounting functions operate on BlockAcctStats Benoît Canet
@ 2014-09-09 9:56 ` Kevin Wolf
2014-09-09 10:48 ` Benoît Canet
4 siblings, 1 reply; 7+ messages in thread
From: Kevin Wolf @ 2014-09-09 9:56 UTC (permalink / raw)
To: Benoît Canet; +Cc: qemu-devel
Am 05.09.2014 um 15:46 hat Benoît Canet geschrieben:
> With the need to add new statistics it's better to modularize asap the I/O
> block accounting code.
>
> This series takes care of extracting this code and making it independant of the
> BlockDriverState structure.
>
> Compile tested and basically runtime tested excepted for the xen_disk.c backend.
>
> Best regards
>
> Benoît
>
> Benoît Canet (4):
> block: Extract the BlockAcctStats structure
> block: Extract the block accounting code
> block: rename BlockAcctType members to start with BLOCK_ instead of
> BDRV_
> block: Make the block accounting functions operate on BlockAcctStats
Thanks, applied all to the block branch.
By the way, I was only CCed on the patches, but not on the cover letter.
Can you please make sure to explicitly CC me for the whole series so I
won't miss comments and can easier reply to the whole series?
Kevin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module
2014-09-09 9:56 ` [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Kevin Wolf
@ 2014-09-09 10:48 ` Benoît Canet
0 siblings, 0 replies; 7+ messages in thread
From: Benoît Canet @ 2014-09-09 10:48 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, Benoît Canet
On Tue, Sep 09, 2014 at 11:56:28AM +0200, Kevin Wolf wrote:
> Am 05.09.2014 um 15:46 hat Benoît Canet geschrieben:
> > With the need to add new statistics it's better to modularize asap the I/O
> > block accounting code.
> >
> > This series takes care of extracting this code and making it independant of the
> > BlockDriverState structure.
> >
> > Compile tested and basically runtime tested excepted for the xen_disk.c backend.
> >
> > Best regards
> >
> > Benoît
> >
> > Benoît Canet (4):
> > block: Extract the BlockAcctStats structure
> > block: Extract the block accounting code
> > block: rename BlockAcctType members to start with BLOCK_ instead of
> > BDRV_
> > block: Make the block accounting functions operate on BlockAcctStats
>
> Thanks, applied all to the block branch.
Thanks,
>
> By the way, I was only CCed on the patches, but not on the cover letter.
> Can you please make sure to explicitly CC me for the whole series so I
> won't miss comments and can easier reply to the whole series?
Yes sure,
>
> Kevin
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-09-09 10:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-05 13:46 [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 1/4] block: Extract the BlockAcctStats structure Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 2/4] block: Extract the block accounting code Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 3/4] block: rename BlockAcctType members to start with BLOCK_ instead of BDRV_ Benoît Canet
2014-09-05 13:46 ` [Qemu-devel] [PATCH 4/4] block: Make the block accounting functions operate on BlockAcctStats Benoît Canet
2014-09-09 9:56 ` [Qemu-devel] [PATCH 0/4] Extract block accounting statistic code in it's own module Kevin Wolf
2014-09-09 10:48 ` Benoît Canet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).