[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 for Xen 4.6 4/4] xl: enabling XL to set per-VCPU parameters of a domain for RTDS scheduler



Change main_sched_rtds and related output functions to support per-VCPU settings
for xl sched-rtds tool.

Signed-off-by: Chong Li <chong.li@xxxxxxxxx>
Signed-off-by: Meng Xu <mengxu@xxxxxxxxxxxxx>
Signed-off-by: Sisu Xi <xisisu@xxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c | 261 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 230 insertions(+), 31 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 648ca08..a57f772 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -5577,6 +5577,37 @@ static int sched_domain_set(int domid, const 
libxl_domain_sched_params *scinfo)
     return rc;
 }
 
+static int sched_vcpu_get(libxl_scheduler sched, int domid,
+                            libxl_vcpu_sched_params *scinfo)
+{
+    int rc;
+
+    rc = libxl_vcpu_sched_params_get(ctx, domid, scinfo);
+    if (rc) {
+        fprintf(stderr, "libxl_vcpu_sched_params_get failed.\n");
+        return rc;
+    }
+    if (scinfo->sched != sched) {
+        fprintf(stderr, "libxl_vcpu_sched_params_get returned %s not %s.\n",
+                libxl_scheduler_to_string(scinfo->sched),
+                libxl_scheduler_to_string(sched));
+        return ERROR_INVAL;
+    }
+
+    return 0;
+}
+
+static int sched_vcpu_set(int domid, const libxl_vcpu_sched_params *scinfo)
+{
+    int rc;
+
+    rc = libxl_vcpu_sched_params_set(ctx, domid, scinfo);
+    if (rc)
+        fprintf(stderr, "libxl_vcpu_sched_params_set failed.\n");
+
+    return rc;
+}
+
 static int sched_credit_params_set(int poolid, libxl_sched_credit_params 
*scinfo)
 {
     int rc;
@@ -5733,6 +5764,41 @@ out:
     return rc;
 }
 
+static int sched_rtds_vcpu_output(
+    int domid)
+{
+    char *domname;
+    libxl_vcpu_sched_params scinfo;
+    int rc = 0;
+    int i;
+
+   if (domid < 0) {
+        printf("%-33s %4s %4s %9s %9s\n", "Name", "ID",
+                        "VCPU", "Period", "Budget");
+        return 0;
+    }
+
+    libxl_vcpu_sched_params_init(&scinfo);
+    rc = sched_vcpu_get(LIBXL_SCHEDULER_RTDS, domid, &scinfo);
+    if (rc)
+        goto out;
+
+    domname = libxl_domid_to_name(ctx, domid);
+     for( i = 0; i < scinfo.num_vcpus; i++ ) {
+        printf("%-33s %4d %4d %9"PRIu32" %9"PRIu32"\n",
+            domname,
+            domid,
+            i,
+            scinfo.vcpus[i].period,
+            scinfo.vcpus[i].budget);
+    }
+    free(domname);
+
+out:
+    libxl_vcpu_sched_params_dispose(&scinfo);
+    return rc;
+}
+
 static int sched_rtds_pool_output(uint32_t poolid)
 {
     char *poolname;
@@ -6120,76 +6186,209 @@ int main_sched_rtds(int argc, char **argv)
 {
     const char *dom = NULL;
     const char *cpupool = NULL;
-    int period = 0; /* period is in microsecond */
-    int budget = 0; /* budget is in microsecond */
+
+    int *vcpus = (int *)xmalloc(sizeof(int)); /* IDs of VCPUs that change */
+    int *periods = (int *)xmalloc(sizeof(int)); /* period is in microsecond */
+    int *budgets = (int *)xmalloc(sizeof(int)); /* budget is in microsecond */
+    int vcpus_size = 1; /* size of vcpus array */
+    int periods_size = 1; /* size of periods array */
+    int budgets_size = 1; /* size of budgets array */
+    int input_size = 0; /* number of the input param set (v, p, b) */
+    bool flag_b = false;
+    bool flag_p = false;
+    bool flag_v = false;
     bool opt_p = false;
     bool opt_b = false;
-    int opt, rc;
+    bool opt_v = false;
+    bool opt_o = false; /* get per-domain info instead of per-vcpu info */
+    int opt, i;
+    int rc = 0;
     static struct option opts[] = {
         {"domain", 1, 0, 'd'},
         {"period", 1, 0, 'p'},
         {"budget", 1, 0, 'b'},
+        {"vcpu",1, 0, 'v'},
         {"cpupool", 1, 0, 'c'},
+        {"output", 1, 0, 'o'},
         COMMON_LONG_OPTS,
         {0, 0, 0, 0}
     };
 
-    SWITCH_FOREACH_OPT(opt, "d:p:b:c:h", opts, "sched-rtds", 0) {
+    SWITCH_FOREACH_OPT(opt, "d:p:b:v:c:h:o", opts, "sched-rtds", 0) {
     case 'd':
         dom = optarg;
         break;
     case 'p':
-        period = strtol(optarg, NULL, 10);
+        if (flag_p == 1) { /* budget or vcpuID is missed */
+            fprintf(stderr, "Must specify period, budget and vcpuID\n");
+            rc = 1;
+            goto out;
+        }
+       if (input_size  >= periods_size) {
+            periods_size *= 2;
+            periods = xrealloc(periods, periods_size);
+            if (!periods) {
+                fprintf(stderr, "Failed to realloc periods\n");
+                rc = 1;
+                goto out;
+            }
+        }
+        periods[input_size] = strtol(optarg, NULL, 10);
         opt_p = 1;
+        flag_p = 1;
+        if (flag_p && flag_b && flag_v) {
+            /* 
+             * Get one complete set of per-VCPU parameters 
+             * (period, budget, vcpuID). 
+             */
+            flag_p = 0;
+            flag_b = 0;
+            flag_v = 0;
+            input_size++;
+        }
         break;
     case 'b':
-        budget = strtol(optarg, NULL, 10);
-        opt_b = 1;
+        if (flag_b == 1) { /* period or vcpuID is missed */
+            fprintf(stderr, "Must specify period, budget and vcpuID\n");
+            rc = 1;
+            goto out;
+        }
+        if (input_size >= budgets_size) {
+            budgets_size *= 2;
+            budgets = xrealloc(budgets, budgets_size);
+            if (!budgets) {
+                fprintf(stderr, "Failed to realloc budgets\n");
+                rc = 1;
+                goto out;
+            }
+        }
+        budgets[input_size] = strtol(optarg, NULL, 10);
+        opt_b = 1; 
+        flag_b = 1;
+        if (flag_p && flag_b && flag_v) {
+            flag_p = 0;
+            flag_b = 0;
+            flag_v = 0;
+            input_size++;
+        }
+        break;
+    case 'v':
+        if (flag_v == 1) { /* period or budget is missed */
+            fprintf(stderr, "Must specify period, budget and vcpuID\n");
+            rc = 1;
+            goto out;
+        }
+        if (input_size >= vcpus_size) {
+            vcpus_size *= 2;
+            vcpus = xrealloc(vcpus, vcpus_size);
+            if (!vcpus) {
+                fprintf(stderr, "Failed to realloc vcpus\n");
+                rc = 1;
+                goto out;
+            }
+        }
+        vcpus[input_size] = strtol(optarg, NULL, 10);
+        opt_v = 1;
+        flag_v = 1;
+        if (flag_p && flag_b && flag_v) {
+            flag_p = 0;
+            flag_b = 0;
+            flag_v = 0;
+            input_size++;
+        }
         break;
     case 'c':
         cpupool = optarg;
         break;
+    case 'o':
+        opt_o = 1;
+        break;
     }
 
-    if (cpupool && (dom || opt_p || opt_b)) {
+    if (cpupool && (dom || opt_p || opt_b || opt_v)) {
         fprintf(stderr, "Specifying a cpupool is not allowed with "
                 "other options.\n");
-        return 1;
+        rc = 1;
+        goto out;
     }
     if (!dom && (opt_p || opt_b)) {
         fprintf(stderr, "Must specify a domain.\n");
-        return 1;
+        rc = 1;
+        goto out;
     }
     if (opt_p != opt_b) {
         fprintf(stderr, "Must specify period and budget\n");
-        return 1;
+        rc = 1;
+        goto out;
+    }
+    if (opt_v && (flag_b|| flag_v || flag_p)) {
+        fprintf(stderr, "Must specify period and budget and vcpuID\n");
+        rc = 1;
+        goto out;
     }
 
-    if (!dom) { /* list all domain's rt scheduler info */
-        return -sched_domain_output(LIBXL_SCHEDULER_RTDS,
-                                    sched_rtds_domain_output,
-                                    sched_rtds_pool_output,
-                                    cpupool);
+    if (!dom) { /* list all domain's rtds scheduler info */
+        if (opt_o) /* show per-domain info */
+            rc = -sched_domain_output(LIBXL_SCHEDULER_RTDS,
+                                        sched_rtds_domain_output,
+                                        sched_rtds_pool_output,
+                                        cpupool);
+        else /* show per-vcpu info */
+            rc = -sched_domain_output(LIBXL_SCHEDULER_RTDS,
+                                        sched_rtds_vcpu_output,
+                                        sched_rtds_pool_output,
+                                        cpupool);
+        goto out;
     } else {
         uint32_t domid = find_domain(dom);
-        if (!opt_p && !opt_b) { /* output rt scheduler info */
-            sched_rtds_domain_output(-1);
-            return -sched_rtds_domain_output(domid);
-        } else { /* set rt scheduler paramaters */
-            libxl_domain_sched_params scinfo;
-            libxl_domain_sched_params_init(&scinfo);
-            scinfo.sched = LIBXL_SCHEDULER_RTDS;
-            scinfo.period = period;
-            scinfo.budget = budget;
-
-            rc = sched_domain_set(domid, &scinfo);
-            libxl_domain_sched_params_dispose(&scinfo);
-            if (rc)
-                return -rc;
+        if (!opt_p && !opt_b && !opt_v) { /* output rtds scheduler info */
+            if (opt_o) {
+                sched_rtds_domain_output(-1);
+                rc = -sched_rtds_domain_output(domid);
+            }
+            else {
+                sched_rtds_vcpu_output(-1);
+                rc = -sched_rtds_vcpu_output(domid);
+            }
+            goto out;
+    } else if (opt_v) { /* set per-vcpu rtds scheduler paramaters */
+        libxl_vcpu_sched_params scinfo;
+        libxl_vcpu_sched_params_init(&scinfo);
+        scinfo.sched = LIBXL_SCHEDULER_RTDS;
+        scinfo.num_vcpus = input_size;
+        scinfo.vcpus = (libxl_rtds_vcpu *)
+                xmalloc(sizeof(libxl_rtds_vcpu) * (input_size));
+        for (i = 0; i < input_size; i++) {
+            scinfo.vcpus[i].vcpuid = vcpus[i];
+            scinfo.vcpus[i].period = periods[i];
+            scinfo.vcpus[i].budget = budgets[i];
+        }
+        rc = sched_vcpu_set(domid, &scinfo);
+        libxl_vcpu_sched_params_dispose(&scinfo);
+        if (rc) {
+            rc = -rc;
+            goto out;
         }
+    } else { /* set per-dom rtds scheduler paramaters */
+        libxl_domain_sched_params scinfo;
+        libxl_domain_sched_params_init(&scinfo);
+        scinfo.sched = LIBXL_SCHEDULER_RTDS;
+        scinfo.period = periods[0];
+        scinfo.budget = budgets[0];
+        rc = sched_domain_set(domid, &scinfo);
+        libxl_domain_sched_params_dispose(&scinfo);
+        if (rc) {
+            rc = -rc;
+            goto out;
+        }
+      }
     }
 
-    return 0;
+out:
+    free(vcpus);
+    free(periods);
+    free(budgets);
+    return rc;
 }
 
 int main_domid(int argc, char **argv)
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.