From: Bean Huo <beanhuo@iokpp.de>
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
"Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>,
Avri Altman <avri.altman@sandisk.com>,
Bart Van Assche <bvanassche@acm.org>,
Jie Zhan <zhanjie9@hisilicon.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, Bean Huo <beanhuo@micron.com>
Subject: [PATCH 3/3] scsi: ufs: core: Report the current clock frequency to devfreq
Date: Mon, 31 Aug 2026 15:01:29 +0200 [thread overview]
Message-ID: <20260831130129.3979454-4-beanhuo@iokpp.de> (raw)
In-Reply-To: <20260831130129.3979454-1-beanhuo@iokpp.de>
From: Bean Huo <beanhuo@micron.com>
When a driver does not provide a ->get_cur_freq() callback, the cur_freq
sysfs attribute shows devfreq->previous_freq, which only tracks the
scaling that the governor itself did.
The UFS controller is also scaled outside the governor. The clearest
example is writing 0 to clkscale_enable: ufshcd_clkscale_enable_store()
sets the clocks to max_freq through ufshcd_devfreq_scale() and suspends
the governor, so devfreq_set_target() is never called. After that,
cur_freq keeps showing the last frequency the governor chose instead of
the one the controller runs at, and it does so as long as clock scaling
stays disabled.
Add ufshcd_devfreq_get_cur_freq(). It reports clk_scaling.target_freq
when OPPs are used and the first clock's curr_freq otherwise, the same
values that ufshcd_devfreq_get_dev_status() reports. Both are 0 until
the controller is scaled for the first time, so return an error in that
case and let devfreq use the frequency it last set.
Signed-off-by: Bean Huo <beanhuo@micron.com>
---
drivers/ufs/core/ufshcd.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 2ba244cf40ac..45187a7e4f4f 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -1716,6 +1716,37 @@ static int ufshcd_devfreq_get_dev_status(struct device *dev,
return 0;
}
+static int ufshcd_devfreq_get_cur_freq(struct device *dev, unsigned long *freq)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ unsigned long cur_freq;
+
+ if (!ufshcd_is_clkscaling_supported(hba))
+ return -EINVAL;
+
+ if (hba->use_pm_opp) {
+ cur_freq = hba->clk_scaling.target_freq;
+ } else {
+ struct ufs_clk_info *clki;
+
+ clki = list_first_entry(&hba->clk_list_head,
+ struct ufs_clk_info, list);
+ cur_freq = clki->curr_freq;
+ }
+
+ /*
+ * target_freq stays 0 until something scales the controller for the
+ * first time. Report nothing rather than 0 so devfreq falls back to
+ * the frequency it last set.
+ */
+ if (!cur_freq)
+ return -EINVAL;
+
+ *freq = cur_freq;
+
+ return 0;
+}
+
static int ufshcd_devfreq_init(struct ufs_hba *hba)
{
struct list_head *clk_list = &hba->clk_list_head;
@@ -9612,6 +9643,7 @@ static struct ufs_hba_variant_params ufs_hba_vps = {
.devfreq_profile.polling_ms = 100,
.devfreq_profile.target = ufshcd_devfreq_target,
.devfreq_profile.get_dev_status = ufshcd_devfreq_get_dev_status,
+ .devfreq_profile.get_cur_freq = ufshcd_devfreq_get_cur_freq,
.ondemand_data.upthreshold = 70,
.ondemand_data.downdifferential = 5,
};
--
2.34.1
next prev parent reply other threads:[~2026-08-31 13:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 13:01 [PATCH 0/3] devfreq: check the get_cur_freq() return value and use it in ufshcd Bean Huo
2026-08-31 13:01 ` [PATCH 1/3] PM / devfreq: Fall back to previous_freq when get_cur_freq() fails Bean Huo
2026-08-31 13:01 ` [PATCH 2/3] PM / devfreq: Add more details to the get_cur_freq() comment Bean Huo
2026-08-31 13:01 ` Bean Huo [this message]
2026-09-01 1:33 ` [PATCH 3/3] scsi: ufs: core: Report the current clock frequency to devfreq Stanley Jhu
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=20260831130129.3979454-4-beanhuo@iokpp.de \
--to=beanhuo@iokpp.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=cw00.choi@samsung.com \
--cc=krzk@kernel.org \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=zhanjie9@hisilicon.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