x86/smt: Support for enabling/disabling SMT at runtime
PATCH v2 1/1 x86/smt: Support for enabling/disabling SMT at runtime
Currently, a user can in combine the output of xl info -n, the APCI tables, and some manual CPUID data to figure out which CPU numbers to feed into xen-hptool cpu-offline to effectively disable SMT at runtime.
A more convenient option is to teach Xen how to perform this action.
Extend XEN_SYSCTL_cpu_hotplug with two new operations. Introduce a new smt_up_down_helper() which wrap the cpu_{up,down}_helper() helpers with logic which understands siblings based on their APIC_ID.
Add libxc stubs, and extend xen-hptool with smt-{enable,disable} options. These are intended to be shorthands for a loop over cpu-{online,offline}. It is intended for use in production scenarios where debugging options such as maxcpus= or other manual plug/unplug configuration has not been used.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
v2:
* Fold smt_{up,down}_helper() into smt_up_down_helper()
* Fix calculation of sibling_mask
* More clearly document the behaviour and expected restrictions.
While testing this, I've found a further bug. This is preexisting and can be provoked on staging, although it is easier to provoke with this patch.
(XEN) Assertion 'entry->prev->next == entry' failed at /local/xen.git/xen/include/xen/list.h:184
(XEN) ----[ Xen-4.13-unstable x86_64 debug=y Not tainted ]----
(XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d080241fad>] migrate_timer+0x1df/0x2da
(XEN) RFLAGS: 0000000000010087 CONTEXT: hypervisor
(XEN) rax: ffff830837088038 rbx: ffff830575928890 rcx: ffff83084d69e320 (XEN) rdx: ffff830575928898 rsi: ffff82d08094002f rdi: ffff830575928890 (XEN) rbp: ffff8300abc27d28 rsp: ffff8300abc27cc8 r8: 0000000000000000 (XEN) r9: ffff830575928780 r10: ffff830575928010 r11: 0000000000000000 (XEN) r12: 0000000000000000 r13: 0000000000000000 r14: ffff82d080962080 (XEN) r15: ffff82d080962080 cr0: 000000008005003b cr4: 00000000001526e0 (XEN) cr3: 00000000abc17000 cr2: ffff880072a9f8c0 (XEN) fsb: 0000000000000000 gsb: ffff88007ce00000 gss: 0000000000000000
(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e010 cs: e008
(XEN) Xen code around <ffff82d080241fad> (migrate_timer+0x1df/0x2da):
(XEN) 8b 4b 10 48 3b 11 74 02 <0f> 0b 48 89 48 08 48 89 01 48 b8 00 01 10 00 01 (XEN) Xen stack trace from rsp=ffff8300abc27cc8:
<snip>
(XEN) Xen call trace:
(XEN) [<ffff82d080241fad>] migrate_timer+0x1df/0x2da (XEN) [<ffff82d0802998b7>] do_IRQ+0x4fc/0x64e (XEN) [<ffff82d0803988aa>] common_interrupt+0x10a/0x120 (XEN) [<ffff82d0802f861c>] mwait-idle.c#mwait_idle+0x31d/0x370 (XEN) [<ffff82d080289499>] domain.c#idle_loop+0xa8/0xc3
(XEN)
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) Assertion 'entry->prev->next == entry' failed at /local/xen.git/xen/include/xen/list.h:184 (XEN) ****************************************
--- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_cpu_hotplug.c | 26 ++++++++++++++++++++ tools/misc/xen-hptool.c | 56 ++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/sysctl.c | 57 ++++++++++++++++++++++++++++++++++++++++++- xen/include/public/sysctl.h | 19 +++++++++++++++ 5 files changed, 159 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +2 -0
@@ -1854,6 +1854,8 @@ int xc_pm_reset_cxstat(xc_interface *xch, int cpuid);int xc_cpu_online (xc_interface *xch,int cpu);int xc_cpu_offline (xc_interface *xch,int cpu); +int xc_smt_enable (xc_interface *xch); +int xc_smt_disable (xc_interface *xch);/* * cpufreq para name of this structure named
tools/libxc/xc_cpu_hotplug.c +26 -0
@@ -46,3 +46,29 @@ int xc_cpu_offline(xc_interface *xch, int cpu)return ret; } +int xc_smt_enable (xc_interface *xch) +{ +DECLARE_SYSCTL ; +int ret; + + sysctl.cmd = XEN_SYSCTL_cpu_hotplug; + sysctl.u.cpu_hotplug.cpu =0 ; + sysctl.u.cpu_hotplug.op =XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE ; + ret =xc_sysctl (xch, &sysctl); + +return ret; +} + +int xc_smt_disable (xc_interface *xch) +{ +DECLARE_SYSCTL ; +int ret; + + sysctl.cmd = XEN_SYSCTL_cpu_hotplug; + sysctl.u.cpu_hotplug.cpu =0 ; + sysctl.u.cpu_hotplug.op =XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE ; + ret =xc_sysctl (xch, &sysctl); + +return ret; +} +
tools/misc/xen-hptool.c +56 -0
74 lines not on this page · raw message
xen/arch/x86/sysctl.c +56 -1
79 lines not on this page · raw message
xen/include/public/sysctl.h +19 -0
@@ -246,8 +246,27 @@ struct xen_sysctl_get_pmstat {struct xen_sysctl_cpu_hotplug {/* IN variables */ uint32_t cpu;/* Physical cpu. */ + +/* Single CPU enable/disable. */ #define XEN_SYSCTL_CPU_HOTPLUG_ONLINE 0#define XEN_SYSCTL_CPU_HOTPLUG_OFFLINE 1 + +/* +* SMT enable/disable. +* +* These two ops loop over all present CPUs, and either online or offline +* every non-primary sibling thread (those with a thread id which is not +* 0). +* +* They are intended as a shorthand for identifying and feeding the cpu +* numbers individually to HOTPLUG_{ON,OFF}LINE. +* +* These are not expected to be used in conjunction with debugging options +* such as `maxcpus=` or when other manual configuration of offline cpus +* is in use. +*/ +#define XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE 2 +#define XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE 3uint32_t op;/* hotplug opcode */ };
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.04.19 at 19:02, <[email protected]> wrote:
Currently, a user can in combine the output of
xl info -n, the APCI tables,
Stray "in"?
Quoted 5 lines
and some manual CPUID data to figure out which CPU numbers to feed into
xen-hptool cpu-offlineto effectively disable SMT at runtime.A more convenient option is to teach Xen how to perform this action.
Quoted 8 lines
Extend
XEN_SYSCTL_cpu_hotplugwith two new operations. Introduce a newsmt_up_down_helper()which wrap the cpu_{up,down}_helper() helpers with logic which understands siblings based on theirAPIC_ID.Add libxc stubs, and extend xen-hptool with smt-{enable,disable} options. These are intended to be shorthands for a loop over cpu-{online,offline}. It is intended for use in production scenarios where debugging options such as
maxcpus=or other manual plug/unplug configuration has not been used.
I'm still missing any mention of the restrictions of the new sub-ops. I do notice that they're described in the public header comment now, but perhaps at least briefly mentioning this here would be helpful. While in the public header it could also be made more clear that the restrictions are a choice of implementation, it being the sysctl one (and hence changeable at any time), I don't mind the chosen wording.
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>
Hypervisor side
with one further remark:
Quoted 34 lines
xen/arch/x86/sysctl.c +28
-0@@ -114,6 +114,48 @@ long cpu_down_helper(void *data)return ret; } +static long smt_up_down_helper (void *data) +{ +bool up = (bool )data; +unsigned int cpu, sibling_mask = boot_cpu_data.x86_num_siblings -1 ; +int ret =0 ; + + opt_smt = up; + +for_each_present_cpu ( cpu ) + { +/* Skip primary siblings (those whose thread id is 0). */ +if ( !(x86_cpu_to_apicid[cpu] & sibling_mask) ) +continue ; + + ret = up ?cpu_up_helper (_p (cpu)) + :cpu_down_helper (_p (cpu)); + +if ( ret && ret != -EEXIST ) +break ; + +/* +* Ensure forward progress by only considering preemption when we have +* changed the state of one or more cpus. +*/ +if ( ret != -EEXIST &&general_preempt_check () ) + { +/* In tasklet context - can't create a contination. */ + ret = -EBUSY ;
xen/arch/x86/sysctl.c long cpu_down_helper(void *data) · line 154
Quoted 10 lines
xen/arch/x86/sysctl.c +10
-0+break ; + } + + ret =0 ;/* Avoid exiting with -EEXIST in the success case. */ + } + +if ( !ret ) +printk (XENLOG_INFO "SMT %s - online CPUs {%*pbl}\n" , + up ?"enabled" :"disabled" , + nr_cpu_ids,cpumask_bits (&cpu_online_map));
While %pbl is likely going to produce more readable output for the "up" case, I'm afraid the "down" case will produce pretty long a line on larger systems. Perhaps better to use %pb in both cases, or alternatively simply log the number of active CPUs?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.04.19 at 19:02, <[email protected]> wrote:
Currently, a user can in combine the output of
xl info -n, the APCI tables,Stray "in"?
Oh yes. I think I first phrased this as "can in principle combine", then changed my mind.
Quoted 14 lines
Quoted 6 lines
and some manual CPUID data to figure out which CPU numbers to feed into
xen-hptool cpu-offlineto effectively disable SMT at runtime.A more convenient option is to teach Xen how to perform this action.
Quoted 8 lines
Extend
XEN_SYSCTL_cpu_hotplugwith two new operations. Introduce a newsmt_up_down_helper()which wrap the cpu_{up,down}_helper() helpers with logic which understands siblings based on theirAPIC_ID.Add libxc stubs, and extend xen-hptool with smt-{enable,disable} options. These are intended to be shorthands for a loop over cpu-{online,offline}. It is intended for use in production scenarios where debugging options such as
maxcpus=or other manual plug/unplug configuration has not been used.
Quoted 7 lines
I'm still missing any mention of the restrictions of the new sub-ops. I do notice that they're described in the public header comment now, but perhaps at least briefly mentioning this here would be helpful. While in the public header it could also be made more clear that the restrictions are a choice of implementation, it being the sysctl one (and hence changeable at any time), I don't mind the chosen wording.
I'll see about extending the comments.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Andrew Cooper <[email protected]>Hypervisor side
Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 43 lines
with one further remark:
Quoted 41 lines
xen/arch/x86/sysctl.c +35
-0@@ -114,6 +114,48 @@ long cpu_down_helper(void *data)return ret; } +static long smt_up_down_helper (void *data) +{ +bool up = (bool )data; +unsigned int cpu, sibling_mask = boot_cpu_data.x86_num_siblings -1 ; +int ret =0 ; + + opt_smt = up; + +for_each_present_cpu ( cpu ) + { +/* Skip primary siblings (those whose thread id is 0). */ +if ( !(x86_cpu_to_apicid[cpu] & sibling_mask) ) +continue ; + + ret = up ?cpu_up_helper (_p (cpu)) + :cpu_down_helper (_p (cpu)); + +if ( ret && ret != -EEXIST ) +break ; + +/* +* Ensure forward progress by only considering preemption when we have +* changed the state of one or more cpus. +*/ +if ( ret != -EEXIST &&general_preempt_check () ) + { +/* In tasklet context - can't create a contination. */ + ret = -EBUSY ; +break ; + } + + ret =0 ;/* Avoid exiting with -EEXIST in the success case. */ + } + +if ( !ret )
Quoted 8 lines
xen/arch/x86/sysctl.c long cpu_down_helper(void *data) · line 154
Quoted 3 lines
xen/arch/x86/sysctl.c +3
-0+printk (XENLOG_INFO "SMT %s - online CPUs {%*pbl}\n" , + up ?"enabled" :"disabled" , + nr_cpu_ids,cpumask_bits (&cpu_online_map));While %pbl is likely going to produce more readable output for the "up" case, I'm afraid the "down" case will produce pretty long a line on larger systems. Perhaps better to use %pb in both cases, or alternatively simply log the number of active CPUs?
I specifically wanted one of the bitmap representations, so you can easily identify the layout. It also makes it very obvious when maxcpu= or other (un)plugging has gone on.
We can switch to %*pb. I haven't tested this yet on a large enough system to notice an issue, due to all the other bugs it has uncovered.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Andrew Cooper
Currently, a user can in combine the output of
xl info -n, the APCI tables, and some manual CPUID data to figure out which CPU numbers to feed intoxen-hptool cpu-offlineto effectively disable SMT at runtime.A more convenient option is to teach Xen how to perform this action.
Extend
XEN_SYSCTL_cpu_hotplugwith two new operations. Introduce a newsmt_up_down_helper()which wrap the cpu_{up,down}_helper() helpers with logic which understands siblings based on theirAPIC_ID.
Quoted 6 lines
Add libxc stubs, and extend xen-hptool with smt-{enable,disable} options. These are intended to be shorthands for a loop over cpu-{online,offline}. It is intended for use in production scenarios where debugging options such as
maxcpus=or other manual plug/unplug configuration has not been used.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel