Skip to contentSkip to conversation

Extract block accounting statistic code in it's own module

PATCH Applied Benoît Canet 2 participants 7 messages Sep 5, 2014 – Sep 9, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

cover Extract block accounting statistic code in it's own module

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
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/4 block: Extract the BlockAcctStats structure

Extract the block accounting statistics into a structure so the block device models can hold them in the future.

CC Kevin Wolf <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Max Reitz <[email protected]>
CC Eric Blake <[email protected]>
---
 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(-)
block.c +6 -5
index cb670fd..f7f559c 100644
@@ -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,
block/qapi.c +10 -9
index 79d1e6a..3d3d30b 100644
@@ -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;
include/block/block.h +7 -0
index 8f4ad16..f47d66f 100644
@@ -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;
include/block/block_int.h +1 -4
index 8a61215..20954f3 100644
@@ -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;
Signature · 1 line
2.1.0
#2 lore raw

PATCH 2/4 block: Extract the block accounting code

In reply to 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 <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Max Reitz <[email protected]>
CC Eric Blake <[email protected]>
CC Benoit Canet <[email protected]>
CC Fam Zheng <[email protected]>
CC Peter Crosthwaite <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 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
block.c +2 -25
index f7f559c..1ae3e6b 100644
@@ -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,
block/Makefile.objs +1 -0
index f45f939..c9c8bbb 100644
@@ -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
block/accounting.c new file +57 -0

57 lines not on this page · raw message

include/block/accounting.h new file +57 -0

57 lines not on this page · raw message

include/block/block.h +0 -24
index f47d66f..5fb36b1 100644
@@ -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,
 
include/block/block_int.h +1 -0
index 20954f3..8d86a6c 100644
@@ -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"
include/hw/virtio/virtio-blk.h +1 -0
index afb7b8d..cf61154 100644
@@ -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) \
include/sysemu/dma.h +1 -0
index 00f21f3..73ff86d 100644
@@ -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;
Signature · 1 line
2.1.0
#3 lore raw

PATCH 3/4 block: rename BlockAcctType members to start with BLOCK_ instead of BDRV_

In reply to Benoît Canet

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 <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Keith Busch <[email protected]>
CC Anthony Liguori <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Paolo Bonzini <[email protected]>
CC John Snow <[email protected]>
CC Richard Henderson <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alexander Graf <[email protected]>i
---
 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(-)
block/accounting.c +2 -2
index 702542e..38932ca 100644
@@ -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]++;
block/qapi.c +8 -8
index 3d3d30b..9733ebd 100644
@@ -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;
hw/block/nvme.c +1 -1
index 04459e5..f9aec24 100644
@@ -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);
hw/block/virtio-blk.c +3 -3
index a7f2827..c2cb815 100644
@@ -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);
hw/block/xen_disk.c +4 -2
index a221d0b..74da7f7 100644
@@ -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,
hw/ide/ahci.c +2 -2
index 0ee713b..9f434b1 100644
@@ -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);
hw/ide/atapi.c +4 -4
index 3d92b52..4b15af1 100644
@@ -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;
hw/ide/core.c +5 -5
index b48127f..697feb4 100644
@@ -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);
 }
 
hw/ide/macio.c +4 -4
index b0c0d40..1b653ae 100644
@@ -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;
hw/scsi/scsi-disk.c +16 -12
index e34a544..14b535c 100644
@@ -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:
include/block/accounting.h +7 -7
index 2b2d857..ea5998d 100644
@@ -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;
 
Signature · 1 line
2.1.0
#4 lore raw

PATCH 4/4 block: Make the block accounting functions operate on BlockAcctStats

In reply to 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 <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Keith Busch <[email protected]>
CC Anthony Liguori <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Eric Blake <[email protected]>
CC Peter Maydell <[email protected]>
CC Michael Tokarev <[email protected]>
CC John Snow <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alexander Graf <[email protected]>
CC Max Reitz <[email protected]>
---
 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(-)
block.c +12 -1
index 1ae3e6b..16499b2 100644
@@ -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;
+}
block/accounting.c +10 -13
index 38932ca..edbb1cc 100644
@@ -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;
     }
 }
dma-helpers.c +1 -1
index 499b52b..f6811fa 100644
@@ -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);
 }
hw/block/nvme.c +1 -1
index f9aec24..b010c9b 100644
@@ -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 {
hw/block/virtio-blk.c +9 -6
index c2cb815..38ad38f 100644
@@ -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);
hw/block/xen_disk.c +5 -5
index 74da7f7..053381b 100644
@@ -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,
hw/ide/ahci.c +2 -1
index 9f434b1..ba69de3 100644
@@ -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;
 }
hw/ide/atapi.c +11 -7
index 4b15af1..6d52cda 100644
@@ -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;
hw/ide/core.c +13 -11
index 697feb4..6df5228 100644
@@ -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);
 }
 
hw/ide/macio.c +11 -8
index 1b653ae..cefc85c 100644
@@ -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;
hw/scsi/scsi-disk.c +25 -20

135 lines not on this page · raw message

include/block/accounting.h +5 -5
index ea5998d..50b42b3 100644
@@ -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
include/block/block.h +3 -0
index 5fb36b1..07d6d8e 100644
@@ -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
Signature · 1 line
2.1.0
Applied
#5 lore raw
In reply to Benoît Canet

Am 05.09.2014 um 15:46 hat Benoît Canet geschrieben:

Quoted 10 lines

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

Quoted 8 lines

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

#6 lore raw
Quoted 13 lines · Kevin Wolf

Am 05.09.2014 um 15:46 hat Benoît Canet geschrieben:

Quoted 12 lines

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

Quoted 8 lines
Quoted 6 lines

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,

Quoted 4 lines

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,

Quoted 2 lines

Kevin