debuggers.hg

changeset 22648:f713cff1a587

Support getting topology info in libxl

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

Signed-off-by: juergen.gross@ts.fujitsu.com
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
author Juergen Gross <juergen.gross@ts.fujitsu.com>
date Thu Dec 09 11:21:30 2010 +0100 (2010-12-09)
parents 8079cba70803
children 8ecbcb19911f
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/libxl.idl tools/libxl/libxl_utils.c tools/libxl/libxl_utils.h tools/python/xen/lowlevel/xl/xl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Fri Dec 03 09:36:47 2010 +0000
     1.2 +++ b/tools/libxl/libxl.c	Thu Dec 09 11:21:30 2010 +0100
     1.3 @@ -3223,6 +3223,59 @@ int libxl_get_physinfo(libxl_ctx *ctx, l
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info)
     1.8 +{
     1.9 +    xc_topologyinfo_t tinfo;
    1.10 +    DECLARE_HYPERCALL_BUFFER(xc_cpu_to_core_t, coremap);
    1.11 +    DECLARE_HYPERCALL_BUFFER(xc_cpu_to_socket_t, socketmap);
    1.12 +    DECLARE_HYPERCALL_BUFFER(xc_cpu_to_node_t, nodemap);
    1.13 +    int i;
    1.14 +    int rc = 0;
    1.15 +
    1.16 +    rc += libxl_cpuarray_alloc(ctx, &info->coremap);
    1.17 +    rc += libxl_cpuarray_alloc(ctx, &info->socketmap);
    1.18 +    rc += libxl_cpuarray_alloc(ctx, &info->nodemap);
    1.19 +    if (rc)
    1.20 +        goto fail;
    1.21 +
    1.22 +    coremap = xc_hypercall_buffer_alloc(ctx->xch, coremap, sizeof(*coremap) * info->coremap.entries);
    1.23 +    socketmap = xc_hypercall_buffer_alloc(ctx->xch, socketmap, sizeof(*socketmap) * info->socketmap.entries);
    1.24 +    nodemap = xc_hypercall_buffer_alloc(ctx->xch, nodemap, sizeof(*nodemap) * info->nodemap.entries);
    1.25 +    if ((coremap == NULL) || (socketmap == NULL) || (nodemap == NULL))
    1.26 +        goto fail;
    1.27 +
    1.28 +    set_xen_guest_handle(tinfo.cpu_to_core, coremap);
    1.29 +    set_xen_guest_handle(tinfo.cpu_to_socket, socketmap);
    1.30 +    set_xen_guest_handle(tinfo.cpu_to_node, nodemap);
    1.31 +    tinfo.max_cpu_index = info->coremap.entries - 1;
    1.32 +    if (xc_topologyinfo(ctx->xch, &tinfo) != 0)
    1.33 +        goto fail;
    1.34 +
    1.35 +    for (i = 0; i <= tinfo.max_cpu_index; i++) {
    1.36 +        if (i < info->coremap.entries)
    1.37 +            info->coremap.array[i] = (coremap[i] == INVALID_TOPOLOGY_ID) ?
    1.38 +                LIBXL_CPUARRAY_INVALID_ENTRY : coremap[i];
    1.39 +        if (i < info->socketmap.entries)
    1.40 +            info->socketmap.array[i] = (socketmap[i] == INVALID_TOPOLOGY_ID) ?
    1.41 +                LIBXL_CPUARRAY_INVALID_ENTRY : socketmap[i];
    1.42 +        if (i < info->nodemap.entries)
    1.43 +            info->nodemap.array[i] = (nodemap[i] == INVALID_TOPOLOGY_ID) ?
    1.44 +                LIBXL_CPUARRAY_INVALID_ENTRY : nodemap[i];
    1.45 +    }
    1.46 +
    1.47 +    xc_hypercall_buffer_free(ctx->xch, coremap);
    1.48 +    xc_hypercall_buffer_free(ctx->xch, socketmap);
    1.49 +    xc_hypercall_buffer_free(ctx->xch, nodemap);
    1.50 +    return 0;
    1.51 +
    1.52 +fail:
    1.53 +    xc_hypercall_buffer_free(ctx->xch, coremap);
    1.54 +    xc_hypercall_buffer_free(ctx->xch, socketmap);
    1.55 +    xc_hypercall_buffer_free(ctx->xch, nodemap);
    1.56 +    libxl_topologyinfo_destroy(info);
    1.57 +    return ERROR_FAIL;
    1.58 +}
    1.59 +
    1.60  const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)
    1.61  {
    1.62      union {
     2.1 --- a/tools/libxl/libxl.h	Fri Dec 03 09:36:47 2010 +0000
     2.2 +++ b/tools/libxl/libxl.h	Thu Dec 09 11:21:30 2010 +0100
     2.3 @@ -149,6 +149,13 @@ typedef struct {
     2.4  } libxl_cpumap;
     2.5  void libxl_cpumap_destroy(libxl_cpumap *map);
     2.6  
     2.7 +typedef struct {
     2.8 +    uint32_t entries;
     2.9 +    uint32_t *array;
    2.10 +} libxl_cpuarray;
    2.11 +#define LIBXL_CPUARRAY_INVALID_ENTRY  ~0
    2.12 +void libxl_cpuarray_destroy(libxl_cpuarray *array);
    2.13 +
    2.14  typedef enum {
    2.15      XENFV = 1,
    2.16      XENPV,
    2.17 @@ -468,6 +475,7 @@ typedef enum {
    2.18  int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button);
    2.19  
    2.20  int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
    2.21 +int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info);
    2.22  libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
    2.23                                         int *nb_vcpu, int *nrcpus);
    2.24  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
     3.1 --- a/tools/libxl/libxl.idl	Fri Dec 03 09:36:47 2010 +0000
     3.2 +++ b/tools/libxl/libxl.idl	Thu Dec 09 11:21:30 2010 +0100
     3.3 @@ -7,6 +7,7 @@ libxl_ctx = Builtin("ctx")
     3.4  libxl_uuid = Builtin("uuid")
     3.5  libxl_mac = Builtin("mac")
     3.6  libxl_cpumap = Builtin("cpumap", destructor_fn="libxl_cpumap_destroy", passby=PASS_BY_REFERENCE)
     3.7 +libxl_cpuarray = Builtin("cpuarray", destructor_fn="libxl_cpuarray_destroy", passby=PASS_BY_REFERENCE)
     3.8  libxl_qemu_machine_type = Number("qemu_machine_type", namespace="libxl_")
     3.9  libxl_console_consback = Number("console_consback", namespace="libxl_")
    3.10  libxl_console_constype = Number("console_constype", namespace="libxl_")
    3.11 @@ -302,6 +303,12 @@ libxl_physinfo = Struct("physinfo", [
    3.12      ("phys_cap", uint32),
    3.13      ], destructor_fn=None)
    3.14  
    3.15 +libxl_topologyinfo = Struct("topologyinfo", [
    3.16 +    ("coremap", libxl_cpuarray,   False, "cpu to core map"),
    3.17 +    ("socketmap", libxl_cpuarray, False, "cpu to socket map"),
    3.18 +    ("nodemap", libxl_cpuarray,   False, "cpu to node map"),
    3.19 +    ])
    3.20 +
    3.21  libxl_sched_credit = Struct("sched_credit", [
    3.22      ("weight", integer),
    3.23      ("cap", integer),
     4.1 --- a/tools/libxl/libxl_utils.c	Fri Dec 03 09:36:47 2010 +0000
     4.2 +++ b/tools/libxl/libxl_utils.c	Thu Dec 09 11:21:30 2010 +0100
     4.3 @@ -751,6 +751,30 @@ void libxl_cpumap_reset(libxl_cpumap *cp
     4.4      cpumap->map[cpu / 8] &= ~(1 << (cpu & 7));
     4.5  }
     4.6  
     4.7 +int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray)
     4.8 +{
     4.9 +    int max_cpus;
    4.10 +    int i;
    4.11 +
    4.12 +    max_cpus = libxl_get_max_cpus(ctx);
    4.13 +    if (max_cpus == 0)
    4.14 +        return ERROR_FAIL;
    4.15 +
    4.16 +    cpuarray->array = calloc(max_cpus, sizeof(*cpuarray->array));
    4.17 +    if (!cpuarray->array)
    4.18 +        return ERROR_NOMEM;
    4.19 +    cpuarray->entries = max_cpus;
    4.20 +    for (i = 0; i < max_cpus; i++)
    4.21 +        cpuarray->array[i] = LIBXL_CPUARRAY_INVALID_ENTRY;
    4.22 +
    4.23 +    return 0;
    4.24 +}
    4.25 +
    4.26 +void libxl_cpuarray_destroy(libxl_cpuarray *array)
    4.27 +{
    4.28 +    free(array->array);
    4.29 +}
    4.30 +
    4.31  int libxl_get_max_cpus(libxl_ctx *ctx)
    4.32  {
    4.33      return xc_get_max_cpus(ctx->xch);
     5.1 --- a/tools/libxl/libxl_utils.h	Fri Dec 03 09:36:47 2010 +0000
     5.2 +++ b/tools/libxl/libxl_utils.h	Thu Dec 09 11:21:30 2010 +0100
     5.3 @@ -82,5 +82,7 @@ void libxl_cpumap_set(libxl_cpumap *cpum
     5.4  void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
     5.5  #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
     5.6  
     5.7 +int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
     5.8 +
     5.9  #endif
    5.10  
     6.1 --- a/tools/python/xen/lowlevel/xl/xl.c	Fri Dec 03 09:36:47 2010 +0000
     6.2 +++ b/tools/python/xen/lowlevel/xl/xl.c	Thu Dec 09 11:21:30 2010 +0100
     6.3 @@ -224,6 +224,11 @@ int attrib__libxl_cpumap_set(PyObject *v
     6.4      return 0;
     6.5  }
     6.6  
     6.7 +int attrib__libxl_cpuarray_set(PyObject *v, libxl_cpuarray *pptr)
     6.8 +{
     6.9 +    return -1;
    6.10 +}
    6.11 +
    6.12  int attrib__libxl_domain_build_state_ptr_set(PyObject *v, libxl_domain_build_state **pptr)
    6.13  {
    6.14      return -1;
    6.15 @@ -286,6 +291,25 @@ PyObject *attrib__libxl_cpumap_get(libxl
    6.16      return cpulist;
    6.17  }
    6.18  
    6.19 +PyObject *attrib__libxl_cpuarray_get(libxl_cpuarray *pptr)
    6.20 +{
    6.21 +    PyObject *list = NULL;
    6.22 +    int i;
    6.23 +
    6.24 +    list = PyList_New(0);
    6.25 +    for (i = 0; i < pptr->entries; i++) {
    6.26 +        if (pptr->array[i] == LIBXL_CPUARRAY_INVALID_ENTRY) {
    6.27 +            PyList_Append(list, Py_None);
    6.28 +        } else {
    6.29 +            PyObject* pyint = PyInt_FromLong(pptr->array[i]);
    6.30 +
    6.31 +            PyList_Append(list, pyint);
    6.32 +            Py_DECREF(pyint);
    6.33 +        }
    6.34 +    }
    6.35 +    return list;
    6.36 +}
    6.37 +
    6.38  PyObject *attrib__libxl_domain_build_state_ptr_get(libxl_domain_build_state **pptr)
    6.39  {
    6.40      return NULL;