[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxl: expose cpu topology as a single list of cpu->{node, core, socket} maps.
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1328027679 0 # Node ID 1d8f40029ddb87c511d0237ab7ae9d4d117ea6cf # Parent bff9e4b818b97d6282b8d427e43ffb194ac7f593 libxl: expose cpu topology as a single list of cpu->{node,core,socket} maps. Rather than the previous tripple list which is more complicated to work with and harder for language bindings. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> Acked-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> Committed-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> --- diff -r bff9e4b818b9 -r 1d8f40029ddb tools/libxl/gentest.py --- a/tools/libxl/gentest.py Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/libxl/gentest.py Tue Jan 31 16:34:39 2012 +0000 @@ -195,6 +195,7 @@ *p = l; } +#if 0 /* To be remove in a subsequent patch */ static void libxl_cpuarray_rand_init(libxl_cpuarray *p) { int i; @@ -209,6 +210,7 @@ p->array[i] = r; } } +#endif """) for ty in builtins + types: if ty.typename not in handcoded: diff -r bff9e4b818b9 -r 1d8f40029ddb tools/libxl/libxl.c --- a/tools/libxl/libxl.c Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/libxl/libxl.c Tue Jan 31 16:34:39 2012 +0000 @@ -2755,57 +2755,68 @@ return 0; } -int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info) +libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nr) { 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); + libxl_cputopology *ret = NULL; 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) + int max_cpus; + + max_cpus = libxl_get_max_cpus(ctx); + if (max_cpus == 0) + { + LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS"); + return NULL; + } + + coremap = xc_hypercall_buffer_alloc + (ctx->xch, coremap, sizeof(*coremap) * max_cpus); + socketmap = xc_hypercall_buffer_alloc + (ctx->xch, socketmap, sizeof(*socketmap) * max_cpus); + nodemap = xc_hypercall_buffer_alloc + (ctx->xch, nodemap, sizeof(*nodemap) * max_cpus); + if ((coremap == NULL) || (socketmap == NULL) || (nodemap == NULL)) { + LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM, + "Unable to allocate hypercall arguments"); 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) + tinfo.max_cpu_index = max_cpus - 1; + if (xc_topologyinfo(ctx->xch, &tinfo) != 0) { + LIBXL__LOG_ERRNO(ctx, XTL_ERROR, "Topology info hypercall failed"); 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; + ret = malloc(sizeof(libxl_cputopology) * max_cpus); + if (ret == NULL) { + LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM, + "Unable to allocate return value"); + goto fail; + } + + for (i = 0; i <= max_cpus; i++) { +#define V(map, i) (map[i] == INVALID_TOPOLOGY_ID) ? \ + LIBXL_CPUTOPOLOGY_INVALID_ENTRY : map[i] + ret[i].core = V(coremap, i); + ret[i].socket = V(socketmap, i); + ret[i].node = V(nodemap, i); +#undef V + } fail: xc_hypercall_buffer_free(ctx->xch, coremap); xc_hypercall_buffer_free(ctx->xch, socketmap); xc_hypercall_buffer_free(ctx->xch, nodemap); - libxl_topologyinfo_dispose(info); - return ERROR_FAIL; + + if (ret) + *nr = max_cpus; + return ret; } const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) @@ -3604,30 +3615,30 @@ int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus) { int rc = 0; - int cpu; + int cpu, nr; libxl_cpumap freemap; - libxl_topologyinfo topology; + libxl_cputopology *topology; if (libxl_get_freecpus(ctx, &freemap)) { return ERROR_FAIL; } - if (libxl_get_topologyinfo(ctx, &topology)) { + topology = libxl_get_cpu_topology(ctx, &nr); + if (!topology) { rc = ERROR_FAIL; goto out; } *cpus = 0; - for (cpu = 0; cpu < topology.nodemap.entries; cpu++) { - if (libxl_cpumap_test(&freemap, cpu) && - (topology.nodemap.array[cpu] == node) && + for (cpu = 0; cpu < nr; cpu++) { + if (libxl_cpumap_test(&freemap, cpu) && (topology[cpu].node == node) && !libxl_cpupool_cpuadd(ctx, poolid, cpu)) { (*cpus)++; } + libxl_cputopology_dispose(&topology[cpu]); } - libxl_topologyinfo_dispose(&topology); - + free(topology); out: libxl_cpumap_dispose(&freemap); return rc; @@ -3651,8 +3662,8 @@ int ret = 0; int n_pools; int p; - int cpu; - libxl_topologyinfo topology; + int cpu, nr_cpus; + libxl_cputopology *topology; libxl_cpupoolinfo *poolinfo; poolinfo = libxl_list_cpupool(ctx, &n_pools); @@ -3660,7 +3671,8 @@ return ERROR_NOMEM; } - if (libxl_get_topologyinfo(ctx, &topology)) { + topology = libxl_get_cpu_topology(ctx, &nr_cpus); + if (!topology) { ret = ERROR_FAIL; goto out; } @@ -3668,8 +3680,8 @@ *cpus = 0; for (p = 0; p < n_pools; p++) { if (poolinfo[p].poolid == poolid) { - for (cpu = 0; cpu < topology.nodemap.entries; cpu++) { - if ((topology.nodemap.array[cpu] == node) && + for (cpu = 0; cpu < nr_cpus; cpu++) { + if ((topology[cpu].node == node) && libxl_cpumap_test(&poolinfo[p].cpumap, cpu) && !libxl_cpupool_cpuremove(ctx, poolid, cpu)) { (*cpus)++; @@ -3678,7 +3690,9 @@ } } - libxl_topologyinfo_dispose(&topology); + for (cpu = 0; cpu < nr_cpus; cpu++) + libxl_cputopology_dispose(&topology[cpu]); + free(topology); out: for (p = 0; p < n_pools; p++) { diff -r bff9e4b818b9 -r 1d8f40029ddb tools/libxl/libxl.h --- a/tools/libxl/libxl.h Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/libxl/libxl.h Tue Jan 31 16:34:39 2012 +0000 @@ -576,7 +576,9 @@ */ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo); -int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info); +#define LIBXL_CPUTOPOLOGY_INVALID_ENTRY (~(uint32_t)0) +libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nr); +void libxl_cputopology_list_free(libxl_cputopology *, int nr); 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 bff9e4b818b9 -r 1d8f40029ddb tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/libxl/libxl_types.idl Tue Jan 31 16:34:39 2012 +0000 @@ -376,10 +376,10 @@ ("phys_cap", uint32), ], dispose_fn=None, dir=DIR_OUT) -libxl_topologyinfo = Struct("topologyinfo", [ - ("coremap", libxl_cpuarray), # cpu to core map - ("socketmap", libxl_cpuarray), # cpu to socket map - ("nodemap", libxl_cpuarray), # cpu to node map +libxl_cputopology = Struct("cputopology", [ + ("core", uint32), + ("socket", uint32), + ("node", uint32), ]) libxl_sched_credit = Struct("sched_credit", [ diff -r bff9e4b818b9 -r 1d8f40029ddb tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/libxl/libxl_utils.c Tue Jan 31 16:34:39 2012 +0000 @@ -557,6 +557,14 @@ return ERROR_FAIL; } +void libxl_cputopology_list_free(libxl_cputopology *list, int nr) +{ + int i; + for (i = 0; i < nr; i++) + libxl_cputopology_dispose(&list[i]); + free(list); +} + /* * Local variables: * mode: C diff -r bff9e4b818b9 -r 1d8f40029ddb tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Tue Jan 31 16:34:39 2012 +0000 @@ -3833,10 +3833,11 @@ static void output_topologyinfo(void) { - libxl_topologyinfo info; - int i; - - if (libxl_get_topologyinfo(ctx, &info)) { + libxl_cputopology *info; + int i, nr; + + info = libxl_get_cpu_topology(ctx, &nr); + if (info == NULL) { fprintf(stderr, "libxl_get_topologyinfo failed.\n"); return; } @@ -3844,16 +3845,16 @@ printf("cpu_topology :\n"); printf("cpu: core socket node\n"); - for (i = 0; i < info.coremap.entries; i++) { - if (info.coremap.array[i] != LIBXL_CPUARRAY_INVALID_ENTRY) - printf("%3d: %4d %4d %4d\n", i, info.coremap.array[i], - info.socketmap.array[i], info.nodemap.array[i]); - } + for (i = 0; i < nr; i++) { + if (info[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY) + printf("%3d: %4d %4d %4d\n", i, + info[i].core, info[i].socket, info[i].node); + } + + libxl_cputopology_list_free(info, nr); printf("numa_info : none\n"); - libxl_topologyinfo_dispose(&info); - return; } @@ -5350,7 +5351,7 @@ libxl_cpumap freemap; libxl_cpumap cpumap; libxl_uuid uuid; - libxl_topologyinfo topology; + libxl_cputopology *topology; while (1) { opt = getopt_long(argc, argv, "hnf:", long_options, &option_index); @@ -5459,16 +5460,18 @@ return -ERROR_FAIL; } if (!xlu_cfg_get_list(config, "nodes", &nodes, 0, 0)) { + int nr; n_cpus = 0; n_nodes = 0; - if (libxl_get_topologyinfo(ctx, &topology)) { + topology = libxl_get_cpu_topology(ctx, &nr); + if (topology == NULL) { fprintf(stderr, "libxl_get_topologyinfo failed\n"); return -ERROR_FAIL; } while ((buf = xlu_cfg_get_listitem(nodes, n_nodes)) != NULL) { n = atoi(buf); - for (i = 0; i < topology.nodemap.entries; i++) { - if ((topology.nodemap.array[i] == n) && + for (i = 0; i < nr; i++) { + if ((topology[i].node == n) && libxl_cpumap_test(&freemap, i)) { libxl_cpumap_set(&cpumap, i); n_cpus++; @@ -5477,7 +5480,7 @@ n_nodes++; } - libxl_topologyinfo_dispose(&topology); + libxl_cputopology_list_free(topology, nr); if (n_cpus == 0) { fprintf(stderr, "no free cpu found\n"); @@ -5799,11 +5802,12 @@ int schedid; int n_pools; int node; + int n_cpus; char name[16]; libxl_uuid uuid; libxl_cpumap cpumap; libxl_cpupoolinfo *poolinfo; - libxl_topologyinfo topology; + libxl_cputopology *topology; libxl_dominfo info; if ((opt = def_getopt(argc, argv, "", "cpupool-numa-split", 0)) != -1) @@ -5825,21 +5829,22 @@ return -ERROR_FAIL; } - if (libxl_get_topologyinfo(ctx, &topology)) { + topology = libxl_get_cpu_topology(ctx, &n_cpus); + if (topology == NULL) { fprintf(stderr, "libxl_get_topologyinfo failed\n"); return -ERROR_FAIL; } if (libxl_cpumap_alloc(ctx, &cpumap)) { fprintf(stderr, "Failed to allocate cpumap\n"); - libxl_topologyinfo_dispose(&topology); + libxl_cputopology_list_free(topology, n_cpus); return -ERROR_FAIL; } /* Reset Pool-0 to 1st node: first add cpus, then remove cpus to avoid a cpupool without cpus in between */ - node = topology.nodemap.array[0]; + node = topology[0].node; if (libxl_cpupool_cpuadd_node(ctx, 0, node, &n)) { fprintf(stderr, "error on adding cpu to Pool 0\n"); return -ERROR_FAIL; @@ -5853,9 +5858,9 @@ } n = 0; - for (c = 0; c < topology.nodemap.entries; c++) { - if (topology.nodemap.array[c] == node) { - topology.nodemap.array[c] = LIBXL_CPUARRAY_INVALID_ENTRY; + for (c = 0; c < n_cpus; c++) { + if (topology[c].node == node) { + topology[c].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY; libxl_cpumap_set(&cpumap, n); n++; } @@ -5880,12 +5885,12 @@ } memset(cpumap.map, 0, cpumap.size); - for (c = 0; c < topology.nodemap.entries; c++) { - if (topology.nodemap.array[c] == LIBXL_CPUARRAY_INVALID_ENTRY) { + for (c = 0; c < n_cpus; c++) { + if (topology[c].node == LIBXL_CPUTOPOLOGY_INVALID_ENTRY) { continue; } - node = topology.nodemap.array[c]; + node = topology[c].node; ret = -libxl_cpupool_cpuremove_node(ctx, 0, node, &n); if (ret) { fprintf(stderr, "error on removing cpu from Pool 0\n"); @@ -5907,15 +5912,15 @@ goto out; } - for (p = c; p < topology.nodemap.entries; p++) { - if (topology.nodemap.array[p] == node) { - topology.nodemap.array[p] = LIBXL_CPUARRAY_INVALID_ENTRY; + for (p = c; p < n_cpus; p++) { + if (topology[p].node == node) { + topology[p].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY; } } } out: - libxl_topologyinfo_dispose(&topology); + libxl_cputopology_list_free(topology, n_cpus); libxl_cpumap_dispose(&cpumap); return ret; diff -r bff9e4b818b9 -r 1d8f40029ddb tools/ocaml/libs/xl/genwrap.py --- a/tools/ocaml/libs/xl/genwrap.py Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/ocaml/libs/xl/genwrap.py Tue Jan 31 16:34:39 2012 +0000 @@ -29,6 +29,8 @@ "device_pci": DEVICE_FUNCTIONS, "physinfo": [ ("get", ["unit", "t"]), ], + "cputopology": [ ("get", ["unit", "t array"]), + ], "sched_credit": [ ("domain_get", ["domid", "t"]), ("domain_set", ["domid", "t", "unit"]), ], @@ -266,7 +268,6 @@ "domain_create_info", "domain_build_info", "vcpuinfo", - "topologyinfo", "event", ] diff -r bff9e4b818b9 -r 1d8f40029ddb tools/ocaml/libs/xl/xenlight.ml.in --- a/tools/ocaml/libs/xl/xenlight.ml.in Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/ocaml/libs/xl/xenlight.ml.in Tue Jan 31 16:34:39 2012 +0000 @@ -19,17 +19,6 @@ (* @@LIBXL_TYPES@@ *) -module Topologyinfo = struct - type t = - { - core : int; - socket : int; - node : int; - } - external get : unit -> t array = "stub_xl_topologyinfo" -end - - external send_trigger : domid -> trigger -> int -> unit = "stub_xl_send_trigger" external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq" external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys" diff -r bff9e4b818b9 -r 1d8f40029ddb tools/ocaml/libs/xl/xenlight.mli.in --- a/tools/ocaml/libs/xl/xenlight.mli.in Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/ocaml/libs/xl/xenlight.mli.in Tue Jan 31 16:34:39 2012 +0000 @@ -19,16 +19,6 @@ (* @@LIBXL_TYPES@@ *) -module Topologyinfo : sig - type t = - { - core : int; - socket : int; - node : int; - } - external get : unit -> t array = "stub_xl_topologyinfo" -end - external send_trigger : domid -> trigger -> int -> unit = "stub_xl_send_trigger" external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq" external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys" diff -r bff9e4b818b9 -r 1d8f40029ddb tools/ocaml/libs/xl/xenlight_stubs.c --- a/tools/ocaml/libs/xl/xenlight_stubs.c Tue Jan 31 16:34:39 2012 +0000 +++ b/tools/ocaml/libs/xl/xenlight_stubs.c Tue Jan 31 16:34:39 2012 +0000 @@ -210,28 +210,6 @@ #include "_libxl_types.inc" -static value Val_topologyinfo(libxl_topologyinfo *c_val) -{ - CAMLparam0(); - CAMLlocal3(v, topology, topologyinfo); - int i; - - topologyinfo = caml_alloc_tuple(c_val->coremap.entries); - for (i = 0; i < c_val->coremap.entries; i++) { - v = Val_none; - if (c_val->coremap.array[i] != LIBXL_CPUARRAY_INVALID_ENTRY) { - topology = caml_alloc_tuple(3); - Store_field(topology, 0, Val_int(c_val->coremap.array[i])); - Store_field(topology, 1, Val_int(c_val->socketmap.array[i])); - Store_field(topology, 2, Val_int(c_val->nodemap.array[i])); - v = Val_some(topology); - } - Store_field(topologyinfo, i, v); - } - - CAMLreturn(topologyinfo); -} - value stub_xl_device_disk_add(value info, value domid) { CAMLparam2(info, domid); @@ -462,22 +440,33 @@ CAMLreturn(physinfo); } -value stub_xl_topologyinfo(value unit) +value stub_xl_cputopology_get(value unit) { CAMLparam1(unit); - CAMLlocal1(topologyinfo); - libxl_topologyinfo c_topologyinfo; - int ret; + CAMLlocal2(topology, v); + libxl_cputopology *c_topology; + int i, nr, ret; INIT_STRUCT(); INIT_CTX(); - ret = libxl_get_topologyinfo(ctx, &c_topologyinfo); + + c_topology = libxl_get_cpu_topology(ctx, &nr); if (ret != 0) failwith_xl("topologyinfo", &lg); + + topology = caml_alloc_tuple(nr); + for (i = 0; i < nr; i++) { + if (c_topology[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY) + v = Val_some(Val_cputopology(&gc, &lg, &c_topology[i])); + else + v = Val_none; + Store_field(topology, i, v); + } + + libxl_cputopology_list_free(c_topology, nr); + FREE_CTX(); - - topologyinfo = Val_topologyinfo(&c_topologyinfo); - CAMLreturn(topologyinfo); + CAMLreturn(topology); } value stub_xl_sched_credit_domain_get(value domid) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |