LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1] scsi: ufs: change msleep to usleep_range
@ 2019-07-15 11:21 Bean Huo (beanhuo)
  2019-07-16  0:56 ` Stanley Chu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bean Huo (beanhuo) @ 2019-07-15 11:21 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, Pedro Sousa, Martin K. Petersen
  Cc: James E.J. Bottomley, Evan Green, Stanley Chu, linux-kernel, linux-scsi

From: Bean Huo <beanhuo@micron.com>

This patch is to change msleep() to usleep_range() based on
Documentation/timers/timers-howto.txt. It suggests using
usleep_range() for small msec(1ms - 20ms) since msleep()
will often sleep longer than desired value.

After changing, booting time will be 5ms-10ms faster than before.
I tested this change on two different platforms, one has 5ms faster,
another one is about 10ms. I think this is different on different
platform.

Actually, from UFS host side, 1ms-5ms delay is already sufficient for
its initialization of the local UIC layer.

Fixes: 7a3e97b0dc4b ([SCSI] ufshcd: UFS Host controller driver)
Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 drivers/scsi/ufs/ufshcd.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index a208589426b1..21f7b3b8026c 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4213,12 +4213,6 @@ static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
 {
 	int retry;
 
-	/*
-	 * msleep of 1 and 5 used in this function might result in msleep(20),
-	 * but it was necessary to send the UFS FPGA to reset mode during
-	 * development and testing of this driver. msleep can be changed to
-	 * mdelay and retry count can be reduced based on the controller.
-	 */
 	if (!ufshcd_is_hba_active(hba))
 		/* change controller state to "reset state" */
 		ufshcd_hba_stop(hba, true);
@@ -4241,7 +4235,7 @@ static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
 	 * instruction might be read back.
 	 * This delay can be changed based on the controller.
 	 */
-	msleep(1);
+	usleep_range(1000, 1100);
 
 	/* wait for the host controller to complete initialization */
 	retry = 10;
@@ -4253,7 +4247,7 @@ static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
 				"Controller enable failed\n");
 			return -EIO;
 		}
-		msleep(5);
+		usleep_range(5000, 5100);
 	}
 
 	/* enable UIC related interrupts */
-- 
2.7.4

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

* Re: [PATCH v1] scsi: ufs: change msleep to usleep_range
  2019-07-15 11:21 [PATCH v1] scsi: ufs: change msleep to usleep_range Bean Huo (beanhuo)
@ 2019-07-16  0:56 ` Stanley Chu
  2019-07-16  6:54 ` Avri Altman
  2019-07-17  2:48 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Stanley Chu @ 2019-07-16  0:56 UTC (permalink / raw)
  To: Bean Huo (beanhuo)
  Cc: Alim Akhtar, Avri Altman, Pedro Sousa, Martin K. Petersen,
	James E.J. Bottomley, Evan Green, linux-kernel, linux-scsi

Hi Bean,

On Mon, 2019-07-15 at 11:21 +0000, Bean Huo (beanhuo) wrote:
> From: Bean Huo <beanhuo@micron.com>
> 
> This patch is to change msleep() to usleep_range() based on
> Documentation/timers/timers-howto.txt. It suggests using
> usleep_range() for small msec(1ms - 20ms) since msleep()
> will often sleep longer than desired value.
> 
> After changing, booting time will be 5ms-10ms faster than before.
> I tested this change on two different platforms, one has 5ms faster,
> another one is about 10ms. I think this is different on different
> platform.
> 
> Actually, from UFS host side, 1ms-5ms delay is already sufficient for
> its initialization of the local UIC layer.
> 
> Fixes: 7a3e97b0dc4b ([SCSI] ufshcd: UFS Host controller driver)
> Signed-off-by: Bean Huo <beanhuo@micron.com>
> ---
>  drivers/scsi/ufs/ufshcd.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index a208589426b1..21f7b3b8026c 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -4213,12 +4213,6 @@ static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
>  {
>  	int retry;
>  
> -	/*
> -	 * msleep of 1 and 5 used in this function might result in msleep(20),
> -	 * but it was necessary to send the UFS FPGA to reset mode during
> -	 * development and testing of this driver. msleep can be changed to
> -	 * mdelay and retry count can be reduced based on the controller.
> -	 */
>  	if (!ufshcd_is_hba_active(hba))
>  		/* change controller state to "reset state" */
>  		ufshcd_hba_stop(hba, true);
> @@ -4241,7 +4235,7 @@ static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
>  	 * instruction might be read back.
>  	 * This delay can be changed based on the controller.
>  	 */
> -	msleep(1);
> +	usleep_range(1000, 1100);
>  
>  	/* wait for the host controller to complete initialization */
>  	retry = 10;
> @@ -4253,7 +4247,7 @@ static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
>  				"Controller enable failed\n");
>  			return -EIO;
>  		}
> -		msleep(5);
> +		usleep_range(5000, 5100);
>  	}
>  
>  	/* enable UIC related interrupts */

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

Thanks,
Stanley




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

* RE: [PATCH v1] scsi: ufs: change msleep to usleep_range
  2019-07-15 11:21 [PATCH v1] scsi: ufs: change msleep to usleep_range Bean Huo (beanhuo)
  2019-07-16  0:56 ` Stanley Chu
@ 2019-07-16  6:54 ` Avri Altman
  2019-07-17  2:48 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Avri Altman @ 2019-07-16  6:54 UTC (permalink / raw)
  To: Bean Huo (beanhuo), Alim Akhtar, Pedro Sousa, Martin K. Petersen
  Cc: James E.J. Bottomley, Evan Green, Stanley Chu, linux-kernel, linux-scsi

> 
> From: Bean Huo <beanhuo@micron.com>
> 
> This patch is to change msleep() to usleep_range() based on
> Documentation/timers/timers-howto.txt. It suggests using
> usleep_range() for small msec(1ms - 20ms) since msleep()
> will often sleep longer than desired value.
> 
> After changing, booting time will be 5ms-10ms faster than before.
> I tested this change on two different platforms, one has 5ms faster,
> another one is about 10ms. I think this is different on different
> platform.
> 
> Actually, from UFS host side, 1ms-5ms delay is already sufficient for
> its initialization of the local UIC layer.
> 
> Fixes: 7a3e97b0dc4b ([SCSI] ufshcd: UFS Host controller driver)
> Signed-off-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>

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

* Re: [PATCH v1] scsi: ufs: change msleep to usleep_range
  2019-07-15 11:21 [PATCH v1] scsi: ufs: change msleep to usleep_range Bean Huo (beanhuo)
  2019-07-16  0:56 ` Stanley Chu
  2019-07-16  6:54 ` Avri Altman
@ 2019-07-17  2:48 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2019-07-17  2:48 UTC (permalink / raw)
  To: Bean Huo (beanhuo)
  Cc: Alim Akhtar, Avri Altman, Pedro Sousa, Martin K. Petersen,
	James E.J. Bottomley, Evan Green, Stanley Chu, linux-kernel,
	linux-scsi


Bean,

> This patch is to change msleep() to usleep_range() based on
> Documentation/timers/timers-howto.txt. It suggests using
> usleep_range() for small msec(1ms - 20ms) since msleep() will often
> sleep longer than desired value.

Applied to 5.4/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2019-07-17  2:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15 11:21 [PATCH v1] scsi: ufs: change msleep to usleep_range Bean Huo (beanhuo)
2019-07-16  0:56 ` Stanley Chu
2019-07-16  6:54 ` Avri Altman
2019-07-17  2:48 ` Martin K. Petersen

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