From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 23 of 26] libxl/xl: Use libxl_vcpuinfo_destroy
Date: Mon, 16 Aug 2010 15:33:47 +0100 [thread overview]
Message-ID: <8c709ca39c91e53add43.1281969227@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1281969204@localhost.localdomain>
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1281969065 -3600
# Node ID 8c709ca39c91e53add430ada580e027af6100eef
# Parent 3b72249bb27c9bd73cf40a09d42ae8f8d663a8f5
libxl/xl: Use libxl_vcpuinfo_destroy
Replaces libxl_free_vcpu_list.
The ->cpumap field is now always a unique allocation rather than each
being an offset into the cpumap allocated in the first
libxl_device_pci in the list.
Refactor vcpulist so that the two cases can share more code.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
diff -r 3b72249bb27c -r 8c709ca39c91 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl.c Mon Aug 16 15:31:05 2010 +0100
@@ -2918,7 +2918,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
xc_domaininfo_t domaininfo;
xc_vcpuinfo_t vcpuinfo;
xc_physinfo_t physinfo = { 0 };
- uint64_t *cpumaps;
unsigned num_cpuwords;
if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
@@ -2936,9 +2935,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
}
num_cpuwords = ((physinfo.max_cpu_id + 64) / 64);
- cpumaps = calloc(num_cpuwords * sizeof(*cpumaps), domaininfo.max_vcpu_id + 1);
for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
- ptr->cpumap = cpumaps + (num_cpuwords * *nb_vcpu);
+ ptr->cpumap = malloc(num_cpuwords * sizeof(*ptr->cpumap));
if (!ptr->cpumap) {
return NULL;
}
@@ -2959,13 +2957,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
ptr->vcpu_time = vcpuinfo.cpu_time;
}
return ret;
-}
-
-void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu)
-{
- if ( vcpu )
- free(vcpu[0].cpumap);
- free(vcpu);
}
int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
diff -r 3b72249bb27c -r 8c709ca39c91 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl.h Mon Aug 16 15:31:05 2010 +0100
@@ -432,7 +432,6 @@ int libxl_get_physinfo(libxl_ctx *ctx, l
int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
int *nb_vcpu, int *nrcpus);
-void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu);
int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
uint64_t *cpumap, int nrcpus);
int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count);
diff -r 3b72249bb27c -r 8c709ca39c91 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Aug 16 15:31:05 2010 +0100
@@ -3299,49 +3299,58 @@ static void print_vcpuinfo(uint32_t tdom
}
}
+static void print_domain_vcpuinfo(uint32_t domid, uint32_t nr_cpus)
+{
+ libxl_vcpuinfo *vcpuinfo;
+ int i, nb_vcpu, nrcpus;
+
+ vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus);
+
+ if (!vcpuinfo) {
+ fprintf(stderr, "libxl_list_vcpu failed.\n");
+ return;
+ }
+
+ for (i = 0; i < nb_vcpu; i++) {
+ print_vcpuinfo(domid, &vcpuinfo[i], nr_cpus);
+ libxl_vcpuinfo_destroy(&vcpuinfo[i]);
+ }
+
+ free(vcpuinfo);
+}
+
void vcpulist(int argc, char **argv)
{
- libxl_dominfo *dominfo, *domlist;
- libxl_vcpuinfo *vcpuinfo, *list = NULL;
+ libxl_dominfo *dominfo;
libxl_physinfo physinfo;
- int nb_vcpu, nb_domain, nrcpus;
+ int i, nb_domain;
if (libxl_get_physinfo(&ctx, &physinfo) != 0) {
fprintf(stderr, "libxl_physinfo failed.\n");
goto vcpulist_out;
}
+
printf("%-32s %5s %5s %5s %5s %9s %s\n",
"Name", "ID", "VCPU", "CPU", "State", "Time(s)", "CPU Affinity");
if (!argc) {
- if (!(domlist = dominfo = libxl_list_domain(&ctx, &nb_domain))) {
+ if (!(dominfo = libxl_list_domain(&ctx, &nb_domain))) {
fprintf(stderr, "libxl_list_domain failed.\n");
goto vcpulist_out;
}
- for (; nb_domain > 0; --nb_domain, ++dominfo) {
- if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu,
- &nrcpus))) {
- fprintf(stderr, "libxl_list_vcpu failed.\n");
- goto vcpulist_out;
- }
- for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
- print_vcpuinfo(dominfo->domid, vcpuinfo, physinfo.nr_cpus);
- }
- libxl_free_vcpu_list(list);
- }
- free(domlist);
+
+ for (i = 0; i<nb_domain; i++)
+ print_domain_vcpuinfo(dominfo[i].domid, physinfo.nr_cpus);
+
+ free(dominfo);
+
} else {
for (; argc > 0; ++argv, --argc) {
if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
- }
- if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus))) {
- fprintf(stderr, "libxl_list_vcpu failed.\n");
goto vcpulist_out;
}
- for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
- print_vcpuinfo(domid, vcpuinfo, physinfo.nr_cpus);
- }
- libxl_free_vcpu_list(list);
+
+ print_domain_vcpuinfo(domid, physinfo.nr_cpus);
}
}
vcpulist_out:
next prev parent reply other threads:[~2010-08-16 14:33 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-16 14:33 [PATCH 00 of 26] libxl: autogenerate type definitions and destructor functions Ian Campbell
2010-08-16 14:33 ` [PATCH 01 of 26] xl: use the regular implicit rules to build the xl .o files Ian Campbell
2010-08-16 14:33 ` [PATCH 02 of 26] libxl: define specific types for string list and key, value list Ian Campbell
2010-08-16 14:33 ` [PATCH 03 of 26] libxl: move various enum and #defines above datastructure definitions Ian Campbell
2010-08-16 14:33 ` [PATCH 04 of 26] libxl: add specific type for cpumap Ian Campbell
2010-08-16 14:33 ` [PATCH 05 of 26] libxl: add specific type for hwcaps Ian Campbell
2010-08-16 14:33 ` [PATCH 06 of 26] libxl: make libxl_console_reader type opaque to users of libxl Ian Campbell
2010-08-16 14:33 ` [PATCH 07 of 26] lbixl: make libxl_device_model_starting " Ian Campbell
2010-08-16 14:33 ` [PATCH 08 of 26] libxl: ensure result of libxl_poolid_to_name is always dynamically allocated Ian Campbell
2010-08-16 14:33 ` [PATCH 09 of 26] libxl: move type definitions into _libxl_types.h Ian Campbell
2010-08-16 14:33 ` [PATCH 10 of 26] libxl: tweak formatting/whitespace of _libxl_types.h Ian Campbell
2010-08-16 14:33 ` [PATCH 11 of 26] libxl: autogenerate _libxl_types.h Ian Campbell
2010-08-17 11:53 ` Stefano Stabellini
2010-08-17 12:20 ` Ian Campbell
2010-08-16 14:33 ` [PATCH 12 of 26] libxl: generate destructors for each libxl defined type Ian Campbell
2010-08-16 14:33 ` [PATCH 13 of 26] libxl: libxl_device_console.build_state is const Ian Campbell
2010-08-16 14:33 ` [PATCH 14 of 26] libxl: build info bootloader{, _args} are not const Ian Campbell
2010-08-16 14:33 ` [PATCH 15 of 26] libxl: do not generate a destructor for data types which do not require one Ian Campbell
2010-08-16 14:33 ` [PATCH 16 of 26] libxl: implement destroy for libxl_file_reference builtin type Ian Campbell
2010-08-16 14:33 ` [PATCH 17 of 26] xl: free the libxl types contained in struct domain_config Ian Campbell
2010-08-16 14:33 ` [PATCH 18 of 26] libxl: use libxl_version_info_destroy instead of hand-coded do_free_version_info Ian Campbell
2010-08-16 14:33 ` [PATCH 19 of 26] xl: destroy device model info after creation Ian Campbell
2010-08-16 14:33 ` [PATCH 20 of 26] xl: free all data on exit from the domain monitor daemon Ian Campbell
2010-08-17 12:27 ` Stefano Stabellini
2010-08-17 12:33 ` Ian Campbell
2010-08-17 15:11 ` Ian Jackson
2010-08-17 15:12 ` Ian Campbell
2010-08-16 14:33 ` [PATCH 21 of 26] libxl/xl: use libxl_diskinfo_destroy and libxl_device_disk_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 22 of 26] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy Ian Campbell
2010-08-16 14:33 ` Ian Campbell [this message]
2010-08-16 14:33 ` [PATCH 24 of 26] xl: use libxl_device_pci_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 25 of 26] libxl: do not GC data returned to the caller by libxl_device_disk_getinfo Ian Campbell
2010-08-16 14:33 ` [PATCH 26 of 26] libxl: xs_read accepts NULL for *len parameter Ian Campbell
2010-08-17 12:14 ` [PATCH 00 of 26] libxl: autogenerate type definitions and destructor functions Gianni Tedesco
2010-08-17 12:25 ` Ian Campbell
2010-08-17 12:24 ` Gianni Tedesco
2010-08-17 12:34 ` Stefano Stabellini
2010-08-17 12:37 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8c709ca39c91e53add43.1281969227@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).