diff mbox

[v2,1/4] cpufreq: Add configurable generic policies

Message ID 1449613890-10403-2-git-send-email-srinivas.pandruvada@linux.intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

srinivas pandruvada Dec. 8, 2015, 10:31 p.m. UTC
For drivers using cpufreq_driver->setpolicy callback, by default two
policies are available (performance and powersave). The client drivers
can't change them, even if there is no support for a policy.
This change adds a new field "available_policies" in the struct
cpufreq_policy. The client driver can optionally set this field during
init() callback. If the client driver doesn't set this field then the
default policies are "performance powersave" matching current
implementation.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/cpufreq/cpufreq.c | 9 ++++++++-
 include/linux/cpufreq.h   | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Viresh Kumar Dec. 9, 2015, 2:18 a.m. UTC | #1
On 08-12-15, 14:31, Srinivas Pandruvada wrote:
> For drivers using cpufreq_driver->setpolicy callback, by default two
> policies are available (performance and powersave). The client drivers
> can't change them, even if there is no support for a policy.
> This change adds a new field "available_policies" in the struct
> cpufreq_policy. The client driver can optionally set this field during
> init() callback. If the client driver doesn't set this field then the
> default policies are "performance powersave" matching current
> implementation.
> 
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---
>  drivers/cpufreq/cpufreq.c | 9 ++++++++-
>  include/linux/cpufreq.h   | 1 +
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 8412ce5..286eaec 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -688,7 +688,10 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
>  	struct cpufreq_governor *t;
>  
>  	if (!has_target()) {
> -		i += sprintf(buf, "performance powersave");
> +		if (policy->available_policies & CPUFREQ_POLICY_PERFORMANCE)
> +			i += sprintf(buf, "performance ");
> +		if (policy->available_policies & CPUFREQ_POLICY_POWERSAVE)
> +			i += sprintf(&buf[i], "powersave ");
>  		goto out;
>  	}
>  
> @@ -966,6 +969,10 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
>  
>  	memcpy(&new_policy, policy, sizeof(*policy));
>  
> +	if (!policy->available_policies)
> +		policy->available_policies = CPUFREQ_POLICY_PERFORMANCE |
> +						CPUFREQ_POLICY_POWERSAVE;
> +
>  	/* Update governor of new_policy to the governor used before hotplug */
>  	gov = find_governor(policy->last_governor);
>  	if (gov)
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 177c768..7cc17df 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -76,6 +76,7 @@ struct cpufreq_policy {
>  	unsigned int		restore_freq; /* = policy->cur before transition */
>  	unsigned int		suspend_freq; /* freq to set during suspend */
>  
> +	u8			available_policies;
>  	unsigned int		policy; /* see above */
>  	unsigned int		last_policy; /* policy before unplug */
>  	struct cpufreq_governor	*governor; /* see below */

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
diff mbox

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 8412ce5..286eaec 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -688,7 +688,10 @@  static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
 	struct cpufreq_governor *t;
 
 	if (!has_target()) {
-		i += sprintf(buf, "performance powersave");
+		if (policy->available_policies & CPUFREQ_POLICY_PERFORMANCE)
+			i += sprintf(buf, "performance ");
+		if (policy->available_policies & CPUFREQ_POLICY_POWERSAVE)
+			i += sprintf(&buf[i], "powersave ");
 		goto out;
 	}
 
@@ -966,6 +969,10 @@  static int cpufreq_init_policy(struct cpufreq_policy *policy)
 
 	memcpy(&new_policy, policy, sizeof(*policy));
 
+	if (!policy->available_policies)
+		policy->available_policies = CPUFREQ_POLICY_PERFORMANCE |
+						CPUFREQ_POLICY_POWERSAVE;
+
 	/* Update governor of new_policy to the governor used before hotplug */
 	gov = find_governor(policy->last_governor);
 	if (gov)
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 177c768..7cc17df 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -76,6 +76,7 @@  struct cpufreq_policy {
 	unsigned int		restore_freq; /* = policy->cur before transition */
 	unsigned int		suspend_freq; /* freq to set during suspend */
 
+	u8			available_policies;
 	unsigned int		policy; /* see above */
 	unsigned int		last_policy; /* policy before unplug */
 	struct cpufreq_governor	*governor; /* see below */