Skip to contentSkip to conversation

cpufreq governors and Intel P state driver compatibility

PATCH In review Srinivas Pandruvada 3 participants 12 messages Dec 8, 2015 – Dec 16, 2015

Subsystems (3)
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

v2 cover cpufreq governors and Intel P state driver compatibility

Intel P State driver implements two policies, performance and powersave. The powersave policy is similar to ondemand cpufreq governor when using acpi-cpufreq. This causes lots of confusion among users. This results in invalid comparison of performance when acpi-cpufreq and Intel P state performance is compared.

The reason Intel P state called powersave when it actually implemented ondemand style P State selection, because the cpufreq core only allows two generic policies "performance and powersave" for drivers which has setpolicy() interface. All drivers using this interface are forced to support these two policies.

This patchset adds feature to have configurable generic policies and allows ondemand as one of the policy. With this approach, Intel P state now adds support for ondemand policy and power save policy both in addition to performance.

v2
- Suggestion by Viresh to remove callback to get policies
- Document update for cpufreq cpu-drivers
- Dropped powersave patch, so that it will still default to ondemand as a possible option suggested by Thomas.

If it breaks any distros are user, who were using Intel P state driver with powersave, please comment.

v1
base version

To be done:
Intel P state document update

Srinivas Pandruvada (4):
cpufreq: Add configurable generic policies
cpufreq: Add ondemand as a generic policy
Documentation: cpu-freq: update setpolicy documentation
cpufreq: intel_pstate: Change powersave to ondemand policy

 Documentation/cpu-freq/cpu-drivers.txt |  9 +++++++--
 drivers/cpufreq/cpufreq.c              | 17 ++++++++++++++++-
 drivers/cpufreq/intel_pstate.c         | 14 ++++++++------
 include/linux/cpufreq.h                |  4 +++-
 4 files changed, 34 insertions(+), 10 deletions(-)
Signature · 1 line
2.4.3
author maintainer
#1 lore raw

PATCH v2 1/4 cpufreq: Add configurable generic policies

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.

---
 drivers/cpufreq/cpufreq.c | 9 ++++++++-
 include/linux/cpufreq.h   | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +8 -1
index 8412ce5..286eaec 100644
@@ -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)
include/linux/cpufreq.h +1 -0
index 177c768..7cc17df 100644
@@ -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 */
Signature · 1 line
2.4.3
maintainer Acked-by on v2 1/4
#2 lore raw

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

Quoted 47 lines · Srinivas Pandruvada

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.

---
 drivers/cpufreq/cpufreq.c | 9 ++++++++-
 include/linux/cpufreq.h   | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +8 -1
index 8412ce5..286eaec 100644
@@ -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)
include/linux/cpufreq.h +0 -0
index 177c768..7cc17df 100644

include/linux/cpufreq.h struct cpufreq_policy { · line 82

Quoted 7 lines
include/linux/cpufreq.h +1 -0
@@ -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 */
Signature · 1 line
viresh
author maintainer
#3 lore raw

PATCH v2 2/4 cpufreq: Add ondemand as a generic policy

In reply to Srinivas Pandruvada

Allow ondemand policy as a supported generic policy. Client drivers can enable this policy by setting struct cpufreq->available_policies during init() callback.

---
 drivers/cpufreq/cpufreq.c | 8 ++++++++
 include/linux/cpufreq.h   | 3 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +8 -0
index 286eaec..7d45fb6 100644
@@ -528,6 +528,10 @@ static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
 						CPUFREQ_NAME_LEN)) {
 			*policy = CPUFREQ_POLICY_POWERSAVE;
 			err = 0;
+		} else if (!strncasecmp(str_governor, "ondemand",
+					CPUFREQ_NAME_LEN)) {
+			*policy = CPUFREQ_POLICY_ONDEMAND;
+			err = 0;
 		}
 	} else {
 		struct cpufreq_governor *t;
@@ -640,6 +644,8 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
 		return sprintf(buf, "powersave\n");
 	else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
 		return sprintf(buf, "performance\n");
+	else if (policy->policy == CPUFREQ_POLICY_ONDEMAND)
+		return sprintf(buf, "ondemand\n");
 	else if (policy->governor)
 		return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
 				policy->governor->name);
@@ -692,6 +698,8 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
 			i += sprintf(buf, "performance ");
 		if (policy->available_policies & CPUFREQ_POLICY_POWERSAVE)
 			i += sprintf(&buf[i], "powersave ");
+		if (policy->available_policies & CPUFREQ_POLICY_ONDEMAND)
+			i += sprintf(&buf[i], "ondemand ");
 		goto out;
 	}
 
include/linux/cpufreq.h +2 -1
index 7cc17df..0b9e119 100644
@@ -230,7 +230,7 @@ struct cpufreq_driver {
 	int		(*init)(struct cpufreq_policy *policy);
 	int		(*verify)(struct cpufreq_policy *policy);
 
-	/* define one out of two */
+	/* define one out of three */
 	int		(*setpolicy)(struct cpufreq_policy *policy);
 
 	/*
@@ -432,6 +432,7 @@ static inline unsigned long cpufreq_scale(unsigned long old, u_int div,
  */
 #define CPUFREQ_POLICY_POWERSAVE	(1)
 #define CPUFREQ_POLICY_PERFORMANCE	(2)
+#define CPUFREQ_POLICY_ONDEMAND		(4)
 
 /* Governor Events */
 #define CPUFREQ_GOV_START	1
Signature · 1 line
2.4.3
author maintainer
#4 lore raw

PATCH v2 3/4 Documentation: cpu-freq: update setpolicy documentation

In reply to Srinivas Pandruvada

Updated documentation for usage of setpolicy interface.

---
 Documentation/cpu-freq/cpu-drivers.txt | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/cpu-freq/cpu-drivers.txt +7 -2
index 14f4e63..144e0ad 100644
@@ -195,8 +195,13 @@ argument. You need to set the lower limit of the in-processor or
 in-chipset dynamic frequency switching to policy->min, the upper limit
 to policy->max, and -if supported- select a performance-oriented
 setting when policy->policy is CPUFREQ_POLICY_PERFORMANCE, and a
-powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE. Also check
-the reference implementation in drivers/cpufreq/longrun.c
+powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE, and a
+optional on demand frequency scaling setting when
+CPUFREQ_POLICY_ONDEMAND. The default supported policies are
+CPUFREQ_POLICY_PERFORMANCE and CPUFREQ_POLICY_POWERSAVE. To change or
+add supported policies set policy->available_policies with a mask of
+supported policies. Also check the reference implementation in
+drivers/cpufreq/longrun.c and intel_pstate.c.
 
 1.7 get_intermediate and target_intermediate
 --------------------------------------------
Signature · 1 line
2.4.3
maintainer Acked-by on v2 3/4
#5 lore raw

Re: [PATCH v2 3/4] Documentation: cpu-freq: update setpolicy documentation

Quoted 17 lines · Srinivas Pandruvada

Updated documentation for usage of setpolicy interface.

---
 Documentation/cpu-freq/cpu-drivers.txt | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/cpu-freq/cpu-drivers.txt +0 -2
index 14f4e63..144e0ad 100644
@@ -195,8 +195,13 @@ argument. You need to set the lower limit of the in-processor or
 in-chipset dynamic frequency switching to policy->min, the upper limit
 to policy->max, and -if supported- select a performance-oriented
 setting when policy->policy is CPUFREQ_POLICY_PERFORMANCE, and a
-powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE. Also check
-the reference implementation in drivers/cpufreq/longrun.c

Documentation/cpu-freq/cpu-drivers.txt argument. You need to set the lower limit of the in-processor or · line 207

Quoted 10 lines
Documentation/cpu-freq/cpu-drivers.txt +7 -0
+powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE, and a
+optional on demand frequency scaling setting when
+CPUFREQ_POLICY_ONDEMAND. The default supported policies are
+CPUFREQ_POLICY_PERFORMANCE and CPUFREQ_POLICY_POWERSAVE. To change or
+add supported policies set policy->available_policies with a mask of
+supported policies. Also check the reference implementation in
+drivers/cpufreq/longrun.c and intel_pstate.c.
 
 1.7 get_intermediate and target_intermediate
 --------------------------------------------
Signature · 1 line
viresh
author maintainer
#6 lore raw

PATCH v2 4/4 cpufreq: intel_pstate: Change powersave to ondemand policy

In reply to Srinivas Pandruvada

Move the current Intel powersave policy processing to ondemand policy.

---
 drivers/cpufreq/intel_pstate.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/cpufreq/intel_pstate.c +8 -6
index fb92402..76108e6 100644
@@ -176,7 +176,7 @@ static struct perf_limits performance_limits = {
 	.min_sysfs_pct = 0,
 };
 
-static struct perf_limits powersave_limits = {
+static struct perf_limits ondemand_limits = {
 	.no_turbo = 0,
 	.turbo_disabled = 0,
 	.max_perf_pct = 100,
@@ -192,7 +192,7 @@ static struct perf_limits powersave_limits = {
 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
 static struct perf_limits *limits = &performance_limits;
 #else
-static struct perf_limits *limits = &powersave_limits;
+static struct perf_limits *limits = &ondemand_limits;
 #endif
 
 static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
@@ -1143,8 +1143,8 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 		return 0;
 	}
 
-	pr_debug("intel_pstate: set powersave\n");
-	limits = &powersave_limits;
+	pr_debug("intel_pstate: set ondemand\n");
+	limits = &ondemand_limits;
 	limits->min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
 	limits->min_policy_pct = clamp_t(int, limits->min_policy_pct, 0 , 100);
 	limits->max_policy_pct = DIV_ROUND_UP(policy->max * 100,
@@ -1180,7 +1180,7 @@ static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
 {
 	cpufreq_verify_within_cpu_limits(policy);
 
-	if (policy->policy != CPUFREQ_POLICY_POWERSAVE &&
+	if (policy->policy != CPUFREQ_POLICY_ONDEMAND &&
 	    policy->policy != CPUFREQ_POLICY_PERFORMANCE)
 		return -EINVAL;
 
@@ -1215,8 +1215,10 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
 	if (limits->min_perf_pct == 100 && limits->max_perf_pct == 100)
 		policy->policy = CPUFREQ_POLICY_PERFORMANCE;
 	else
-		policy->policy = CPUFREQ_POLICY_POWERSAVE;
+		policy->policy = CPUFREQ_POLICY_ONDEMAND;
 
+	policy->available_policies = CPUFREQ_POLICY_PERFORMANCE |
+						CPUFREQ_POLICY_ONDEMAND;
 	policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling;
 	policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
 
Signature · 1 line
2.4.3
#7 lore raw
In reply to Srinivas Pandruvada
Quoted 12 lines · Srinivas Pandruvada

Intel P State driver implements two policies, performance and powersave. The powersave policy is similar to ondemand cpufreq governor when using acpi-cpufreq. This causes lots of confusion among users. This results in invalid comparison of performance when acpi-cpufreq and Intel P state performance is compared.

The reason Intel P state called powersave when it actually implemented ondemand style P State selection, because the cpufreq core only allows two generic policies "performance and powersave" for drivers which has setpolicy() interface. All drivers using this interface are forced to support these two policies.

Quoted 4 lines

This patchset adds feature to have configurable generic policies and allows ondemand as one of the policy. With this approach, Intel P state now adds support for ondemand policy and power save policy both in addition to performance.

Srinivas, if I read the patchset correctly then this means that ondemand == powersave ?

If so, is the intention to one day remove powersave altogether and switch to only ondemand & performance?

P.

author maintainer
#8 lore raw
Quoted 14 lines · Prarit Bhargava
Quoted 12 lines · Srinivas Pandruvada

Intel P State driver implements two policies, performance and powersave. The powersave policy is similar to ondemand cpufreq governor when using acpi-cpufreq. This causes lots of confusion among users. This results in invalid comparison of performance when acpi-cpufreq and Intel P state performance is compared.

The reason Intel P state called powersave when it actually implemented ondemand style P State selection, because the cpufreq core only allows two generic policies "performance and powersave" for drivers which has setpolicy() interface. All drivers using this interface are forced to support these two policies.

Quoted 5 lines
Quoted 4 lines

This patchset adds feature to have configurable generic policies and allows ondemand as one of the policy. With this approach, Intel P state now adds support for ondemand policy and power save policy both in addition to performance.

Prarit,

Quoted 2 lines

Srinivas, if I read the patchset correctly then this means that ondemand == powersave ?

Yes. Will it cause problem to you?

Quoted 3 lines

If so, is the intention to one day remove powersave altogether and switch to only ondemand & performance?

Yes. But we can add powersave, which all requests P state to max efficiency ratio. But I want to check, if it will this cause more confusion.

Thanks,
Srinivas

Quoted 2 lines

P.

#9 lore raw
Quoted 20 lines · Srinivas Pandruvada
Quoted 14 lines · Prarit Bhargava
Quoted 12 lines · Srinivas Pandruvada

Intel P State driver implements two policies, performance and powersave. The powersave policy is similar to ondemand cpufreq governor when using acpi-cpufreq. This causes lots of confusion among users. This results in invalid comparison of performance when acpi-cpufreq and Intel P state performance is compared.

The reason Intel P state called powersave when it actually implemented ondemand style P State selection, because the cpufreq core only allows two generic policies "performance and powersave" for drivers which has setpolicy() interface. All drivers using this interface are forced to support these two policies.

Quoted 5 lines
Quoted 4 lines

This patchset adds feature to have configurable generic policies and allows ondemand as one of the policy. With this approach, Intel P state now adds support for ondemand policy and power save policy both in addition to performance.

Quoted 4 lines

Prarit,

Quoted 2 lines

Srinivas, if I read the patchset correctly then this means that ondemand == powersave ?

Yes. Will it cause problem to you?

Nope :) I like that option. I was just asking to make sure I understood the nature of the change.

Quoted 7 lines
Quoted 3 lines

If so, is the intention to one day remove powersave altogether and switch to only ondemand & performance?

Yes. But we can add powersave, which all requests P state to max efficiency ratio. But I want to check, if it will this cause more confusion.

I'm thinking of end users -- we (Red Hat, but I'm pretty sure this applies to all distributions) have spent a significant amount of effort in educating users about the differences between the cpufreq and intel-pstate governors.

Google search yields several results detailing the difference between the powersave and userspace governors as well, so I think that making changes at this point, especially after years of use, will only lead to more confusion for users.

IOW, I agree with the technical argument, but I think that our users will really be confused.

P.

author maintainer
#10 lore raw
Quoted 59 lines · Prarit Bhargava
Quoted 31 lines · Srinivas Pandruvada
Quoted 22 lines · Prarit Bhargava
Quoted 20 lines · Srinivas Pandruvada

Intel P State driver implements two policies, performance and powersave.
The powersave policy is similar to ondemand cpufreq governor when using
acpi-cpufreq. This causes lots of confusion among users. This results
in invalid comparison of performance when acpi-cpufreq and Intel P state
performance is compared.

The reason Intel P state called powersave when it actually implemented
ondemand style P State selection, because the cpufreq core only allows
two generic policies "performance and powersave" for drivers which has
setpolicy() interface. All drivers using this interface are forced to
support these two policies.

Quoted 8 lines
Quoted 7 lines

This patchset adds feature to have configurable generic policies and
allows ondemand as one of the policy. With this approach, Intel P state
now adds support for ondemand policy and power save policy both in
addition to performance.

Quoted 5 lines

Prarit,

Quoted 3 lines

Srinivas, if I read the patchset correctly then this means that ondemand ==
powersave ?

Yes. Will it cause problem to you?

Nope :) I like that option. I was just asking to make sure I understood
the nature of the change.

Quoted 8 lines
Quoted 4 lines

If so, is the intention to one day remove powersave altogether and switch to
only ondemand & performance?

Yes. But we can add powersave, which all requests P state to max efficiency ratio. But I want to check, if it will this cause more confusion.

I'm thinking of end users -- we (Red Hat, but I'm pretty sure this applies
to all distributions) have spent a significant amount of effort in educating
users about the differences between the cpufreq and intel-pstate governors.

Quoted 8 lines

Google search yields several results detailing the difference between the
powersave and userspace governors as well, so I think that making changes at
this point, especially after years of use, will only lead to more confusion
for users.

Good point. We have customers in both camps. This is tough one.

Quoted 4 lines

IOW, I agree with the technical argument, but I think that our users will
really be confused.

Thanks,
Srinivas

Quoted 1 line

P.

author maintainer
#11 lore raw
In reply to Srinivas Pandruvada
Quoted 12 lines · Srinivas Pandruvada

Intel P State driver implements two policies, performance and powersave. The powersave policy is similar to ondemand cpufreq governor when using acpi-cpufreq. This causes lots of confusion among users. This results in invalid comparison of performance when acpi-cpufreq and Intel P state performance is compared.

The reason Intel P state called powersave when it actually implemented ondemand style P State selection, because the cpufreq core only allows two generic policies "performance and powersave" for drivers which has setpolicy() interface. All drivers using this interface are forced to support these two policies.

Quoted 5 lines

This patchset adds feature to have configurable generic policies and allows ondemand as one of the policy. With this approach, Intel P state now adds support for ondemand policy and power save policy both in addition to performance.

Since there is negative feedback from Redhat and Suse as this will cause more confusion to their customers, I will drop this patchset. Thanks for reviews and feedback.

Thanks,
Srinivas

Quoted 28 lines

v2
- Suggestion by Viresh to remove callback to get policies
- Document update for cpufreq cpu-drivers
- Dropped powersave patch, so that it will still default to ondemand as a possible option suggested by Thomas.

If it breaks any distros are user, who were using Intel P state driver with powersave, please comment.

v1
base version

To be done:
Intel P state document update

Srinivas Pandruvada (4):
cpufreq: Add configurable generic policies
cpufreq: Add ondemand as a generic policy
Documentation: cpu-freq: update setpolicy documentation
cpufreq: intel_pstate: Change powersave to ondemand policy

 Documentation/cpu-freq/cpu-drivers.txt |  9 +++++++--
 drivers/cpufreq/cpufreq.c              | 17 ++++++++++++++++-
 drivers/cpufreq/intel_pstate.c         | 14 ++++++++------
 include/linux/cpufreq.h                |  4 +++-
 4 files changed, 34 insertions(+), 10 deletions(-)