From: Xuewen Yan <xuewen.yan@unisoc.com>
To: <rafael@kernel.org>, <viresh.kumar@linaro.org>,
<linux-pm@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <guohua.yan@unisoc.com>,
<ke.wang@unisoc.com>, <xuewen.yan94@gmail.com>
Subject: [RFC PATCH] cpufreq: userspace: Add fast-switch support for userspace
Date: Mon, 9 Dec 2024 16:14:29 +0800 [thread overview]
Message-ID: <20241209081429.1871-1-xuewen.yan@unisoc.com> (raw)
Now, the userspace governor does not support userspace,
if the driver only use the fast-switch and not add target_index(),
it will cause uerspace not work.
So add fast-switch support for userspace governor.
Co-developed-by: Guohua Yan <guohua.yan@unisoc.com>
Signed-off-by: Guohua Yan <guohua.yan@unisoc.com>
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
drivers/cpufreq/cpufreq_userspace.c | 35 +++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index 2c42fee76daa..3a99197246ed 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -21,6 +21,30 @@ struct userspace_policy {
struct mutex mutex;
};
+static int cpufreq_userspace_target_freq(struct cpufreq_policy *policy,
+ unsigned int target_freq, unsigned int relation)
+{
+ int ret;
+
+ if (policy->fast_switch_enabled) {
+ unsigned int idx;
+
+ target_freq = clamp_val(target_freq, policy->min, policy->max);
+
+ if (!policy->freq_table)
+ return target_freq;
+
+ idx = cpufreq_frequency_table_target(policy, target_freq, relation);
+ policy->cached_resolved_idx = idx;
+ policy->cached_target_freq = target_freq;
+ ret = !cpufreq_driver_fast_switch(policy, policy->freq_table[idx].frequency);
+ } else {
+ ret = __cpufreq_driver_target(policy, target_freq, relation);
+ }
+
+ return ret;
+}
+
/**
* cpufreq_set - set the CPU frequency
* @policy: pointer to policy struct where freq is being set
@@ -41,7 +65,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
userspace->setspeed = freq;
- ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L);
+ ret = cpufreq_userspace_target_freq(policy, freq, CPUFREQ_RELATION_L);
err:
mutex_unlock(&userspace->mutex);
return ret;
@@ -62,6 +86,8 @@ static int cpufreq_userspace_policy_init(struct cpufreq_policy *policy)
mutex_init(&userspace->mutex);
+ cpufreq_enable_fast_switch(policy);
+
policy->governor_data = userspace;
return 0;
}
@@ -72,6 +98,7 @@ static int cpufreq_userspace_policy_init(struct cpufreq_policy *policy)
*/
static void cpufreq_userspace_policy_exit(struct cpufreq_policy *policy)
{
+ cpufreq_disable_fast_switch(policy);
kfree(policy->governor_data);
policy->governor_data = NULL;
}
@@ -112,13 +139,13 @@ static void cpufreq_userspace_policy_limits(struct cpufreq_policy *policy)
policy->cpu, policy->min, policy->max, policy->cur, userspace->setspeed);
if (policy->max < userspace->setspeed)
- __cpufreq_driver_target(policy, policy->max,
+ cpufreq_userspace_target_freq(policy, policy->max,
CPUFREQ_RELATION_H);
else if (policy->min > userspace->setspeed)
- __cpufreq_driver_target(policy, policy->min,
+ cpufreq_userspace_target_freq(policy, policy->min,
CPUFREQ_RELATION_L);
else
- __cpufreq_driver_target(policy, userspace->setspeed,
+ cpufreq_userspace_target_freq(policy, userspace->setspeed,
CPUFREQ_RELATION_L);
mutex_unlock(&userspace->mutex);
--
2.25.1
next reply other threads:[~2024-12-09 8:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 8:14 Xuewen Yan [this message]
2024-12-09 10:36 ` Christian Loehle
2024-12-10 3:27 ` Xuewen Yan
2024-12-10 10:20 ` Christian Loehle
2024-12-12 6:56 ` Viresh Kumar
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=20241209081429.1871-1-xuewen.yan@unisoc.com \
--to=xuewen.yan@unisoc.com \
--cc=guohua.yan@unisoc.com \
--cc=ke.wang@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=xuewen.yan94@gmail.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
all inboxes | Powered by JetHome®