diff mbox series

[v4] scsi: ufs: wb: Add explicit flush_threshold sysfs attribute

Message ID 20230609091113.22531-1-luhongfei@vivo.com (mailing list archive)
State Superseded
Headers show
Series [v4] scsi: ufs: wb: Add explicit flush_threshold sysfs attribute | expand

Commit Message

Lu Hongfei June 9, 2023, 9:11 a.m. UTC
There are three flags that control Write Booster Feature:

    1. WB ON/OFF
    2. WB Hibern Flush ON/OFF (implicitly)
    3. WB Flush ON/OFF (explicit)

In the case of "Hibern Flush", one of the conditions for flush WB buffer is
that avail_wb_buff < wb_flush_threshold.

As we know, different users have different requirements for power
consumption and performance. Therefore, we need the ability to manually
set wb_flush_threshold, so that users can easily and flexibly adjust
the wb_flush_threshold value, thereby achieving a balance between power
consumption and performance.

So the sysfs attribute that controls this is necessary.

The meaning of wb_flush_threshold is the percentage of WB's total size,
such as 1 representing 10%, 2 representing 20%, and so on.

Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
---
The modifications made compared to the previous version are as follows:
1. Add wb_flush_threshold related information to sysfs documentation.

 Documentation/ABI/testing/sysfs-driver-ufs |  8 ++++++
 drivers/ufs/core/ufs-sysfs.c               | 33 ++++++++++++++++++++++
 2 files changed, 41 insertions(+)

Comments

Avri Altman June 9, 2023, 10:18 a.m. UTC | #1
> 
> There are three flags that control Write Booster Feature:
> 
>     1. WB ON/OFF
>     2. WB Hibern Flush ON/OFF (implicitly)
>     3. WB Flush ON/OFF (explicit)
> 
> In the case of "Hibern Flush", one of the conditions for flush WB buffer is
> that avail_wb_buff < wb_flush_threshold.
> 
> As we know, different users have different requirements for power
> consumption and performance. Therefore, we need the ability to manually
> set wb_flush_threshold, so that users can easily and flexibly adjust
> the wb_flush_threshold value, thereby achieving a balance between power
> consumption and performance.
> 
> So the sysfs attribute that controls this is necessary.
> 
> The meaning of wb_flush_threshold is the percentage of WB's total size,
> such as 1 representing 10%, 2 representing 20%, and so on.
> 
> Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Bart Van Assche June 12, 2023, 6:21 p.m. UTC | #2
On 6/9/23 02:11, Lu Hongfei wrote:
> +What:		/sys/bus/platform/drivers/ufshcd/*/wb_flush_threshold
> +What:		/sys/bus/platform/devices/*.ufs/wb_flush_threshold
> +Date:		June 2023
> +Contact:	Lu Hongfei <luhongfei@vivo.com>
> +Description:	wb_flush_threshold is a percentage that represents the threshold for flush WB.
> +		When avail_wb_buff < wb_flush_threshold, the dev will flush WB when entered H8.
> +		When avail_wb_buff >= wb_flush_threshold, it is not necessary.

"Percentage" suggests a number in the range 0..100 while the valid range is 0..10.
Please fix this.

Thanks,

Bart.
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs
index 228aa43e14ed..25bc2db78ff5
--- a/Documentation/ABI/testing/sysfs-driver-ufs
+++ b/Documentation/ABI/testing/sysfs-driver-ufs
@@ -1426,6 +1426,14 @@  Description:	This entry shows the status of WriteBooster buffer flushing
 		If flushing is enabled, the device executes the flush
 		operation when the command queue is empty.
 
+What:		/sys/bus/platform/drivers/ufshcd/*/wb_flush_threshold
+What:		/sys/bus/platform/devices/*.ufs/wb_flush_threshold
+Date:		June 2023
+Contact:	Lu Hongfei <luhongfei@vivo.com>
+Description:	wb_flush_threshold is a percentage that represents the threshold for flush WB.
+		When avail_wb_buff < wb_flush_threshold, the dev will flush WB when entered H8.
+		When avail_wb_buff >= wb_flush_threshold, it is not necessary.
+
 What:		/sys/bus/platform/drivers/ufshcd/*/device_descriptor/hpb_version
 What:		/sys/bus/platform/devices/*.ufs/device_descriptor/hpb_version
 Date:		June 2021
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index cdf3d5f2b77b..347207f4e8ee 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -298,6 +298,37 @@  static ssize_t enable_wb_buf_flush_store(struct device *dev,
 	return res < 0 ? res : count;
 }
 
+static ssize_t wb_flush_threshold_show(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", hba->vps->wb_flush_threshold);
+}
+
+static ssize_t wb_flush_threshold_store(struct device *dev,
+					  struct device_attribute *attr,
+					  const char *buf, size_t count)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+	unsigned int wb_flush_threshold;
+
+	if (kstrtouint(buf, 0, &wb_flush_threshold))
+		return -EINVAL;
+
+	/* The range of values for wb_flush_threshold is (0,10] */
+	if (wb_flush_threshold > UFS_WB_BUF_REMAIN_PERCENT(100) ||
+		wb_flush_threshold == 0) {
+		dev_err(dev, "The value of wb_flush_threshold is invalid!\n");
+		return -EINVAL;
+	}
+
+	hba->vps->wb_flush_threshold = wb_flush_threshold;
+
+	return count;
+}
+
 static DEVICE_ATTR_RW(rpm_lvl);
 static DEVICE_ATTR_RO(rpm_target_dev_state);
 static DEVICE_ATTR_RO(rpm_target_link_state);
@@ -307,6 +338,7 @@  static DEVICE_ATTR_RO(spm_target_link_state);
 static DEVICE_ATTR_RW(auto_hibern8);
 static DEVICE_ATTR_RW(wb_on);
 static DEVICE_ATTR_RW(enable_wb_buf_flush);
+static DEVICE_ATTR_RW(wb_flush_threshold);
 
 static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_rpm_lvl.attr,
@@ -318,6 +350,7 @@  static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_auto_hibern8.attr,
 	&dev_attr_wb_on.attr,
 	&dev_attr_enable_wb_buf_flush.attr,
+	&dev_attr_wb_flush_threshold.attr,
 	NULL
 };