Fix abnormal clock scaling behaviors
Subsystems (3)
cover Fix abnormal clock scaling behaviors
From: Peter Wang <[email protected]>
This patch fix abnormal clock scaling behaviors.
Peter Wang (3):
ufs: core: only suspend clock scaling if scale down
ufs: core: fix abnormal scale up after last cmd finish
ufs: core: fix abnormal scale up after scale down
drivers/ufs/core/ufshcd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/3 ufs: core: only suspend clock scaling if scale down
From: Peter Wang <[email protected]>
If clock scale up and suspend clock scaling, ufs will keep high performance/power mode but no read/write requests on going. It is logic wrong and have power concern.
--- drivers/ufs/core/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +1 -1
@@ -1458,7 +1458,7 @@ static int ufshcd_devfreq_target(struct device *dev, ktime_to_us(ktime_sub(ktime_get(), start)), ret); out: -if (sched_clk_scaling_suspend_work) +if (sched_clk_scaling_suspend_work && !scale_up)queue_work (hba->clk_scaling.workq, &hba->clk_scaling.suspend_work);
Signature · 1 line
2.18.0
Bart Van Assche
reviewerRe: [PATCH v1 1/3] ufs: core: only suspend clock scaling if scale down
Quoted 16 lines · On 8/23/23 02:29, [email protected] wrote:
From: Peter Wang <[email protected]>
If clock scale up and suspend clock scaling, ufs will keep high performance/power mode but no read/write requests on going. It is logic wrong and have power concern.
Signed-off-by Peter Wang <[email protected]>--- drivers/ufs/core/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/ufs/core/ufshcd.c +0
-0
drivers/ufs/core/ufshcd.c static int ufshcd_devfreq_target(struct device *dev, · line 1464
Quoted 8 lines
drivers/ufs/core/ufshcd.c +1
-1@@ -1458,7 +1458,7 @@ static int ufshcd_devfreq_target(struct device *dev, ktime_to_us(ktime_sub(ktime_get(), start)), ret); out: -if (sched_clk_scaling_suspend_work) +if (sched_clk_scaling_suspend_work && !scale_up)queue_work (hba->clk_scaling.workq, &hba->clk_scaling.suspend_work);
Is this perhaps the same patch as
https://lore.kernel.org/linux-scsi/[email protected]/ ?
Thanks,
Bart.
Re: [PATCH v1 1/3] ufs: core: only suspend clock scaling if scale down
In reply to [email protected]Quoted 3 lines · On 8/23/23 02:29, [email protected] wrote:
If clock scale up and suspend clock scaling, ufs will keep high performance/power mode but no read/write requests on going. It is logic wrong and have power concern.
PATCH 2/3 ufs: core: fix abnormal scale up after last cmd finish
In reply to [email protected]From: Peter Wang <[email protected]>
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);
--- drivers/ufs/core/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +2 -1
@@ -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)
Signature · 1 line
2.18.0
Bart Van Assche
reviewerRe: [PATCH v1 2/3] ufs: core: fix abnormal scale up after last cmd finish
Quoted 36 lines · On 8/23/23 02:29, [email protected] wrote:
From: Peter Wang <[email protected]>
When
ufshcd_clk_scaling_suspend_work(Thread A)running and new command coming,ufshcd_clk_scaling_start_busy(Thread B)may gethost_lockafter Thread A first time releasehost_lock. Then Thread A second time gethost_lockwill set clk_scaling.window_start_t = 0 which scale up clock abnormal nextpolling_mstime.Below is racing step:
1hba->clk_scaling.suspend_work(Thread A)
ufshcd_clk_scaling_suspend_work
2spin_lock_irqsave(hba->host->host_lock, irq_flags);
3hba->clk_scaling.is_suspended= true;
4spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
__ufshcd_suspend_clkscaling
7spin_lock_irqsave(hba->host->host_lock, flags);
8hba->clk_scaling.window_start_t= 0;
9spin_unlock_irqrestore(hba->host->host_lock, flags);
ufshcd_send_command(Thread B)
ufshcd_clk_scaling_start_busy5 spin_lock_irqsave(hba->host->host_lock, flags); ....6
spin_unlock_irqrestore(hba->host->host_lock, flags);Signed-off-by Peter Wang <[email protected]>--- drivers/ufs/core/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/ufs/core/ufshcd.c +0
-0@@ -1385,9 +1385,10 @@ static void ufshcd_clk_scaling_suspend_work(struct work_struct *work)return ;
drivers/ufs/core/ufshcd.c static void ufshcd_clk_scaling_suspend_work(struct work_struct *work) · line 1394
Quoted 10 lines
drivers/ufs/core/ufshcd.c +2
-1} 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.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Bart Van Assche
reviewerRe: [PATCH v1 2/3] ufs: core: fix abnormal scale up after last cmd finish
Quoted 3 lines · Peter Wang (王信友)
Second
__ufshcd_suspend_clkscalingis called from ufs wl suspend, which no on-going cmd.So, it should be not a problem. (cmd finish suspend clock scaling racing with new cmd start busy)
This patch inlines one of the two __ufshcd_suspend_clkscaling() calls. I think it would be better if both calls are inlined.
Thanks,
Bart.
Re: [PATCH v1 2/3] ufs: core: fix abnormal scale up after last cmd finish
Quoted 10 lines · Bart Van Assche
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 1 line · Peter Wang (王信友)
Second
__ufshcd_suspend_clkscalingis called from ufs wl suspend,which no on-going cmd.
Quoted 2 lines
So, it should be not a problem. (cmd finish suspend clock scaling
racing with new cmd start busy)
Quoted 7 lines
This patch inlines one of the two
__ufshcd_suspend_clkscaling()calls.
I think it would be better if both calls are inlined.Thanks,
Bart.
Hi Bart,
Could you help review the new patch.
Thanks.
Peter
PATCH 3/3 ufs: core: fix abnormal scale up after scale down
In reply to [email protected]From: Peter Wang <[email protected]>
When no active_reqs, devfreq_monitor(Thread A) will suspend clock scaling. But it may have racing with clk_scaling.suspend_work(Thread B) and actually not suspend clock scaling(requue after suspend).
Next time after polling_ms, devfreq_monitor read clk_scaling.window_start_t = 0 then scale up clock abnormal.
Below is racing step:
devfreq->work (Thread A) devfreq_monitor update_devfreq ..... ufshcd_devfreq_target queue_work(hba->clk_scaling.workq, 1 &hba->clk_scaling.suspend_work) ..... 5 queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms));
2 hba->clk_scaling.suspend_work (Thread B)
ufshcd_clk_scaling_suspend_work __ufshcd_suspend_clkscaling devfreq_suspend_device(hba->devfreq); 3 cancel_delayed_work_sync(&devfreq->work); 4 hba->clk_scaling.window_start_t = 0; .....
--- drivers/ufs/core/ufshcd.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/ufs/core/ufshcd.c +7 -0
@@ -1431,6 +1431,13 @@ static int ufshcd_devfreq_target(struct device *dev,return 0 ; } +/* Skip scaling clock when clock scaling is suspended */ +if (hba->clk_scaling.is_suspended) { +spin_unlock_irqrestore (hba->host->host_lock, irq_flags); +dev_warn (hba->dev,"clock scaling is suspended, skip" ); +return 0 ; + } +if (!hba->clk_scaling.active_reqs) sched_clk_scaling_suspend_work = true;
Signature · 1 line
2.18.0
Re: [PATCH v1 3/3] ufs: core: fix abnormal scale up after scale down
Quoted 5 lines · On 8/23/23 02:29, [email protected] wrote:
When no
active_reqs,devfreq_monitor(Thread A)will suspend clock scaling. But it may have racing withclk_scaling.suspend_work(Thread B)and actually not suspend clock scaling(requue after suspend).
Next time afterpolling_ms,devfreq_monitorread clk_scaling.window_start_t = 0 then scale up clock abnormal.
Re: [PATCH v1 3/3] ufs: core: fix abnormal scale up after scale down
In reply to [email protected]Quoted 5 lines · On 8/23/23 02:29, [email protected] wrote:
When no
active_reqs,devfreq_monitor(Thread A)will suspend clock scaling. But it may have racing withclk_scaling.suspend_work(Thread B)and actually not suspend clock scaling(requue after suspend).
Next time afterpolling_ms,devfreq_monitorread clk_scaling.window_start_t = 0 then scale up clock abnormal.
Bart Van Assche
reviewerQuoted 1 line · On 8/23/23 02:29, [email protected] wrote:
This patch fix abnormal clock scaling behaviors.
For a reason that is not known to me this patch series did not show up in my mailbox. I have imported these patches manually from lore into my mailbox.
Bart.