diff mbox series

[v1,3/3] ufs: core: fix abnormal scale up after scale down

Message ID 20230823092948.22734-4-peter.wang@mediatek.com (mailing list archive)
State Superseded
Headers show
Series Fix abnormal clock scaling behaviors | expand

Commit Message

Peter Wang (王信友) Aug. 23, 2023, 9:29 a.m. UTC
From: Peter Wang <peter.wang@mediatek.com>

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

Signed-off-by: Peter Wang <peter.wang@mediatek.com>
---
 drivers/ufs/core/ufshcd.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Bart Van Assche Aug. 29, 2023, 5:05 p.m. UTC | #1
On 8/23/23 02:29, peter.wang@mediatek.com wrote:
> 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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Bart Van Assche Aug. 30, 2023, 7:41 p.m. UTC | #2
On 8/23/23 02:29, peter.wang@mediatek.com wrote:
> 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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 017f32b3a789..d3b913d389f4 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -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;