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
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;
+}
+
" mem-online <mfn> online MEMORY <mfn>\n"
" mem-offline <mfn> offline MEMORY <mfn>\n"
" mem-status <mfn> query Memory status<mfn>\n"
+ " smt-enable onlines all SMT threads\n"
+ " smt-disable offlines all SMT threads\n"
);
}
return ret;
}
+static int main_smt_enable(int argc, char *argv[])
+{
+ int ret;
+
+ if ( argc )
+ {
+ show_help();
+ return -1;
+ }
+
+ for ( ;; )
+ {
+ ret = xc_smt_enable(xch);
+ if ( (ret >= 0) || (errno != EBUSY) )
+ break;
+ }
+
+ if ( ret < 0 )
+ fprintf(stderr, "Unable to enable SMT: errno %d, %s\n",
+ errno, strerror(errno));
+ else
+ printf("Enabled SMT\n");
+
+ return ret;
+}
+
+static int main_smt_disable(int argc, char *argv[])
+{
+ int ret;
+
+ if ( argc )
+ {
+ show_help();
+ return -1;
+ }
+
+ for ( ;; )
+ {
+ ret = xc_smt_disable(xch);
+ if ( (ret >= 0) || (errno != EBUSY) )
+ break;
+ }
+
+ if ( ret < 0 )
+ fprintf(stderr, "Unable to disable SMT: errno %d, %s\n",
+ errno, strerror(errno));
+ else
+ printf("Disabled SMT\n");
+
+ return ret;
+}
+
struct {
const char *name;
int (*function)(int argc, char *argv[]);
{ "mem-status", hp_mem_query_func},
{ "mem-online", hp_mem_online_func},
{ "mem-offline", hp_mem_offline_func},
+ { "smt-enable", main_smt_enable },
+ { "smt-disable", main_smt_disable },
};
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 )
+ printk(XENLOG_INFO "SMT %s - online CPUs 0x%*pb\n",
+ up ? "enabled" : "disabled",
+ nr_cpu_ids, cpumask_bits(&cpu_online_map));
+
+ return ret;
+}
+
void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
{
memcpy(pi->hw_cap, boot_cpu_data.x86_capability,
case XEN_SYSCTL_cpu_hotplug:
{
unsigned int cpu = sysctl->u.cpu_hotplug.cpu;
+ unsigned int op = sysctl->u.cpu_hotplug.op;
bool plug;
long (*fn)(void *);
void *hcpu;
- switch ( sysctl->u.cpu_hotplug.op )
+ switch ( op )
{
case XEN_SYSCTL_CPU_HOTPLUG_ONLINE:
plug = true;
hcpu = _p(cpu);
break;
+ case XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE:
+ case XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE:
+ if ( !cpu_has_htt || boot_cpu_data.x86_num_siblings < 2 )
+ {
+ ret = -EOPNOTSUPP;
+ break;
+ }
+ plug = op == XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE;
+ fn = smt_up_down_helper;
+ hcpu = _p(plug);
+ break;
+
default:
ret = -EOPNOTSUPP;
break;
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). This behaviour is chosen to simplify the implementation.
+ *
+ * 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 3
uint32_t op; /* hotplug opcode */
};