From patchwork Fri Oct 2 14:26:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 525609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1A8D11402B6 for ; Sat, 3 Oct 2015 02:00:42 +1000 (AEST) Received: from localhost ([::1]:60977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi2lE-0007KK-07 for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 12:00:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi1JC-0001gP-GE for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:27:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi1JA-0005Ms-Uk for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:27:38 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:19591 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi1JA-0004y4-LD; Fri, 02 Oct 2015 10:27:36 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BFBgCRkw5W/5tjdVteHAEBAYMIgUKpKgEBAQEBAQUBgQ0BjxyMIwKBNDwQAQEBAQEBAYEKhCUBAQQnUhA4BxI8GxmIMgHLdyyGLIpSBwqEIgWHNIVRcj+HRo0XgVaHW5IyOCuCDgMdFoFBbol4AQEB X-IPAS-Result: A2BFBgCRkw5W/5tjdVteHAEBAYMIgUKpKgEBAQEBAQUBgQ0BjxyMIwKBNDwQAQEBAQEBAYEKhCUBAQQnUhA4BxI8GxmIMgHLdyyGLIpSBwqEIgWHNIVRcj+HRo0XgVaHW5IyOCuCDgMdFoFBbol4AQEB X-IronPort-AV: E=Sophos;i="5.17,623,1437429600"; d="scan'208";a="29069587" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 02 Oct 2015 16:26:55 +0200 Received: from dsl-hkibrasgw4-50df50-201.dhcp.inet.fi ([80.223.80.201] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim) id 1Zi1IT-0006yp-NT; Fri, 02 Oct 2015 16:26:54 +0200 Received: from berto by perseus.local with local (Exim 4.86) (envelope-from ) id 1Zi1IG-00070R-GF; Fri, 02 Oct 2015 17:26:40 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 17:26:18 +0300 Message-Id: <91b3bacda30ba46e1d2fa9e3801e0bd45629bf71.1443793122.git.berto@igalia.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 08/22] block: Allow configuring whether to account failed and invalid ops 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 This patch adds two options, "stats-account-invalid" and "stats-account-failed", that can be used to decide whether invalid and failed I/O operations must be used when collecting statistics for latency and last access time. Signed-off-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi --- block/accounting.c | 24 +++++++++++++++++++----- block/qapi.c | 3 +++ blockdev.c | 16 ++++++++++++++++ include/block/accounting.h | 5 +++++ qapi/block-core.json | 17 ++++++++++++++++- qmp-commands.hx | 25 ++++++++++++++++++++----- 6 files changed, 79 insertions(+), 11 deletions(-) diff --git a/block/accounting.c b/block/accounting.c index eb86a47..9584450 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -28,6 +28,13 @@ static QEMUClockType clock_type = QEMU_CLOCK_REALTIME; +void block_acct_init(BlockAcctStats *stats, bool account_invalid, + bool account_failed) +{ + stats->account_invalid = account_invalid; + stats->account_failed = account_failed; +} + void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie, int64_t bytes, enum BlockAcctType type) { @@ -53,13 +60,17 @@ void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie) { - int64_t time_ns = qemu_clock_get_ns(clock_type); - assert(cookie->type < BLOCK_MAX_IOTYPE); stats->failed_ops[cookie->type]++; - stats->total_time_ns[cookie->type] += time_ns - cookie->start_time_ns; - stats->last_access_time_ns = time_ns; + + if (stats->account_failed) { + int64_t time_ns = qemu_clock_get_ns(clock_type); + int64_t latency_ns = time_ns - cookie->start_time_ns; + + stats->total_time_ns[cookie->type] += latency_ns; + stats->last_access_time_ns = time_ns; + } } void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type) @@ -67,7 +78,10 @@ void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type) assert(type < BLOCK_MAX_IOTYPE); stats->invalid_ops[type]++; - stats->last_access_time_ns = qemu_clock_get_ns(clock_type); + + if (stats->account_invalid) { + stats->last_access_time_ns = qemu_clock_get_ns(clock_type); + } } void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type, diff --git a/block/qapi.c b/block/qapi.c index 1b787ba..7dd9128 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -374,6 +374,9 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs, if (s->stats->has_idle_time_ns) { s->stats->idle_time_ns = block_acct_idle_time_ns(stats); } + + s->stats->account_invalid = stats->account_invalid; + s->stats->account_failed = stats->account_failed; } s->stats->wr_highest_offset = bs->wr_highest_offset; diff --git a/blockdev.c b/blockdev.c index 4731843..61a80fb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -461,6 +461,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, const char *buf; int bdrv_flags = 0; int on_read_error, on_write_error; + bool account_invalid, account_failed; BlockBackend *blk; BlockDriverState *bs; ThrottleConfig cfg; @@ -497,6 +498,9 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, /* extract parameters */ snapshot = qemu_opt_get_bool(opts, "snapshot", 0); + account_invalid = qemu_opt_get_bool(opts, "stats-account-invalid", true); + account_failed = qemu_opt_get_bool(opts, "stats-account-failed", true); + extract_common_blockdev_options(opts, &bdrv_flags, &cfg, &detect_zeroes, &throttling_group, &error); if (error) { @@ -597,6 +601,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, if (bdrv_key_required(bs)) { autostart = 0; } + + block_acct_init(blk_get_stats(blk), account_invalid, account_failed); } blk_set_on_error(blk, on_read_error, on_write_error); @@ -3528,6 +3534,16 @@ QemuOptsList qemu_common_drive_opts = { .name = "detect-zeroes", .type = QEMU_OPT_STRING, .help = "try to optimize zero writes (off, on, unmap)", + },{ + .name = "stats-account-invalid", + .type = QEMU_OPT_BOOL, + .help = "whether to account for invalid I/O operations " + "in the statistics", + },{ + .name = "stats-account-failed", + .type = QEMU_OPT_BOOL, + .help = "whether to account for failed I/O operations " + "in the statistics", }, { /* end of list */ } }, diff --git a/include/block/accounting.h b/include/block/accounting.h index b50e3cc..0d9b076 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -25,6 +25,7 @@ #define BLOCK_ACCOUNTING_H #include +#include #include "qemu/typedefs.h" @@ -43,6 +44,8 @@ typedef struct BlockAcctStats { uint64_t total_time_ns[BLOCK_MAX_IOTYPE]; uint64_t merged[BLOCK_MAX_IOTYPE]; int64_t last_access_time_ns; + bool account_invalid; + bool account_failed; } BlockAcctStats; typedef struct BlockAcctCookie { @@ -51,6 +54,8 @@ typedef struct BlockAcctCookie { enum BlockAcctType type; } BlockAcctCookie; +void block_acct_init(BlockAcctStats *stats, bool account_invalid, + bool account_failed); void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie, int64_t bytes, enum BlockAcctType type); void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie); diff --git a/qapi/block-core.json b/qapi/block-core.json index f1c7277..251f67b 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -470,6 +470,12 @@ # @invalid_flush_operations: The number of invalid flush operations # performed by the device (Since 2.5) # +# @account_invalid: Whether invalid operations are included in the +# last access statistics (Since 2.5) +# +# @account_failed: Whether failed operations are included in the +# latency and last access statistics (Since 2.5) +# # Since: 0.14.0 ## { 'struct': 'BlockDeviceStats', @@ -480,7 +486,8 @@ 'rd_merged': 'int', 'wr_merged': 'int', '*idle_time_ns': 'int', 'failed_rd_operations': 'int', 'failed_wr_operations': 'int', 'failed_flush_operations': 'int', 'invalid_rd_operations': 'int', - 'invalid_wr_operations': 'int', 'invalid_flush_operations': 'int' } } + 'invalid_wr_operations': 'int', 'invalid_flush_operations': 'int', + 'account_invalid': 'bool', 'account_failed': 'bool' } } ## # @BlockStats: @@ -1436,6 +1443,12 @@ # (default: enospc) # @read-only: #optional whether the block device should be read-only # (default: false) +# @stats-account-invalid: #optional whether to include invalid +# operations when computing last access statistics +# (default: true) (Since 2.5) +# @stats-account-failed: #optional whether to include failed +# operations when computing latency and last +# access statistics (default: true) (Since 2.5) # @detect-zeroes: #optional detect and optimize zero writes (Since 2.1) # (default: off) # @@ -1451,6 +1464,8 @@ '*rerror': 'BlockdevOnError', '*werror': 'BlockdevOnError', '*read-only': 'bool', + '*stats-account-invalid': 'bool', + '*stats-account-failed': 'bool', '*detect-zeroes': 'BlockdevDetectZeroesOptions' } } ## diff --git a/qmp-commands.hx b/qmp-commands.hx index 4985e3b..d87bc6c 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2528,6 +2528,11 @@ Each json-object contain the following: (json-int) - "invalid_flush_operations": number of invalid flush operations (json-int) + - "account_invalid": whether invalid operations are included in + the last access statistics (json-bool) + - "account_failed": whether failed operations are included in the + latency and last access statistics + (json-bool) - "parent": Contains recursively the statistics of the underlying protocol (e.g. the host file for a qcow2 image). If there is no underlying protocol, this field is omitted @@ -2554,7 +2559,9 @@ Example: "flush_operations":61, "rd_merged":0, "wr_merged":0, - "idle_time_ns":2953431879 + "idle_time_ns":2953431879, + "account_invalid":true, + "account_failed":false } }, "supports_stats":true, @@ -2570,7 +2577,9 @@ Example: "flush_total_times_ns":49653, "rd_merged":0, "wr_merged":0, - "idle_time_ns":2953431879 + "idle_time_ns":2953431879, + "account_invalid":true, + "account_failed":false } }, { @@ -2587,7 +2596,9 @@ Example: "rd_total_times_ns":0 "flush_total_times_ns":0, "rd_merged":0, - "wr_merged":0 + "wr_merged":0, + "account_invalid":false, + "account_failed":false } }, { @@ -2604,7 +2615,9 @@ Example: "rd_total_times_ns":0 "flush_total_times_ns":0, "rd_merged":0, - "wr_merged":0 + "wr_merged":0, + "account_invalid":false, + "account_failed":false } }, { @@ -2621,7 +2634,9 @@ Example: "rd_total_times_ns":0 "flush_total_times_ns":0, "rd_merged":0, - "wr_merged":0 + "wr_merged":0, + "account_invalid":false, + "account_failed":false } } ]