tools/libxc: allow controlling the max C-state sub-state Signed-off-by: Ross Lagerwall Make handling in do_pm_op() more homogeneous: Before interpreting op->cpuid as such, handle all operations not acting on a particular CPU. Signed-off-by: Jan Beulich --- a/tools/libxc/xc_pm.c +++ b/tools/libxc/xc_pm.c @@ -386,7 +386,7 @@ int xc_get_vcpu_migration_delay(xc_inter 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; @@ -396,7 +396,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; @@ -404,7 +404,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; @@ -413,12 +423,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/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2159,6 +2159,9 @@ int xc_get_vcpu_migration_delay(xc_inter 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/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -400,7 +400,51 @@ 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_set_vcpu_migration_delay: + if ( op->cpuid != 0 ) + return -EINVAL; + set_vcpu_migration_delay(op->u.set_vcpu_migration_delay); + return 0; + + case XEN_SYSCTL_pm_op_get_vcpu_migration_delay: + if ( op->cpuid != 0 ) + return -EINVAL; + op->u.get_vcpu_migration_delay = get_vcpu_migration_delay(); + return 0; + + case XEN_SYSCTL_pm_op_get_max_cstate: + 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]; @@ -440,41 +484,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_set_vcpu_migration_delay: - { - set_vcpu_migration_delay(op->u.set_vcpu_migration_delay); - break; - } - - case XEN_SYSCTL_pm_op_get_vcpu_migration_delay: - { - op->u.get_vcpu_migration_delay = get_vcpu_migration_delay(); - break; - } - - case XEN_SYSCTL_pm_op_get_max_cstate: - { - 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 @@ -354,7 +354,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 @@ -149,9 +149,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