From patchwork Mon Aug 29 14:53:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 112099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B5636B6F8C for ; Tue, 30 Aug 2011 02:00:10 +1000 (EST) Received: from localhost ([::1]:49883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy3CG-000213-HD for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2011 10:52:20 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy3BL-0000hI-Ll for qemu-devel@nongnu.org; Mon, 29 Aug 2011 10:51:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qy3BI-0000fH-CZ for qemu-devel@nongnu.org; Mon, 29 Aug 2011 10:51:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2318) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy3BH-0000eu-Qp for qemu-devel@nongnu.org; Mon, 29 Aug 2011 10:51:20 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7TEpHPJ005367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Aug 2011 10:51:17 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7TEoed7021975; Mon, 29 Aug 2011 10:51:16 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Mon, 29 Aug 2011 16:53:37 +0200 Message-Id: <1314629618-8308-30-git-send-email-kwolf@redhat.com> In-Reply-To: <1314629618-8308-1-git-send-email-kwolf@redhat.com> References: <1314629618-8308-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 29/30] block: latency accounting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Christoph Hellwig Account the total latency for read/write/flush requests. This allows management tools to average it based on a snapshot of the nr ops counters and allow checking for SLAs or provide statistics. Signed-off-by: Christoph Hellwig Signed-off-by: Kevin Wolf --- block.c | 20 +++++++++++++++++--- block.h | 1 + block_int.h | 2 ++ qmp-commands.hx | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 24fba37..03a21d8 100644 --- a/block.c +++ b/block.c @@ -1916,12 +1916,18 @@ static void bdrv_stats_iter(QObject *data, void *opaque) " rd_operations=%" PRId64 " wr_operations=%" PRId64 " flush_operations=%" PRId64 + " wr_total_time_ns=%" PRId64 + " rd_total_time_ns=%" PRId64 + " flush_total_time_ns=%" PRId64 "\n", qdict_get_int(qdict, "rd_bytes"), qdict_get_int(qdict, "wr_bytes"), qdict_get_int(qdict, "rd_operations"), qdict_get_int(qdict, "wr_operations"), - qdict_get_int(qdict, "flush_operations")); + qdict_get_int(qdict, "flush_operations"), + qdict_get_int(qdict, "wr_total_time_ns"), + qdict_get_int(qdict, "rd_total_time_ns"), + qdict_get_int(qdict, "flush_total_time_ns")); } void bdrv_stats_print(Monitor *mon, const QObject *data) @@ -1940,7 +1946,10 @@ static QObject* bdrv_info_stats_bs(BlockDriverState *bs) "'rd_operations': %" PRId64 "," "'wr_operations': %" PRId64 "," "'wr_highest_offset': %" PRId64 "," - "'flush_operations': %" PRId64 + "'flush_operations': %" PRId64 "," + "'wr_total_time_ns': %" PRId64 "," + "'rd_total_time_ns': %" PRId64 "," + "'flush_total_time_ns': %" PRId64 "} }", bs->nr_bytes[BDRV_ACCT_READ], bs->nr_bytes[BDRV_ACCT_WRITE], @@ -1948,7 +1957,10 @@ static QObject* bdrv_info_stats_bs(BlockDriverState *bs) bs->nr_ops[BDRV_ACCT_WRITE], bs->wr_highest_sector * (uint64_t)BDRV_SECTOR_SIZE, - bs->nr_ops[BDRV_ACCT_FLUSH]); + bs->nr_ops[BDRV_ACCT_FLUSH], + bs->total_time_ns[BDRV_ACCT_WRITE], + bs->total_time_ns[BDRV_ACCT_READ], + bs->total_time_ns[BDRV_ACCT_FLUSH]); dict = qobject_to_qdict(res); if (*bs->device_name) { @@ -3160,6 +3172,7 @@ bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, int64_t bytes, assert(type < BDRV_MAX_IOTYPE); cookie->bytes = bytes; + cookie->start_time_ns = get_clock(); cookie->type = type; } @@ -3170,6 +3183,7 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie) bs->nr_bytes[cookie->type] += cookie->bytes; bs->nr_ops[cookie->type]++; + bs->total_time_ns[cookie->type] += get_clock() - cookie->start_time_ns; } int bdrv_img_create(const char *filename, const char *fmt, diff --git a/block.h b/block.h index df06af5..3ac0b94 100644 --- a/block.h +++ b/block.h @@ -264,6 +264,7 @@ enum BlockAcctType { typedef struct BlockAcctCookie { int64_t bytes; + int64_t start_time_ns; enum BlockAcctType type; } BlockAcctCookie; diff --git a/block_int.h b/block_int.h index 5f8050d..8a72b80 100644 --- a/block_int.h +++ b/block_int.h @@ -28,6 +28,7 @@ #include "qemu-option.h" #include "qemu-queue.h" #include "qemu-coroutine.h" +#include "qemu-timer.h" #define BLOCK_FLAG_ENCRYPT 1 #define BLOCK_FLAG_COMPAT6 4 @@ -186,6 +187,7 @@ struct BlockDriverState { /* 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; /* Whether the disk can expand beyond total_sectors */ diff --git a/qmp-commands.hx b/qmp-commands.hx index 8570b33..27cc66e 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1202,6 +1202,9 @@ Each json-object contain the following: - "rd_operations": read operations (json-int) - "wr_operations": write operations (json-int) - "flush_operations": cache flush operations (json-int) + - "wr_total_time_ns": total time spend on writes in nano-seconds (json-int) + - "rd_total_time_ns": total time spend on reads in nano-seconds (json-int) + - "flush_total_time_ns": total time spend on cache flushes in nano-seconds (json-int) - "wr_highest_offset": Highest offset of a sector written since the BlockDriverState has been opened (json-int) - "parent": Contains recursively the statistics of the underlying @@ -1223,6 +1226,9 @@ Example: "wr_operations":751, "rd_bytes":122567168, "rd_operations":36772 + "wr_total_times_ns":313253456 + "rd_total_times_ns":3465673657 + "flush_total_times_ns":49653 "flush_operations":61, } }, @@ -1233,6 +1239,9 @@ Example: "rd_bytes":122739200, "rd_operations":36604 "flush_operations":51, + "wr_total_times_ns":313253456 + "rd_total_times_ns":3465673657 + "flush_total_times_ns":49653 } }, { @@ -1244,6 +1253,9 @@ Example: "rd_bytes":0, "rd_operations":0 "flush_operations":0, + "wr_total_times_ns":0 + "rd_total_times_ns":0 + "flush_total_times_ns":0 } }, { @@ -1255,6 +1267,9 @@ Example: "rd_bytes":0, "rd_operations":0 "flush_operations":0, + "wr_total_times_ns":0 + "rd_total_times_ns":0 + "flush_total_times_ns":0 } }, { @@ -1266,6 +1281,9 @@ Example: "rd_bytes":0, "rd_operations":0 "flush_operations":0, + "wr_total_times_ns":0 + "rd_total_times_ns":0 + "flush_total_times_ns":0 } } ]