Skip to contentSkip to conversation

ubi: Expose interface for detailed erase counters

PATCH Superseded Rickard Andersson 4 participants 8 messages Dec 6, 2024 – Dec 9, 2024

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 ubi: Expose interface for detailed erase counters

Using the ioctl command 'UBI_IOCECNFO' user space can obtain detailed erase counter information of all blocks of a device.

---
 include/uapi/mtd/ubi-user.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
include/uapi/mtd/ubi-user.h +33 -0
index e1571603175e..aa872a41ffb9 100644
@@ -175,6 +175,8 @@
 #define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32)
 /* Force scrubbing on the specified PEB */
 #define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32)
+/* Read detailed device erase counter information */
+#define UBI_IOCECNFO _IOWR(UBI_IOC_MAGIC, 6, struct ubi_ecinfo_req)
 
 /* ioctl commands of the UBI control character device */
 
@@ -412,6 +414,37 @@ struct ubi_rnvol_req {
 	} ents[UBI_MAX_RNVOL];
 } __packed;
 
+/**
+ * struct ubi_ecinfo_req - a data structure used for requesting and receiving
+ * erase block counter information from a UBI device.
+ *
+ * @start: index of first physical erase block to read (in)
+ * @length: number of erase counters to read (in)
+ * @read_length: number of erase counters that was actually read (out)
+ * @padding: reserved for future, not used, has to be zeroed
+ * @erase_counters: array of erase counter values (out)
+ *
+ * This structure is used to retrieve erase counter information for a specified
+ * range of PEBs on a UBI device.
+ * Erase counters are read from @start and attempts to read @length number of
+ * erase counters.
+ * The retrieved values are stored in the @erase_counters array. It is the
+ * responsibility of the caller to allocate enough memory for storing @length
+ * elements in the @erase_counters array.
+ * If a block is bad or if the erase counter is unknown the corresponding value
+ * in the array will be set to -1.
+ * The @read_length field will indicate the number of erase counters actually
+ * read. Typically @read_length will be limited due to memory or the number of
+ * PEBs on the UBI device.
+ */
+struct ubi_ecinfo_req {
+	__s32 start;
+	__s32 length;
+	__s32 read_length;
+	__s8  padding[16];
+	__s32 erase_counters[];
+}  __packed;
+
 /**
  * struct ubi_leb_change_req - a data structure used in atomic LEB change
  *                             requests.
Signature · 6 lines
2.30.2


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

PATCH v3 2/2 ubi: Implement ioctl for detailed erase counters

Currently, "max_ec" can be read from sysfs, which provides a limited view of the flash device’s wear. In certain cases, such as bugs in the wear-leveling algorithm, specific blocks can be worn down more than others, resulting in uneven wear distribution. Also some use cases can wear the erase blocks of the fastmap area more heavily than other parts of flash.
Providing detailed erase counter values give a better understanding of the overall flash wear and is needed to be able to calculate for example expected life time.
There exists more detailed info in debugfs, but this information is only available for debug builds.

---
 drivers/mtd/ubi/cdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
drivers/mtd/ubi/cdev.c +72 -0
index 0d8f04cf03c5..bcdc47374578 100644
@@ -828,6 +828,72 @@ static int rename_volumes(struct ubi_device *ubi,
 	return err;
 }
 
+static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user *ureq)
+{
+	struct ubi_ecinfo_req req;
+	struct ubi_wl_entry *wl;
+	int i;
+	int peb;
+	int end_peb;
+
+	/* Copy the input arguments */
+	if (copy_from_user(&req, ureq, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;
+
+	/* Check input arguments */
+	if (req.length <= 0 || req.start < 0)
+		return -EINVAL;
+
+	if (check_add_overflow(req.start, req.length, &end_peb))
+		return -EINVAL;
+
+	if (end_peb > ubi->peb_count)
+		end_peb = ubi->peb_count;
+
+	if (req.start > end_peb)
+		return -EINVAL;
+
+	/* Check access rights before filling erase_counters array */
+	if (!access_ok(ureq->erase_counters, (end_peb-req.start) * sizeof(int32_t)))
+		return -EFAULT;
+
+	/* Fill erase counter array */
+	i = 0;
+	for (peb = req.start; peb < end_peb; i++, peb++) {
+		int ec;
+
+		if (ubi_io_is_bad(ubi, peb)) {
+			if (__put_user(UBI_UNKNOWN, ureq->erase_counters+i))
+				return -EFAULT;
+
+			continue;
+		}
+
+		spin_lock(&ubi->wl_lock);
+
+		wl = ubi->lookuptbl[peb];
+		if (wl)
+			ec = wl->ec;
+		else
+			ec = UBI_UNKNOWN;
+
+		spin_unlock(&ubi->wl_lock);
+
+		if (__put_user(ec, ureq->erase_counters+i))
+			return -EFAULT;
+
+	}
+
+	/* Return actual read length */
+	req.read_length = i;
+
+	/* Copy everything except erase counter array */
+	if (copy_to_user(ureq, &req, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
 			   unsigned long arg)
 {
@@ -991,6 +1057,12 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
 		break;
 	}
 
+	case UBI_IOCECNFO:
+	{
+		err = ubi_get_ec_info(ubi, argp);
+		break;
+	}
+
 	default:
 		err = -ENOTTY;
 		break;
Signature · 6 lines
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
reviewer
#2 lore raw

Re: [PATCH v3 2/2] ubi: Implement ioctl for detailed erase counters

Quoted 12 lines · Rickard Andersson

Currently, "max_ec" can be read from sysfs, which provides a limited view of the flash device’s wear. In certain cases, such as bugs in the wear-leveling algorithm, specific blocks can be worn down more than others, resulting in uneven wear distribution. Also some use cases can wear the erase blocks of the fastmap area more heavily than other parts of flash.
Providing detailed erase counter values give a better understanding of the overall flash wear and is needed to be able to calculate for example expected life time.
There exists more detailed info in debugfs, but this information is only available for debug builds.

Quoted 4 lines
---
  drivers/mtd/ubi/cdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 72 insertions(+)

Hi Rickard. Some small nits below.

Quoted 6 lines
drivers/mtd/ubi/cdev.c +0 -0
index 0d8f04cf03c5..bcdc47374578 100644

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 835

Quoted 8 lines
drivers/mtd/ubi/cdev.c +5 -0
@@ -828,6 +828,72 @@ static int rename_volumes(struct ubi_device *ubi,
  	return err;
  }
 
+static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user *ureq)
+{
+	struct ubi_ecinfo_req req;
+	struct ubi_wl_entry *wl;
+	int i;

We can use a obvious name like 'read_cnt' or 'read_length', instead of 'i'.

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 844

Quoted 9 lines
drivers/mtd/ubi/cdev.c +9 -0
+	int peb;
+	int end_peb;
+
+	/* Copy the input arguments */
+	if (copy_from_user(&req, ureq, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;
+
+	/* Check input arguments */
+	if (req.length <= 0 || req.start < 0)

How about 'if (req.length <= 0 || req.start < 0 || req.start >= ubi->peb_count)'? Then 'if (req.start > end_peb)' below can be deleted.

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 847

Quoted 3 lines
drivers/mtd/ubi/cdev.c +3 -0
+		return -EINVAL;
+
+	if (check_add_overflow(req.start, req.length, &end_peb))

How about 'if (unlikely(check_add_overflow(req.start, req.length, &end_peb)))' ?

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 853

Quoted 6 lines
drivers/mtd/ubi/cdev.c +6 -0
+		return -EINVAL;
+
+	if (end_peb > ubi->peb_count)
+		end_peb = ubi->peb_count;
+
+	if (req.start > end_peb)

This check can be removed.

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 858

Quoted 5 lines
drivers/mtd/ubi/cdev.c +5 -0
+		return -EINVAL;
+
+	/* Check access rights before filling erase_counters array */
+	if (!access_ok(ureq->erase_counters, (end_peb-req.start) * sizeof(int32_t)))
+		return -EFAULT;

We can use 'put_user' below to replace the check 'access_ok'.

for (peb = req.start; peb < end_peb; i++, peb++) {
	int ec = UBI_UNKNOWN;

	if (!ubi_io_is_bad(ubi, peb)) {
		spin_lock(&ubi->wl_lock);
		wl = ubi->lookuptbl[peb];
		if (wl)
			ec = wl->ec;
		else
			ec = UBI_UNKNOWN;
		spin_unlock(&ubi->wl_lock);
	}

	if (unlikely(put_user(ec, ureq->erase_counters+i)))
		return -EFAULT;
}
Quoted 26 lines
drivers/mtd/ubi/cdev.c +26 -0
+
+	/* Fill erase counter array */
+	i = 0;
+	for (peb = req.start; peb < end_peb; i++, peb++) {
+		int ec;
+
+		if (ubi_io_is_bad(ubi, peb)) {
+			if (__put_user(UBI_UNKNOWN, ureq->erase_counters+i))
+				return -EFAULT;
+
+			continue;
+		}
+
+		spin_lock(&ubi->wl_lock);
+
+		wl = ubi->lookuptbl[peb];
+		if (wl)
+			ec = wl->ec;
+		else
+			ec = UBI_UNKNOWN;
+
+		spin_unlock(&ubi->wl_lock);
+
+		if (__put_user(ec, ureq->erase_counters+i))
+			return -EFAULT;
+

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 892

Quoted 10 lines
drivers/mtd/ubi/cdev.c +8 -0
+	}
 
 
+
+	/* Return actual read length */
+	req.read_length = i;
+
+	/* Copy everything except erase counter array */
+	if (copy_to_user(ureq, &req, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;

if (unlikely(...

Quoted 11 lines
drivers/mtd/ubi/cdev.c +4 -0
+
+	return 0;
+}
+
  static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
  			   unsigned long arg)
  {
drivers/mtd/ubi/cdev.c +0 -0
@@ -991,6 +1057,12 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
  		break;
  	}

drivers/mtd/ubi/cdev.c static long ubi_cdev_ioctl(struct file *file, unsigned int cmd, · line 1068

Quoted 10 lines
drivers/mtd/ubi/cdev.c +6 -0
 
+	case UBI_IOCECNFO:
+	{
+		err = ubi_get_ec_info(ubi, argp);
+		break;
+	}
+
  	default:
  		err = -ENOTTY;
  		break;

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

#3 lore raw

Re: [PATCH v3 2/2] ubi: Implement ioctl for detailed erase counters

----- Ursprüngliche Mail -----

Quoted 15 lines

Von: "chengzhihao1" <[email protected]>
An: "Rickard X Andersson" <[email protected]>, "richard" <[email protected]>, "linux-mtd"

Quoted 12 lines · Rickard Andersson

Currently, "max_ec" can be read from sysfs, which provides a limited view of the flash device’s wear. In certain cases, such as bugs in the wear-leveling algorithm, specific blocks can be worn down more than others, resulting in uneven wear distribution. Also some use cases can wear the erase blocks of the fastmap area more heavily than other parts of flash.
Providing detailed erase counter values give a better understanding of the overall flash wear and is needed to be able to calculate for example expected life time.
There exists more detailed info in debugfs, but this information is only available for debug builds.

Quoted 6 lines
Quoted 4 lines
---
  drivers/mtd/ubi/cdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 72 insertions(+)

Hi Rickard. Some small nits below.

Please also run checkpatch.pl, there are some coding style issues. Overall the change looks good to me and can be merged soon!

Quoted 29 lines
Quoted 6 lines
drivers/mtd/ubi/cdev.c +0 -0
index 0d8f04cf03c5..bcdc47374578 100644

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 836

Quoted 9 lines
drivers/mtd/ubi/cdev.c +5 -0
@@ -828,6 +828,72 @@ static int rename_volumes(struct ubi_device *ubi,
  	return err;
  }
 
+static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user
 *ureq)
+{
+	struct ubi_ecinfo_req req;
+	struct ubi_wl_entry *wl;
+	int i;

We can use a obvious name like 'read_cnt' or 'read_length', instead of 'i'.

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 844

Quoted 9 lines
drivers/mtd/ubi/cdev.c +9 -0
+	int peb;
+	int end_peb;
+
+	/* Copy the input arguments */
+	if (copy_from_user(&req, ureq, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;
+
+	/* Check input arguments */
+	if (req.length <= 0 || req.start < 0)

How about 'if (req.length <= 0 || req.start < 0 || req.start >= ubi->peb_count)'? Then 'if (req.start > end_peb)' below can be deleted.

Quoted 6 lines

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 847

Quoted 3 lines
drivers/mtd/ubi/cdev.c +3 -0
+		return -EINVAL;
+
+	if (check_add_overflow(req.start, req.length, &end_peb))

How about 'if (unlikely(check_add_overflow(req.start, req.length, &end_peb)))' ?

Well, this is not a hot path. What is the benefit of an unlikely() here?

Quoted 8 lines

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 853

Quoted 6 lines
drivers/mtd/ubi/cdev.c +6 -0
+		return -EINVAL;
+
+	if (end_peb > ubi->peb_count)
+		end_peb = ubi->peb_count;
+
+	if (req.start > end_peb)

This check can be removed.

Quoted 7 lines

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 858

Quoted 5 lines
drivers/mtd/ubi/cdev.c +5 -0
+		return -EINVAL;
+
+	/* Check access rights before filling erase_counters array */
+	if (!access_ok(ureq->erase_counters, (end_peb-req.start) * sizeof(int32_t)))
+		return -EFAULT;

We can use 'put_user' below to replace the check 'access_ok'.

Depending on the architecture, access_ok() can bit rather expensive. That's why using access_ok() once on the whole range and then using the cheap __put_user() in loops is a common pattern.

Quoted 68 lines
for (peb = req.start; peb < end_peb; i++, peb++) {
	int ec = UBI_UNKNOWN;

	if (!ubi_io_is_bad(ubi, peb)) {
		spin_lock(&ubi->wl_lock);
		wl = ubi->lookuptbl[peb];
		if (wl)
			ec = wl->ec;
		else
			ec = UBI_UNKNOWN;
		spin_unlock(&ubi->wl_lock);
	}

	if (unlikely(put_user(ec, ureq->erase_counters+i)))
		return -EFAULT;
}
Quoted 26 lines
drivers/mtd/ubi/cdev.c +26 -0
+
+	/* Fill erase counter array */
+	i = 0;
+	for (peb = req.start; peb < end_peb; i++, peb++) {
+		int ec;
+
+		if (ubi_io_is_bad(ubi, peb)) {
+			if (__put_user(UBI_UNKNOWN, ureq->erase_counters+i))
+				return -EFAULT;
+
+			continue;
+		}
+
+		spin_lock(&ubi->wl_lock);
+
+		wl = ubi->lookuptbl[peb];
+		if (wl)
+			ec = wl->ec;
+		else
+			ec = UBI_UNKNOWN;
+
+		spin_unlock(&ubi->wl_lock);
+
+		if (__put_user(ec, ureq->erase_counters+i))
+			return -EFAULT;
+

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 892

Quoted 10 lines
drivers/mtd/ubi/cdev.c +8 -0
+	}
 
 
+
+	/* Return actual read length */
+	req.read_length = i;
+
+	/* Copy everything except erase counter array */
+	if (copy_to_user(ureq, &req, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;

if (unlikely(...

Quoted 12 lines
drivers/mtd/ubi/cdev.c +4 -0
+
+	return 0;
+}
+

static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{

drivers/mtd/ubi/cdev.c +0 -0
@@ -991,6 +1057,12 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int
 cmd,
  		break;
  	}
 
Quoted 9 lines
Quoted 9 lines
drivers/mtd/ubi/cdev.c +6 -0
+	case UBI_IOCECNFO:
+	{
+		err = ubi_get_ec_info(ubi, argp);
+		break;
+	}
+
  	default:
  		err = -ENOTTY;

break;

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

reviewer
#4 lore raw

Re: [PATCH v3 2/2] ubi: Implement ioctl for detailed erase counters

Quoted 55 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 15 lines

Von: "chengzhihao1" <[email protected]>
An: "Rickard X Andersson" <[email protected]>, "richard" <[email protected]>, "linux-mtd"

Quoted 12 lines · Rickard Andersson

Currently, "max_ec" can be read from sysfs, which provides a limited view of the flash device’s wear. In certain cases, such as bugs in the wear-leveling algorithm, specific blocks can be worn down more than others, resulting in uneven wear distribution. Also some use cases can wear the erase blocks of the fastmap area more heavily than other parts of flash.
Providing detailed erase counter values give a better understanding of the overall flash wear and is needed to be able to calculate for example expected life time.
There exists more detailed info in debugfs, but this information is only available for debug builds.

Quoted 6 lines
Quoted 4 lines
---
   drivers/mtd/ubi/cdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 72 insertions(+)

Hi Rickard. Some small nits below.

Please also run checkpatch.pl, there are some coding style issues. Overall the change looks good to me and can be merged soon!

Quoted 29 lines
Quoted 6 lines
drivers/mtd/ubi/cdev.c +0 -0
index 0d8f04cf03c5..bcdc47374578 100644

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 836

Quoted 9 lines
drivers/mtd/ubi/cdev.c +5 -0
@@ -828,6 +828,72 @@ static int rename_volumes(struct ubi_device *ubi,
   	return err;
   }
 
+static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user
 *ureq)
+{
+	struct ubi_ecinfo_req req;
+	struct ubi_wl_entry *wl;
+	int i;

We can use a obvious name like 'read_cnt' or 'read_length', instead of 'i'.

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 844

Quoted 9 lines
drivers/mtd/ubi/cdev.c +9 -0
+	int peb;
+	int end_peb;
+
+	/* Copy the input arguments */
+	if (copy_from_user(&req, ureq, sizeof(struct ubi_ecinfo_req)))
+		return -EFAULT;
+
+	/* Check input arguments */
+	if (req.length <= 0 || req.start < 0)

How about 'if (req.length <= 0 || req.start < 0 || req.start >= ubi->peb_count)'? Then 'if (req.start > end_peb)' below can be deleted.

Quoted 8 lines
Quoted 6 lines

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 847

Quoted 3 lines
drivers/mtd/ubi/cdev.c +3 -0
+		return -EINVAL;
+
+	if (check_add_overflow(req.start, req.length, &end_peb))

How about 'if (unlikely(check_add_overflow(req.start, req.length, &end_peb)))' ?

Well, this is not a hot path. What is the benefit of an unlikely() here?

Maybe the 'unlikely' is not needed, I'm not sure whether the user will call this ioctl frequently. I'm also fine without the 'unlikely'.

Quoted 17 lines
Quoted 9 lines

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 853

Quoted 7 lines
drivers/mtd/ubi/cdev.c +6 -0
+		return -EINVAL;
+
+	if (end_peb > ubi->peb_count)
+		end_peb = ubi->peb_count;
+
+	if (req.start > end_peb)

This check can be removed.

Quoted 7 lines

drivers/mtd/ubi/cdev.c static int rename_volumes(struct ubi_device *ubi, · line 858

Quoted 5 lines
drivers/mtd/ubi/cdev.c +5 -0
+		return -EINVAL;
+
+	/* Check access rights before filling erase_counters array */
+	if (!access_ok(ureq->erase_counters, (end_peb-req.start) * sizeof(int32_t)))
+		return -EFAULT;

We can use 'put_user' below to replace the check 'access_ok'.

Quoted 3 lines

Depending on the architecture, access_ok() can bit rather expensive. That's why using access_ok() once on the whole range and then using the cheap __put_user() in loops is a common pattern.

Make sense. please keep using access_ok() once and then invoking __put_user() in loop.

Quoted 15 lines
Quoted 15 lines

for (peb = req.start; peb < end_peb; i++, peb++) {
	int ec = UBI_UNKNOWN;

	if (!ubi_io_is_bad(ubi, peb)) {
		spin_lock(&ubi->wl_lock);
		wl = ubi->lookuptbl[peb];
		if (wl)
			ec = wl->ec;
		else
			ec = UBI_UNKNOWN;
		spin_unlock(&ubi->wl_lock);
	}
Quoted 3 lines
Quoted 3 lines
	if (unlikely(put_user(ec, ureq->erase_counters+i)))
		return -EFAULT;
}

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

#5 lore raw

Re: [PATCH v3 2/2] ubi: Implement ioctl for detailed erase counters

In reply to Richard Weinberger
Quoted 21 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 20 lines

Von: "chengzhihao1" <[email protected]>
An: "Rickard X Andersson" <[email protected]>, "richard" <[email protected]>, "linux-mtd"

Quoted 16 lines · Rickard Andersson

Currently, "max_ec" can be read from sysfs, which provides a limited view of the flash device’s wear. In certain cases, such as bugs in the wear-leveling algorithm, specific blocks can be worn down more than others, resulting in uneven wear distribution. Also some use cases can wear the erase blocks of the fastmap area more heavily than other parts of flash.
Providing detailed erase counter values give a better understanding of the overall flash wear and is needed to be able to calculate for example expected life time.
There exists more detailed info in debugfs, but this information is only available for debug builds.

---
   drivers/mtd/ubi/cdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 72 insertions(+)
Quoted 4 lines
Quoted 1 line

Hi Rickard. Some small nits below.

Please also run checkpatch.pl, there are some coding style issues. Overall the change looks good to me and can be merged soon!

I have actually been running checkpatch.pl, but it gives no warnings or errors.

Best regards,
Rickard A.

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

#6 lore raw

Re: [PATCH v3 2/2] ubi: Implement ioctl for detailed erase counters

----- Ursprüngliche Mail -----

Quoted 7 lines

Von: "Rickard x Andersson" <[email protected]>

Quoted 2 lines

Please also run checkpatch.pl, there are some coding style issues. Overall the change looks good to me and can be merged soon!

I have actually been running checkpatch.pl, but it gives no warnings or errors.

Okay. Then I've interpreted my personal taste too much into the patch. :-D If checkpatch.pl is happy, I'm also happy.

Thanks,
//richard

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

reviewer Reviewed-by on v3 1/2
#7 lore raw
In reply to Rickard Andersson
Quoted 7 lines · Rickard Andersson

Using the ioctl command 'UBI_IOCECNFO' user space can obtain detailed erase counter information of all blocks of a device.

---
  include/uapi/mtd/ubi-user.h | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
Quoted 43 lines
include/uapi/mtd/ubi-user.h +26 -0
index e1571603175e..aa872a41ffb9 100644
@@ -175,6 +175,8 @@
  #define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32)
  /* Force scrubbing on the specified PEB */
  #define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32)
+/* Read detailed device erase counter information */
+#define UBI_IOCECNFO _IOWR(UBI_IOC_MAGIC, 6, struct ubi_ecinfo_req)
 
  /* ioctl commands of the UBI control character device */
 
@@ -412,6 +414,37 @@ struct ubi_rnvol_req {
  	} ents[UBI_MAX_RNVOL];
  } __packed;
 
+/**
+ * struct ubi_ecinfo_req - a data structure used for requesting and receiving
+ * erase block counter information from a UBI device.
+ *
+ * @start: index of first physical erase block to read (in)
+ * @length: number of erase counters to read (in)
+ * @read_length: number of erase counters that was actually read (out)
+ * @padding: reserved for future, not used, has to be zeroed
+ * @erase_counters: array of erase counter values (out)
+ *
+ * This structure is used to retrieve erase counter information for a specified
+ * range of PEBs on a UBI device.
+ * Erase counters are read from @start and attempts to read @length number of
+ * erase counters.
+ * The retrieved values are stored in the @erase_counters array. It is the
+ * responsibility of the caller to allocate enough memory for storing @length
+ * elements in the @erase_counters array.
+ * If a block is bad or if the erase counter is unknown the corresponding value
+ * in the array will be set to -1.
+ * The @read_length field will indicate the number of erase counters actually
+ * read. Typically @read_length will be limited due to memory or the number of
+ * PEBs on the UBI device.
+ */
+struct ubi_ecinfo_req {

include/uapi/mtd/ubi-user.h struct ubi_rnvol_req { · line 450

Quoted 10 lines
include/uapi/mtd/ubi-user.h +7 -0
+	__s32 start;
+	__s32 length;
+	__s32 read_length;
+	__s8  padding[16];
+	__s32 erase_counters[];
+}  __packed;
+
  /**
   * struct ubi_leb_change_req - a data structure used in atomic LEB change
   *                             requests.

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