aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/libxc/xc_pm.c20
-rw-r--r--tools/libxc/xenctrl.h16
-rw-r--r--tools/misc/xenpm.c44
-rw-r--r--tools/python/xen/lowlevel/xc/xc.c44
-rw-r--r--tools/python/xen/xend/XendNode.py18
-rw-r--r--xen/arch/x86/sysctl.c53
-rw-r--r--xen/drivers/acpi/pmstat.c52
-rw-r--r--xen/include/public/sysctl.h25
8 files changed, 77 insertions, 195 deletions
diff --git a/tools/libxc/xc_pm.c b/tools/libxc/xc_pm.c
index 7e20231a33..e979ba12b3 100644
--- a/tools/libxc/xc_pm.c
+++ b/tools/libxc/xc_pm.c
@@ -326,26 +326,6 @@ int xc_get_cpufreq_avgfreq(int xc_handle, int cpuid, int *avg_freq)
return ret;
}
-int xc_get_cputopo(int xc_handle, struct xc_get_cputopo *info)
-{
- int rc;
- DECLARE_SYSCTL;
-
- sysctl.cmd = XEN_SYSCTL_pm_op;
- sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_get_cputopo;
- sysctl.u.pm_op.cpuid = 0;
- set_xen_guest_handle( sysctl.u.pm_op.u.get_topo.cpu_to_core,
- info->cpu_to_core );
- set_xen_guest_handle( sysctl.u.pm_op.u.get_topo.cpu_to_socket,
- info->cpu_to_socket );
- sysctl.u.pm_op.u.get_topo.max_cpus = info->max_cpus;
-
- rc = do_sysctl(xc_handle, &sysctl);
- info->nr_cpus = sysctl.u.pm_op.u.get_topo.nr_cpus;
-
- return rc;
-}
-
/* value: 0 - disable sched_smt_power_savings
1 - enable sched_smt_power_savings
*/
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index a12388db72..497e211a43 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -1303,22 +1303,6 @@ int xc_set_cpufreq_para(int xc_handle, int cpuid,
int ctrl_type, int ctrl_value);
int xc_get_cpufreq_avgfreq(int xc_handle, int cpuid, int *avg_freq);
-struct xc_get_cputopo {
- /* IN: maximum addressable entry in
- * the caller-provided cpu_to_core/socket.
- */
- uint32_t max_cpus;
- uint32_t *cpu_to_core;
- uint32_t *cpu_to_socket;
-
- /* OUT: number of cpus returned
- * If OUT is greater than IN then the cpu_to_core/socket is truncated!
- */
- uint32_t nr_cpus;
-};
-
-int xc_get_cputopo(int xc_handle, struct xc_get_cputopo *info);
-
int xc_set_sched_opt_smt(int xc_handle, uint32_t value);
int xc_set_vcpu_migration_delay(int xc_handle, uint32_t value);
int xc_get_vcpu_migration_delay(int xc_handle, uint32_t *value);
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c
index e168659200..19a6e2f2ba 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -842,32 +842,32 @@ void cpu_topology_func(int argc, char *argv[])
{
uint32_t cpu_to_core[MAX_NR_CPU];
uint32_t cpu_to_socket[MAX_NR_CPU];
- struct xc_get_cputopo info;
- int i, ret;
-
- info.cpu_to_core = cpu_to_core;
- info.cpu_to_socket = cpu_to_socket;
- info.max_cpus = MAX_NR_CPU;
- ret = xc_get_cputopo(xc_fd, &info);
- if (!ret)
+ uint32_t cpu_to_node[MAX_NR_CPU];
+ xc_topologyinfo_t info = { 0 };
+ int i;
+
+ set_xen_guest_handle(info.cpu_to_core, cpu_to_core);
+ set_xen_guest_handle(info.cpu_to_socket, cpu_to_socket);
+ set_xen_guest_handle(info.cpu_to_node, cpu_to_node);
+ info.max_cpu_index = MAX_NR_CPU-1;
+
+ if ( xc_topologyinfo(xc_fd, &info) )
{
- printf("CPU\tcore\tsocket\n");
- for (i=0; i<info.nr_cpus; i++)
- {
- if ( info.cpu_to_core[i] != INVALID_TOPOLOGY_ID &&
- info.cpu_to_socket[i] != INVALID_TOPOLOGY_ID )
- {
- printf("CPU%d\t %d\t %d\n", i, info.cpu_to_core[i],
- info.cpu_to_socket[i]);
- }
- }
+ printf("Can not get Xen CPU topology: %d\n", errno);
+ return;
}
- else
+
+ if ( info.max_cpu_index > (MAX_NR_CPU-1) )
+ info.max_cpu_index = MAX_NR_CPU-1;
+
+ printf("CPU\tcore\tsocket\tnode\n");
+ for ( i = 0; i < info.max_cpu_index; i++ )
{
- printf("Can not get Xen CPU topology!\n");
+ if ( cpu_to_core[i] == INVALID_TOPOLOGY_ID )
+ continue;
+ printf("CPU%d\t %d\t %d\t %d\n",
+ i, cpu_to_core[i], cpu_to_socket[i], cpu_to_node[i]);
}
-
- return ;
}
void set_sched_smt_func(int argc, char *argv[])
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 514e48e760..4dc56c2821 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -1191,7 +1191,7 @@ static PyObject *pyxc_physinfo(XcObject *self)
static PyObject *pyxc_topologyinfo(XcObject *self)
{
#define MAX_CPU_INDEX 255
- xc_topologyinfo_t tinfo;
+ xc_topologyinfo_t tinfo = { 0 };
int i, max_cpu_index;
PyObject *ret_obj;
PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj;
@@ -1199,7 +1199,6 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
xc_cpu_to_socket_t socketmap[MAX_CPU_INDEX + 1];
xc_cpu_to_node_t nodemap[MAX_CPU_INDEX + 1];
-
set_xen_guest_handle(tinfo.cpu_to_core, coremap);
set_xen_guest_handle(tinfo.cpu_to_socket, socketmap);
set_xen_guest_handle(tinfo.cpu_to_node, nodemap);
@@ -1218,19 +1217,38 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
cpu_to_node_obj = PyList_New(0);
for ( i = 0; i < max_cpu_index; i++ )
{
- PyObject *pyint;
-
- pyint = PyInt_FromLong(coremap[i]);
- PyList_Append(cpu_to_core_obj, pyint);
- Py_DECREF(pyint);
+ if ( coremap[i] == INVALID_TOPOLOGY_ID )
+ {
+ PyList_Append(cpu_to_core_obj, Py_None);
+ }
+ else
+ {
+ PyObject *pyint = PyInt_FromLong(coremap[i]);
+ PyList_Append(cpu_to_core_obj, pyint);
+ Py_DECREF(pyint);
+ }
- pyint = PyInt_FromLong(socketmap[i]);
- PyList_Append(cpu_to_socket_obj, pyint);
- Py_DECREF(pyint);
+ if ( socketmap[i] == INVALID_TOPOLOGY_ID )
+ {
+ PyList_Append(cpu_to_socket_obj, Py_None);
+ }
+ else
+ {
+ PyObject *pyint = PyInt_FromLong(socketmap[i]);
+ PyList_Append(cpu_to_socket_obj, pyint);
+ Py_DECREF(pyint);
+ }
- pyint = PyInt_FromLong(nodemap[i]);
- PyList_Append(cpu_to_node_obj, pyint);
- Py_DECREF(pyint);
+ if ( nodemap[i] == INVALID_TOPOLOGY_ID )
+ {
+ PyList_Append(cpu_to_node_obj, Py_None);
+ }
+ else
+ {
+ PyObject *pyint = PyInt_FromLong(nodemap[i]);
+ PyList_Append(cpu_to_node_obj, pyint);
+ Py_DECREF(pyint);
+ }
}
ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpu_index);
diff --git a/tools/python/xen/xend/XendNode.py b/tools/python/xen/xend/XendNode.py
index 713967e2d5..c3fe85ab97 100644
--- a/tools/python/xen/xend/XendNode.py
+++ b/tools/python/xen/xend/XendNode.py
@@ -879,16 +879,16 @@ class XendNode:
return self.format_pairs(self.list_to_rangepairs(list))
def format_cpu_to_core_socket_node(self, tinfo):
- try:
- nr_cpus=tinfo['max_cpu_index']
- str='\ncpu: core socket node\n'
- for i in range(0, nr_cpus):
+ max_cpu_index=tinfo['max_cpu_index']
+ str='\ncpu: core socket node\n'
+ for i in range(0, max_cpu_index+1):
+ try:
str+='%3d:%8d %8d %8d\n' % (i,
- tinfo['cpu_to_core'][i],
- tinfo['cpu_to_socket'][i],
- tinfo['cpu_to_node'][i])
- except:
- str='none\n'
+ tinfo['cpu_to_core'][i],
+ tinfo['cpu_to_socket'][i],
+ tinfo['cpu_to_node'][i])
+ except:
+ pass
return str[:-1];
def format_numa_info(self, ninfo):
diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index ed09bffeea..bc3fc8d25a 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -80,64 +80,37 @@ long arch_do_sysctl(
case XEN_SYSCTL_topologyinfo:
{
- uint32_t i, max_cpu_index;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_core_arr;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_socket_arr;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_node_arr;
-
+ uint32_t i, max_cpu_index, last_online_cpu;
xen_sysctl_topologyinfo_t *ti = &sysctl->u.topologyinfo;
- max_cpu_index = ti->max_cpu_index;
- cpu_to_core_arr = ti->cpu_to_core;
- cpu_to_socket_arr = ti->cpu_to_socket;
- cpu_to_node_arr = ti->cpu_to_node;
-
- memset(ti, 0, sizeof(*ti));
- ti->cpu_to_core = cpu_to_core_arr;
- ti->cpu_to_socket = cpu_to_socket_arr;
- ti->cpu_to_node = cpu_to_node_arr;
-
- max_cpu_index = min_t(uint32_t, max_cpu_index, num_online_cpus());
- ti->max_cpu_index = max_cpu_index;
-
- ret = 0;
+ last_online_cpu = last_cpu(cpu_online_map);
+ max_cpu_index = min_t(uint32_t, ti->max_cpu_index, last_online_cpu);
+ ti->max_cpu_index = last_online_cpu;
- for ( i = 0; i < max_cpu_index; i++ )
+ for ( i = 0; i <= max_cpu_index; i++ )
{
- if ( !guest_handle_is_null(cpu_to_core_arr) )
+ if ( !guest_handle_is_null(ti->cpu_to_core) )
{
uint32_t core = cpu_online(i) ? cpu_to_core(i) : ~0u;
- if ( copy_to_guest_offset(cpu_to_core_arr, i, &core, 1) )
- {
- ret = -EFAULT;
+ if ( copy_to_guest_offset(ti->cpu_to_core, i, &core, 1) )
break;
- }
}
- if ( !guest_handle_is_null(cpu_to_socket_arr) )
+ if ( !guest_handle_is_null(ti->cpu_to_socket) )
{
uint32_t socket = cpu_online(i) ? cpu_to_socket(i) : ~0u;
- if ( copy_to_guest_offset(cpu_to_socket_arr, i, &socket, 1) )
- {
- ret = -EFAULT;
+ if ( copy_to_guest_offset(ti->cpu_to_socket, i, &socket, 1) )
break;
- }
}
- if ( !guest_handle_is_null(cpu_to_node_arr) )
+ if ( !guest_handle_is_null(ti->cpu_to_node) )
{
uint32_t node = cpu_online(i) ? cpu_to_node(i) : ~0u;
- if ( copy_to_guest_offset(cpu_to_node_arr, i, &node, 1) )
- {
- ret = -EFAULT;
+ if ( copy_to_guest_offset(ti->cpu_to_node, i, &node, 1) )
break;
- }
}
}
- if (ret)
- break;
-
- if ( copy_to_guest(u_sysctl, sysctl, 1) )
- ret = -EFAULT;
+ ret = ((i <= max_cpu_index) || copy_to_guest(u_sysctl, sysctl, 1))
+ ? -EFAULT : 0;
}
break;
diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c
index c93f98f70a..110e779dd8 100644
--- a/xen/drivers/acpi/pmstat.c
+++ b/xen/drivers/acpi/pmstat.c
@@ -419,52 +419,6 @@ static int get_cpufreq_avgfreq(struct xen_sysctl_pm_op *op)
return 0;
}
-static int get_cputopo (struct xen_sysctl_pm_op *op)
-{
- uint32_t i, nr_cpus;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_core_arr;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_socket_arr;
- int arr_size, ret=0;
-
- cpu_to_core_arr = op->u.get_topo.cpu_to_core;
- cpu_to_socket_arr = op->u.get_topo.cpu_to_socket;
- arr_size= min_t(uint32_t, op->u.get_topo.max_cpus, NR_CPUS);
-
- if ( guest_handle_is_null( cpu_to_core_arr ) ||
- guest_handle_is_null( cpu_to_socket_arr) )
- {
- ret = -EINVAL;
- goto out;
- }
-
- nr_cpus = 0;
- for ( i = 0; i < arr_size; i++ )
- {
- uint32_t core, socket;
- if ( cpu_online(i) )
- {
- core = cpu_to_core(i);
- socket = cpu_to_socket(i);
- nr_cpus = i;
- }
- else
- {
- core = socket = INVALID_TOPOLOGY_ID;
- }
-
- if ( copy_to_guest_offset(cpu_to_core_arr, i, &core, 1) ||
- copy_to_guest_offset(cpu_to_socket_arr, i, &socket, 1))
- {
- ret = -EFAULT;
- goto out;
- }
- }
-
- op->u.get_topo.nr_cpus = nr_cpus + 1;
-out:
- return ret;
-}
-
int do_pm_op(struct xen_sysctl_pm_op *op)
{
int ret = 0;
@@ -510,12 +464,6 @@ int do_pm_op(struct xen_sysctl_pm_op *op)
break;
}
- case XEN_SYSCTL_pm_op_get_cputopo:
- {
- ret = get_cputopo(op);
- break;
- }
-
case XEN_SYSCTL_pm_op_set_sched_opt_smt:
{
uint32_t saved_value;
diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
index ab6897d1da..87967823b4 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -336,22 +336,6 @@ struct xen_set_cpufreq_para {
uint32_t ctrl_value;
};
-/* Get physical CPU topology information. */
-#define INVALID_TOPOLOGY_ID (~0U)
-struct xen_get_cputopo {
- /* IN: maximum addressable entry in
- * the caller-provided cpu_to_core/socket.
- */
- uint32_t max_cpus;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_core;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_socket;
-
- /* OUT: number of cpus returned
- * If OUT is greater than IN then the cpu_to_core/socket is truncated!
- */
- uint32_t nr_cpus;
-};
-
struct xen_sysctl_pm_op {
#define PM_PARA_CATEGORY_MASK 0xf0
#define CPUFREQ_PARA 0x10
@@ -362,9 +346,6 @@ struct xen_sysctl_pm_op {
#define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03)
#define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04)
- /* get CPU topology */
- #define XEN_SYSCTL_pm_op_get_cputopo 0x20
-
/* set/reset scheduler power saving option */
#define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21
@@ -387,7 +368,6 @@ struct xen_sysctl_pm_op {
struct xen_set_cpufreq_gov set_gov;
struct xen_set_cpufreq_para set_para;
uint64_aligned_t get_avgfreq;
- struct xen_get_cputopo get_topo;
uint32_t set_sched_opt_smt;
uint32_t get_max_cstate;
uint32_t set_max_cstate;
@@ -477,8 +457,8 @@ typedef struct xen_sysctl_lockprof_op xen_sysctl_lockprof_op_t;
DEFINE_XEN_GUEST_HANDLE(xen_sysctl_lockprof_op_t);
#define XEN_SYSCTL_topologyinfo 16
+#define INVALID_TOPOLOGY_ID (~0U)
struct xen_sysctl_topologyinfo {
-
/*
* IN: maximum addressable entry in the caller-provided cpu_to_core,
* cpu_to_socket & cpu_to_node arrays.
@@ -498,8 +478,7 @@ struct xen_sysctl_topologyinfo {
*/
XEN_GUEST_HANDLE_64(uint32) cpu_to_core;
XEN_GUEST_HANDLE_64(uint32) cpu_to_socket;
- XEN_GUEST_HANDLE_64(uint32) cpu_to_node; /* node_number */
-
+ XEN_GUEST_HANDLE_64(uint32) cpu_to_node;
};
typedef struct xen_sysctl_topologyinfo xen_sysctl_topologyinfo_t;
DEFINE_XEN_GUEST_HANDLE(xen_sysctl_topologyinfo_t);