Skip to contentSkip to conversation

x86/intel_pstate: add new policy fields and a new driver interface

PATCH In review Wei Wang 2 participants 4 messages May 13, 2015 – May 28, 2015

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v2 4/9 x86/intel_pstate: add new policy fields and a new driver interface

In order to better support future Intel processors, intel_pstate changes to use percentage values to tune P-states. The intel_pstate driver uses its own internal governor, and it is recorded in the "policy->policy" field. The setpolicy driver interface is used to configure the intel_pstate internal policy. The __cpufreq_set_policy needs to be intercepted to use the setpolicy driver if it exists.

---
 xen/drivers/cpufreq/utility.c      |  5 +++++
 xen/include/acpi/cpufreq/cpufreq.h | 11 +++++++++++
 2 files changed, 16 insertions(+)
xen/drivers/cpufreq/utility.c +5 -0
index 519f862..04f88c2 100644
@@ -456,6 +456,11 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,
 
     data->min = policy->min;
     data->max = policy->max;
+    data->min_perf_pct = policy->min_perf_pct;
+    data->max_perf_pct = policy->max_perf_pct;
+
+    if (cpufreq_driver->setpolicy)
+        return cpufreq_driver->setpolicy(data);
 
     if (policy->governor != data->governor) {
         /* save old, working values */
xen/include/acpi/cpufreq/cpufreq.h +11 -0
index f96c3e4..67c9be2 100644
@@ -52,6 +52,10 @@ struct cpufreq_policy {
     unsigned int        max;    /* in kHz */
     unsigned int        cur;    /* in kHz, only needed if cpufreq
                                  * governors are used */
+    int                 min_perf_pct; /* min performance in percentage */
+    int                 max_perf_pct; /* max performance in percentage */
+    int                 turbo_pct;
+    unsigned int        policy;
     struct cpufreq_governor     *governor;
 
     bool_t              resume; /* flag for cpufreq 1st run
@@ -87,6 +91,12 @@ struct cpufreq_freqs {
  *                          CPUFREQ GOVERNORS                        *
  *********************************************************************/
 
+/* the four internal governors used in intel_pstate */
+#define CPUFREQ_POLICY_POWERSAVE        (1)
+#define CPUFREQ_POLICY_PERFORMANCE      (2)
+#define CPUFREQ_POLICY_USERSPACE        (3)
+#define CPUFREQ_POLICY_ONDEMAND         (4)
+
 #define CPUFREQ_GOV_START  1
 #define CPUFREQ_GOV_STOP   2
 #define CPUFREQ_GOV_LIMITS 3
@@ -145,6 +155,7 @@ struct cpufreq_driver {
     char   name[CPUFREQ_NAME_LEN];
     int    (*init)(struct cpufreq_policy *policy);
     int    (*verify)(struct cpufreq_policy *policy);
+    int    (*setpolicy)(struct cpufreq_policy *policy);
     int    (*update)(int cpuid, struct cpufreq_policy *policy);
     int    (*target)(struct cpufreq_policy *policy,
                      unsigned int target_freq,
Signature · 1 line
1.9.1
#1 lore raw

xen/drivers/cpufreq/utility.c int __cpufreq_set_policy(struct cpufreq_policy *data, · line 460

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:50, <[email protected]> wrote:
xen/drivers/cpufreq/utility.c +2 -0
@@ -456,6 +456,11 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,
 
     data->min = policy->min;
     data->max = policy->max;
+    data->min_perf_pct = policy->min_perf_pct;
+    data->max_perf_pct = policy->max_perf_pct;

Shouldn't you do similar sanity checks on them as are being done on ->min and ->max? (Admittedly they look a little strange, but I'm not asking you to copy what is there without sanity checking the original).

xen/drivers/cpufreq/utility.c int __cpufreq_set_policy(struct cpufreq_policy *data, · line 462

Quoted 1 line
xen/drivers/cpufreq/utility.c +1 -0
+    if (cpufreq_driver->setpolicy)

Also I wonder whether the additions shouldn't move into this if()'s body.

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 57

Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +3 -0
@@ -52,6 +52,10 @@ struct cpufreq_policy {
     unsigned int        max;    /* in kHz */
     unsigned int        cur;    /* in kHz, only needed if cpufreq
                                  * governors are used */
+    int                 min_perf_pct; /* min performance in percentage */
+    int                 max_perf_pct; /* max performance in percentage */
+    int                 turbo_pct;

Can any of these legitimately be negative? If not, they should be of unsigned int type.

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 98

Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +5 -0
@@ -87,6 +91,12 @@ struct cpufreq_freqs {
  *                          CPUFREQ GOVERNORS                        *
  *********************************************************************/
 
+/* the four internal governors used in intel_pstate */
+#define CPUFREQ_POLICY_POWERSAVE        (1)
+#define CPUFREQ_POLICY_PERFORMANCE      (2)
+#define CPUFREQ_POLICY_USERSPACE        (3)
+#define CPUFREQ_POLICY_ONDEMAND         (4)

Why are they being added in this header and at this point in the sequence of patches? If they're local to intel_pstate, they should go there. If they're needed by multiple files, they should be added when needed, so that one can easily judge whether their addition is indeed necessary.

Jan

#2 lore raw

On 26/05/2015 21:00, Jan Beulich wrote

Quoted 15 lines

xen/drivers/cpufreq/utility.c int __cpufreq_set_policy(struct cpufreq_policy · line 461

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:50, <[email protected]> wrote:
xen/drivers/cpufreq/utility.c +2 -0
@@ -456,6 +456,11 @@ int __cpufreq_set_policy(struct cpufreq_policy
 *data,
 
     data->min = policy->min;
     data->max = policy->max;
+    data->min_perf_pct = policy->min_perf_pct;
+    data->max_perf_pct = policy->max_perf_pct;

Shouldn't you do similar sanity checks on them as are being done on ->min and ->max? (Admittedly they look a little strange, but I'm not asking you to copy what is there without sanity checking the original).

Quoted 3 lines

xen/drivers/cpufreq/utility.c int __cpufreq_set_policy(struct cpufreq_policy *data, · line 462

Quoted 1 line
xen/drivers/cpufreq/utility.c +1 -0
+    if (cpufreq_driver->setpolicy)

Also I wonder whether the additions shouldn't move into this if()'s body.

Will change it to the if()'s body:

	if (cpufreq_driver->setpolicy) {
	    data->min_perf_pct = policy->min_perf_pct;
	    data->max_perf_pct = policy->max_perf_pct;
	    ....
	}
Quoted 13 lines

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 57

Quoted 10 lines
xen/include/acpi/cpufreq/cpufreq.h +3 -0
@@ -52,6 +52,10 @@ struct cpufreq_policy {
     unsigned int        max;    /* in kHz */
     unsigned int        cur;    /* in kHz, only needed if cpufreq
                                  * governors are used */
+    int                 min_perf_pct; /* min performance in percentage */
+    int                 max_perf_pct; /* max performance in percentage */
+    int                 turbo_pct;

Can any of these legitimately be negative? If not, they should be of unsigned int type.

I think we have to keep using "int". Though the expected pct value range is 0-100, it is possible that people may input a negative value. For example, if the input value is "-1":
1) using int, the output value after clamp_t(0,100) will be 0;
2) using unsigned int, the output value after clamp_t(0,100) will be 100.
I think case 1) is what we need.

Quoted 8 lines

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 93

Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +0 -0
@@ -87,6 +91,12 @@ struct cpufreq_freqs {
  *                          CPUFREQ GOVERNORS                        *
 
 

**********************************************************
***********/

Quoted 1 line
Quoted 10 lines

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 98

Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +5 -0
+/* the four internal governors used in intel_pstate */
+#define CPUFREQ_POLICY_POWERSAVE        (1)
+#define CPUFREQ_POLICY_PERFORMANCE      (2)
+#define CPUFREQ_POLICY_USERSPACE        (3)
+#define CPUFREQ_POLICY_ONDEMAND         (4)

Why are they being added in this header and at this point in the sequence of patches? If they're local to intel_pstate, they should go there. If they're needed by multiple files, they should be added when needed, so that one can easily judge whether their addition is indeed necessary.

Will change to add the 4 macros in the "main body of intel_pstate driver" patch (6/9). Can we keep them in this file? These are cpufreq related things.

Best,
Wei

#3 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 28.05.15 at 11:47, <[email protected]> wrote:

On 26/05/2015 21:00, Jan Beulich wrote

Quoted 13 lines

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 57

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:50, <[email protected]> wrote:
xen/include/acpi/cpufreq/cpufreq.h +3 -0
@@ -52,6 +52,10 @@ struct cpufreq_policy {
     unsigned int        max;    /* in kHz */
     unsigned int        cur;    /* in kHz, only needed if cpufreq
                                  * governors are used */
+    int                 min_perf_pct; /* min performance in percentage */
+    int                 max_perf_pct; /* max performance in percentage */
+    int                 turbo_pct;

Can any of these legitimately be negative? If not, they should be of unsigned int type.

Quoted 6 lines

I think we have to keep using "int". Though the expected pct value range is 0-100, it is possible that people may input a negative value. For example, if the input value is "-1":
1) using int, the output value after clamp_t(0,100) will be 0;
2) using unsigned int, the output value after clamp_t(0,100) will be 100. I think case 1) is what we need.

There are no "people" involved here. If you think negative values make sense to be accepted by the xenpm tool, deal with them there. Already at the hypercall interface only sane values should be passed (and insane ones, like percentage values outside the [0,100] range, probably be rejected).

Quoted 18 lines
Quoted 7 lines

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 93

Quoted 4 lines
xen/include/acpi/cpufreq/cpufreq.h +0 -0
@@ -87,6 +91,12 @@ struct cpufreq_freqs {
  *                          CPUFREQ GOVERNORS                        *
 
 

**********************************************************
***********/

Quoted 1 line
Quoted 10 lines

xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 98

Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +5 -0
+/* the four internal governors used in intel_pstate */
+#define CPUFREQ_POLICY_POWERSAVE        (1)
+#define CPUFREQ_POLICY_PERFORMANCE      (2)
+#define CPUFREQ_POLICY_USERSPACE        (3)
+#define CPUFREQ_POLICY_ONDEMAND         (4)

Why are they being added in this header and at this point in the sequence of patches? If they're local to intel_pstate, they should go there. If they're needed by multiple files, they should be added when needed, so that one can easily judge whether their addition is indeed necessary.

Quoted 3 lines

Will change to add the 4 macros in the "main body of intel_pstate driver" patch (6/9).
Can we keep them in this file? These are cpufreq related things.

Perhaps - what I do mind is the combination of the when and where. Fixing the when may eliminate the where complaint.

Jan