From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Chanudet Subject: [PATCH] xl: vcpu-list command Date: Mon, 29 Mar 2010 13:15:55 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This patch add vcpu-list command to xl. Acked-by: Vincent Hanquez diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2221,3 +2221,64 @@ int libxl_button_press(struct libxl_ctx return rc; } + +int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo) +{ + xc_physinfo_t xcphysinfo = { 0 }; + int rc; + + rc = xc_physinfo(ctx->xch, &xcphysinfo); + if (rc != 0) { + return rc; + } + physinfo->threads_per_core = xcphysinfo.threads_per_core; + physinfo->cores_per_socket = xcphysinfo.cores_per_socket; + physinfo->nr_cpus = xcphysinfo.nr_cpus; + physinfo->cpu_khz = xcphysinfo.cpu_khz; + physinfo->total_pages = xcphysinfo.total_pages; + physinfo->free_pages = xcphysinfo.free_pages; + physinfo->scrub_pages = xcphysinfo.scrub_pages; + return 0; +} + +struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid, + int *nb_vcpu, int *cpusize) +{ + struct libxl_vcpuinfo *ptr, *ret; + xc_domaininfo_t domaininfo; + xc_vcpuinfo_t vcpuinfo; + xc_physinfo_t physinfo = { 0 }; + + if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) { + return NULL; + } + if (xc_physinfo(ctx->xch, &physinfo) == -1) { + return NULL; + } + *cpusize = physinfo.max_cpu_id + 1; + ptr = libxl_calloc(ctx, domaininfo.max_vcpu_id + 1, sizeof (struct libxl_vcpuinfo)); + if (!ptr) { + return NULL; + } + + ret = ptr; + for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) { + ptr->cpumap = libxl_calloc(ctx, (*cpusize + 63) / 64, sizeof (uint64_t)); + if (!ptr->cpumap) { + return NULL; + } + if (xc_vcpu_getinfo(ctx->xch, domid, *nb_vcpu, &vcpuinfo) == -1) { + return NULL; + } + if (xc_vcpu_getaffinity(ctx->xch, domid, *nb_vcpu, ptr->cpumap, *cpusize) == -1) { + return NULL; + } + ptr->vcpuid = *nb_vcpu; + ptr->cpu = vcpuinfo.cpu; + ptr->online = !!vcpuinfo.online; + ptr->blocked = !!vcpuinfo.blocked; + ptr->running = !!vcpuinfo.running; + ptr->vcpu_time = vcpuinfo.cpu_time; + } + return ret; +} diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -360,5 +360,31 @@ typedef enum { int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button); +struct libxl_vcpuinfo { + uint32_t vcpuid; /* vcpu's id */ + uint32_t cpu; /* current mapping */ + uint8_t online:1; /* currently online (not hotplugged)? */ + uint8_t blocked:1; /* blocked waiting for an event? */ + uint8_t running:1; /* currently scheduled on its CPU? */ + uint64_t vcpu_time; /* total vcpu time ran (ns) */ + uint64_t *cpumap; /* current cpu's affinities */ +}; + +struct libxl_physinfo { + uint32_t threads_per_core; + uint32_t cores_per_socket; + + uint32_t nr_cpus; + uint32_t cpu_khz; + + uint64_t total_pages; + uint64_t free_pages; + uint64_t scrub_pages; +}; + +int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo); +struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid, + int *nb_vcpu, int *cpusize); + #endif /* LIBXL_H */ diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -876,6 +876,7 @@ static void help(char *command) printf(" cd-eject eject a cdrom from a guest's cd drive\n\n"); printf(" mem-set set the current memory usage for a domain\n\n"); printf(" button-press indicate an ACPI button press to the domain\n\n"); + printf(" vcpu-list list the VCPUs for all/some domains.\n\n"); } else if(!strcmp(command, "create")) { printf("Usage: xl create [options] [vars]\n\n"); printf("Create a domain based on .\n\n"); @@ -933,6 +934,9 @@ static void help(char *command) printf("Usage: xl button-press