qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Benoît Canet" <benoit.canet@nodalink.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Benoît Canet" <benoit.canet@nodalink.com>,
	"Max Reitz" <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 1/4] block: Extract the BlockAcctStats structure
Date: Fri,  5 Sep 2014 15:46:15 +0200	[thread overview]
Message-ID: <1409924778-29424-2-git-send-email-benoit.canet@nodalink.com> (raw)
In-Reply-To: <1409924778-29424-1-git-send-email-benoit.canet@nodalink.com>

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

  reply	other threads:[~2014-09-05 13:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409924778-29424-2-git-send-email-benoit.canet@nodalink.com \
    --to=benoit.canet@nodalink.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).