From patchwork Mon Jun 24 06:49:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 11012409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C49B13AF for ; Mon, 24 Jun 2019 06:51:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BB4928ABA for ; Mon, 24 Jun 2019 06:51:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F14228B0D; Mon, 24 Jun 2019 06:51:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B47328ABA for ; Mon, 24 Jun 2019 06:51:30 +0000 (UTC) Received: from localhost ([::1]:48302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfIp7-00063A-Me for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 02:51:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46152) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfIna-0004cA-2n for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfInX-0003Cq-Aw for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:53 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:40655) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfInU-000301-Cd for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:49 -0400 Received: by mail-pg1-x541.google.com with SMTP id w10so6561444pgj.7 for ; Sun, 23 Jun 2019 23:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KK+YGEA0uSCnrX+5Jr/a/tEimY4fAc66vitG4iWRbas=; b=IfDy3cysG+tq1Ob4DJ7brxU8iHWSBgVk2XYJ2WPZLQKtOraT6xJqxCw/udiT5Ohau1 sTUUcMwmZocDs72CZ5Vy9FoLTBF7bMfoZS6VeY6sFa0Jz15dk6Pz2kz7DWlLDx0uUs/r HHgpoPXtwC6BMt2iLyvAKKpBMY70i7zFUX8l3xYVn//moEqT5oG+tZtBNnpIK4Cu6wAF db52lFEDtEgxLlqSJ0Whr+kgUF93oaU4OSAw9eUx1k6qg3uVMIm5hVN8PZ/j3RUf1n5+ a4u5pYhjyMuuXRSuFow6nQ0IFB2ewS7E11fL87BIcBvSw12UYA83L+ob4f80LDQWr5V7 sIpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KK+YGEA0uSCnrX+5Jr/a/tEimY4fAc66vitG4iWRbas=; b=ghcHcMSAIMxC+VguNU1BpFwmBRBuqaN4E8EhluWro7ocrQmtrPvAuQ73u0O+4+gyV6 YWjP7fHyc10WryDgYakK1VIZFat5B6M5sD2e11mQ2pmJp9tWzmOlpNSSjFfJXUT4OZzH jUXWhnowiV7uXSf352Df2KoVQw0Ge8XhDT6FPaXBop1DU1+TMFGMNIGTAohSTLawDcfu BJkck8F6ePunNnIaI2Lgmyh2wiJPfrGl5sUztqIME4wrNm7muAMGlDk7RCLCVYT5k6KT EG6ZgB5HZa/j7qESPX5kgkR3UcU4SGy+mlW2jaU8g5jv+syaj/oYNdk4AMg+zu0JNJhM +NTQ== X-Gm-Message-State: APjAAAVfjZZMIGBFim4PxpkwGx/YLlg/utXasX/2DqfQkiHGHU7qYIF4 kmzAkFWIAtKfFS39vN6GR8UCYg== X-Google-Smtp-Source: APXvYqx2FpgsyMhBTG1p/95UuwZbslrZlNum1M4oVHZcS5LyxNlepvtrJUj6wxDe6N7sbSCjTH+hwA== X-Received: by 2002:a63:f146:: with SMTP id o6mr30655438pgk.179.1561358985979; Sun, 23 Jun 2019 23:49:45 -0700 (PDT) Received: from always-ThinkPad-T480.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id n17sm17734259pfq.182.2019.06.23.23.49.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Jun 2019 23:49:45 -0700 (PDT) From: zhenwei pi To: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com Date: Mon, 24 Jun 2019 14:49:34 +0800 Message-Id: <1561358976-5183-2-git-send-email-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561358976-5183-1-git-send-email-pizhenwei@bytedance.com> References: <1561358976-5183-1-git-send-email-pizhenwei@bytedance.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH V2 1/3] block/accounting: rename struct BlockLatencyHistogram X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, qemu-block@nongnu.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, pizhenwei@bytedance.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Rename struct BlockLatencyHistogram to BlockHistogram, and rename related functions. Make this struct and functions be common, they can be used widely. Signed-off-by: zhenwei pi Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/accounting.c | 44 +++++++++++++++++++++++++++----------------- block/qapi.c | 23 +++++++++++------------ include/block/accounting.h | 8 ++++---- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/block/accounting.c b/block/accounting.c index 70a3d9a426..d210a73fe9 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -94,13 +94,14 @@ void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie, cookie->type = type; } -/* block_latency_histogram_compare_func: +/** + * block_histogram_compare_func: * Compare @key with interval [@it[0], @it[1]). * Return: -1 if @key < @it[0] * 0 if @key in [@it[0], @it[1]) * +1 if @key >= @it[1] */ -static int block_latency_histogram_compare_func(const void *key, const void *it) +static int block_histogram_compare_func(const void *key, const void *it) { uint64_t k = *(uint64_t *)key; uint64_t a = ((uint64_t *)it)[0]; @@ -109,8 +110,7 @@ static int block_latency_histogram_compare_func(const void *key, const void *it) return k < a ? -1 : (k < b ? 0 : 1); } -static void block_latency_histogram_account(BlockLatencyHistogram *hist, - int64_t latency_ns) +static void block_histogram_account(BlockHistogram *hist, int64_t val) { uint64_t *pos; @@ -120,28 +120,26 @@ static void block_latency_histogram_account(BlockLatencyHistogram *hist, } - if (latency_ns < hist->boundaries[0]) { + if (val < hist->boundaries[0]) { hist->bins[0]++; return; } - if (latency_ns >= hist->boundaries[hist->nbins - 2]) { + if (val >= hist->boundaries[hist->nbins - 2]) { hist->bins[hist->nbins - 1]++; return; } - pos = bsearch(&latency_ns, hist->boundaries, hist->nbins - 2, + pos = bsearch(&val, hist->boundaries, hist->nbins - 2, sizeof(hist->boundaries[0]), - block_latency_histogram_compare_func); + block_histogram_compare_func); assert(pos != NULL); hist->bins[pos - hist->boundaries + 1]++; } -int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type, - uint64List *boundaries) +static int block_histogram_set(BlockHistogram *hist, uint64List *boundaries) { - BlockLatencyHistogram *hist = &stats->latency_histogram[type]; uint64List *entry; uint64_t *ptr; uint64_t prev = 0; @@ -170,15 +168,27 @@ int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type, return 0; } +static void block_histogram_clear(BlockHistogram *hist) +{ + g_free(hist->bins); + g_free(hist->boundaries); + memset(hist, 0, sizeof(*hist)); +} + +int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type, + uint64List *boundaries) +{ + BlockHistogram *hist = &stats->latency_histogram[type]; + + return block_histogram_set(hist, boundaries); +} + void block_latency_histograms_clear(BlockAcctStats *stats) { int i; for (i = 0; i < BLOCK_MAX_IOTYPE; i++) { - BlockLatencyHistogram *hist = &stats->latency_histogram[i]; - g_free(hist->bins); - g_free(hist->boundaries); - memset(hist, 0, sizeof(*hist)); + block_histogram_clear(&stats->latency_histogram[i]); } } @@ -204,8 +214,8 @@ static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie, stats->nr_ops[cookie->type]++; } - block_latency_histogram_account(&stats->latency_histogram[cookie->type], - latency_ns); + block_histogram_account(&stats->latency_histogram[cookie->type], + latency_ns); if (!failed || stats->account_failed) { stats->total_time_ns[cookie->type] += latency_ns; diff --git a/block/qapi.c b/block/qapi.c index 917435f022..9d9b2f1927 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -415,9 +415,8 @@ static uint64List *uint64_list(uint64_t *list, int size) return out_list; } -static void bdrv_latency_histogram_stats(BlockLatencyHistogram *hist, - bool *not_null, - BlockLatencyHistogramInfo **info) +static void bdrv_histogram_stats(BlockHistogram *hist, bool *not_null, + BlockLatencyHistogramInfo **info) { *not_null = hist->bins != NULL; if (*not_null) { @@ -494,15 +493,15 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) block_acct_queue_depth(ts, BLOCK_ACCT_WRITE); } - bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_READ], - &ds->has_rd_latency_histogram, - &ds->rd_latency_histogram); - bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_WRITE], - &ds->has_wr_latency_histogram, - &ds->wr_latency_histogram); - bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUSH], - &ds->has_flush_latency_histogram, - &ds->flush_latency_histogram); + bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_READ], + &ds->has_rd_latency_histogram, + &ds->rd_latency_histogram); + bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_WRITE], + &ds->has_wr_latency_histogram, + &ds->wr_latency_histogram); + bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUSH], + &ds->has_flush_latency_histogram, + &ds->flush_latency_histogram); } static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, diff --git a/include/block/accounting.h b/include/block/accounting.h index d1f67b10dd..270fddb69c 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -46,7 +46,7 @@ struct BlockAcctTimedStats { QSLIST_ENTRY(BlockAcctTimedStats) entries; }; -typedef struct BlockLatencyHistogram { +typedef struct BlockHistogram { /* The following histogram is represented like this: * * 5| * @@ -57,7 +57,7 @@ typedef struct BlockLatencyHistogram { * +------------------ * 10 50 100 * - * BlockLatencyHistogram histogram = { + * BlockHistogram histogram = { * .nbins = 4, * .boundaries = {10, 50, 100}, * .bins = {3, 1, 5, 2}, @@ -74,7 +74,7 @@ typedef struct BlockLatencyHistogram { uint64_t *boundaries; /* @nbins-1 numbers here (all boundaries, except 0 and +inf) */ uint64_t *bins; -} BlockLatencyHistogram; +} BlockHistogram; struct BlockAcctStats { QemuMutex lock; @@ -88,7 +88,7 @@ struct BlockAcctStats { QSLIST_HEAD(, BlockAcctTimedStats) intervals; bool account_invalid; bool account_failed; - BlockLatencyHistogram latency_histogram[BLOCK_MAX_IOTYPE]; + BlockHistogram latency_histogram[BLOCK_MAX_IOTYPE]; }; typedef struct BlockAcctCookie { From patchwork Mon Jun 24 06:49:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 11012413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24C5276 for ; Mon, 24 Jun 2019 06:53:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14D0428ABA for ; Mon, 24 Jun 2019 06:53:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08D2B28B16; Mon, 24 Jun 2019 06:53:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9022B28ABA for ; Mon, 24 Jun 2019 06:53:45 +0000 (UTC) Received: from localhost ([::1]:48324 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfIrI-0000Bu-Ul for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 02:53:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46177) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfInc-0004dF-TL for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfIna-0003Hl-0Q for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:56 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:37952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfInX-00035t-Rf for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:52 -0400 Received: by mail-pl1-x642.google.com with SMTP id g4so6301971plb.5 for ; Sun, 23 Jun 2019 23:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h8g/nC6vUT95D9nx3c9BGLOpS2Xrlhhb+4JSssXi+BA=; b=IFtiLPEbF3y2XTvShN4yk9BIFbZWnS9SjMG5Pd1YD3wACDtubaRGgQ4ZR/WhZVHr5d b8y7kdeydwwJ64+c8YHOF+JQbgzT982Nm64ctTgSNHtTvLg/2BmRteA5LegtaOplOml7 W9LDTNYyZBZiLz4OEscdiiL5G/Rjdo9/SdWkqdF+jApf7R/EmGjggm5B007TYqK/iS6d Ppr7FyNIcMfZfscKnl1w6y+v+a+dbv73HJ0c4uNPX0eFpDmlo0jk0ProoELvARwEhMbx 8uRJ0sNnKbIEqtcRHowWQX9/yCM3jiWdhNnkL/7ZXcRmqVyZQ7mx8C+Cm9Mk80HK5UHL qT1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h8g/nC6vUT95D9nx3c9BGLOpS2Xrlhhb+4JSssXi+BA=; b=pA9dg3VN6ZPmMPknCblVYfG3D7Qu/xexbD4dPAVlmRhZ3K7nnklQ7RALijHnTRoWDV 4ZUUwdcyIATNKnZuc1UzIBxL27HEN+kDyi5jsEUE17fTZ4SwaEA8SRL3i1RYuJheJbzj ld/alcq4S+LqPO52fcp5qGsi0jdiY3owQdJXYiu28EVP9teJ+78v0vcgMuxFtiZphhc/ BvCmsJd+sNkSjICYwhogZ/agEShwAXoy2N+emd/Tg0hy7Ehdq8EA2SdkW5ko97CuQZb4 B4GuxRzM+0JerdR34ATOVmRvbpru+CrXhH/gJC+xug933Fd7y2yoIvI1IXYhSzwG+qMt GQTg== X-Gm-Message-State: APjAAAXmV1kOJbQ78i24rRS6akqcCMAbjOMB5GMxuqjLBVO5sMjcjkAa ENy+/dzxVSTP7yqLjp2Axa3BnQ== X-Google-Smtp-Source: APXvYqwpCmcMvTfnVXBoxY1paM6DWUYbBjd6EZTR+7lZ2h55ByO/PJsnEatwV85Nzq5uwxSlWXYnOQ== X-Received: by 2002:a17:902:2ae7:: with SMTP id j94mr62003836plb.270.1561358988845; Sun, 23 Jun 2019 23:49:48 -0700 (PDT) Received: from always-ThinkPad-T480.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id n17sm17734259pfq.182.2019.06.23.23.49.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Jun 2019 23:49:48 -0700 (PDT) From: zhenwei pi To: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com Date: Mon, 24 Jun 2019 14:49:35 +0800 Message-Id: <1561358976-5183-3-git-send-email-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561358976-5183-1-git-send-email-pizhenwei@bytedance.com> References: <1561358976-5183-1-git-send-email-pizhenwei@bytedance.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH V2 2/3] block/accounting: introduce block size histogram X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, qemu-block@nongnu.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, pizhenwei@bytedance.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce block size histogram statics for block devices. For read/write/flush operation type, the block size region [0, +inf) is divided into subregions by several points. It works like block latency histogram. Signed-off-by: zhenwei pi Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/accounting.c | 18 ++++++++++++++++++ include/block/accounting.h | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/block/accounting.c b/block/accounting.c index d210a73fe9..3a1e41a971 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -192,6 +192,22 @@ void block_latency_histograms_clear(BlockAcctStats *stats) } } +int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type, + uint64List *boundaries) +{ + BlockHistogram *hist = &stats->size_histogram[type]; + + return block_histogram_set(hist, boundaries); +} + +void block_size_histograms_clear(BlockAcctStats *stats) +{ + int i; + + for (i = 0; i < BLOCK_MAX_IOTYPE; i++) { + block_histogram_clear(&stats->size_histogram[i]); + } +} static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie, bool failed) { @@ -216,6 +232,8 @@ static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie, block_histogram_account(&stats->latency_histogram[cookie->type], latency_ns); + block_histogram_account(&stats->size_histogram[cookie->type], + cookie->bytes); if (!failed || stats->account_failed) { stats->total_time_ns[cookie->type] += latency_ns; diff --git a/include/block/accounting.h b/include/block/accounting.h index 270fddb69c..0fbba64408 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -89,6 +89,7 @@ struct BlockAcctStats { bool account_invalid; bool account_failed; BlockHistogram latency_histogram[BLOCK_MAX_IOTYPE]; + BlockHistogram size_histogram[BLOCK_MAX_IOTYPE]; }; typedef struct BlockAcctCookie { @@ -117,5 +118,7 @@ double block_acct_queue_depth(BlockAcctTimedStats *stats, int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type, uint64List *boundaries); void block_latency_histograms_clear(BlockAcctStats *stats); - +int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type, + uint64List *boundaries); +void block_size_histograms_clear(BlockAcctStats *stats); #endif From patchwork Mon Jun 24 06:49:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 11012411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAE8476 for ; Mon, 24 Jun 2019 06:53:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9FFF28ABA for ; Mon, 24 Jun 2019 06:53:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDED628B0D; Mon, 24 Jun 2019 06:53:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ECCA128ABA for ; Mon, 24 Jun 2019 06:53:10 +0000 (UTC) Received: from localhost ([::1]:48322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfIqk-00089y-BE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 02:53:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46208) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfIng-0004eE-BT for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:50:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfIne-0003OI-8c for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:50:00 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:41331) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfIna-0003Ef-Cb for qemu-devel@nongnu.org; Mon, 24 Jun 2019 02:49:56 -0400 Received: by mail-pg1-x544.google.com with SMTP id y72so6564519pgd.8 for ; Sun, 23 Jun 2019 23:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FJXIlK+69aNv2aDNGdU+aI20EoP4M3xQmlBMOMtoYhk=; b=V2uuhN95tWvrfysvyAvayGH3tr68H7Zu9XfwC5tIVZliM3zJNmdkSEG9cqC1nUBVXx WVtjx3RIDaIjH9osIBjGl6oaNH/mnOMtO0nha0lhAbjw80bND3bAIsUCSZ78TTk3KLB9 nQ3cP/uQfZvKeZXFKJqmvClZGDoJ2p6K8ruG4IiLSakualq9q0fFVfqvQ9Y7KzVjgWWJ zW7Yrhd91PiJVQFIPoUrsoQLQNdGq/0t2wOKCGKMmW1+hMya4XO+rqznnsbFxGVcEtvS EuV35Y87OLiceabO6ArqcjgmRRVWTt9cx2IEFu9GwfCmrRPA4155qGIMI9OqJF6Hx73h B3pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FJXIlK+69aNv2aDNGdU+aI20EoP4M3xQmlBMOMtoYhk=; b=Obzv4GsxU32G/jj297b7OqHe5h8p0SwNrh+wMXCIEUUW43XvNBsXfxPKB0NZmmt3Ae K5ODl2akcNtxAPm1zGArWIuIJnBEI+nOdHx3AnopnkstQI0Q2k0FKb5J9zWDgF5bGVjo fuAEb9N3+2jzZon4qln0BTUcXeu/5MW6URdWzXJsQAH1BgGnNAr+dAL7jo6OUKJNGk+i 6cUq/qEXPj0cJLqn4rwNwwPmAey0F0cSlr2EDLdDlilQZJLlqpHpaiCBQIw8S9QWo2m/ HMIQzNlfflbpeq0aRmPeIvNN1+ftGQK2XuHYpDD12O0Y/Ry0X7yGdewBX++jeKMlPaZp DODQ== X-Gm-Message-State: APjAAAWBReBi0mkw9JynByjpBUAcq2qbSH5DNQk7UuKMS21Y/iVVLtzN eDMICG2xMQwW3jXThAJKoxjGvg== X-Google-Smtp-Source: APXvYqykJlUnSCIwO+qIMX1OxcjHqeUoZvgwW+CQvV/5XbX6rBZW36DgYnYMgyTqJs+Zhu74AbB6DQ== X-Received: by 2002:a63:8b41:: with SMTP id j62mr17149606pge.299.1561358991667; Sun, 23 Jun 2019 23:49:51 -0700 (PDT) Received: from always-ThinkPad-T480.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id n17sm17734259pfq.182.2019.06.23.23.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Jun 2019 23:49:51 -0700 (PDT) From: zhenwei pi To: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com Date: Mon, 24 Jun 2019 14:49:36 +0800 Message-Id: <1561358976-5183-4-git-send-email-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561358976-5183-1-git-send-email-pizhenwei@bytedance.com> References: <1561358976-5183-1-git-send-email-pizhenwei@bytedance.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH V2 3/3] qapi: make block histogram interface common X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, qemu-block@nongnu.org, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, pizhenwei@bytedance.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Modify command 'block-latency-histogram-set' to 'block-histogram-set' and modify struct 'BlockLatencyHistogramInfo' to struct 'BlockHistogramInfo', this makes block histogram interface common to use. Currently 'BlockHistogramType' supports 'latency', it works as same as the old command 'block-latency-histogram-set'. New enum 'size' allows QEMU to fill histogram by block I/O size in byte. Signed-off-by: zhenwei pi Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qapi.c | 11 +++++- blockdev.c | 33 +++++++++++++---- qapi/block-core.json | 101 +++++++++++++++++++++++++++++++-------------------- 3 files changed, 95 insertions(+), 50 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 9d9b2f1927..c778b2c376 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -416,11 +416,11 @@ static uint64List *uint64_list(uint64_t *list, int size) } static void bdrv_histogram_stats(BlockHistogram *hist, bool *not_null, - BlockLatencyHistogramInfo **info) + BlockHistogramInfo **info) { *not_null = hist->bins != NULL; if (*not_null) { - *info = g_new0(BlockLatencyHistogramInfo, 1); + *info = g_new0(BlockHistogramInfo, 1); (*info)->boundaries = uint64_list(hist->boundaries, hist->nbins - 1); (*info)->bins = uint64_list(hist->bins, hist->nbins); @@ -502,6 +502,13 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) bdrv_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUSH], &ds->has_flush_latency_histogram, &ds->flush_latency_histogram); + bdrv_histogram_stats(&stats->size_histogram[BLOCK_ACCT_READ], + &ds->has_rd_size_histogram, &ds->rd_size_histogram); + bdrv_histogram_stats(&stats->size_histogram[BLOCK_ACCT_WRITE], + &ds->has_wr_size_histogram, &ds->wr_size_histogram); + bdrv_histogram_stats(&stats->size_histogram[BLOCK_ACCT_FLUSH], + &ds->has_flush_size_histogram, + &ds->flush_size_histogram); } static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, diff --git a/blockdev.c b/blockdev.c index 5d6a13dea9..82240ae8c5 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4507,8 +4507,9 @@ void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread, aio_context_release(old_context); } -void qmp_block_latency_histogram_set( +void qmp_block_histogram_set( const char *id, + BlockHistogramType type, bool has_boundaries, uint64List *boundaries, bool has_boundaries_read, uint64List *boundaries_read, bool has_boundaries_write, uint64List *boundaries_write, @@ -4517,24 +4518,42 @@ void qmp_block_latency_histogram_set( { BlockBackend *blk = qmp_get_blk(NULL, id, errp); BlockAcctStats *stats; + void (*clear_func)(BlockAcctStats *stats); + int (*set_func)(BlockAcctStats *stats, enum BlockAcctType type, + uint64List *boundaries); int ret; if (!blk) { return; } + switch (type) { + case BLOCK_HISTOGRAM_TYPE_LATENCY: { + clear_func = block_latency_histograms_clear; + set_func = block_latency_histogram_set; + break; + } + case BLOCK_HISTOGRAM_TYPE_SIZE: { + clear_func = block_size_histograms_clear; + set_func = block_size_histogram_set; + break; + } + default: + error_setg(errp, "Unsupported block histogram type"); + return; + } + stats = blk_get_stats(blk); if (!has_boundaries && !has_boundaries_read && !has_boundaries_write && !has_boundaries_flush) { - block_latency_histograms_clear(stats); + clear_func(stats); return; } if (has_boundaries || has_boundaries_read) { - ret = block_latency_histogram_set( - stats, BLOCK_ACCT_READ, + ret = set_func(stats, BLOCK_ACCT_READ, has_boundaries_read ? boundaries_read : boundaries); if (ret) { error_setg(errp, "Device '%s' set read boundaries fail", id); @@ -4543,8 +4562,7 @@ void qmp_block_latency_histogram_set( } if (has_boundaries || has_boundaries_write) { - ret = block_latency_histogram_set( - stats, BLOCK_ACCT_WRITE, + ret = set_func(stats, BLOCK_ACCT_WRITE, has_boundaries_write ? boundaries_write : boundaries); if (ret) { error_setg(errp, "Device '%s' set write boundaries fail", id); @@ -4553,8 +4571,7 @@ void qmp_block_latency_histogram_set( } if (has_boundaries || has_boundaries_flush) { - ret = block_latency_histogram_set( - stats, BLOCK_ACCT_FLUSH, + ret = set_func(stats, BLOCK_ACCT_FLUSH, has_boundaries_flush ? boundaries_flush : boundaries); if (ret) { error_setg(errp, "Device '%s' set flush boundaries fail", id); diff --git a/qapi/block-core.json b/qapi/block-core.json index 0d43d4f37c..b3b8d714d3 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -533,12 +533,12 @@ 'flags': ['Qcow2BitmapInfoFlags'] } } ## -# @BlockLatencyHistogramInfo: +# @BlockHistogramInfo: # -# Block latency histogram. +# Block histogram. # -# @boundaries: list of interval boundary values in nanoseconds, all greater -# than zero and in ascending order. +# @boundaries: list of interval boundary values, all greater than zero and in +# ascending order. # For example, the list [10, 50, 100] produces the following # histogram intervals: [0, 10), [10, 50), [50, 100), [100, +inf). # @@ -555,57 +555,72 @@ # +------------------ # 10 50 100 # -# Since: 4.0 +# Since: 4.1 ## -{ 'struct': 'BlockLatencyHistogramInfo', +{ 'struct': 'BlockHistogramInfo', 'data': {'boundaries': ['uint64'], 'bins': ['uint64'] } } ## -# @block-latency-histogram-set: +# @BlockHistogramType: # -# Manage read, write and flush latency histograms for the device. +# An enumeration of block histogram type. # -# If only @id parameter is specified, remove all present latency histograms -# for the device. Otherwise, add/reset some of (or all) latency histograms. +# @latency: The histogram is filled by block I/O latency in nanosecond. +# +# @size: The histogram is filled by block I/O size in byte. +# +# Since: 4.1 +## +{ 'enum': 'BlockHistogramType', 'data': [ 'latency', 'size' ] } + +## +# @block-histogram-set: +# +# Manage read, write and flush @BlockHistogramType histograms for the device. +# +# If only @id and @type parameter are specified, remove all present @type +# histograms for the device. Otherwise, add/reset some of (or all) @type +# histograms. # # @id: The name or QOM path of the guest device. # +# @type: The type @BlockHistogramType of histogram. +# # @boundaries: list of interval boundary values (see description in -# BlockLatencyHistogramInfo definition). If specified, all -# latency histograms are removed, and empty ones created for all -# io types with intervals corresponding to @boundaries (except for -# io types, for which specific boundaries are set through the -# following parameters). +# BlockHistogramInfo definition). If specified, all histograms +# are removed, and empty ones created for all io types with +# intervals corresponding to @boundaries (except for io types +# for which specific boundaries are set through the following +# parameters). # -# @boundaries-read: list of interval boundary values for read latency -# histogram. If specified, old read latency histogram is -# removed, and empty one created with intervals -# corresponding to @boundaries-read. The parameter has higher -# priority then @boundaries. +# @boundaries-read: list of interval boundary values for read histogram. If +# specified, old read histogram is removed, and empty one +# created with intervals corresponding to @boundaries-read. +# The parameter has higher priority then @boundaries. # -# @boundaries-write: list of interval boundary values for write latency -# histogram. +# @boundaries-write: list of interval boundary values for write histogram. # -# @boundaries-flush: list of interval boundary values for flush latency -# histogram. +# @boundaries-flush: list of interval boundary values for flush histogram. # # Returns: error if device is not found or any boundary arrays are invalid. # -# Since: 4.0 +# Since: 4.1 # -# Example: set new histograms for all io types with intervals +# Example: set new latency histograms for all io types with intervals # [0, 10), [10, 50), [50, 100), [100, +inf): # -# -> { "execute": "block-latency-histogram-set", +# -> { "execute": "block-histogram-set", # "arguments": { "id": "drive0", +# "type":"latency", # "boundaries": [10, 50, 100] } } # <- { "return": {} } # -# Example: set new histogram only for write, other histograms will remain -# not changed (or not created): +# Example: set new latency histogram only for write, other histograms will +# remain not changed (or not created): # -# -> { "execute": "block-latency-histogram-set", +# -> { "execute": "block-histogram-set", # "arguments": { "id": "drive0", +# "type":"latency", # "boundaries-write": [10, 50, 100] } } # <- { "return": {} } # @@ -613,20 +628,23 @@ # read, flush: [0, 10), [10, 50), [50, 100), [100, +inf) # write: [0, 1000), [1000, 5000), [5000, +inf) # -# -> { "execute": "block-latency-histogram-set", +# -> { "execute": "block-histogram-set", # "arguments": { "id": "drive0", +# "type":"latency", # "boundaries": [10, 50, 100], # "boundaries-write": [1000, 5000] } } # <- { "return": {} } # # Example: remove all latency histograms: # -# -> { "execute": "block-latency-histogram-set", -# "arguments": { "id": "drive0" } } +# -> { "execute": "block-histogram-set", +# "arguments": { "id": "drive0" +# "type":"latency"} } # <- { "return": {} } ## -{ 'command': 'block-latency-histogram-set', +{ 'command': 'block-histogram-set', 'data': {'id': 'str', + 'type': 'BlockHistogramType', '*boundaries': ['uint64'], '*boundaries-read': ['uint64'], '*boundaries-write': ['uint64'], @@ -912,11 +930,11 @@ # @timed_stats: Statistics specific to the set of previously defined # intervals of time (Since 2.5) # -# @rd_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) +# @rd_latency_histogram: @BlockHistogramInfo. (Since 4.1) # -# @wr_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) +# @wr_latency_histogram: @BlockHistogramInfo. (Since 4.1) # -# @flush_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) +# @flush_latency_histogram: @BlockHistogramInfo. (Since 4.1) # # Since: 0.14.0 ## @@ -931,9 +949,12 @@ 'invalid_wr_operations': 'int', 'invalid_flush_operations': 'int', 'account_invalid': 'bool', 'account_failed': 'bool', 'timed_stats': ['BlockDeviceTimedStats'], - '*rd_latency_histogram': 'BlockLatencyHistogramInfo', - '*wr_latency_histogram': 'BlockLatencyHistogramInfo', - '*flush_latency_histogram': 'BlockLatencyHistogramInfo' } } + '*rd_latency_histogram': 'BlockHistogramInfo', + '*wr_latency_histogram': 'BlockHistogramInfo', + '*flush_latency_histogram': 'BlockHistogramInfo', + '*rd_size_histogram': 'BlockHistogramInfo', + '*wr_size_histogram': 'BlockHistogramInfo', + '*flush_size_histogram': 'BlockHistogramInfo' } } ## # @BlockStats: