WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Support getting topology info in libxl

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Support getting topology info in libxl
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Dec 2010 15:46:18 -0800
Delivery-date: Fri, 24 Dec 2010 15:50:06 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Juergen Gross <juergen.gross@xxxxxxxxxxxxxx>
# Date 1291890090 -3600
# Node ID f713cff1a5870b44927db041745b54d5424014c2
# Parent  8079cba70803523dccaaeee22d35e5adc9932597
Support getting topology info in libxl

Added new function libxl_get_topologyinfo() to obtain this information from
hypervisor.

Signed-off-by: juergen.gross@xxxxxxxxxxxxxx
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
---
 tools/libxl/libxl.c               |   53 ++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h               |    8 +++++
 tools/libxl/libxl.idl             |    7 +++++
 tools/libxl/libxl_utils.c         |   24 +++++++++++++++++
 tools/libxl/libxl_utils.h         |    2 +
 tools/python/xen/lowlevel/xl/xl.c |   24 +++++++++++++++++
 6 files changed, 118 insertions(+)

diff -r 8079cba70803 -r f713cff1a587 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Dec 03 09:36:47 2010 +0000
+++ b/tools/libxl/libxl.c       Thu Dec 09 11:21:30 2010 +0100
@@ -3223,6 +3223,59 @@ int libxl_get_physinfo(libxl_ctx *ctx, l
     return 0;
 }
 
+int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info)
+{
+    xc_topologyinfo_t tinfo;
+    DECLARE_HYPERCALL_BUFFER(xc_cpu_to_core_t, coremap);
+    DECLARE_HYPERCALL_BUFFER(xc_cpu_to_socket_t, socketmap);
+    DECLARE_HYPERCALL_BUFFER(xc_cpu_to_node_t, nodemap);
+    int i;
+    int rc = 0;
+
+    rc += libxl_cpuarray_alloc(ctx, &info->coremap);
+    rc += libxl_cpuarray_alloc(ctx, &info->socketmap);
+    rc += libxl_cpuarray_alloc(ctx, &info->nodemap);
+    if (rc)
+        goto fail;
+
+    coremap = xc_hypercall_buffer_alloc(ctx->xch, coremap, sizeof(*coremap) * 
info->coremap.entries);
+    socketmap = xc_hypercall_buffer_alloc(ctx->xch, socketmap, 
sizeof(*socketmap) * info->socketmap.entries);
+    nodemap = xc_hypercall_buffer_alloc(ctx->xch, nodemap, sizeof(*nodemap) * 
info->nodemap.entries);
+    if ((coremap == NULL) || (socketmap == NULL) || (nodemap == NULL))
+        goto fail;
+
+    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);
+    tinfo.max_cpu_index = info->coremap.entries - 1;
+    if (xc_topologyinfo(ctx->xch, &tinfo) != 0)
+        goto fail;
+
+    for (i = 0; i <= tinfo.max_cpu_index; i++) {
+        if (i < info->coremap.entries)
+            info->coremap.array[i] = (coremap[i] == INVALID_TOPOLOGY_ID) ?
+                LIBXL_CPUARRAY_INVALID_ENTRY : coremap[i];
+        if (i < info->socketmap.entries)
+            info->socketmap.array[i] = (socketmap[i] == INVALID_TOPOLOGY_ID) ?
+                LIBXL_CPUARRAY_INVALID_ENTRY : socketmap[i];
+        if (i < info->nodemap.entries)
+            info->nodemap.array[i] = (nodemap[i] == INVALID_TOPOLOGY_ID) ?
+                LIBXL_CPUARRAY_INVALID_ENTRY : nodemap[i];
+    }
+
+    xc_hypercall_buffer_free(ctx->xch, coremap);
+    xc_hypercall_buffer_free(ctx->xch, socketmap);
+    xc_hypercall_buffer_free(ctx->xch, nodemap);
+    return 0;
+
+fail:
+    xc_hypercall_buffer_free(ctx->xch, coremap);
+    xc_hypercall_buffer_free(ctx->xch, socketmap);
+    xc_hypercall_buffer_free(ctx->xch, nodemap);
+    libxl_topologyinfo_destroy(info);
+    return ERROR_FAIL;
+}
+
 const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)
 {
     union {
diff -r 8079cba70803 -r f713cff1a587 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Fri Dec 03 09:36:47 2010 +0000
+++ b/tools/libxl/libxl.h       Thu Dec 09 11:21:30 2010 +0100
@@ -148,6 +148,13 @@ typedef struct {
     uint8_t *map;
 } libxl_cpumap;
 void libxl_cpumap_destroy(libxl_cpumap *map);
+
+typedef struct {
+    uint32_t entries;
+    uint32_t *array;
+} libxl_cpuarray;
+#define LIBXL_CPUARRAY_INVALID_ENTRY  ~0
+void libxl_cpuarray_destroy(libxl_cpuarray *array);
 
 typedef enum {
     XENFV = 1,
@@ -468,6 +475,7 @@ int libxl_button_press(libxl_ctx *ctx, u
 int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button);
 
 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
+int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info);
 libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
                                        int *nb_vcpu, int *nrcpus);
 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
diff -r 8079cba70803 -r f713cff1a587 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Fri Dec 03 09:36:47 2010 +0000
+++ b/tools/libxl/libxl.idl     Thu Dec 09 11:21:30 2010 +0100
@@ -7,6 +7,7 @@ libxl_uuid = Builtin("uuid")
 libxl_uuid = Builtin("uuid")
 libxl_mac = Builtin("mac")
 libxl_cpumap = Builtin("cpumap", destructor_fn="libxl_cpumap_destroy", 
passby=PASS_BY_REFERENCE)
+libxl_cpuarray = Builtin("cpuarray", destructor_fn="libxl_cpuarray_destroy", 
passby=PASS_BY_REFERENCE)
 libxl_qemu_machine_type = Number("qemu_machine_type", namespace="libxl_")
 libxl_console_consback = Number("console_consback", namespace="libxl_")
 libxl_console_constype = Number("console_constype", namespace="libxl_")
@@ -302,6 +303,12 @@ libxl_physinfo = Struct("physinfo", [
     ("phys_cap", uint32),
     ], destructor_fn=None)
 
+libxl_topologyinfo = Struct("topologyinfo", [
+    ("coremap", libxl_cpuarray,   False, "cpu to core map"),
+    ("socketmap", libxl_cpuarray, False, "cpu to socket map"),
+    ("nodemap", libxl_cpuarray,   False, "cpu to node map"),
+    ])
+
 libxl_sched_credit = Struct("sched_credit", [
     ("weight", integer),
     ("cap", integer),
diff -r 8079cba70803 -r f713cff1a587 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Fri Dec 03 09:36:47 2010 +0000
+++ b/tools/libxl/libxl_utils.c Thu Dec 09 11:21:30 2010 +0100
@@ -751,6 +751,30 @@ void libxl_cpumap_reset(libxl_cpumap *cp
     cpumap->map[cpu / 8] &= ~(1 << (cpu & 7));
 }
 
+int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray)
+{
+    int max_cpus;
+    int i;
+
+    max_cpus = libxl_get_max_cpus(ctx);
+    if (max_cpus == 0)
+        return ERROR_FAIL;
+
+    cpuarray->array = calloc(max_cpus, sizeof(*cpuarray->array));
+    if (!cpuarray->array)
+        return ERROR_NOMEM;
+    cpuarray->entries = max_cpus;
+    for (i = 0; i < max_cpus; i++)
+        cpuarray->array[i] = LIBXL_CPUARRAY_INVALID_ENTRY;
+
+    return 0;
+}
+
+void libxl_cpuarray_destroy(libxl_cpuarray *array)
+{
+    free(array->array);
+}
+
 int libxl_get_max_cpus(libxl_ctx *ctx)
 {
     return xc_get_max_cpus(ctx->xch);
diff -r 8079cba70803 -r f713cff1a587 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h Fri Dec 03 09:36:47 2010 +0000
+++ b/tools/libxl/libxl_utils.h Thu Dec 09 11:21:30 2010 +0100
@@ -82,5 +82,7 @@ void libxl_cpumap_reset(libxl_cpumap *cp
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
 
+int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
+
 #endif
 
diff -r 8079cba70803 -r f713cff1a587 tools/python/xen/lowlevel/xl/xl.c
--- a/tools/python/xen/lowlevel/xl/xl.c Fri Dec 03 09:36:47 2010 +0000
+++ b/tools/python/xen/lowlevel/xl/xl.c Thu Dec 09 11:21:30 2010 +0100
@@ -224,6 +224,11 @@ int attrib__libxl_cpumap_set(PyObject *v
     return 0;
 }
 
+int attrib__libxl_cpuarray_set(PyObject *v, libxl_cpuarray *pptr)
+{
+    return -1;
+}
+
 int attrib__libxl_domain_build_state_ptr_set(PyObject *v, 
libxl_domain_build_state **pptr)
 {
     return -1;
@@ -284,6 +289,25 @@ PyObject *attrib__libxl_cpumap_get(libxl
         }
     }
     return cpulist;
+}
+
+PyObject *attrib__libxl_cpuarray_get(libxl_cpuarray *pptr)
+{
+    PyObject *list = NULL;
+    int i;
+
+    list = PyList_New(0);
+    for (i = 0; i < pptr->entries; i++) {
+        if (pptr->array[i] == LIBXL_CPUARRAY_INVALID_ENTRY) {
+            PyList_Append(list, Py_None);
+        } else {
+            PyObject* pyint = PyInt_FromLong(pptr->array[i]);
+
+            PyList_Append(list, pyint);
+            Py_DECREF(pyint);
+        }
+    }
+    return list;
 }
 
 PyObject *attrib__libxl_domain_build_state_ptr_get(libxl_domain_build_state 
**pptr)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Support getting topology info in libxl, Xen patchbot-unstable <=