From patchwork Tue Jul 17 10:30:19 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: 944880 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="m1mKQvIy"; 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 41VGmY4Bj4z9s4Z for ; Tue, 17 Jul 2018 20:31:57 +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=cDyweU03MNDcWnIEmqbfQ0+XmNKmmoGwqoC664Ejj3c=; b=m1m KQvIy5Nl0nrvCzGWMBC8fhTYUlggG1vH0DowsQXk0CFnf5EBz13NjAOOEXEzBPpM2adpos4AfeAq8 /SyEDLb8Dhd418mI7mqqaESNVDZy5N99tGF6LtYP0aso8+u2mHa6uS/6ojVQgMaXEswyaZtAdr+Wk AEpMHLjiHftDv18hFQZjvQYPkwsPBg9o43Bq3rrUAZSpeCK1g7RhhVsZ7kXHn4XDlTPDhrxRghdf9 96k1WhU1GPZm0rdEUfQxPUhEbS5g7hZanBLP1Ou0Afuqo1J7sDsgANcWr0vNr4ZF4KJCWRX6AqEal MbRkhIzPwgwhLFfJ7Zvd11pCowmQnXA==; 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 1ffNGm-0008Sl-Py; Tue, 17 Jul 2018 10:31:48 +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 1ffNGi-0008RG-0M for linux-mtd@lists.infradead.org; Tue, 17 Jul 2018 10:31:47 +0000 Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id 4EE9E184C2; Tue, 17 Jul 2018 12:31:29 +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 ZPzaM5cOk0Iv; Tue, 17 Jul 2018 12:31:28 +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 3D1DD1841E; Tue, 17 Jul 2018 12:31:28 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 265001A092; Tue, 17 Jul 2018 12:31:28 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 190C11A091; Tue, 17 Jul 2018 12:31:28 +0200 (CEST) Received: from thoth.se.axis.com (unknown [10.0.2.173]) by boulder02.se.axis.com (Postfix) with ESMTP; Tue, 17 Jul 2018 12:31:28 +0200 (CEST) Received: from lnxperfn.se.axis.com (lnxperfn.se.axis.com [10.92.8.4]) by thoth.se.axis.com (Postfix) with ESMTP id 0CA602FA4; Tue, 17 Jul 2018 12:31:28 +0200 (CEST) Received: by lnxperfn.se.axis.com (Postfix, from userid 11346) id 05818800C8; Tue, 17 Jul 2018 12:31:28 +0200 (CEST) From: Per Forlin To: linux-mtd@lists.infradead.org Subject: [PATCH] UBI: Add volume read and write statistics Date: Tue, 17 Jul 2018 12:30:19 +0200 Message-Id: <1531823419-8665-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-20180717_033144_387485_7A9B177F X-CRM114-Status: GOOD ( 13.95 ) 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: 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. * Bytes read * Bytes written * Number of reads * Number of writes This is useful to find out how the storage is being utilized. For block devices this already exists via /proc/diskstats. The intention of this patch is to add similar stats for UBI as well. --- drivers/mtd/ubi/eba.c | 6 ++++++ drivers/mtd/ubi/ubi.h | 19 +++++++++++++++++++ drivers/mtd/ubi/vmt.c | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index b98481b..8d708c4 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c @@ -618,6 +618,9 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, if (err) return err; + vol->stats.rcount++; + vol->stats.rbytes += len; + pnum = vol->eba_tbl->entries[lnum].pnum; if (pnum >= 0) { err = check_mapping(ubi, vol, lnum, &pnum); @@ -1032,6 +1035,9 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, if (err) return err; + vol->stats.wcount++; + vol->stats.wbytes += len; + pnum = vol->eba_tbl->entries[lnum].pnum; if (pnum >= 0) { err = check_mapping(ubi, vol, lnum, &pnum); diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index f5ba97c..08a313fe 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_stats - 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_stats { + 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_stats stats; }; /** diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 0be5167..021de10 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_stats = + __ATTR(stats, 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_stats) + ret = sprintf(buf, "rbytes wbytes rcount wcount:\n" + "%llu %llu %u %u\n", + vol->stats.rbytes, vol->stats.wbytes, + vol->stats.rcount, vol->stats.wcount); 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_stats.attr, NULL }; ATTRIBUTE_GROUPS(volume_dev);