Skip to contentSkip to conversation

xl: vcpu commands and tsc_mode parameter

PATCH New Eric Chanudet 1 participant 5 messages Apr 1, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl: vcpu commands and tsc_mode parameter

This patch series provides the following vcpu control commands to xl:
- vcpu-list: list the VCPUs for all/some domains.
- vcpu-pin: Set which CPUs a VCPU can use.
- vcpu-set: Set the number of active VCPUs allowed for the domain.

Also provides tsc_mode parameter handling from guest configuration file.

Signature · 1 line
Eric Chanudet
#1 lore raw

PATCH 1/1 xl: vcpu-list command

This patch add vcpu-list command to xl.

tools/libxl/libxl.c +61 -0
@@ -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;
+}
tools/libxl/libxl.h +26 -0
@@ -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 */
 
tools/libxl/xl.c +144 -1

172 lines not on this page · raw message

#2 lore raw

PATCH 1/1 xl: vcpu-pin command

In reply to Eric Chanudet

This patch add vcpu-pin command to xl.

tools/libxl/libxl.c +7 -0
@@ -2233,6 +2233,7 @@ int libxl_get_physinfo(struct libxl_ctx 
     }
     physinfo->threads_per_core = xcphysinfo.threads_per_core;
     physinfo->cores_per_socket = xcphysinfo.cores_per_socket;
+    physinfo->max_cpu_id = xcphysinfo.max_cpu_id;
     physinfo->nr_cpus = xcphysinfo.nr_cpus;
     physinfo->cpu_khz = xcphysinfo.cpu_khz;
     physinfo->total_pages = xcphysinfo.total_pages;
@@ -2282,3 +2283,9 @@ struct libxl_vcpuinfo *libxl_list_vcpu(s
     }
     return ret;
 }
+
+int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
+                           uint64_t *cpumap, int cpusize)
+{
+    return (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize));
+}
tools/libxl/libxl.h +3 -1
@@ -374,6 +374,7 @@ struct libxl_physinfo {
     uint32_t threads_per_core;
     uint32_t cores_per_socket;
 
+    uint32_t max_cpu_id;
     uint32_t nr_cpus;
     uint32_t cpu_khz;
 
@@ -385,6 +386,7 @@ struct libxl_physinfo {
 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);
-
+int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
+                           uint64_t *cpumap, int cpusize);
 #endif /* LIBXL_H */
 
tools/libxl/xl.c +119 -0

143 lines not on this page · raw message

#3 lore raw

PATCH 1/1 xl: vcpu-set command

In reply to Eric Chanudet

This patch add vcpu-set command to xl.

tools/libxl/libxl.c +23 -0
@@ -2289,3 +2289,26 @@ int libxl_set_vcpuaffinity(struct libxl_
 {
     return (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize));
 }
+
+int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count)
+{
+    xc_domaininfo_t domaininfo;
+    char *dompath;
+    int i;
+
+    if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
+        return ERROR_FAIL;
+    }
+    if (!count || ((domaininfo.max_vcpu_id + 1) < count)) {
+        return ERROR_INVAL;
+    }
+    if (!(dompath = libxl_xs_get_dompath(ctx, domid)))
+        return ERROR_FAIL;
+
+    for (i = 0; i <= domaininfo.max_vcpu_id; ++i) {
+        libxl_xs_write(ctx, XBT_NULL,
+                       libxl_sprintf(ctx, "%s/cpu/%u/availability", dompath, i),
+                       "%s", ((1 << i) & ((1 << count) - 1)) ? "online" : "offline");
+    }
+    return 0;
+}
tools/libxl/libxl.h +1 -0
@@ -388,5 +388,6 @@ struct libxl_vcpuinfo *libxl_list_vcpu(s
                                        int *nb_vcpu, int *cpusize);
 int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
                            uint64_t *cpumap, int cpusize);
+int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count);
 #endif /* LIBXL_H */
 
tools/libxl/xl.c +60 -0

84 lines not on this page · raw message

#4 lore raw

PATCH 1/1 xl: tsc_mode parameter in guest configuration file

In reply to Eric Chanudet

This patch handle tsc_mode argument in guest configuration file.

tools/libxl/libxl.h +1 -0
@@ -74,6 +74,7 @@ typedef struct {
     int vpt_align;
     int max_vcpus;
     int cur_vcpus;
+    int tsc_mode;
     uint32_t max_memkb;
     uint32_t target_memkb;
     uint32_t video_memkb;
tools/libxl/libxl_dom.c +1 -0
@@ -72,6 +72,7 @@ int build_pre(struct libxl_ctx *ctx, uin
     xc_domain_set_memmap_limit(ctx->xch, domid, 
             (info->hvm) ? info->max_memkb : 
             (info->max_memkb + info->u.pv.slack_memkb));
+    xc_domain_set_tsc_info(ctx->xch, domid, info->tsc_mode, 0, 0, 0);
 
     if (info->hvm) {
         unsigned long shadow;
tools/libxl/xl.c +4 -0
@@ -235,6 +235,7 @@ static void printf_info(libxl_domain_cre
     printf("hpet: %d\n", b_info->hpet);
     printf("vpt_align: %d\n", b_info->vpt_align);
     printf("max_vcpus: %d\n", b_info->max_vcpus);
+    printf("tsc_mode: %d\n", b_info->tsc_mode);
     printf("max_memkb: %d\n", b_info->max_memkb);
     printf("target_memkb: %d\n", b_info->target_memkb);
     printf("kernel: %s\n", b_info->kernel);
@@ -382,6 +383,9 @@ static void parse_config_file(const char
         b_info->target_memkb = b_info->max_memkb;
     }
 
+    if (!xlu_cfg_get_long(config, "tsc_mode", &l))
+        b_info->tsc_mode = l;
+
     if (!xlu_cfg_get_long (config, "shadow_memory", &l))
         b_info->shadow_memkb = l * 1024;