Skip to contentSkip to conversation

Improve xenpm output under HWP

PATCH Superseded Jason Andryuk 2 participants 6 messages Jan 24, 2024 – Jan 25, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Improve xenpm output under HWP

Have xen return -EOPNOTSUPP for more pmstat hypercalls instead of returning misleading data under HWP. Enhance xenpm to handle -EOPNOTSUPP and provide more informative messages.

Jason Andryuk (2):
pmstat: Limit hypercalls under HWP
xenpm: Print message for disabled commands

 tools/misc/xenpm.c        | 19 +++++++++++++++----
 xen/drivers/acpi/pmstat.c |  5 +++++
 2 files changed, 20 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 pmstat: Limit hypercalls under HWP

When HWP is active, the cpufreq P-state information is not updated. In that case, return -EOPNOTSUPP instead of bogus, incomplete info.

Similarly, set_cpufreq_para() is not applicable when HWP is active. Many of the options already checked the governor and were inaccessible, but SCALING_MIN/MAX_FREQ was still accessible (though it would do nothing). Add an ealier HWP check to handle all cases.

---
v2:
Use -EOPNOTSUPP in both places

 xen/drivers/acpi/pmstat.c | 5 +++++
 1 file changed, 5 insertions(+)
xen/drivers/acpi/pmstat.c +5 -0
index 85097d463c..86588ddd42 100644
@@ -66,6 +66,8 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op)
             return -ENODEV;
         if ( !cpufreq_driver.init )
             return -ENODEV;
+        if ( hwp_active() )
+            return -EOPNOTSUPP;
         if ( !pmpt || !(pmpt->perf.init & XEN_PX_INIT) )
             return -EINVAL;
         break;
@@ -329,6 +331,9 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op)
     if ( !policy || !policy->governor )
         return -EINVAL;
 
+    if ( hwp_active() )
+        return -EOPNOTSUPP;
+
     switch(op->u.set_para.ctrl_type)
     {
     case SCALING_MAX_FREQ:
Signature · 1 line
2.43.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] pmstat: Limit hypercalls under HWP

Quoted 9 lines · Jason Andryuk

When HWP is active, the cpufreq P-state information is not updated. In that case, return -EOPNOTSUPP instead of bogus, incomplete info.

Similarly, set_cpufreq_para() is not applicable when HWP is active. Many of the options already checked the governor and were inaccessible, but SCALING_MIN/MAX_FREQ was still accessible (though it would do nothing). Add an ealier HWP check to handle all cases.

#3 lore raw

PATCH v2 2/2 xenpm: Print message for disabled commands

In reply to Jason Andryuk

xenpm get-cpufreq-states currently just prints no output when cpufreq is disabled or HWP is running. Have it print an appropriate message. The cpufreq disabled one mirros the cpuidle disabled one.

cpufreq disabled:

$ xenpm get-cpufreq-states
Either Xen cpufreq is disabled or no valid information is registered!

Under HWP:

$ xenpm get-cpufreq-states
P-State information not supported.  Try get-cpufreq-average or start.

Also allow xenpm to handle EOPNOTSUPP from the pmstat hypercalls. EOPNOTSUPP is returned when HWP is active in some cases and allows the differentiation from cpufreq being disabled.

---
v2:
New

 tools/misc/xenpm.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
tools/misc/xenpm.c +15 -4
index d982482a3f..79c618590b 100644
@@ -362,7 +362,15 @@ static int show_pxstat_by_cpuid(xc_interface *xc_handle, int cpuid)
 
     ret = get_pxstat_by_cpuid(xc_handle, cpuid, &pxstatinfo);
     if ( ret )
+    {
+        if ( ret == -ENODEV )
+            fprintf(stderr,
+                    "Either Xen cpufreq is disabled or no valid information is registered!\n");
+       else if ( ret == -EOPNOTSUPP )
+            fprintf(stderr,
+                    "P-State information not supported.  Try get-cpufreq-average or start.\n");
         return ret;
+    }
 
     print_pxstat(cpuid, &pxstatinfo);
 
@@ -382,9 +390,11 @@ void pxstat_func(int argc, char *argv[])
     {
         /* show pxstates on all cpus */
         int i;
-        for ( i = 0; i < max_cpu_nr; i++ )
-            if ( show_pxstat_by_cpuid(xc_handle, i) == -ENODEV )
+        for ( i = 0; i < max_cpu_nr; i++ ) {
+            int ret = show_pxstat_by_cpuid(xc_handle, i);
+            if ( ret == -ENODEV || ret == -EOPNOTSUPP )
                 break;
+	}
     }
     else
         show_pxstat_by_cpuid(xc_handle, cpuid);
@@ -432,7 +442,7 @@ static uint64_t *sum, *sum_cx, *sum_px;
 
 static void signal_int_handler(int signo)
 {
-    int i, j, k;
+    int i, j, k, ret;
     struct timeval tv;
     int cx_cap = 0, px_cap = 0;
     xc_cputopo_t *cputopo = NULL;
@@ -473,7 +483,8 @@ static void signal_int_handler(int signo)
                 }
     }
 
-    if ( get_pxstat_by_cpuid(xc_handle, 0, NULL) != -ENODEV )
+    ret = get_pxstat_by_cpuid(xc_handle, 0, NULL);
+    if ( ret != -ENODEV && ret != -EOPNOTSUPP )
     {
         px_cap = 1;
         for ( i = 0; i < max_cpu_nr; i++ )
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v2 2/2] xenpm: Print message for disabled commands

Quoted 9 lines · Jason Andryuk

xenpm get-cpufreq-states currently just prints no output when cpufreq is disabled or HWP is running. Have it print an appropriate message. The cpufreq disabled one mirros the cpuidle disabled one.

cpufreq disabled:

$ xenpm get-cpufreq-states
Either Xen cpufreq is disabled or no valid information is registered!

Under HWP:

Quoted 8 lines
$ xenpm get-cpufreq-states
P-State information not supported.  Try get-cpufreq-average or start.

Also allow xenpm to handle EOPNOTSUPP from the pmstat hypercalls. EOPNOTSUPP is returned when HWP is active in some cases and allows the differentiation from cpufreq being disabled.

Largely okay, but a number of cosmetic remarks / nits:

tools/misc/xenpm.c static int show_pxstat_by_cpuid(xc_interface *xc_handle, int cpuid) · line 369

Quoted 11 lines
tools/misc/xenpm.c +5 -0
@@ -362,7 +362,15 @@ static int show_pxstat_by_cpuid(xc_interface *xc_handle, int cpuid)
 
     ret = get_pxstat_by_cpuid(xc_handle, cpuid, &pxstatinfo);
     if ( ret )
+    {
+        if ( ret == -ENODEV )
+            fprintf(stderr,
+                    "Either Xen cpufreq is disabled or no valid information is registered!\n");
+       else if ( ret == -EOPNOTSUPP )

One too few blanks for indentation.

tools/misc/xenpm.c static int show_pxstat_by_cpuid(xc_interface *xc_handle, int cpuid) · line 371

Quoted 2 lines
tools/misc/xenpm.c +2 -0
+            fprintf(stderr,
+                    "P-State information not supported.  Try get-cpufreq-average or start.\n");

Especially the "or start" part reads odd without any quotation.

tools/misc/xenpm.c void pxstat_func(int argc, char *argv[]) · line 393

Quoted 7 lines
tools/misc/xenpm.c +1 -2
@@ -382,9 +390,11 @@ void pxstat_func(int argc, char *argv[])
     {
         /* show pxstates on all cpus */
         int i;
-        for ( i = 0; i < max_cpu_nr; i++ )
-            if ( show_pxstat_by_cpuid(xc_handle, i) == -ENODEV )
+        for ( i = 0; i < max_cpu_nr; i++ ) {

This file tries to follow hypervisor style, so the brace ought to go on its own line. While there may I ask that you also add the missing blank line (separating declaration from statements)? This then also applies ...

tools/misc/xenpm.c void pxstat_func(int argc, char *argv[]) · line 395

Quoted 2 lines
tools/misc/xenpm.c +2 -0
+            int ret = show_pxstat_by_cpuid(xc_handle, i);
+            if ( ret == -ENODEV || ret == -EOPNOTSUPP )

... between these two new lines.

tools/misc/xenpm.c void pxstat_func(int argc, char *argv[]) · line 397

Quoted 2 lines
tools/misc/xenpm.c +1 -0
                 break;
+	}

Hard tab?

tools/misc/xenpm.c static void signal_int_handler(int signo) · line 487

Quoted 7 lines
tools/misc/xenpm.c +2 -1
@@ -473,7 +483,8 @@ static void signal_int_handler(int signo)
                 }
     }
 
-    if ( get_pxstat_by_cpuid(xc_handle, 0, NULL) != -ENODEV )
+    ret = get_pxstat_by_cpuid(xc_handle, 0, NULL);
+    if ( ret != -ENODEV && ret != -EOPNOTSUPP )

While looking odd, I can see why it wants to be this way.

Jan

#5 lore raw

Re: [PATCH v2 2/2] xenpm: Print message for disabled commands

Quoted 14 lines · Jan Beulich
Quoted 12 lines · Jason Andryuk

xenpm get-cpufreq-states currently just prints no output when cpufreq is disabled or HWP is running. Have it print an appropriate message. The cpufreq disabled one mirros the cpuidle disabled one.

cpufreq disabled:

$ xenpm get-cpufreq-states
Either Xen cpufreq is disabled or no valid information is registered!

Under HWP:

$ xenpm get-cpufreq-states
P-State information not supported.  Try get-cpufreq-average or start.
Quoted 7 lines
Quoted 5 lines

Also allow xenpm to handle EOPNOTSUPP from the pmstat hypercalls. EOPNOTSUPP is returned when HWP is active in some cases and allows the differentiation from cpufreq being disabled.

Largely okay, but a number of cosmetic remarks / nits:

Thanks for taking a look. Sorry about the cosmetic issues. All your suggestions are good with me.

Thanks,
Jason