From nobody Sat Apr 27 21:19:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1562578468; cv=none; d=zoho.com; s=zohoarc; b=bWRQLaBHSqgRM9fXTa/ayJOfp0jgAkZyw0Haae8pham3L8zgKWw0nspr/jaBdSObqtZ/5n7f9DR9opJCCJu37anQBgyBU2SMhd7i/9Ws8ORRyTK/aWCPqR7Tyy+xWiRiYqee2Anz7Z3fVIeX09vGwXXpViFAk1yuVtSHLquS/BI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562578468; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KK+YGEA0uSCnrX+5Jr/a/tEimY4fAc66vitG4iWRbas=; b=Q1DOO9DEXCj26YVB7abPeQ5x6AvaRe62d7BmvhT+Z0tpL/kcY5gS/sPlZVCSZ/p8ewUvOSoX0/HvC+qnIHhvHutYeTxm8oT5JLKqUT9RFfPMQoo3vV/JtMQVrvKLxx2YBWpN7vULMEKhzfQ4uRbxsStkp98SlLpemFla5BA9EEo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562578468488590.6954792054086; Mon, 8 Jul 2019 02:34:28 -0700 (PDT) Received: from localhost ([::1]:39780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkQ2Q-0001ss-G4 for importer@patchew.org; Mon, 08 Jul 2019 05:34:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47916) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkQ0y-0000so-Vf for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkQ0w-00056i-O0 for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:52 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:46013) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkQ0u-0004zF-OT for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:50 -0400 Received: by mail-pf1-x441.google.com with SMTP id r1so7283631pfq.12 for ; Mon, 08 Jul 2019 02:32:38 -0700 (PDT) Received: from always-ThinkPad-T480.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id q7sm236504pff.2.2019.07.08.02.32.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jul 2019 02:32:37 -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=N9cPepx5lucgL54X7VFcnhf4ZIB1DTXIsvsUmogTHCvZ0nqjL53pL9IcJm9kNwU95t DNTqQG9pdm8RJhaCAwJBlvKE7Lnz8oHSiiXOB/H7RFIkcKSb6ct89vWSCRPvQG9Jn5O4 VHz9ojYSItRZdQZjIUnpXAW29YmzDJ/X2zLNYurf+dYZ8uYpZbWd1XYG1J3rijL6UjQJ ZxA50pYLuic4t8UkZmVEHSKdAXaUPvONk0nKxbpLuYuVVgzy42YHNEqbeTPW4oW4Vx6G AOqKogMfDSaVkDPnFAMbMf1TA6I4uKE2I/0vdkfF0vBs+PGZ/P6HidgB3SNs4Aple8s6 OLmw== 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=uGwAqHHaah89Rn3IJnD++LPy1T+7oiwyxXSXPwfBS//7PsncSmBPXGsrDw9Ma566or U/t8XS/R9u0T4QE0elUJ7ObMutAIM5h+VjUUw+mftE+PLchGgVmRjrTxu97TO1kOwWua R74TXjJjrjk/2JDX+9B7nbXSBJF4KEt1gXu06WRGmAYSkEavQunh9EKm4dz7mN9TtOCJ rOAKnK1HleQ05lXJxCOavw7XEwvfc0mSzWBAqisKfD/RVLJt2BiTaXiKWtiCJ0emeoE7 vrsKIHv7TVHye3rGz3ioyPjKkTlM/5+Uj7MBZiSwyMUMw3JrYCKPVhBT/H/b0oH5tv1y A1gg== X-Gm-Message-State: APjAAAV+uniRr081iRH9zWwjxewhFXXcgsdYEJkaCavhYHL+q/nBz6h0 ax+X/fv5mlJwsY/sGKYj2X8fwQ== X-Google-Smtp-Source: APXvYqzhCC+trjTr9MSTCg3rKN6uqQEbr8x44acp9RL7Y2CyTPpir6S33Jryp23n3jHBRTi4Uc/nyw== X-Received: by 2002:a63:e5a:: with SMTP id 26mr21306749pgo.3.1562578357839; Mon, 08 Jul 2019 02:32:37 -0700 (PDT) From: zhenwei pi To: kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com Date: Mon, 8 Jul 2019 17:32:27 +0800 Message-Id: <1562578349-12333-2-git-send-email-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1562578349-12333-1-git-send-email-pizhenwei@bytedance.com> References: <1562578349-12333-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::441 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: qemu-devel@nongnu.org, qemu-block@nongnu.org, pizhenwei@bytedance.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, BlockAcctC= ookie *cookie, cookie->type =3D type; } =20 -/* 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 >=3D @it[1] */ -static int block_latency_histogram_compare_func(const void *key, const voi= d *it) +static int block_histogram_compare_func(const void *key, const void *it) { uint64_t k =3D *(uint64_t *)key; uint64_t a =3D ((uint64_t *)it)[0]; @@ -109,8 +110,7 @@ static int block_latency_histogram_compare_func(const v= oid *key, const void *it) return k < a ? -1 : (k < b ? 0 : 1); } =20 -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; =20 @@ -120,28 +120,26 @@ static void block_latency_histogram_account(BlockLate= ncyHistogram *hist, } =20 =20 - if (latency_ns < hist->boundaries[0]) { + if (val < hist->boundaries[0]) { hist->bins[0]++; return; } =20 - if (latency_ns >=3D hist->boundaries[hist->nbins - 2]) { + if (val >=3D hist->boundaries[hist->nbins - 2]) { hist->bins[hist->nbins - 1]++; return; } =20 - pos =3D bsearch(&latency_ns, hist->boundaries, hist->nbins - 2, + pos =3D bsearch(&val, hist->boundaries, hist->nbins - 2, sizeof(hist->boundaries[0]), - block_latency_histogram_compare_func); + block_histogram_compare_func); assert(pos !=3D NULL); =20 hist->bins[pos - hist->boundaries + 1]++; } =20 -int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType = type, - uint64List *boundaries) +static int block_histogram_set(BlockHistogram *hist, uint64List *boundarie= s) { - BlockLatencyHistogram *hist =3D &stats->latency_histogram[type]; uint64List *entry; uint64_t *ptr; uint64_t prev =3D 0; @@ -170,15 +168,27 @@ int block_latency_histogram_set(BlockAcctStats *stats= , enum BlockAcctType type, return 0; } =20 +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 =3D &stats->latency_histogram[type]; + + return block_histogram_set(hist, boundaries); +} + void block_latency_histograms_clear(BlockAcctStats *stats) { int i; =20 for (i =3D 0; i < BLOCK_MAX_IOTYPE; i++) { - BlockLatencyHistogram *hist =3D &stats->latency_histogram[i]; - g_free(hist->bins); - g_free(hist->boundaries); - memset(hist, 0, sizeof(*hist)); + block_histogram_clear(&stats->latency_histogram[i]); } } =20 @@ -204,8 +214,8 @@ static void block_account_one_io(BlockAcctStats *stats,= BlockAcctCookie *cookie, stats->nr_ops[cookie->type]++; } =20 - block_latency_histogram_account(&stats->latency_histogram[cookie->type= ], - latency_ns); + block_histogram_account(&stats->latency_histogram[cookie->type], + latency_ns); =20 if (!failed || stats->account_failed) { stats->total_time_ns[cookie->type] +=3D 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; } =20 -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 =3D hist->bins !=3D 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); } =20 - 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_WRIT= E], - &ds->has_wr_latency_histogram, - &ds->wr_latency_histogram); - bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUS= H], - &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); } =20 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; }; =20 -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 =3D { + * BlockHistogram histogram =3D { * .nbins =3D 4, * .boundaries =3D {10, 50, 100}, * .bins =3D {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; =20 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]; }; =20 typedef struct BlockAcctCookie { --=20 2.11.0 From nobody Sat Apr 27 21:19:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1562578716; cv=none; d=zoho.com; s=zohoarc; b=X8B8re36/ZbT12PenTqowPu4521G/gubhmP/YTXn256TfuTZIf2+riWw7VCXQLp83emKmi/O4ZLQUgsLv0TZ/BsXt6AuqPioRcQUYNM8Xj1VZfeKS/lv75DUc8PjNAwkWoEGltg3HlmqQcCsPCKyRd6GAAx5HIPSPkqi+btGmFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562578716; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=h8g/nC6vUT95D9nx3c9BGLOpS2Xrlhhb+4JSssXi+BA=; b=AzK5vwOQi9wlR9wn/OsUy7QTpTJmgkRH/WkwU8CKrG+7TjHViaUR0PaUjlFehlIFogGYRHZpbWJ4hv1B5dCGV9/QGPpgNAVb3xsI+oBA3YchKIDJEvuHC4R6JmCWHIgMzaSJYcYQbFEQwDK2MTUIAkATAQIVtA6vaFNdKmvz1+A= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562578716341566.3079277926549; Mon, 8 Jul 2019 02:38:36 -0700 (PDT) Received: from localhost ([::1]:39820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkQ6T-0006Al-CK for importer@patchew.org; Mon, 08 Jul 2019 05:38:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47909) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkQ0y-0000sk-UP for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkQ0w-00057H-Rd for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:52 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:37321) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkQ0w-00050G-Jq for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:50 -0400 Received: by mail-pl1-x643.google.com with SMTP id b3so4637544plr.4 for ; Mon, 08 Jul 2019 02:32:41 -0700 (PDT) Received: from always-ThinkPad-T480.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id q7sm236504pff.2.2019.07.08.02.32.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jul 2019 02:32:40 -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=Ymb0nKSANQB+l2iVjf+ggRc4wX5NWTZtSviJM1li7jgKHFtkP+VV2kZ7zuybOZXvoR IuIyKrfGaKh1pKRcV7LlpKWHdl1+YyEsGw4CukkgTSSOAU37mGz8KL8FD1aIZAFxOdqE 969OONJDcS3OKTySs9/Pd9SyaDSIzx1+btuPD196BU7IoQRN0Of5nT/OieCURju7nzOS clmHEmTeXDYmett9PrWqvDfrnUBS23AOQVtmUMIKHeOwSEOjELWbJrPcGrs//JYqxqx2 ZKrFH3Mcx7qWyWJ7MdaaZedWyk2fIQFr4LEwf0+FQ53Y0vf7M2vAVQPghURFISfYrv8I KTJg== 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=N7AWDzlwRRJlsGrQxsq3sZXJ7FYQ6PMAg+5vzDYIa4S1hmUsr8ig4c83LFa0+Vkayh q10nf09ezWlk7tRxEV3yy3fmBaCCrpfg8P+irBFgAkzu5h8e3J1PvXNkuhVzfFw5piEa LhauMO63E3QWwu1siBMLfVIqi9ZhTKVj5Vhos/k4OUM5UWQyhTFEoAPPmbU3oJxRrkI3 NPTuBoOX/jSq53LJ5uepIPPVgKu3kf5VX3vj/edJyZHpSwHWPP0sFMsHxx04j65HrQ+q NHi2Lqs7X0nkhoLhZLK/6CWCKAaoRoc98rHDGM3YxXffqgRwUteR6TSyPwNeUuYoC9J9 KYbQ== X-Gm-Message-State: APjAAAWgubex5AZHW1DG5ByzMvBawxPUsQ/n+U8P9+MUdxnfgu413/x/ C1mE1LtxTMXvySevogMudcmFtg== X-Google-Smtp-Source: APXvYqzrPkjCDllcxlq+LB2PEsfz+0879g2ZHxeeFs7QGXDcN2BbRHUbpq4L/JxTl9xV5xjU/m6Trw== X-Received: by 2002:a17:902:7087:: with SMTP id z7mr22887740plk.184.1562578360512; Mon, 08 Jul 2019 02:32:40 -0700 (PDT) From: zhenwei pi To: kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com Date: Mon, 8 Jul 2019 17:32:28 +0800 Message-Id: <1562578349-12333-3-git-send-email-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1562578349-12333-1-git-send-email-pizhenwei@bytedance.com> References: <1562578349-12333-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::643 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: qemu-devel@nongnu.org, qemu-block@nongnu.org, pizhenwei@bytedance.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 *st= ats) } } =20 +int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType typ= e, + uint64List *boundaries) +{ + BlockHistogram *hist =3D &stats->size_histogram[type]; + + return block_histogram_set(hist, boundaries); +} + +void block_size_histograms_clear(BlockAcctStats *stats) +{ + int i; + + for (i =3D 0; i < BLOCK_MAX_IOTYPE; i++) { + block_histogram_clear(&stats->size_histogram[i]); + } +} static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *c= ookie, bool failed) { @@ -216,6 +232,8 @@ static void block_account_one_io(BlockAcctStats *stats,= BlockAcctCookie *cookie, =20 block_histogram_account(&stats->latency_histogram[cookie->type], latency_ns); + block_histogram_account(&stats->size_histogram[cookie->type], + cookie->bytes); =20 if (!failed || stats->account_failed) { stats->total_time_ns[cookie->type] +=3D 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]; }; =20 typedef struct BlockAcctCookie { @@ -117,5 +118,7 @@ double block_acct_queue_depth(BlockAcctTimedStats *stat= s, 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 typ= e, + uint64List *boundaries); +void block_size_histograms_clear(BlockAcctStats *stats); #endif --=20 2.11.0 From nobody Sat Apr 27 21:19:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1562578457; cv=none; d=zoho.com; s=zohoarc; b=NLgXrRawsZ6F4us5FNCHiQguYDdmIRraOhaHv/Iy2IdrH8oSePj4IYbPVg1tSrLwK/yl8UU+eEg9e/y4XcivkQZJ7ImkehL4Qhu8UoWpPL4BX1aSJ+o4I7SQ3UrHrWh8bfX/rstn8dUbaOZWgmID1qVy921FxoGTHnJLZyH8MTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562578457; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FJXIlK+69aNv2aDNGdU+aI20EoP4M3xQmlBMOMtoYhk=; b=mjU446Fe8For0HbLNAbxPHrOeaiqaWjZc8ECJTAWlcXJ3Rvn7GZyOr5qKkNoT5sX9f37kYSrCUYm3tB9/hLsNW7ZVfADijehsEXODuSej5wM686jXZOYJBuDH7CL35dMT2A/j5e+6PMcbDpN1zHu9aUOf+EXS/ioQTRFqTUveGg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562578456780815.5867487696336; Mon, 8 Jul 2019 02:34:16 -0700 (PDT) Received: from localhost ([::1]:39778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkQ27-0001rX-9Y for importer@patchew.org; Mon, 08 Jul 2019 05:34:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47856) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkQ0w-0000s6-MH for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkQ0u-000553-Lc for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:50 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:39810) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkQ0s-000525-J5 for qemu-devel@nongnu.org; Mon, 08 Jul 2019 05:32:48 -0400 Received: by mail-pl1-x644.google.com with SMTP id b7so7953714pls.6 for ; Mon, 08 Jul 2019 02:32:44 -0700 (PDT) Received: from always-ThinkPad-T480.bytedance.net ([61.120.150.76]) by smtp.gmail.com with ESMTPSA id q7sm236504pff.2.2019.07.08.02.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jul 2019 02:32:42 -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=q3/iwZPKunDeUSQgvQLpVsUUEP0oRxVC1av6anVGb/uMQq5fMPkYSc7fgyPePvFVyt YpvouLGnxnPDw7OBR4H4eujJuHrTlBQguNr5AqLcn4K4lwDYeMN5HzwmmVorqS85kIce OBOj98LfA2hCCpmGZhl6wW8bH7jyqDiB1s2OjzYjZ/sJCSNTk4FtLSZRard/eW/cZGLa Lc9L8dAdNrEHTeFSrItkS3I6zIv/xcpa6gB6fd9xS7K+1lyHJ/BEZjQx3hj+GR848Kcn e/RnjN+rp+/TsY4VEM98KaQwZQdOj8pWaCQgWHEO5Ms50FrFbKhxjILrw2/hnqgC8kq3 E6VQ== 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=MIyHnz6a1+G8Ep2jNUj2yvw9Y9HXs/APwzPsUYPyISZSD5m1h28l7OEt8qUgNFgrh/ Fn8nofuV5WYRaH3x+h2P5xr8Q5uoGkROddCI/yTrP2W8mUV9nhRGvICJvs+ZTgcA33Pi 7SHrnohlh+bDrznGFnkvVutyj8WaWOcj0KuTSgRTDPLxjBeLqWhZsFm86/blJ/5dskAT jYq6vjj428Zsux5eHYmKFGaWDug6ETJImpGnPdKoMK6v7treCoBTUkYRq47su/tkG3SH tc1PH8PEFsvwyEDdErV4Htcyju/k/buNDrS743ODSKuNUKC28zyZDAn+cY7BUPeElcXL YzIQ== X-Gm-Message-State: APjAAAUG2RdcLaEsd+PwcmblDAUqGIBE7Ho3qoSFD9IW3ooGHpfi8PZ0 y/Tpzcu3venYGcxT0ObCWijsMQ== X-Google-Smtp-Source: APXvYqyCPUQX74hlMfQO0Vh9LYnf/kKhTLfVn16l1u84PNs/D7MM49d94KkJLgSWKiexoaXpAfHKtQ== X-Received: by 2002:a17:902:684:: with SMTP id 4mr23295792plh.138.1562578363281; Mon, 08 Jul 2019 02:32:43 -0700 (PDT) From: zhenwei pi To: kwolf@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com Date: Mon, 8 Jul 2019 17:32:29 +0800 Message-Id: <1562578349-12333-4-git-send-email-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1562578349-12333-1-git-send-email-pizhenwei@bytedance.com> References: <1562578349-12333-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::644 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: qemu-devel@nongnu.org, qemu-block@nongnu.org, pizhenwei@bytedance.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 si= ze) } =20 static void bdrv_histogram_stats(BlockHistogram *hist, bool *not_null, - BlockLatencyHistogramInfo **info) + BlockHistogramInfo **info) { *not_null =3D hist->bins !=3D NULL; if (*not_null) { - *info =3D g_new0(BlockLatencyHistogramInfo, 1); + *info =3D g_new0(BlockHistogramInfo, 1); =20 (*info)->boundaries =3D uint64_list(hist->boundaries, hist->nbins = - 1); (*info)->bins =3D 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_histogra= m); + bdrv_histogram_stats(&stats->size_histogram[BLOCK_ACCT_WRITE], + &ds->has_wr_size_histogram, &ds->wr_size_histogra= m); + bdrv_histogram_stats(&stats->size_histogram[BLOCK_ACCT_FLUSH], + &ds->has_flush_size_histogram, + &ds->flush_size_histogram); } =20 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_nam= e, StrOrNull *iothread, aio_context_release(old_context); } =20 -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 =3D 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; =20 if (!blk) { return; } =20 + switch (type) { + case BLOCK_HISTOGRAM_TYPE_LATENCY: { + clear_func =3D block_latency_histograms_clear; + set_func =3D block_latency_histogram_set; + break; + } + case BLOCK_HISTOGRAM_TYPE_SIZE: { + clear_func =3D block_size_histograms_clear; + set_func =3D block_size_histogram_set; + break; + } + default: + error_setg(errp, "Unsupported block histogram type"); + return; + } + stats =3D blk_get_stats(blk); =20 if (!has_boundaries && !has_boundaries_read && !has_boundaries_write && !has_boundaries_flush) { - block_latency_histograms_clear(stats); + clear_func(stats); return; } =20 if (has_boundaries || has_boundaries_read) { - ret =3D block_latency_histogram_set( - stats, BLOCK_ACCT_READ, + ret =3D 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( } =20 if (has_boundaries || has_boundaries_write) { - ret =3D block_latency_histogram_set( - stats, BLOCK_ACCT_WRITE, + ret =3D 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( } =20 if (has_boundaries || has_boundaries_flush) { - ret =3D block_latency_histogram_set( - stats, BLOCK_ACCT_FLUSH, + ret =3D 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'] } } =20 ## -# @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, +i= nf). # @@ -555,57 +555,72 @@ # +------------------ # 10 50 100 # -# Since: 4.0 +# Since: 4.1 ## -{ 'struct': 'BlockLatencyHistogramInfo', +{ 'struct': 'BlockHistogramInfo', 'data': {'boundaries': ['uint64'], 'bins': ['uint64'] } } =20 ## -# @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 devi= ce. +# +# 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 (excep= t 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 h= igher -# 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-re= ad. +# 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': 'in= t', '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' } } =20 ## # @BlockStats: --=20 2.11.0