Skip to contentSkip to conversation

scsi: ufs: Reduce the power mode change timeout

PATCH In review Bart Van Assche 3 participants 4 messages Aug 11, 2022 – Aug 16, 2022

Subsystems (2)
lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

PATCH 1/1 scsi: ufs: Reduce the power mode change timeout

The current power mode change timeout (180 s) is so large that it can cause a watchdog timer to fire. Reduce the power mode change timeout to 10 seconds.

---
 drivers/ufs/core/ufshcd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +8 -1
index e32b6b834b7f..2dd355a5da54 100644
@@ -8776,6 +8776,8 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
 	struct scsi_device *sdp;
 	unsigned long flags;
 	int ret, retries;
+	unsigned long deadline;
+	int32_t remaining;
 
 	spin_lock_irqsave(hba->host->host_lock, flags);
 	sdp = hba->ufs_device_wlun;
@@ -8808,9 +8810,14 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
 	 * callbacks hence set the RQF_PM flag so that it doesn't resume the
 	 * already suspended childs.
 	 */
+	deadline = jiffies + 10 * HZ;
 	for (retries = 3; retries > 0; --retries) {
+		ret = -ETIMEDOUT;
+		remaining = deadline - jiffies;
+		if (remaining <= 0)
+			break;
 		ret = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
-				START_STOP_TIMEOUT, 0, 0, RQF_PM, NULL);
+				   remaining / HZ, 0, 0, RQF_PM, NULL);
 		if (!scsi_status_is_check_condition(ret) ||
 				!scsi_sense_valid(&sshdr) ||
 				sshdr.sense_key != UNIT_ATTENTION)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Bart Van Assche

The current power mode change timeout (180 s) is so large that it can cause a watchdog timer to fire. Reduce the power mode change timeout to 10 seconds.

---
 drivers/ufs/core/ufshcd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
reviewer
#2 lore raw
In reply to Bart Van Assche
Quoted 3 lines

The current power mode change timeout (180 s) is so large that it can cause a watchdog timer to fire. Reduce the power mode change timeout to 10 seconds.

Maybe also worth noting that it was invented 20 years ago for scsi ioctl, And is less applicable for nowadays ufs devices

Quoted 11 lines
---
 drivers/ufs/core/ufshcd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +0 -0
index e32b6b834b7f..2dd355a5da54 100644

drivers/ufs/core/ufshcd.c static int ufshcd_set_dev_pwr_mode(struct · line 8781

Quoted 6 lines
drivers/ufs/core/ufshcd.c +2 -0
@@ -8776,6 +8776,8 @@ static int ufshcd_set_dev_pwr_mode(struct
 ufs_hba *hba,
        struct scsi_device *sdp;
        unsigned long flags;
        int ret, retries;
+       unsigned long deadline;
+       int32_t remaining;

Maybe use ktime api, like its done throughout the driver?

Thanks,
Avri

Quoted 20 lines
drivers/ufs/core/ufshcd.c +6 -1
        spin_lock_irqsave(hba->host->host_lock, flags);
        sdp = hba->ufs_device_wlun;
@@ -8808,9 +8810,14 @@ static int ufshcd_set_dev_pwr_mode(struct
 ufs_hba *hba,
         * callbacks hence set the RQF_PM flag so that it doesn't resume the
         * already suspended childs.
         */
+       deadline = jiffies + 10 * HZ;
        for (retries = 3; retries > 0; --retries) {
+               ret = -ETIMEDOUT;
+               remaining = deadline - jiffies;
+               if (remaining <= 0)
+                       break;
                ret = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
-                               START_STOP_TIMEOUT, 0, 0, RQF_PM, NULL);
+                                  remaining / HZ, 0, 0, RQF_PM, NULL);
                if (!scsi_status_is_check_condition(ret) ||
                                !scsi_sense_valid(&sshdr) ||
                                sshdr.sense_key != UNIT_ATTENTION)
author reviewer
#3 lore raw
Quoted 12 lines · Avri Altman
Quoted 3 lines

The current power mode change timeout (180 s) is so large that it can cause a watchdog timer to fire. Reduce the power mode change timeout to 10 seconds.

Maybe also worth noting that it was invented 20 years ago for scsi ioctl, And is less applicable for nowadays ufs devices

Quoted 6 lines
---
  drivers/ufs/core/ufshcd.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
Quoted 13 lines

drivers/ufs/core/ufshcd.c static int ufshcd_set_dev_pwr_mode(struct · line 8781

Quoted 11 lines
drivers/ufs/core/ufshcd.c +2 -0
index e32b6b834b7f..2dd355a5da54 100644
@@ -8776,6 +8776,8 @@ static int ufshcd_set_dev_pwr_mode(struct
 ufs_hba *hba,
         struct scsi_device *sdp;
         unsigned long flags;
         int ret, retries;
+       unsigned long deadline;
+       int32_t remaining;

Maybe use ktime api, like its done throughout the driver?

Hi Avri,

Calling ktime_get() is much more expensive than reading the jiffies counter. That's why I prefer to use the jiffies counter if the timeout is significantly larger than 1 / HZ and if the accuracy of 1 / HZ is sufficient.

Thanks,

Bart.