[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 5/5] tools/libxc: allow controlling the max C-state sub-state



From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>

Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>

Make handling in do_pm_op() more homogeneous: Before interpreting
op->cpuid as such, handle all operations not acting on a particular
CPU. Also expose the setting via xenpm.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
v2: Adjust xenpm's usage message. Also adjust its output wording a
     little.

--- a/tools/libxc/xc_pm.c
+++ b/tools/libxc/xc_pm.c
@@ -367,7 +367,7 @@ int xc_set_sched_opt_smt(xc_interface *x
     return rc;
  }
  
-int xc_get_cpuidle_max_cstate(xc_interface *xch, uint32_t *value)
+static int get_max_cstate(xc_interface *xch, uint32_t *value, uint32_t type)
  {
      int rc;
      DECLARE_SYSCTL;
@@ -379,7 +379,7 @@ int xc_get_cpuidle_max_cstate(xc_interfa
      }
      sysctl.cmd = XEN_SYSCTL_pm_op;
      sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_get_max_cstate;
-    sysctl.u.pm_op.cpuid = 0;
+    sysctl.u.pm_op.cpuid = type;
      sysctl.u.pm_op.u.get_max_cstate = 0;
      rc = do_sysctl(xch, &sysctl);
      *value = sysctl.u.pm_op.u.get_max_cstate;
@@ -387,7 +387,17 @@ int xc_get_cpuidle_max_cstate(xc_interfa
      return rc;
  }
  
-int xc_set_cpuidle_max_cstate(xc_interface *xch, uint32_t value)
+int xc_get_cpuidle_max_cstate(xc_interface *xch, uint32_t *value)
+{
+    return get_max_cstate(xch, value, 0);
+}
+
+int xc_get_cpuidle_max_csubstate(xc_interface *xch, uint32_t *value)
+{
+    return get_max_cstate(xch, value, 1);
+}
+
+static int set_max_cstate(xc_interface *xch, uint32_t value, uint32_t type)
  {
      DECLARE_SYSCTL;
  
@@ -398,12 +408,22 @@ int xc_set_cpuidle_max_cstate(xc_interfa
      }
      sysctl.cmd = XEN_SYSCTL_pm_op;
      sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_set_max_cstate;
-    sysctl.u.pm_op.cpuid = 0;
+    sysctl.u.pm_op.cpuid = type;
      sysctl.u.pm_op.u.set_max_cstate = value;
  
      return do_sysctl(xch, &sysctl);
  }
  
+int xc_set_cpuidle_max_cstate(xc_interface *xch, uint32_t value)
+{
+    return set_max_cstate(xch, value, 0);
+}
+
+int xc_set_cpuidle_max_csubstate(xc_interface *xch, uint32_t value)
+{
+    return set_max_cstate(xch, value, 1);
+}
+
  int xc_enable_turbo(xc_interface *xch, int cpuid)
  {
      DECLARE_SYSCTL;
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1906,6 +1906,9 @@ int xc_set_sched_opt_smt(xc_interface *x
  int xc_get_cpuidle_max_cstate(xc_interface *xch, uint32_t *value);
  int xc_set_cpuidle_max_cstate(xc_interface *xch, uint32_t value);
  
+int xc_get_cpuidle_max_csubstate(xc_interface *xch, uint32_t *value);
+int xc_set_cpuidle_max_csubstate(xc_interface *xch, uint32_t value);
+
  int xc_enable_turbo(xc_interface *xch, int cpuid);
  int xc_disable_turbo(xc_interface *xch, int cpuid);
  
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -64,7 +64,9 @@ void show_help(void)
              " set-sched-smt           enable|disable enable/disable scheduler 
smt power saving\n"
              " set-vcpu-migration-delay      <num> set scheduler vcpu 
migration delay in us\n"
              " get-vcpu-migration-delay            get scheduler vcpu 
migration delay\n"
-            " set-max-cstate        <num>|'unlimited' set the C-State 
limitation (<num> >= 0)\n"
+            " set-max-cstate        <num>|'unlimited'[,<num2>|'unlimited']\n"
+            "                                     set the C-State limitation 
(<num> >= 0) and\n"
+            "                                     optionally the C-sub-state 
limitation (<num2> >= 0)\n"
              " start [seconds]                     start collect Cx/Px 
statistics,\n"
              "                                     output after CTRL-C or 
SIGINT or several seconds.\n"
              " enable-turbo-mode     [cpuid]       enable Turbo Mode for 
processors that support it.\n"
@@ -195,7 +197,15 @@ static int show_max_cstate(xc_interface
          return ret;
  
      if ( value < XEN_SYSCTL_CX_UNLIMITED )
-        printf("Max possible C-state: C%"PRIu32"\n\n", value);
+    {
+        printf("Max possible C-state: C%"PRIu32"\n", value);
+        if ( (ret = xc_get_cpuidle_max_csubstate(xc_handle, &value)) )
+            return ret;
+        if ( value < XEN_SYSCTL_CX_UNLIMITED )
+            printf("Max possible substate: %"PRIu32"\n\n", value);
+        else
+            puts("");
+    }
      else
          printf("All C-states allowed\n\n");
  
@@ -1120,13 +1130,17 @@ void get_vcpu_migration_delay_func(int a
  
  void set_max_cstate_func(int argc, char *argv[])
  {
-    int value;
+    int value, subval = XEN_SYSCTL_CX_UNLIMITED;
      char buf[12];
  
-    if ( argc != 1 ||
+    if ( argc < 1 || argc > 2 ||
           (sscanf(argv[0], "%d", &value) == 1
            ? value < 0
-          : (value = XEN_SYSCTL_CX_UNLIMITED, strcmp(argv[0], "unlimited"))) )
+          : (value = XEN_SYSCTL_CX_UNLIMITED, strcmp(argv[0], "unlimited"))) ||
+         (argc == 2 &&
+          (sscanf(argv[1], "%d", &subval) == 1
+           ? subval < 0
+           : (subval = XEN_SYSCTL_CX_UNLIMITED, strcmp(argv[1], 
"unlimited")))) )
      {
          fprintf(stderr, "Missing, excess, or invalid argument(s)\n");
          exit(EINVAL);
@@ -1137,8 +1151,23 @@ void set_max_cstate_func(int argc, char
      if ( !xc_set_cpuidle_max_cstate(xc_handle, (uint32_t)value) )
          printf("max C-state set to %s\n", value >= 0 ? buf : argv[0]);
      else
+    {
          fprintf(stderr, "Failed to set max C-state to %s (%d - %s)\n",
                  value >= 0 ? buf : argv[0], errno, strerror(errno));
+        return;
+    }
+
+    if ( value != XEN_SYSCTL_CX_UNLIMITED )
+    {
+        snprintf(buf, ARRAY_SIZE(buf), "%d", subval);
+
+        if ( !xc_set_cpuidle_max_csubstate(xc_handle, (uint32_t)subval) )
+            printf("max C-substate set to %s succeeded\n",
+                   subval >= 0 ? buf : "unlimited");
+        else
+            fprintf(stderr, "Failed to set max C-substate to %s (%d - %s)\n",
+                    subval >= 0 ? buf : "unlimited", errno, strerror(errno));
+    }
  }
  
  void enable_turbo_mode(int argc, char *argv[])
--- a/xen/drivers/acpi/pmstat.c
+++ b/xen/drivers/acpi/pmstat.c
@@ -398,7 +398,40 @@ int do_pm_op(struct xen_sysctl_pm_op *op
      int ret = 0;
      const struct processor_pminfo *pmpt;
  
-    if ( !op || op->cpuid >= nr_cpu_ids || !cpu_online(op->cpuid) )
+    switch ( op->cmd )
+    {
+    case XEN_SYSCTL_pm_op_set_sched_opt_smt:
+    {
+        uint32_t saved_value = sched_smt_power_savings;
+
+        if ( op->cpuid != 0 )
+            return -EINVAL;
+        sched_smt_power_savings = !!op->u.set_sched_opt_smt;
+        op->u.set_sched_opt_smt = saved_value;
+        return 0;
+    }
+
+    case XEN_SYSCTL_pm_op_get_max_cstate:
+        BUILD_BUG_ON(XEN_SYSCTL_CX_UNLIMITED != UINT_MAX);
+        if ( op->cpuid == 0 )
+            op->u.get_max_cstate = acpi_get_cstate_limit();
+        else if ( op->cpuid == 1 )
+            op->u.get_max_cstate = acpi_get_csubstate_limit();
+        else
+            ret = -EINVAL;
+        return ret;
+
+    case XEN_SYSCTL_pm_op_set_max_cstate:
+        if ( op->cpuid == 0 )
+            acpi_set_cstate_limit(op->u.set_max_cstate);
+        else if ( op->cpuid == 1 )
+            acpi_set_csubstate_limit(op->u.set_max_cstate);
+        else
+            ret = -EINVAL;
+        return ret;
+    }
+
+    if ( op->cpuid >= nr_cpu_ids || !cpu_online(op->cpuid) )
          return -EINVAL;
      pmpt = processor_pminfo[op->cpuid];
  
@@ -438,30 +471,6 @@ int do_pm_op(struct xen_sysctl_pm_op *op
          break;
      }
  
-    case XEN_SYSCTL_pm_op_set_sched_opt_smt:
-    {
-        uint32_t saved_value;
-
-        saved_value = sched_smt_power_savings;
-        sched_smt_power_savings = !!op->u.set_sched_opt_smt;
-        op->u.set_sched_opt_smt = saved_value;
-
-        break;
-    }
-
-    case XEN_SYSCTL_pm_op_get_max_cstate:
-    {
-        BUILD_BUG_ON(XEN_SYSCTL_CX_UNLIMITED != UINT_MAX);
-        op->u.get_max_cstate = acpi_get_cstate_limit();
-        break;
-    }
-
-    case XEN_SYSCTL_pm_op_set_max_cstate:
-    {
-        acpi_set_cstate_limit(op->u.set_max_cstate);
-        break;
-    }
-
      case XEN_SYSCTL_pm_op_enable_turbo:
      {
          ret = cpufreq_update_turbo(op->cpuid, CPUFREQ_TURBO_ENABLED);
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -350,7 +350,11 @@ struct xen_sysctl_pm_op {
      /* set/reset scheduler power saving option */
      #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21
  
-    /* cpuidle max_cstate access command */
+    /*
+     * cpuidle max C-state and max C-sub-state access command:
+     * Set cpuid to 0 for max C-state.
+     * Set cpuid to 1 for max C-sub-state.
+     */
      #define XEN_SYSCTL_pm_op_get_max_cstate       0x22
      #define XEN_SYSCTL_pm_op_set_max_cstate       0x23
  
--- a/xen/include/xen/acpi.h
+++ b/xen/include/xen/acpi.h
@@ -166,9 +166,22 @@ static inline void acpi_set_cstate_limit
        max_cstate = new_limit;
        return;
  }
+
+static inline unsigned int acpi_get_csubstate_limit(void)
+{
+       return max_csubstate;
+}
+
+static inline void acpi_set_csubstate_limit(unsigned int new_limit)
+{
+       max_csubstate = new_limit;
+}
+
  #else
  static inline unsigned int acpi_get_cstate_limit(void) { return 0; }
  static inline void acpi_set_cstate_limit(unsigned int new_limit) { return; }
+static inline unsigned int acpi_get_csubstate_limit(void) { return 0; }
+static inline void acpi_set_csubstate_limit(unsigned int new_limit) { return; }
  #endif
  
  #ifdef XEN_GUEST_HANDLE_PARAM

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.