Skip to contentSkip to conversation

scsi: core: allow auto suspend override by low-level driver

PATCH Superseded Stanley Chu 3 participants 7 messages Sep 16, 2019

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover scsi: core: allow auto suspend override by low-level driver

Until now the scsi mid-layer forbids runtime suspend till userspace enables it. This is mainly to quarantine some disks with broken runtime power management or have high latencies executing suspend resume callbacks. If the userspace doesn't enable the runtime suspend the underlying hardware will be always on even when it is not doing any useful work and thus wasting power.

Some low-level drivers for the controllers can efficiently use runtime power management to reduce power consumption and improve battery life.

This patchset allows runtime suspend parameters override within the LLD itself instead of waiting for userspace to control the power management, and make UFS as the first user of this capability.

v2 => v3:
- Create a member indicating autosuspend delay for the same SCSI host in SCSI host template (Bart)
- Use separate variables to control different things, (Bart)
(a) Whether or not runtime suspend is enabled at device creation time
(b) The power management autosuspend delay

v1 => v2:
- Allow "zero" sdev->rpm_autosuspend_delay (Avri)
- Fix format of some lines (Avri)

Stanley Chu (3):
scsi: core: allow auto suspend override by low-level driver
scsi: ufs: override auto suspend tunables for ufs
scsi: ufs-mediatek: enable auto suspend capability

 drivers/scsi/scsi_sysfs.c       |  3 ++-
 drivers/scsi/sd.c               |  4 ++++
 drivers/scsi/ufs/ufs-mediatek.c |  3 +++
 drivers/scsi/ufs/ufshcd.c       |  9 +++++++++
 drivers/scsi/ufs/ufshcd.h       | 10 ++++++++++
 include/scsi/scsi_device.h      |  2 +-
 include/scsi/scsi_host.h        |  3 +++
 7 files changed, 32 insertions(+), 2 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH v3 1/3 scsi: core: allow auto suspend override by low-level driver

Rework from previous work by:
Sujit Reddy Thumma <[email protected]>

Until now the scsi mid-layer forbids runtime suspend till userspace enables it. This is mainly to quarantine some disks with broken runtime power management or have high latencies executing suspend resume callbacks. If the userspace doesn't enable the runtime suspend the underlying hardware will be always on even when it is not doing any useful work and thus wasting power.

Some low-level drivers for the controllers can efficiently use runtime power management to reduce power consumption and improve battery life. Allow runtime suspend parameters override within the LLD itself instead of waiting for userspace to control the power management.

---
 drivers/scsi/scsi_sysfs.c  | 3 ++-
 drivers/scsi/sd.c          | 4 ++++
 include/scsi/scsi_device.h | 2 +-
 include/scsi/scsi_host.h   | 3 +++
 4 files changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +2 -1
index 64c96c7828ee..d879073b0bbb 100644
@@ -1300,7 +1300,8 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
 	device_enable_async_suspend(&sdev->sdev_gendev);
 	scsi_autopm_get_target(starget);
 	pm_runtime_set_active(&sdev->sdev_gendev);
-	pm_runtime_forbid(&sdev->sdev_gendev);
+	if (!sdev->rpm_autosuspend_on)
+		pm_runtime_forbid(&sdev->sdev_gendev);
 	pm_runtime_enable(&sdev->sdev_gendev);
 	scsi_autopm_put_target(starget);
 
drivers/scsi/sd.c +4 -0
index 149d406aacc9..c810cc5071d8 100644
@@ -3371,6 +3371,10 @@ static int sd_probe(struct device *dev)
 	}
 
 	blk_pm_runtime_init(sdp->request_queue, dev);
+	if (sdp->rpm_autosuspend_on) {
+		pm_runtime_set_autosuspend_delay(dev,
+			sdp->host->hostt->rpm_autosuspend_delay);
+	}
 	device_add_disk(dev, gd, NULL);
 	if (sdkp->capacity)
 		sd_dif_config_host(sdkp);
include/scsi/scsi_device.h +1 -1
index 202f4d6a4342..495e30adb53f 100644
@@ -199,7 +199,7 @@ struct scsi_device {
 	unsigned broken_fua:1;		/* Don't set FUA bit */
 	unsigned lun_in_cdb:1;		/* Store LUN bits in CDB[1] */
 	unsigned unmap_limit_for_ws:1;	/* Use the UNMAP limit for WRITE SAME */
-
+	unsigned rpm_autosuspend_on:1;	/* Runtime autosuspend */
 	atomic_t disk_events_disable_depth; /* disable depth for disk events */
 
 	DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */
include/scsi/scsi_host.h +3 -0
index cc139dbd71e5..3cb64f0a7e3a 100644
@@ -474,6 +474,9 @@ struct scsi_host_template {
 	 */
 	unsigned int cmd_size;
 	struct scsi_host_cmd_pool *cmd_pool;
+
+	/* Delay for runtime autosuspend */
+	int rpm_autosuspend_delay;
 };
 
 /*
Signature · 1 line
2.18.0
Reviewed-by on v3 1/3
#2 lore raw

include/scsi/scsi_device.h struct scsi_device { · line 203

Quoted 11 lines · Stanley Chu
include/scsi/scsi_device.h +1 -1
index 202f4d6a4342..495e30adb53f 100644
@@ -199,7 +199,7 @@ struct scsi_device {
  	unsigned broken_fua:1;		/* Don't set FUA bit */
  	unsigned lun_in_cdb:1;		/* Store LUN bits in CDB[1] */
  	unsigned unmap_limit_for_ws:1;	/* Use the UNMAP limit for WRITE SAME */
-
+	unsigned rpm_autosuspend_on:1;	/* Runtime autosuspend */
  	atomic_t disk_events_disable_depth; /* disable depth for disk events */

The "_on" part in the variable name "rpm_autosuspend_on" is probably
redundant and the comment could have been more elaborate. Anyway:

#3 lore raw

Hi Bart,

Quoted 5 lines

include/scsi/scsi_device.h struct scsi_device { · line 203

Quoted 3 lines
include/scsi/scsi_device.h +1 -1
-
+	unsigned rpm_autosuspend_on:1;	/* Runtime autosuspend */
  	atomic_t disk_events_disable_depth; /* disable depth for disk events */

The "_on" part in the variable name "rpm_autosuspend_on" is probably
redundant and the comment could have been more elaborate. Anyway:

OK! Thanks for suggestions. Will fix both in next version.

Quoted 2 lines

Thanks,
Stanley

#4 lore raw

PATCH v3 2/3 scsi: ufs: override auto suspend tunables for ufs

In reply to Stanley Chu

Rework from previous work by:
Sujit Reddy Thumma <[email protected]>

Override auto suspend tunables for UFS device LUNs during initialization so as to efficiently manage background operations and the power consumption.

---
 drivers/scsi/ufs/ufshcd.c |  9 +++++++++
 drivers/scsi/ufs/ufshcd.h | 10 ++++++++++
 2 files changed, 19 insertions(+)
drivers/scsi/ufs/ufshcd.c +9 -0
index 30b752c61b97..d35de21dc394 100644
@@ -88,6 +88,9 @@
 /* Interrupt aggregation default timeout, unit: 40us */
 #define INT_AGGR_DEF_TO	0x02
 
+/* default delay of autosuspend: 2000 ms */
+#define RPM_AUTOSUSPEND_DELAY_MS 2000
+
 #define ufshcd_toggle_vreg(_dev, _vreg, _on)				\
 	({                                                              \
 		int _ret;                                               \
@@ -4612,9 +4615,14 @@ static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth)
  */
 static int ufshcd_slave_configure(struct scsi_device *sdev)
 {
+	struct ufs_hba *hba = shost_priv(sdev->host);
 	struct request_queue *q = sdev->request_queue;
 
 	blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
+
+	if (ufshcd_is_rpm_autosuspend_allowed(hba))
+		sdev->rpm_autosuspend_on = 1;
+
 	return 0;
 }
 
@@ -7041,6 +7049,7 @@ static struct scsi_host_template ufshcd_driver_template = {
 	.track_queue_depth	= 1,
 	.sdev_groups		= ufshcd_driver_groups,
 	.dma_boundary		= PAGE_SIZE - 1,
+	.rpm_autosuspend_delay	= RPM_AUTOSUSPEND_DELAY_MS,
 };
 
 static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
drivers/scsi/ufs/ufshcd.h +10 -0
index a43c7135f33d..99ea416519af 100644
@@ -714,6 +714,12 @@ struct ufs_hba {
 	 * the performance of ongoing read/write operations.
 	 */
 #define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1 << 5)
+	/*
+	 * This capability allows host controller driver to automatically
+	 * enable runtime power management by itself instead of waiting
+	 * for userspace to control the power management.
+	 */
+#define UFSHCD_CAP_RPM_AUTOSUSPEND (1 << 6)
 
 	struct devfreq *devfreq;
 	struct ufs_clk_scaling clk_scaling;
@@ -747,6 +753,10 @@ static inline bool ufshcd_can_autobkops_during_suspend(struct ufs_hba *hba)
 {
 	return hba->caps & UFSHCD_CAP_AUTO_BKOPS_SUSPEND;
 }
+static inline bool ufshcd_is_rpm_autosuspend_allowed(struct ufs_hba *hba)
+{
+	return hba->caps & UFSHCD_CAP_RPM_AUTOSUSPEND;
+}
 
 static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba)
 {
Signature · 1 line
2.18.0
#6 lore raw

PATCH v3 3/3 scsi: ufs-mediatek: enable auto suspend capability

In reply to Stanley Chu

Enable auto suspend capability in MediaTek UFS driver.

---
 drivers/scsi/ufs/ufs-mediatek.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/scsi/ufs/ufs-mediatek.c +3 -0
index 0f6ff33ce52e..83e28edc3ac5 100644
@@ -147,6 +147,9 @@ static int ufs_mtk_init(struct ufs_hba *hba)
 	if (err)
 		goto out_variant_clear;
 
+	/* Enable runtime autosuspend */
+	hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
+
 	/*
 	 * ufshcd_vops_init() is invoked after
 	 * ufshcd_setup_clock(true) in ufshcd_hba_init() thus
Signature · 1 line
2.18.0