Skip to contentSkip to conversation

x86/intel_pstate: support the use of intel_pstate in pmstat.c

PATCH In review Wei Wang 2 participants 5 messages May 13, 2015 – Jun 5, 2015

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v2 8/9 x86/intel_pstate: support the use of intel_pstate in pmstat.c

Add support in the pmstat.c so that the xenpm tool can request to access the intel_pstate driver.

---
 tools/libxc/xc_pm.c         |   4 +-
 xen/drivers/acpi/pmstat.c   | 106 +++++++++++++++++++++++++++++++++++---------
 xen/include/public/sysctl.h |  16 ++++++-
 3 files changed, 100 insertions(+), 26 deletions(-)
tools/libxc/xc_pm.c +2 -2
index 5a7148e..c49d1c0 100644
@@ -265,8 +265,8 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
         user_para->cpuinfo_max_freq = sys_para->cpuinfo_max_freq;
         user_para->cpuinfo_min_freq = sys_para->cpuinfo_min_freq;
         user_para->scaling_cur_freq = sys_para->scaling_cur_freq;
-        user_para->scaling_max_freq = sys_para->scaling_max_freq;
-        user_para->scaling_min_freq = sys_para->scaling_min_freq;
+        user_para->scaling_max_freq = sys_para->scaling_max.max_freq;
+        user_para->scaling_min_freq = sys_para->scaling_min.min_freq;
         user_para->turbo_enabled    = sys_para->turbo_enabled;
 
         memcpy(user_para->scaling_driver,
xen/drivers/acpi/pmstat.c +84 -22

172 lines not on this page · raw message

xen/include/public/sysctl.h +14 -2
index 711441f..fe56864 100644
@@ -314,8 +314,18 @@ struct xen_get_cpufreq_para {
     uint32_t scaling_cur_freq;
 
     char scaling_governor[CPUFREQ_NAME_LEN];
-    uint32_t scaling_max_freq;
-    uint32_t scaling_min_freq;
+
+    union {
+        uint32_t max_freq;
+        int32_t  max_perf_pct;
+    } scaling_max;
+
+    union {
+        uint32_t min_freq;
+        int32_t  min_perf_pct;
+    } scaling_min;
+
+    int32_t scaling_turbo_pct;
 
     /* for specific governor */
     union {
@@ -336,6 +346,8 @@ struct xen_set_cpufreq_para {
     #define SCALING_SETSPEED           3
     #define SAMPLING_RATE              4
     #define UP_THRESHOLD               5
+    #define SCALING_MAX_PCT            6
+    #define SCALING_MIN_PCT            7
 
     uint32_t ctrl_type;
     uint32_t ctrl_value;
Signature · 1 line
1.9.1
#1 lore raw

xen/drivers/acpi/pmstat.c int do_get_pm_info(struct xen_sysctl_get_pmstat *op) · line 171

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:51, <[email protected]> wrote:
xen/drivers/acpi/pmstat.c +1 -1
@@ -167,7 +167,7 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op)
  * 2. Provide user PM control
  */
 static int read_scaling_available_governors(char 
 *scaling_available_governors,
-                                            unsigned int size)
+                              unsigned int size, unsigned int is_internal)

Please don't break indentation aiming at suitable alignment. And is_internal looks like it wants to be bool_t (and probably doesn't need the is_ prefix).

xen/drivers/acpi/pmstat.c static int read_scaling_available_governors(char *scaling_available_governors, · line 178

Quoted 11 lines
xen/drivers/acpi/pmstat.c +1 -6
@@ -175,12 +175,19 @@ static int read_scaling_available_governors(char *scaling_available_governors,
     if ( !scaling_available_governors )
         return -EINVAL;
 
-    list_for_each_entry(t, &cpufreq_governor_list, governor_list)
-    {
-        i += scnprintf(&scaling_available_governors[i],
-                       CPUFREQ_NAME_LEN, "%s ", t->name);
-        if ( i > size )
-            return -EINVAL;
+    if (is_internal) {

Coding style (throughout the changes to this file).

xen/drivers/acpi/pmstat.c static int read_scaling_available_governors(char *scaling_available_governors, · line 182

Quoted 4 lines
xen/drivers/acpi/pmstat.c +4 -0
+        i += scnprintf(&scaling_available_governors[0], CPUFREQ_NAME_LEN, "%s ", "performance");
+        i += scnprintf(&scaling_available_governors[i], CPUFREQ_NAME_LEN, "%s ", "powersave");
+        i += scnprintf(&scaling_available_governors[i], CPUFREQ_NAME_LEN, "%s ", "userspace");
+        i += scnprintf(&scaling_available_governors[i], CPUFREQ_NAME_LEN, "%s ", "ondemand");

Long lines.

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op · line 218

Quoted 13 lines
xen/drivers/acpi/pmstat.c +3 -3
@@ -203,11 +210,15 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op 
 *op)
     policy = per_cpu(cpufreq_cpu_policy, op->cpuid);
 
     if ( !pmpt || !pmpt->perf.states ||
-         !policy || !policy->governor )
+         !policy || (!policy->governor && !policy->policy) )
         return -EINVAL;
 
-    list_for_each(pos, &cpufreq_governor_list)
-        gov_num++;
+    if (policy->policy)
+        gov_num = 4;

This literal number again needs a #define.

Quoted 4 lines
xen/drivers/acpi/pmstat.c +0 -0
@@ -261,29 +272,47 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq;
     op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq;
     op->u.get_para.scaling_cur_freq = policy->cur;

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 282

Quoted 10 lines
xen/drivers/acpi/pmstat.c +8 -2
-    op->u.get_para.scaling_max_freq = policy->max;
-    op->u.get_para.scaling_min_freq = policy->min;
+    if (policy->policy) {
+        op->u.get_para.scaling_max.max_perf_pct = policy->max_perf_pct;
+        op->u.get_para.scaling_min.min_perf_pct = policy->min_perf_pct;
+        op->u.get_para.scaling_turbo_pct = policy->turbo_pct;
+    } else {
+        op->u.get_para.scaling_max.max_freq = policy->max;
+        op->u.get_para.scaling_min.min_freq = policy->min;
+    }

How does the caller then know which of the union member meanings apply?

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 290

Quoted 3 lines
xen/drivers/acpi/pmstat.c +1 -2
-    if ( policy->governor->name[0] )
-        strlcpy(op->u.get_para.scaling_governor, 
+    if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)

switch() again.

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 315

Quoted 10 lines
xen/drivers/acpi/pmstat.c +2 -2
     /* governor specific para */
-    if ( !strnicmp(op->u.get_para.scaling_governor, 
+    if ( !strnicmp(op->u.get_para.scaling_governor,
                    "userspace", CPUFREQ_NAME_LEN) )
     {
         op->u.get_para.u.userspace.scaling_setspeed = policy->cur;
     }
 
-    if ( !strnicmp(op->u.get_para.scaling_governor, 
+    if ( !strnicmp(op->u.get_para.scaling_governor,

Please can you avoid such white space adjustments to otherwise untouched code in an already big patch?

xen/drivers/acpi/pmstat.c static int set_cpufreq_para(struct xen_sysctl_pm_op *op) · line 398

Quoted 8 lines
xen/drivers/acpi/pmstat.c +4 -0
@@ -348,6 +392,24 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op)
         break;
     }
 
+    case SCALING_MAX_PCT:
+    {
+        struct cpufreq_policy new_policy;
+        memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));

Blank line between declarations and statements please. Also please use structure assignment (type safe) instead of memcpy() (not type safe), and then perhaps right as initializer for the variable.

Quoted 10 lines
xen/include/public/sysctl.h +2 -2
@@ -314,8 +314,18 @@ struct xen_get_cpufreq_para {
     uint32_t scaling_cur_freq;
 
     char scaling_governor[CPUFREQ_NAME_LEN];
-    uint32_t scaling_max_freq;
-    uint32_t scaling_min_freq;
+
+    union {

xen/include/public/sysctl.h struct xen_get_cpufreq_para { · line 328

Quoted 10 lines
xen/include/public/sysctl.h +10 -0
+        uint32_t max_freq;
+        int32_t  max_perf_pct;
+    } scaling_max;
+
+    union {
+        uint32_t min_freq;
+        int32_t  min_perf_pct;
+    } scaling_min;
+
+    int32_t scaling_turbo_pct;

Again all of these should presumably be uint32_t. Plus the max/min duplication should be avoided (i.e. drop the prefixes from the union fields). Nor do I think perf_pct is really all that useful - pct or percentage would do afaict.

Jan

#2 lore raw

On 26/05/2015 22:16, Jan Beulich wrote

Quoted 19 lines

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:51, <[email protected]> wrote:
xen/drivers/acpi/pmstat.c +0 -0
@@ -261,29 +272,47 @@ static int get_cpufreq_para(struct

xen_sysctl_pm_op *op)

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 282

Quoted 13 lines
xen/drivers/acpi/pmstat.c +8 -2
     op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq;
     op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq;
     op->u.get_para.scaling_cur_freq = policy->cur;
-    op->u.get_para.scaling_max_freq = policy->max;
-    op->u.get_para.scaling_min_freq = policy->min;
+    if (policy->policy) {
+        op->u.get_para.scaling_max.max_perf_pct = policy->max_perf_pct;
+        op->u.get_para.scaling_min.min_perf_pct = policy->min_perf_pct;
+        op->u.get_para.scaling_turbo_pct = policy->turbo_pct;
+    } else {
+        op->u.get_para.scaling_max.max_freq = policy->max;
+        op->u.get_para.scaling_min.min_freq = policy->min;
+    }
Quoted 2 lines

How does the caller then know which of the union member meanings apply?

The end caller is xenpm. It's aware of the running pstate driver, so it knows the difference between freq and pct.

Quoted 17 lines
Quoted 17 lines
xen/include/public/sysctl.h +9 -2
@@ -314,8 +314,18 @@ struct xen_get_cpufreq_para {
     uint32_t scaling_cur_freq;
 
     char scaling_governor[CPUFREQ_NAME_LEN];
-    uint32_t scaling_max_freq;
-    uint32_t scaling_min_freq;
+
+    union {
+        uint32_t max_freq;
+        int32_t  max_perf_pct;
+    } scaling_max;
+
+    union {
+        uint32_t min_freq;
+        int32_t  min_perf_pct;
Quoted 8 lines

xen/include/public/sysctl.h struct xen_get_cpufreq_para { · line 328

Quoted 3 lines
xen/include/public/sysctl.h +3 -0
+    } scaling_min;
+
+    int32_t scaling_turbo_pct;

Again all of these should presumably be uint32_t. Plus the max/min duplication should be avoided (i.e. drop the prefixes from the union fields). Nor do I think perf_pct is really all that useful - pct or percentage would do afaict.

Will change it to:

union {
        uint32_t freq;
        uint32_t  pct;
} scaling_max;
union {
        uint32_t freq;
        uint32_t  pct;
} scaling_min;

Best,
Wei

#3 lore raw
Quoted 21 lines
Quoted 1 line
Quoted 1 line

"Wang, Wei W" <[email protected]> 06/04/15 4:21 AM >>>

On 26/05/2015 22:16, Jan Beulich wrote

Quoted 19 lines

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:51, <[email protected]> wrote:
xen/drivers/acpi/pmstat.c +0 -0
@@ -261,29 +272,47 @@ static int get_cpufreq_para(struct

xen_sysctl_pm_op *op)

Quoted 13 lines
xen/drivers/acpi/pmstat.c +8 -2
     op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq;
     op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq;
     op->u.get_para.scaling_cur_freq = policy->cur;
-    op->u.get_para.scaling_max_freq = policy->max;
-    op->u.get_para.scaling_min_freq = policy->min;
+    if (policy->policy) {
+        op->u.get_para.scaling_max.max_perf_pct = policy->max_perf_pct;
+        op->u.get_para.scaling_min.min_perf_pct = policy->min_perf_pct;
+        op->u.get_para.scaling_turbo_pct = policy->turbo_pct;
+    } else {
+        op->u.get_para.scaling_max.max_freq = policy->max;
+        op->u.get_para.scaling_min.min_freq = policy->min;
+    }
Quoted 5 lines
Quoted 2 lines

How does the caller then know which of the union member meanings apply?

The end caller is xenpm. It's aware of the running pstate driver, so it knows the difference between freq and pct.

xenpm is one of the possible callers. We don't make hypercalls with just a single consumer in mind, excluding any other potential one(s). And hence a hypercall like this should be kind of self contained, i.e. in the case here the caller ought to be able to know from its result which of the union fields are in use.

Jan

#4 lore raw

On 05/06/2015 15:22, Jan Beulich wrote

Quoted 25 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line

"Wang, Wei W" <[email protected]> 06/04/15 4:21 AM >>>

On 26/05/2015 22:16, Jan Beulich wrote

Quoted 12 lines

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:51, <[email protected]> wrote:
xen/drivers/acpi/pmstat.c +0 -0
@@ -261,29 +272,47 @@ static int get_cpufreq_para(struct

xen_sysctl_pm_op *op)

Quoted 7 lines
xen/drivers/acpi/pmstat.c +2 -2
     op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq;
     op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq;
     op->u.get_para.scaling_cur_freq = policy->cur;
-    op->u.get_para.scaling_max_freq = policy->max;
-    op->u.get_para.scaling_min_freq = policy->min;
+    if (policy->policy) {
+        op->u.get_para.scaling_max.max_perf_pct = policy-

max_perf_pct;

Quoted 9 lines

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 282

Quoted 6 lines
xen/drivers/acpi/pmstat.c +6 -0
+        op->u.get_para.scaling_min.min_perf_pct = policy->min_perf_pct;
+        op->u.get_para.scaling_turbo_pct = policy->turbo_pct;
+    } else {
+        op->u.get_para.scaling_max.max_freq = policy->max;
+        op->u.get_para.scaling_min.min_freq = policy->min;
+    }

How does the caller then know which of the union member meanings apply?

Quoted 8 lines
Quoted 2 lines

The end caller is xenpm. It's aware of the running pstate driver, so it knows the difference between freq and pct.

xenpm is one of the possible callers. We don't make hypercalls with just a single consumer in mind, excluding any other potential one(s). And hence a hypercall like this should be kind of self contained, i.e. in the case here the caller ought to be able to know from its result which of the union fields are in use.

Ok. It's actually already self-contained. The "scaling_driver" field indicates which union filed the caller should use. This is also how xenpm uses it.

Best,
Wei