public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Rickard Andersson <rickard.andersson@axis.com>
To: <richard@nod.at>, <chengzhihao1@huawei.com>,
	<linux-mtd@lists.infradead.org>, <rickard314.andersson@gmail.com>
Cc: <rickard.andersson@axis.com>, <kernel@axis.com>
Subject: [PATCH v3 03/10] ubi: Expose max erase counter for fastmap in sysfs
Date: Fri, 11 Oct 2024 14:58:57 +0200	[thread overview]
Message-ID: <20241011125904.2915983-3-rickard.andersson@axis.com> (raw)
In-Reply-To: <20241011125904.2915983-1-rickard.andersson@axis.com>

Since the fastmap area has its own wear levelling it is valuable to
provide a max erase counter value specifically for that area.

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Rickard Andersson <rickard.andersson@axis.com>
---
 drivers/mtd/ubi/build.c | 43 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 1c531d623a62..a5a2e6e3be38 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -134,6 +134,8 @@ static struct device_attribute dev_max_ec =
 static struct device_attribute dev_mean_ec =
 	__ATTR(mean_ec, S_IRUGO, dev_attribute_show, NULL);
 #ifdef CONFIG_MTD_UBI_FASTMAP
+static struct device_attribute dev_max_ec_fastmap =
+	__ATTR(max_ec_fastmap, S_IRUGO, dev_attribute_show, NULL);
 static struct device_attribute dev_mean_ec_fastmap =
 	__ATTR(mean_ec_fastmap, S_IRUGO, dev_attribute_show, NULL);
 #endif
@@ -384,6 +386,44 @@ static int ubi_calc_mean_ec(struct ubi_device *ubi, int start_peb, int end_peb)
 	return mean_ec;
 }
 
+/**
+ * ubi_calc_max_ec_fastmap - calculate max erase counter value.
+ * @ubi: UBI device description object
+ * @start_peb: First PEB in the range
+ * @end_peb: End PEB in the half-open range
+ *
+ * Returns the max erase counter value that can be found in the range.
+ * Range is half-open i.e end_peb is not actually included.
+ */
+#ifdef CONFIG_MTD_UBI_FASTMAP
+static int ubi_calc_max_ec(struct ubi_device *ubi, int start_peb, int end_peb)
+{
+	struct ubi_wl_entry *wl;
+	int peb;
+	int max_ec = 0;
+
+	for (peb = start_peb; peb < end_peb; peb++) {
+		int err;
+
+		err = ubi_io_is_bad(ubi, peb);
+		if (err)
+			continue;
+
+		spin_lock(&ubi->wl_lock);
+
+		wl = ubi->lookuptbl[peb];
+		if (wl) {
+			if (max_ec < wl->ec)
+				max_ec = wl->ec;
+		}
+
+		spin_unlock(&ubi->wl_lock);
+	}
+
+	return max_ec;
+}
+#endif
+
 /* "Show" method for files in '/<sysfs>/class/ubi/ubiX/' */
 static ssize_t dev_attribute_show(struct device *dev,
 				  struct device_attribute *attr, char *buf)
@@ -416,6 +456,8 @@ static ssize_t dev_attribute_show(struct device *dev,
 	else if (attr == &dev_mean_ec)
 		ret = sprintf(buf, "%d\n", ubi_calc_mean_ec(ubi, 0, ubi->peb_count));
 #ifdef CONFIG_MTD_UBI_FASTMAP
+	else if (attr == &dev_max_ec_fastmap)
+		ret = sprintf(buf, "%d\n", ubi_calc_max_ec(ubi, 0, UBI_FM_MAX_START));
 	else if (attr == &dev_mean_ec_fastmap)
 		ret = sprintf(buf, "%d\n", ubi_calc_mean_ec(ubi, 0, UBI_FM_MAX_START));
 #endif
@@ -447,6 +489,7 @@ static struct attribute *ubi_dev_attrs[] = {
 	&dev_max_ec.attr,
 	&dev_mean_ec.attr,
 #ifdef CONFIG_MTD_UBI_FASTMAP
+	&dev_max_ec_fastmap.attr,
 	&dev_mean_ec_fastmap.attr,
 #endif
 	&dev_reserved_for_bad.attr,
-- 
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2024-10-11 13:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 12:58 [PATCH v3 01/10] ubi: Expose mean erase counter in sysfs Rickard Andersson
2024-10-11 12:58 ` [PATCH v3 02/10] ubi: Expose mean erase counter for fastmap " Rickard Andersson
2024-11-06 20:20   ` Richard Weinberger
2024-11-07 10:28     ` Rickard x Andersson
2024-11-07 11:31       ` Richard Weinberger
2024-11-07 12:12         ` Rickard x Andersson
2024-10-11 12:58 ` Rickard Andersson [this message]
2024-10-11 12:58 ` [PATCH v3 04/10] ubi: Expose mean erase counter for data " Rickard Andersson
2024-10-11 12:58 ` [PATCH v3 05/10] ubi: Expose max " Rickard Andersson
2024-10-11 12:59 ` [PATCH v3 06/10] ubi: Add mean erase counter sysfs attribute Rickard Andersson
2024-10-11 12:59 ` [PATCH v3 07/10] ubi: Add mean erase counter sysfs attribute for fastmap area Rickard Andersson
2024-10-11 12:59 ` [PATCH v3 08/10] ubi: Add max " Rickard Andersson
2024-10-11 12:59 ` [PATCH v3 09/10] ubi: Add mean erase counter sysfs attribute for data area Rickard Andersson
2024-10-11 12:59 ` [PATCH v3 10/10] ubi: Add max " Rickard Andersson
2024-11-06 20:34 ` [PATCH v3 01/10] ubi: Expose mean erase counter in sysfs Richard Weinberger
2024-11-07  1:39   ` Zhihao Cheng
2024-11-14 18:50     ` Richard Weinberger
2024-11-15  9:00       ` Rickard x Andersson
2024-11-16  2:55         ` Zhihao Cheng
2024-11-18 17:00           ` Rickard X Andersson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241011125904.2915983-3-rickard.andersson@axis.com \
    --to=rickard.andersson@axis.com \
    --cc=chengzhihao1@huawei.com \
    --cc=kernel@axis.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=rickard314.andersson@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox