[PATCH v1 2/3] ufs: core: fix abnormal scale up after last cmd finish
Bart Van Assche
bvanassche at acm.org
Tue Aug 29 10:04:26 PDT 2023
On 8/23/23 02:29, peter.wang at mediatek.com wrote:
> From: Peter Wang <peter.wang at mediatek.com>
>
> When ufshcd_clk_scaling_suspend_work(Thread A) running and new command
> coming, ufshcd_clk_scaling_start_busy(Thread B) may get host_lock
> after Thread A first time release host_lock. Then Thread A second time
> get host_lock will set clk_scaling.window_start_t = 0 which scale up
> clock abnormal next polling_ms time.
>
> Below is racing step:
> 1 hba->clk_scaling.suspend_work (Thread A)
> ufshcd_clk_scaling_suspend_work
> 2 spin_lock_irqsave(hba->host->host_lock, irq_flags);
> 3 hba->clk_scaling.is_suspended = true;
> 4 spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
> __ufshcd_suspend_clkscaling
> 7 spin_lock_irqsave(hba->host->host_lock, flags);
> 8 hba->clk_scaling.window_start_t = 0;
> 9 spin_unlock_irqrestore(hba->host->host_lock, flags);
>
> ufshcd_send_command (Thread B)
> ufshcd_clk_scaling_start_busy
> 5 spin_lock_irqsave(hba->host->host_lock, flags);
> ....
> 6 spin_unlock_irqrestore(hba->host->host_lock, flags);
>
> Signed-off-by: Peter Wang <peter.wang at mediatek.com>
> ---
> drivers/ufs/core/ufshcd.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index e3672e55efae..017f32b3a789 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -1385,9 +1385,10 @@ static void ufshcd_clk_scaling_suspend_work(struct work_struct *work)
> return;
> }
> hba->clk_scaling.is_suspended = true;
> + hba->clk_scaling.window_start_t = 0;
> spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
>
> - __ufshcd_suspend_clkscaling(hba);
> + devfreq_suspend_device(hba->devfreq);
> }
>
> static void ufshcd_clk_scaling_resume_work(struct work_struct *work)
There is a second __ufshcd_suspend_clkscaling() call in the same source
file. Please fix that call too.
Thanks,
Bart.
More information about the Linux-mediatek
mailing list