From patchwork Mon Jul 23 15:39:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Per_F=C3=B6rlin?= X-Patchwork-Id: 947840 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AqvzblZm"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Z5Jx39djz9s2M for ; Tue, 24 Jul 2018 01:39:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=3rdB+RIjtlQSm8M98+0bOZuf5JbXVliCDK8SynxT8n8=; b=Aqv zblZmYPZEel/0g4hmFUK1KHPPHVFI3Y236NCQjmGRh59Tyj37kNZLFtqlyQBy+lXwoIc9k2kFW9E0 fJ5xCgKQJGJSZwR2GC24O4Fb4qXw9O/YSjMFKMXV4jVVlIJd0RneT4Y0mEPwGeMwaK7p7LJOtzm/9 l5dMldJBtp2cy3aH9SS1oI6+OUv29HcbSf2qh7Vc9vs3x/nGf2ezDzaHMy/UXTBqq9B2+XF3+glnS KSL3JcvxQes42Uxl2M5EYRbUl0FlYvJETK6/W5KIqvFHZFsEQIPxfVrBGg+HijXuy96LPVjF3XK6b 1nVYz9hGCGpbuLSc3Wagi1DCcH8FuYQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhcvq-0007H7-Az; Mon, 23 Jul 2018 15:39:30 +0000 Received: from bastet.se.axis.com ([195.60.68.11]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhcvl-0007FZ-Ry for linux-mtd@lists.infradead.org; Mon, 23 Jul 2018 15:39:27 +0000 Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id B785618349; Mon, 23 Jul 2018 17:39:10 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1mU_8rFabJOj; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) Received: from boulder02.se.axis.com (boulder02.se.axis.com [10.0.8.16]) by bastet.se.axis.com (Postfix) with ESMTPS id 7904918432; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 649751A06D; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 582BC1A06B; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) Received: from seth.se.axis.com (unknown [10.0.2.172]) by boulder02.se.axis.com (Postfix) with ESMTP; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) Received: from lnxperfn.se.axis.com (lnxperfn.se.axis.com [10.92.8.4]) by seth.se.axis.com (Postfix) with ESMTP id 4B2191B70; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) Received: by lnxperfn.se.axis.com (Postfix, from userid 11346) id 44379800C8; Mon, 23 Jul 2018 17:39:08 +0200 (CEST) From: Per Forlin To: linux-mtd@lists.infradead.org Subject: [PATCH v2] UBI: Add volume read and write statistics Date: Mon, 23 Jul 2018 17:39:02 +0200 Message-Id: <1532360342-52055-1-git-send-email-perfn@axis.com> X-Mailer: git-send-email 2.1.4 X-TM-AS-GCONF: 00 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_083926_245914_4D8EE097 X-CRM114-Status: GOOD ( 15.89 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [195.60.68.11 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: derosier@gmail.com, Richard Weinberger , Per Forlin , Artem Bityutskiy MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Simple read and write statistics. * Number of reads * Number of writes * Bytes read * Bytes written This is useful to find out how the storage is being utilized. For block devices this already exists here: /sys/class/block//stat For UBI it now exists here: /sys/class/ubi//stat Example: /sys/class/ubi/ubi0_21/stat 864 0 3106756 0 1057 0 2144256 0 0 0 0 The output format is same as for block devices except that not all metrics are supported yet. Unsupported values are set to 0. --- Changelog: v2 * Question: Translate bytes to sectors? iostats format expects sector unit. * Align with iostats format * Only count successful reads and writes drivers/mtd/ubi/eba.c | 11 ++++++++++- drivers/mtd/ubi/ubi.h | 19 +++++++++++++++++++ drivers/mtd/ubi/vmt.c | 8 ++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index b98481b..c9a88b2 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c @@ -731,6 +731,11 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, } } + if (!err) { + vol->stat.rcount++; + vol->stat.rbytes += len; + } + if (scrub) err = ubi_wl_scrub_peb(ubi, pnum); @@ -1091,8 +1096,12 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, ubi_free_vid_buf(vidb); out: - if (err) + if (err) { ubi_ro_mode(ubi); + } else { + vol->stat.wcount++; + vol->stat.wbytes += len; + } leb_write_unlock(ubi, vol_id, lnum); diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index f5ba97c..0cb00f0 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -293,6 +293,23 @@ struct ubi_eba_leb_desc { }; /** + * struct ubi_volume_stat - Volume statistics + * @rbytes: the number of bytes read + * @wbytes: the number of bytes written + * @rcount: the number of read requests + * @wcount: the number of write requests + * + * This structure contains read and write statistics. + * + */ +struct ubi_volume_stat { + u64 rbytes; + u64 wbytes; + u32 rcount; + u32 wcount; +}; + +/** * struct ubi_volume - UBI volume description data structure. * @dev: device object to make use of the the Linux device model * @cdev: character device object to create character device @@ -384,6 +401,8 @@ struct ubi_volume { #ifdef CONFIG_MTD_UBI_FASTMAP unsigned long *checkmap; #endif + + struct ubi_volume_stat stat; }; /** diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 0be5167..69b5375 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -51,6 +51,8 @@ static struct device_attribute attr_vol_data_bytes = __ATTR(data_bytes, S_IRUGO, vol_attribute_show, NULL); static struct device_attribute attr_vol_upd_marker = __ATTR(upd_marker, S_IRUGO, vol_attribute_show, NULL); +static struct device_attribute attr_vol_stat = + __ATTR(stat, S_IRUGO, vol_attribute_show, NULL); /* * "Show" method for files in '//class/ubi/ubiX_Y/'. @@ -107,6 +109,11 @@ static ssize_t vol_attribute_show(struct device *dev, ret = sprintf(buf, "%lld\n", vol->used_bytes); else if (attr == &attr_vol_upd_marker) ret = sprintf(buf, "%d\n", vol->upd_marker); + else if (attr == &attr_vol_stat) + /* Format conforming to Documentation/iostats.txt */ + ret = sprintf(buf, "%u 0 %llu 0 %u 0 %llu 0 0 0 0\n", + vol->stat.rcount, vol->stat.rbytes, + vol->stat.wcount, vol->stat.wbytes); else /* This must be a bug */ ret = -EINVAL; @@ -129,6 +136,7 @@ static struct attribute *volume_dev_attrs[] = { &attr_vol_usable_eb_size.attr, &attr_vol_data_bytes.attr, &attr_vol_upd_marker.attr, + &attr_vol_stat.attr, NULL }; ATTRIBUTE_GROUPS(volume_dev);