linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: Reduce the power mode change timeout
@ 2022-08-11 23:43 Bart Van Assche
  2022-08-12  0:01 ` Stanley Chu
  2022-08-14  7:45 ` Avri Altman
  0 siblings, 2 replies; 4+ messages in thread
From: Bart Van Assche @ 2022-08-11 23:43 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: Jaegeuk Kim, linux-scsi, Adrian Hunter, Bart Van Assche,
	James E.J. Bottomley, Bean Huo, Avri Altman

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.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/core/ufshcd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index e32b6b834b7f..2dd355a5da54 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -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)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: ufs: Reduce the power mode change timeout
  2022-08-11 23:43 [PATCH] scsi: ufs: Reduce the power mode change timeout Bart Van Assche
@ 2022-08-12  0:01 ` Stanley Chu
  2022-08-14  7:45 ` Avri Altman
  1 sibling, 0 replies; 4+ messages in thread
From: Stanley Chu @ 2022-08-12  0:01 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, Jaegeuk Kim, linux-scsi, Adrian Hunter,
	James E.J. Bottomley, Bean Huo, Avri Altman

On Fri, Aug 12, 2022 at 7:52 AM Bart Van Assche <bvanassche@acm.org> wrote:
>
> 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.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  drivers/ufs/core/ufshcd.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>

Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] scsi: ufs: Reduce the power mode change timeout
  2022-08-11 23:43 [PATCH] scsi: ufs: Reduce the power mode change timeout Bart Van Assche
  2022-08-12  0:01 ` Stanley Chu
@ 2022-08-14  7:45 ` Avri Altman
  2022-08-16 17:42   ` Bart Van Assche
  1 sibling, 1 reply; 4+ messages in thread
From: Avri Altman @ 2022-08-14  7:45 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: Jaegeuk Kim, linux-scsi, Adrian Hunter, James E.J. Bottomley, Bean Huo

> 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

> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  drivers/ufs/core/ufshcd.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index e32b6b834b7f..2dd355a5da54 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -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

> 
>         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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: ufs: Reduce the power mode change timeout
  2022-08-14  7:45 ` Avri Altman
@ 2022-08-16 17:42   ` Bart Van Assche
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2022-08-16 17:42 UTC (permalink / raw)
  To: Avri Altman, Martin K . Petersen
  Cc: Jaegeuk Kim, linux-scsi, Adrian Hunter, James E.J. Bottomley, Bean Huo

On 8/14/22 00:45, Avri Altman wrote:
>> 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
> 
>>
>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>> ---
>>   drivers/ufs/core/ufshcd.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
>> index e32b6b834b7f..2dd355a5da54 100644
>> --- a/drivers/ufs/core/ufshcd.c
>> +++ b/drivers/ufs/core/ufshcd.c
>> @@ -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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-16 17:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 23:43 [PATCH] scsi: ufs: Reduce the power mode change timeout Bart Van Assche
2022-08-12  0:01 ` Stanley Chu
2022-08-14  7:45 ` Avri Altman
2022-08-16 17:42   ` Bart Van Assche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).