Skip to content

Commit e3d5562

Browse files
Lu Hongfeimartinkpetersen
authored andcommitted
scsi: ufs: wb: Add explicit flush_threshold sysfs attribute
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. wb_flush_threshold represents the threshold for flushing WB buffer, whose value expressed in unit of 10% granularity, such as '1' representing 10%, '2' representing 20%, and so on. Signed-off-by: Lu Hongfei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 56541c7 commit e3d5562

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Documentation/ABI/testing/sysfs-driver-ufs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,17 @@ Description: This entry shows the status of WriteBooster buffer flushing
14261426
If flushing is enabled, the device executes the flush
14271427
operation when the command queue is empty.
14281428

1429+
What: /sys/bus/platform/drivers/ufshcd/*/wb_flush_threshold
1430+
What: /sys/bus/platform/devices/*.ufs/wb_flush_threshold
1431+
Date: June 2023
1432+
Contact: Lu Hongfei <[email protected]>
1433+
Description:
1434+
wb_flush_threshold represents the threshold for flushing WriteBooster buffer,
1435+
whose value expressed in unit of 10% granularity, such as '1' representing 10%,
1436+
'2' representing 20%, and so on.
1437+
If avail_wb_buff < wb_flush_threshold, it indicates that WriteBooster buffer needs to
1438+
be flushed, otherwise it is not necessary.
1439+
14291440
What: /sys/bus/platform/drivers/ufshcd/*/device_descriptor/hpb_version
14301441
What: /sys/bus/platform/devices/*.ufs/device_descriptor/hpb_version
14311442
Date: June 2021

drivers/ufs/core/ufs-sysfs.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,37 @@ static ssize_t enable_wb_buf_flush_store(struct device *dev,
298298
return res < 0 ? res : count;
299299
}
300300

301+
static ssize_t wb_flush_threshold_show(struct device *dev,
302+
struct device_attribute *attr,
303+
char *buf)
304+
{
305+
struct ufs_hba *hba = dev_get_drvdata(dev);
306+
307+
return sysfs_emit(buf, "%u\n", hba->vps->wb_flush_threshold);
308+
}
309+
310+
static ssize_t wb_flush_threshold_store(struct device *dev,
311+
struct device_attribute *attr,
312+
const char *buf, size_t count)
313+
{
314+
struct ufs_hba *hba = dev_get_drvdata(dev);
315+
unsigned int wb_flush_threshold;
316+
317+
if (kstrtouint(buf, 0, &wb_flush_threshold))
318+
return -EINVAL;
319+
320+
/* The range of values for wb_flush_threshold is (0,10] */
321+
if (wb_flush_threshold > UFS_WB_BUF_REMAIN_PERCENT(100) ||
322+
wb_flush_threshold == 0) {
323+
dev_err(dev, "The value of wb_flush_threshold is invalid!\n");
324+
return -EINVAL;
325+
}
326+
327+
hba->vps->wb_flush_threshold = wb_flush_threshold;
328+
329+
return count;
330+
}
331+
301332
static DEVICE_ATTR_RW(rpm_lvl);
302333
static DEVICE_ATTR_RO(rpm_target_dev_state);
303334
static DEVICE_ATTR_RO(rpm_target_link_state);
@@ -307,6 +338,7 @@ static DEVICE_ATTR_RO(spm_target_link_state);
307338
static DEVICE_ATTR_RW(auto_hibern8);
308339
static DEVICE_ATTR_RW(wb_on);
309340
static DEVICE_ATTR_RW(enable_wb_buf_flush);
341+
static DEVICE_ATTR_RW(wb_flush_threshold);
310342

311343
static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
312344
&dev_attr_rpm_lvl.attr,
@@ -318,6 +350,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
318350
&dev_attr_auto_hibern8.attr,
319351
&dev_attr_wb_on.attr,
320352
&dev_attr_enable_wb_buf_flush.attr,
353+
&dev_attr_wb_flush_threshold.attr,
321354
NULL
322355
};
323356

0 commit comments

Comments
 (0)