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

[Xen-devel] [PATCH v1 3/4] libxl: enabling XL to set per-VCPU parameters of a domain for RTDS scheduler



Change sched_rtds_domain_get/set functions to support per-VCPU settings for 
RTDS scheduler.

Signed-off-by: Chong Li <chong.li@xxxxxxxxx>
Signed-off-by: Meng Xu <mengxu@xxxxxxxxxxxxx>
Signed-off-by: Sisu Xi <xisisu@xxxxxxxxx>
---
 tools/libxl/libxl.c         | 143 +++++++++++++++++++++++++++++++++-----------
 tools/libxl/libxl.h         |   6 ++
 tools/libxl/libxl_types.idl |  11 ++++
 3 files changed, 126 insertions(+), 34 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index feb3aa9..5f66753 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5800,10 +5800,17 @@ static int sched_sedf_domain_set(libxl__gc *gc, 
uint32_t domid,
 static int sched_rtds_domain_get(libxl__gc *gc, uint32_t domid,
                                libxl_domain_sched_params *scinfo)
 {
-    struct xen_domctl_sched_rtds sdom;
-    int rc;
-
-    rc = xc_sched_rtds_domain_get(CTX->xch, domid, &sdom);
+    uint16_t num_vcpus;
+    int rc, i;
+    xc_dominfo_t info;
+    rc = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (rc < 0) {
+        LOGE(ERROR, "getting domain info");
+        return ERROR_FAIL;
+    }
+    num_vcpus = info.nr_online_vcpus;
+    struct xen_domctl_sched_rtds_params  sdom[num_vcpus];
+    rc = xc_sched_rtds_vcpu_get(CTX->xch, domid, sdom, num_vcpus);
     if (rc != 0) {
         LOGE(ERROR, "getting domain sched rtds");
         return ERROR_FAIL;
@@ -5812,8 +5819,15 @@ static int sched_rtds_domain_get(libxl__gc *gc, uint32_t 
domid,
     libxl_domain_sched_params_init(scinfo);
 
     scinfo->sched = LIBXL_SCHEDULER_RTDS;
-    scinfo->period = sdom.period;
-    scinfo->budget = sdom.budget;
+    scinfo->rtds.num_vcpus = num_vcpus;
+    scinfo->rtds.vcpus = (libxl_vcpu *)
+            libxl__malloc(NOGC, sizeof(libxl_vcpu) * num_vcpus);
+
+    for( i = 0; i < num_vcpus; i++) {
+        scinfo->rtds.vcpus[i].period = sdom[i].period;
+        scinfo->rtds.vcpus[i].budget = sdom[i].budget;
+        scinfo->rtds.vcpus[i].index = sdom[i].index;
+    }
 
     return 0;
 }
@@ -5821,43 +5835,104 @@ static int sched_rtds_domain_get(libxl__gc *gc, 
uint32_t domid,
 static int sched_rtds_domain_set(libxl__gc *gc, uint32_t domid,
                                const libxl_domain_sched_params *scinfo)
 {
-    struct xen_domctl_sched_rtds sdom;
     int rc;
+    int i;
 
-    rc = xc_sched_rtds_domain_get(CTX->xch, domid, &sdom);
-    if (rc != 0) {
-        LOGE(ERROR, "getting domain sched rtds");
-        return ERROR_FAIL;
-    }
+    if(scinfo->rtds.num_vcpus <= 0) {/*set per-dom rtds parameters*/
+        struct xen_domctl_sched_rtds  sdom;
+        rc = xc_sched_rtds_domain_get(CTX->xch, domid, &sdom);
+        if (rc != 0) {
+            LOGE(ERROR, "getting domain sched rtds");
+            return ERROR_FAIL;
+        }
 
-    if (scinfo->period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
-        if (scinfo->period < 1) {
-            LOG(ERROR, "VCPU period is not set or out of range, "
-                       "valid values are larger than 1");
-            return ERROR_INVAL;
+        if (scinfo->period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
+            if (scinfo->period < 1) {
+                LOG(ERROR, "VCPU period is not set or out of range, "
+                           "valid values are larger than 1");
+                return ERROR_INVAL;
+            }
+            sdom.period = scinfo->period;
+        }
+
+        if (scinfo->budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
+            if (scinfo->budget < 1) {
+                LOG(ERROR, "VCPU budget is not set or out of range, "
+                           "valid values are larger than 1");
+                return ERROR_INVAL;
+            }
+            sdom.budget = scinfo->budget;
         }
-        sdom.period = scinfo->period;
-    }
 
-    if (scinfo->budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
-        if (scinfo->budget < 1) {
-            LOG(ERROR, "VCPU budget is not set or out of range, "
-                       "valid values are larger than 1");
+        if (sdom.budget > sdom.period) {
+            LOG(ERROR, "VCPU budget is larger than VCPU period, "
+                       "VCPU budget should be no larger than VCPU period");
             return ERROR_INVAL;
         }
-        sdom.budget = scinfo->budget;
-    }
 
-    if (sdom.budget > sdom.period) {
-        LOG(ERROR, "VCPU budget is larger than VCPU period, "
-                   "VCPU budget should be no larger than VCPU period");
-        return ERROR_INVAL;
-    }
+        rc = xc_sched_rtds_domain_set(CTX->xch, domid, &sdom);
+        if (rc < 0) {
+            LOGE(ERROR, "setting domain sched rtds");
+            return ERROR_FAIL;
+        }
 
-    rc = xc_sched_rtds_domain_set(CTX->xch, domid, &sdom);
-    if (rc < 0) {
-        LOGE(ERROR, "setting domain sched rtds");
-        return ERROR_FAIL;
+        return rc;
+    } else { /*set per-vcpu rtds parameters*/
+        uint16_t num_vcpus;
+        xc_dominfo_t info;
+        rc = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+        if (rc < 0) {
+            LOGE(ERROR, "getting domain info");
+            return ERROR_FAIL;
+        }
+        num_vcpus = info.nr_online_vcpus;
+        for (i = 0; i < scinfo->rtds.num_vcpus; i++) {
+            int vcpu_index, budget, period;
+            vcpu_index = scinfo->rtds.vcpus[i].index;
+            budget = scinfo->rtds.vcpus[i].budget;
+            period = scinfo->rtds.vcpus[i].period;
+
+            if(budget > period) {
+                LOG(ERROR, "VCPU budget is larger than VCPU period, "
+                           "VCPU %d budget should be no larger than period",
+                           vcpu_index);
+                return ERROR_INVAL;
+            }
+
+            if (vcpu_index < 0 || vcpu_index >= num_vcpus) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           num_vcpus);
+                return ERROR_INVAL;
+            }
+
+            if (period < 1) {
+                LOG(ERROR, "VCPU period is out of range, "
+                           "valid values are larger than 1");
+                return ERROR_INVAL;
+            }
+
+            if (budget < 1) {
+                LOG(ERROR, "VCPU budget is out of range, "
+                           "valid values are larger than 1");
+                return ERROR_INVAL;
+            }
+        }
+
+        struct xen_domctl_sched_rtds_params  sdom[scinfo->rtds.num_vcpus];
+        for (i = 0; i < scinfo->rtds.num_vcpus; i++) {
+            sdom[i].index = scinfo->rtds.vcpus[i].index;
+            sdom[i].budget = scinfo->rtds.vcpus[i].budget;
+            sdom[i].period = scinfo->rtds.vcpus[i].period;
+        }
+        rc = xc_sched_rtds_vcpu_set(CTX->xch, domid,
+                       &sdom[0], scinfo->rtds.num_vcpus);
+        if (rc < 0) {
+            LOGE(ERROR, "setting domain sched rtds");
+            return ERROR_FAIL;
+        }
+
+        return rc;
     }
 
     return 0;
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 44bd8e2..8284ce1 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1460,6 +1460,12 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, 
uint32_t poolid,
 #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
 #define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT    -1
 
+/*RTDS Per-VCPU parameters*/
+#define LIBXL_DOMAIN_SCHED_PARAM_VCPU_INDEX_DEFAULT -1
+
+/* Consistent with XEN_LEGACY_MAX_VCPUS xen/arch-x86/xen.h*/
+#define LIBXL_XEN_LEGACY_MAX_VCPUS                  32
+
 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                   libxl_domain_sched_params *params);
 int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 117b61d..806316a 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -347,6 +347,16 @@ libxl_domain_restore_params = 
Struct("domain_restore_params", [
     ("checkpointed_stream", integer),
     ])
 
+libxl_rtds_vcpu = Struct("vcpu",[
+    ("period",       uint64, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT'}),
+    ("budget",       uint64, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
+    ("index",        integer, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_VCPU_INDEX_DEFAULT'}),
+    ])
+
+libxl_domain_sched_rtds_params = Struct("domain_sched_rtds_params",[
+    ("vcpus",        Array(libxl_rtds_vcpu, "num_vcpus")),
+    ])
+
 libxl_domain_sched_params = Struct("domain_sched_params",[
     ("sched",        libxl_scheduler),
     ("weight",       integer, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
@@ -356,6 +366,7 @@ libxl_domain_sched_params = Struct("domain_sched_params",[
     ("latency",      integer, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT'}),
     ("extratime",    integer, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT'}),
     ("budget",       integer, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
+    ("rtds",             libxl_domain_sched_rtds_params),  
     ])
 
 libxl_vnode_info = Struct("vnode_info", [
-- 
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®.