linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] cpufreq: respect the min/max settings from user space
@ 2014-11-10  6:14 Vince Hsu
  2014-11-14 23:56 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Vince Hsu @ 2014-11-10  6:14 UTC (permalink / raw)
  To: rjw, viresh.kumar
  Cc: linux-pm, linux-kernel, =bilhuang, dgreid, olofj, Vince Hsu

When the user space tries to set scaling_(max|min)_freq through
sysfs, the cpufreq_set_policy() asks other driver's opinions
for the max/min frequencies. Some device drivers, like Tegra
CPU EDP which is not upstreamed yet though, may constrain the
CPU maximum frequency dynamically because of board design.
So if the user space access happens and some driver is capping
the cpu frequency at the same time, the user_policy->(max|min)
is overridden by the capped value, and that's not expected by
the user space. And if the user space is not invoked again,
the CPU will always be capped by the user_policy->(max|min)
even no drivers limit the CPU frequency any more.

This patch preserves the user specified min/max settings, so that
every time the cpufreq policy is updated, the new max/min can
be re-evaluated correctly based on the user's expection and
the present device drivers' status.

Signed-off-by: Vince Hsu <vinceh@nvidia.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
---
v2: added Viresh's Acked-by

 drivers/cpufreq/cpufreq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 644b54e1e7d1..0721ab352e2a 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -535,7 +535,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
 static ssize_t store_##file_name					\
 (struct cpufreq_policy *policy, const char *buf, size_t count)		\
 {									\
-	int ret;							\
+	int ret, temp;							\
 	struct cpufreq_policy new_policy;				\
 									\
 	ret = cpufreq_get_policy(&new_policy, policy->cpu);		\
@@ -546,8 +546,10 @@ static ssize_t store_##file_name					\
 	if (ret != 1)							\
 		return -EINVAL;						\
 									\
+	temp = new_policy.object;					\
 	ret = cpufreq_set_policy(policy, &new_policy);		\
-	policy->user_policy.object = policy->object;			\
+	if (!ret)							\
+		policy->user_policy.object = temp;			\
 									\
 	return ret ? ret : count;					\
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] cpufreq: respect the min/max settings from user space
  2014-11-10  6:14 [PATCH V2] cpufreq: respect the min/max settings from user space Vince Hsu
@ 2014-11-14 23:56 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2014-11-14 23:56 UTC (permalink / raw)
  To: Vince Hsu; +Cc: viresh.kumar, linux-pm, linux-kernel, =bilhuang, dgreid, olofj

On Monday, November 10, 2014 02:14:50 PM Vince Hsu wrote:
> When the user space tries to set scaling_(max|min)_freq through
> sysfs, the cpufreq_set_policy() asks other driver's opinions
> for the max/min frequencies. Some device drivers, like Tegra
> CPU EDP which is not upstreamed yet though, may constrain the
> CPU maximum frequency dynamically because of board design.
> So if the user space access happens and some driver is capping
> the cpu frequency at the same time, the user_policy->(max|min)
> is overridden by the capped value, and that's not expected by
> the user space. And if the user space is not invoked again,
> the CPU will always be capped by the user_policy->(max|min)
> even no drivers limit the CPU frequency any more.
> 
> This patch preserves the user specified min/max settings, so that
> every time the cpufreq policy is updated, the new max/min can
> be re-evaluated correctly based on the user's expection and
> the present device drivers' status.
> 
> Signed-off-by: Vince Hsu <vinceh@nvidia.com>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Queued up for 3.19, thanks!

> ---
> v2: added Viresh's Acked-by
> 
>  drivers/cpufreq/cpufreq.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 644b54e1e7d1..0721ab352e2a 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -535,7 +535,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
>  static ssize_t store_##file_name					\
>  (struct cpufreq_policy *policy, const char *buf, size_t count)		\
>  {									\
> -	int ret;							\
> +	int ret, temp;							\
>  	struct cpufreq_policy new_policy;				\
>  									\
>  	ret = cpufreq_get_policy(&new_policy, policy->cpu);		\
> @@ -546,8 +546,10 @@ static ssize_t store_##file_name					\
>  	if (ret != 1)							\
>  		return -EINVAL;						\
>  									\
> +	temp = new_policy.object;					\
>  	ret = cpufreq_set_policy(policy, &new_policy);		\
> -	policy->user_policy.object = policy->object;			\
> +	if (!ret)							\
> +		policy->user_policy.object = temp;			\
>  									\
>  	return ret ? ret : count;					\
>  }
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-14 23:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-10  6:14 [PATCH V2] cpufreq: respect the min/max settings from user space Vince Hsu
2014-11-14 23:56 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).