From: "Peter Wang (王信友)" <peter.wang@mediatek.com>
To: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"avri.altman@wdc.com" <avri.altman@wdc.com>,
"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
"Stanley Chu (朱原陞)" <stanley.chu@mediatek.com>,
"jejb@linux.ibm.com" <jejb@linux.ibm.com>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
"bvanassche@acm.org" <bvanassche@acm.org>
Cc: "linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"Jiajie Hao (郝加节)" <jiajie.hao@mediatek.com>,
"CC Chou (周志杰)" <cc.chou@mediatek.com>,
"Eddie Huang (黃智傑)" <eddie.huang@mediatek.com>,
"Alice Chao (趙珮均)" <Alice.Chao@mediatek.com>,
wsd_upstream <wsd_upstream@mediatek.com>,
"Lin Gui (桂林)" <Lin.Gui@mediatek.com>,
"Chun-Hung Wu (巫駿宏)" <Chun-hung.Wu@mediatek.com>,
"Tun-yu Yu (游敦聿)" <Tun-yu.Yu@mediatek.com>,
"Chaotian Jing (井朝天)" <Chaotian.Jing@mediatek.com>,
"Powen Kao (高伯文)" <Powen.Kao@mediatek.com>,
"Naomi Chu (朱詠田)" <Naomi.Chu@mediatek.com>,
"Qilin Tan (谭麒麟)" <Qilin.Tan@mediatek.com>
Subject: Re: [PATCH v2 2/3] ufs: core: fix abnormal scale up after last cmd finish
Date: Fri, 13 Oct 2023 09:42:23 +0000 [thread overview]
Message-ID: <5afd3b643d75cd3a65adba84b2d31ef355e58abe.camel@mediatek.com> (raw)
In-Reply-To: <20230831130826.5592-3-peter.wang@mediatek.com>
Hi Bart,
This patch still need your review.
Thanks.
Peter
On Thu, 2023-08-31 at 21:08 +0800, peter.wang@mediatek.com wrote:
> From: Peter Wang <peter.wang@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.
> Also inlines another __ufshcd_suspend_clkscaling calls.
>
> 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@mediatek.com>
> ---
> drivers/ufs/core/ufshcd.c | 17 ++++-------------
> 1 file changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index e3672e55efae..057549b0e586 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -275,7 +275,6 @@ static inline void
> ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
> static int ufshcd_host_reset_and_restore(struct ufs_hba *hba);
> static void ufshcd_resume_clkscaling(struct ufs_hba *hba);
> static void ufshcd_suspend_clkscaling(struct ufs_hba *hba);
> -static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba);
> static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up);
> static irqreturn_t ufshcd_intr(int irq, void *__hba);
> static int ufshcd_change_power_mode(struct ufs_hba *hba,
> @@ -1385,9 +1384,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)
> @@ -1564,16 +1564,6 @@ static void ufshcd_devfreq_remove(struct
> ufs_hba *hba)
> dev_pm_opp_remove(hba->dev, clki->max_freq);
> }
>
> -static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba)
> -{
> - unsigned long flags;
> -
> - devfreq_suspend_device(hba->devfreq);
> - spin_lock_irqsave(hba->host->host_lock, flags);
> - hba->clk_scaling.window_start_t = 0;
> - spin_unlock_irqrestore(hba->host->host_lock, flags);
> -}
> -
> static void ufshcd_suspend_clkscaling(struct ufs_hba *hba)
> {
> unsigned long flags;
> @@ -1586,11 +1576,12 @@ static void ufshcd_suspend_clkscaling(struct
> ufs_hba *hba)
> if (!hba->clk_scaling.is_suspended) {
> suspend = true;
> hba->clk_scaling.is_suspended = true;
> + hba->clk_scaling.window_start_t = 0;
> }
> spin_unlock_irqrestore(hba->host->host_lock, flags);
>
> if (suspend)
> - __ufshcd_suspend_clkscaling(hba);
> + devfreq_suspend_device(hba->devfreq);
> }
>
> static void ufshcd_resume_clkscaling(struct ufs_hba *hba)
next prev parent reply other threads:[~2023-10-13 9:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 13:08 [PATCH v2 0/3] Fix abnormal clock scaling behaviors peter.wang
2023-08-31 13:08 ` [PATCH v2 1/3] ufs: core: only suspend clock scaling if scale down peter.wang
2023-08-31 13:08 ` [PATCH v2 2/3] ufs: core: fix abnormal scale up after last cmd finish peter.wang
2023-10-13 9:42 ` Peter Wang (王信友) [this message]
2023-10-13 16:25 ` Bart Van Assche
2023-10-13 16:33 ` Bart Van Assche
2023-10-13 17:59 ` Martin K. Petersen
2023-08-31 13:08 ` [PATCH v2 3/3] ufs: core: fix abnormal scale up after scale down peter.wang
2023-10-17 1:11 ` [PATCH v2 0/3] Fix abnormal clock scaling behaviors Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5afd3b643d75cd3a65adba84b2d31ef355e58abe.camel@mediatek.com \
--to=peter.wang@mediatek.com \
--cc=Alice.Chao@mediatek.com \
--cc=Chaotian.Jing@mediatek.com \
--cc=Chun-hung.Wu@mediatek.com \
--cc=Lin.Gui@mediatek.com \
--cc=Naomi.Chu@mediatek.com \
--cc=Powen.Kao@mediatek.com \
--cc=Qilin.Tan@mediatek.com \
--cc=Tun-yu.Yu@mediatek.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@wdc.com \
--cc=bvanassche@acm.org \
--cc=cc.chou@mediatek.com \
--cc=eddie.huang@mediatek.com \
--cc=jejb@linux.ibm.com \
--cc=jiajie.hao@mediatek.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stanley.chu@mediatek.com \
--cc=wsd_upstream@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox