From: "Jan Beulich" Subject: [PATCH v3A 2/3] tools/libxc: allow controlling the max C-state sub-state Date: Mon, 23 Jun 2014 16:43:48 +0100 Message-ID: <53A86754020000780001C80D@mail.emea.novell.com> References: <1403521791-28859-1-git-send-email-ross.lagerwall@citrix.com> <1403521791-28859-3-git-send-email-ross.lagerwall@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartFCCE0A24.2__=" Return-path: In-Reply-To: <1403521791-28859-3-git-send-email-ross.lagerwall@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ross Lagerwall , Xen-devel Cc: Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartFCCE0A24.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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; } =20 -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 =20 sysctl.cmd =3D XEN_SYSCTL_pm_op; sysctl.u.pm_op.cmd =3D XEN_SYSCTL_pm_op_get_max_cstate; - sysctl.u.pm_op.cpuid =3D 0; + sysctl.u.pm_op.cpuid =3D type; sysctl.u.pm_op.u.get_max_cstate =3D 0; rc =3D do_sysctl(xch, &sysctl); *value =3D sysctl.u.pm_op.u.get_max_cstate; @@ -404,7 +404,17 @@ int xc_get_cpuidle_max_cstate(xc_interfa return rc; } =20 -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; =20 @@ -413,12 +423,22 @@ int xc_set_cpuidle_max_cstate(xc_interfa =20 sysctl.cmd =3D XEN_SYSCTL_pm_op; sysctl.u.pm_op.cmd =3D XEN_SYSCTL_pm_op_set_max_cstate; - sysctl.u.pm_op.cpuid =3D 0; + sysctl.u.pm_op.cpuid =3D type; sysctl.u.pm_op.u.set_max_cstate =3D value; =20 return do_sysctl(xch, &sysctl); } =20 +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); =20 +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 =3D 0; const struct processor_pminfo *pmpt; =20 - if ( !op || op->cpuid >=3D nr_cpu_ids || !cpu_online(op->cpuid) ) + switch ( op->cmd ) + { + case XEN_SYSCTL_pm_op_set_sched_opt_smt: + { + uint32_t saved_value =3D sched_smt_power_savings; + + if ( op->cpuid !=3D 0 ) + return -EINVAL; + sched_smt_power_savings =3D !!op->u.set_sched_opt_smt; + op->u.set_sched_opt_smt =3D saved_value; + return 0; + } + + case XEN_SYSCTL_pm_op_set_vcpu_migration_delay: + if ( op->cpuid !=3D 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 !=3D 0 ) + return -EINVAL; + op->u.get_vcpu_migration_delay =3D get_vcpu_migration_delay(); + return 0; + + case XEN_SYSCTL_pm_op_get_max_cstate: + if ( op->cpuid =3D=3D 0 ) + op->u.get_max_cstate =3D acpi_get_cstate_limit(); + else if ( op->cpuid =3D=3D 1 ) + op->u.get_max_cstate =3D acpi_get_csubstate_limit(); + else + ret =3D -EINVAL; + return ret; + + case XEN_SYSCTL_pm_op_set_max_cstate: + if ( op->cpuid =3D=3D 0 ) + acpi_set_cstate_limit(op->u.set_max_cstate); + else if ( op->cpuid =3D=3D 1 ) + acpi_set_csubstate_limit(op->u.set_max_cstate); + else + ret =3D -EINVAL; + return ret; + } + + if ( op->cpuid >=3D nr_cpu_ids || !cpu_online(op->cpuid) ) return -EINVAL; pmpt =3D processor_pminfo[op->cpuid]; =20 @@ -440,41 +484,6 @@ int do_pm_op(struct xen_sysctl_pm_op *op break; } =20 - case XEN_SYSCTL_pm_op_set_sched_opt_smt: - { - uint32_t saved_value; - - saved_value =3D sched_smt_power_savings; - sched_smt_power_savings =3D !!op->u.set_sched_opt_smt; - op->u.set_sched_opt_smt =3D 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 =3D get_vcpu_migration_delay(); - break; - } - - case XEN_SYSCTL_pm_op_get_max_cstate: - { - op->u.get_max_cstate =3D 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 =3D 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 =20 - /* 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 =20 --- 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 =3D 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 =3D 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 =20 #ifdef XEN_GUEST_HANDLE_PARAM --=__PartFCCE0A24.2__= Content-Type: text/plain; name="libxc-allow-controlling-C-sub-state.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="libxc-allow-controlling-C-sub-state.patch" tools/libxc: allow controlling the max C-state sub-state=0A=0ASigned-off-by= : Ross Lagerwall =0A=0AMake handling in = do_pm_op() more homogeneous: Before interpreting=0Aop->cpuid as such, = handle all operations not acting on a particular=0ACPU.=0A=0ASigned-off-by:= Jan Beulich =0A=0A--- a/tools/libxc/xc_pm.c=0A+++ = b/tools/libxc/xc_pm.c=0A@@ -386,7 +386,7 @@ int xc_get_vcpu_migration_delay= (xc_inter=0A return rc;=0A }=0A =0A-int xc_get_cpuidle_max_cstate(xc_int= erface *xch, uint32_t *value)=0A+static int get_max_cstate(xc_interface = *xch, uint32_t *value, uint32_t type)=0A {=0A int rc;=0A DECLARE_SY= SCTL;=0A@@ -396,7 +396,7 @@ int xc_get_cpuidle_max_cstate(xc_interfa=0A = =0A sysctl.cmd =3D XEN_SYSCTL_pm_op;=0A sysctl.u.pm_op.cmd =3D = XEN_SYSCTL_pm_op_get_max_cstate;=0A- sysctl.u.pm_op.cpuid =3D 0;=0A+ = sysctl.u.pm_op.cpuid =3D type;=0A sysctl.u.pm_op.u.get_max_cstate =3D = 0;=0A rc =3D do_sysctl(xch, &sysctl);=0A *value =3D sysctl.u.pm_op.= u.get_max_cstate;=0A@@ -404,7 +404,17 @@ int xc_get_cpuidle_max_cstate(xc_i= nterfa=0A return rc;=0A }=0A =0A-int xc_set_cpuidle_max_cstate(xc_inter= face *xch, uint32_t value)=0A+int xc_get_cpuidle_max_cstate(xc_interface = *xch, uint32_t *value)=0A+{=0A+ return get_max_cstate(xch, value, = 0);=0A+}=0A+=0A+int xc_get_cpuidle_max_csubstate(xc_interface *xch, = uint32_t *value)=0A+{=0A+ return get_max_cstate(xch, value, 1);=0A+}=0A+= =0A+static int set_max_cstate(xc_interface *xch, uint32_t value, uint32_t = type)=0A {=0A DECLARE_SYSCTL;=0A =0A@@ -413,12 +423,22 @@ int = xc_set_cpuidle_max_cstate(xc_interfa=0A =0A sysctl.cmd =3D XEN_SYSCTL_p= m_op;=0A sysctl.u.pm_op.cmd =3D XEN_SYSCTL_pm_op_set_max_cstate;=0A- = sysctl.u.pm_op.cpuid =3D 0;=0A+ sysctl.u.pm_op.cpuid =3D type;=0A = sysctl.u.pm_op.u.set_max_cstate =3D value;=0A =0A return do_sysctl(xch,= &sysctl);=0A }=0A =0A+int xc_set_cpuidle_max_cstate(xc_interface *xch, = uint32_t value)=0A+{=0A+ return set_max_cstate(xch, value, 0);=0A+}=0A+= =0A+int xc_set_cpuidle_max_csubstate(xc_interface *xch, uint32_t value)=0A+= {=0A+ return set_max_cstate(xch, value, 1);=0A+}=0A+=0A int xc_enable_tu= rbo(xc_interface *xch, int cpuid)=0A {=0A DECLARE_SYSCTL;=0A--- = a/tools/libxc/xenctrl.h=0A+++ b/tools/libxc/xenctrl.h=0A@@ -2159,6 +2159,9 = @@ int xc_get_vcpu_migration_delay(xc_inter=0A int xc_get_cpuidle_max_cstat= e(xc_interface *xch, uint32_t *value);=0A int xc_set_cpuidle_max_cstate(xc_= interface *xch, uint32_t value);=0A =0A+int xc_get_cpuidle_max_csubstate(xc= _interface *xch, uint32_t *value);=0A+int xc_set_cpuidle_max_csubstate(xc_i= nterface *xch, uint32_t value);=0A+=0A int xc_enable_turbo(xc_interface = *xch, int cpuid);=0A int xc_disable_turbo(xc_interface *xch, int cpuid);=0A= /**=0A--- a/xen/drivers/acpi/pmstat.c=0A+++ b/xen/drivers/acpi/pmstat.c=0A= @@ -400,7 +400,51 @@ int do_pm_op(struct xen_sysctl_pm_op *op=0A int = ret =3D 0;=0A const struct processor_pminfo *pmpt;=0A =0A- if ( !op = || op->cpuid >=3D nr_cpu_ids || !cpu_online(op->cpuid) )=0A+ switch ( = op->cmd )=0A+ {=0A+ case XEN_SYSCTL_pm_op_set_sched_opt_smt:=0A+ = {=0A+ uint32_t saved_value =3D sched_smt_power_savings;=0A+=0A+ = if ( op->cpuid !=3D 0 )=0A+ return -EINVAL;=0A+ = sched_smt_power_savings =3D !!op->u.set_sched_opt_smt;=0A+ = op->u.set_sched_opt_smt =3D saved_value;=0A+ return 0;=0A+ = }=0A+=0A+ case XEN_SYSCTL_pm_op_set_vcpu_migration_delay:=0A+ if = ( op->cpuid !=3D 0 )=0A+ return -EINVAL;=0A+ set_vcpu_mig= ration_delay(op->u.set_vcpu_migration_delay);=0A+ return 0;=0A+=0A+ = case XEN_SYSCTL_pm_op_get_vcpu_migration_delay:=0A+ if ( = op->cpuid !=3D 0 )=0A+ return -EINVAL;=0A+ op->u.get_vcpu= _migration_delay =3D get_vcpu_migration_delay();=0A+ return = 0;=0A+=0A+ case XEN_SYSCTL_pm_op_get_max_cstate:=0A+ if ( = op->cpuid =3D=3D 0 )=0A+ op->u.get_max_cstate =3D acpi_get_cstat= e_limit();=0A+ else if ( op->cpuid =3D=3D 1 )=0A+ = op->u.get_max_cstate =3D acpi_get_csubstate_limit();=0A+ else=0A+ = ret =3D -EINVAL;=0A+ return ret;=0A+=0A+ case XEN_SYSCTL= _pm_op_set_max_cstate:=0A+ if ( op->cpuid =3D=3D 0 )=0A+ = acpi_set_cstate_limit(op->u.set_max_cstate);=0A+ else if ( = op->cpuid =3D=3D 1 )=0A+ acpi_set_csubstate_limit(op->u.set_max_= cstate);=0A+ else=0A+ ret =3D -EINVAL;=0A+ return = ret;=0A+ }=0A+=0A+ if ( op->cpuid >=3D nr_cpu_ids || !cpu_online(op->= cpuid) )=0A return -EINVAL;=0A pmpt =3D processor_pminfo[op->cp= uid];=0A =0A@@ -440,41 +484,6 @@ int do_pm_op(struct xen_sysctl_pm_op = *op=0A break;=0A }=0A =0A- case XEN_SYSCTL_pm_op_set_sched_o= pt_smt:=0A- {=0A- uint32_t saved_value;=0A-=0A- saved_valu= e =3D sched_smt_power_savings;=0A- sched_smt_power_savings =3D = !!op->u.set_sched_opt_smt;=0A- op->u.set_sched_opt_smt =3D = saved_value;=0A-=0A- break;=0A- }=0A-=0A- case XEN_SYSCTL_pm_o= p_set_vcpu_migration_delay:=0A- {=0A- set_vcpu_migration_delay(op= ->u.set_vcpu_migration_delay);=0A- break;=0A- }=0A-=0A- case = XEN_SYSCTL_pm_op_get_vcpu_migration_delay:=0A- {=0A- op->u.get_vc= pu_migration_delay =3D get_vcpu_migration_delay();=0A- break;=0A- = }=0A-=0A- case XEN_SYSCTL_pm_op_get_max_cstate:=0A- {=0A- = op->u.get_max_cstate =3D acpi_get_cstate_limit();=0A- break;=0A- = }=0A-=0A- case XEN_SYSCTL_pm_op_set_max_cstate:=0A- {=0A- = acpi_set_cstate_limit(op->u.set_max_cstate);=0A- break;=0A- = }=0A-=0A case XEN_SYSCTL_pm_op_enable_turbo:=0A {=0A ret = =3D cpufreq_update_turbo(op->cpuid, CPUFREQ_TURBO_ENABLED);=0A--- = a/xen/include/public/sysctl.h=0A+++ b/xen/include/public/sysctl.h=0A@@ = -354,7 +354,11 @@ struct xen_sysctl_pm_op {=0A /* set/reset scheduler = power saving option */=0A #define XEN_SYSCTL_pm_op_set_sched_opt_smt = 0x21=0A =0A- /* cpuidle max_cstate access command */=0A+ /*=0A+ = * cpuidle max C-state and max C-sub-state access command:=0A+ * Set = cpuid to 0 for max C-state.=0A+ * Set cpuid to 1 for max C-sub-state.= =0A+ */=0A #define XEN_SYSCTL_pm_op_get_max_cstate 0x22=0A = #define XEN_SYSCTL_pm_op_set_max_cstate 0x23=0A =0A--- a/xen/includ= e/xen/acpi.h=0A+++ b/xen/include/xen/acpi.h=0A@@ -149,9 +149,22 @@ static = inline void acpi_set_cstate_limit=0A max_cstate =3D new_limit;=0A = return;=0A }=0A+=0A+static inline unsigned int acpi_get_csubstate_limit(voi= d)=0A+{=0A+ return max_csubstate;=0A+}=0A+=0A+static inline void = acpi_set_csubstate_limit(unsigned int new_limit)=0A+{=0A+ max_csubsta= te =3D new_limit;=0A+}=0A+=0A #else=0A static inline unsigned int = acpi_get_cstate_limit(void) { return 0; }=0A static inline void acpi_set_cs= tate_limit(unsigned int new_limit) { return; }=0A+static inline unsigned = int acpi_get_csubstate_limit(void) { return 0; }=0A+static inline void = acpi_set_csubstate_limit(unsigned int new_limit) { return; }=0A #endif=0A = =0A #ifdef XEN_GUEST_HANDLE_PARAM=0A --=__PartFCCE0A24.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartFCCE0A24.2__=--