Skip to contentSkip to conversation

Enable per-VCPU parameter settings for RTDS scheduler

PATCH Superseded Chong Li 6 participants 51 messages Mar 6, 2016 – Mar 16, 2016

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Chong Li

author
#0 lore raw

v6 cover Enable per-VCPU parameter settings for RTDS scheduler

[Goal]
The current xl sched-rtds tool can only set the VCPUs of a domain to the same parameter although the scheduler supports VCPUs with different parameters. This patchset is to enable xl sched-rtds tool to configure the VCPUs of a domain with different parameters.

This per-VCPU settings can be used in many scenarios. For example, based on Dario's statement in our pervious discussion
(http://lists.xen.org/archives/html/xen-devel/2014-09/msg00423.html),
if there are two real-time applications, which have different timing requirements, running in a multi-VCPU guest domain, it is beneficial to pin these two applications to two seperate VCPUs with different scheduling parameters.

What this patchset includes is a wanted and planned feature for RTDS scheudler(http://wiki.xenproject.org/wiki/RTDS-Based-Scheduler) in Xen 4.7. The interface design of the xl sched-rtds tool is based on Meng's previous discussion with Dario, George and Wei
(http://lists.xen.org/archives/html/xen-devel/2015-02/msg02606.html).
Basically, there are two main changes:

1) in xl, we create an array that records all VCPUs whose parameters are about to modify or output.

2) in libxl, we receive the array and call different xc functions to handle it.

3) in xen and libxc, we use XEN_DOMCTL_SCHEDOP_getvcpuinfo/putvcpuinfo(introduced by this patchset) as the hypercall for per-VCPU operations(get/set method).

[Usage]
With this patchset in use, xl sched-rtds tool can:

1) show the budget and period of each VCPU of each domain, by using "xl sched-rtds -v all" command. An example would be like:

# xl sched-rtds -v all
Cpupool Pool-0: sched=RTDS
Name                                ID VCPU    Period    Budget
Domain-0                             0    0     10000      4000
vm1                                  1    0       300       150
vm1                                  1    1       400       200
vm1                                  1    2     10000      4000
vm1                                  1    3      1000       500
vm2                                  2    0     10000      4000
vm2                                  2    1     10000      4000

Using "xl sched-rtds" will output the default scheduling parameters for each domain. An example would be like:

# xl sched-rtds
Cpupool Pool-0: sched=RTDS
Name                                ID    Period    Budget
Domain-0                             0     10000      4000
vm1                                  1     10000      4000
vm2                                  2     10000      4000

2) show the budget and period of each VCPU of a specific domain, by using, e.g., "xl sched-rtds -d vm1 -v all" command. The output would be like:

# xl sched-rtds -d vm1 -v all
Name                                ID VCPU    Period    Budget
vm1                                  1    0       300       150
vm1                                  1    1       400       200
vm1                                  1    2     10000      4000
vm1                                  1    3      1000       500

To show a subset of the parameters of the VCPUs of a specific domain, please use, e.g.,"xl sched-rtds -d vm1 -v 0 -v 3" command. The output would be:

# xl sched-rtds -d vm1 -v 0 -v 3
Name                                ID VCPU    Period    Budget
vm1                                  1    0       300       150
vm1                                  1    3      1000       500

Using command, e.g., "xl sched-rtds -d vm1" will output the default scheduling parameters of vm1. An example would be like:

# xl sched-rtds -d vm1
Name                                ID    Period    Budget
vm1                                  1     10000      4000

3) Users can set the budget and period of multiple VCPUs of a specific domain with only one command,
e.g., "xl sched-rtds -d vm1 -v 0 -p 100 -b 50 -v 3 -p 300 -b 150".

Users can set all VCPUs with the same parameters, by one command. e.g., "xl sched-rtds -d vm1 -v all -p 500 -b 250".

---
Previous conclusion:
On PATCH v4, our concern was about the usage of hypercall_preemption_check and the print of warning message (both in xen). These issues are addressed in this patch.

Chong Li (4):
xen: enable per-VCPU parameter settings for RTDS scheduler
libxc: enable per-VCPU parameter settings for RTDS scheduler
libxl: enable per-VCPU parameter settings for RTDS scheduler
xl: enable per-VCPU parameter settings for RTDS scheduler

 docs/man/xl.pod.1             |   4 +
 tools/libxc/include/xenctrl.h |  16 ++-
 tools/libxc/xc_rt.c           |  68 +++++++++
 tools/libxl/libxl.c           | 326 +++++++++++++++++++++++++++++++++++++++---
 tools/libxl/libxl.h           |  37 +++++
 tools/libxl/libxl_types.idl   |  14 ++
 tools/libxl/xl_cmdimpl.c      | 292 ++++++++++++++++++++++++++++++++-----
 tools/libxl/xl_cmdtable.c     |  10 +-
 xen/common/sched_credit.c     |   4 +
 xen/common/sched_credit2.c    |   4 +
 xen/common/sched_rt.c         | 130 +++++++++++++++--
 xen/common/schedule.c         |  15 +-
 xen/include/public/domctl.h   |  59 ++++++--
 13 files changed, 885 insertions(+), 94 deletions(-)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v6 1/4 xen: enable per-VCPU parameter settings for RTDS scheduler

Add XEN_DOMCTL_SCHEDOP_getvcpuinfo and _putvcpuinfo hypercalls to independently get and set the scheduling parameters of each vCPU of a domain

---
Changes on PATCH v5:
1) When processing XEN_DOMCTL_SCHEDOP_get/putvcpuinfo, we do preemption check in a similar way to XEN_SYSCTL_pcitopoinfo

Changes on PATCH v4:
1) Add uint32_t vcpu_index to struct xen_domctl_scheduler_op. When processing XEN_DOMCTL_SCHEDOP_get/putvcpuinfo, we call hypercall_preemption_check in case the current hypercall lasts too long. If we decide to preempt the current hypercall, we record the index of the most-recent finished vcpu into the vcpu_index of struct xen_domctl_scheduler_op. So when we resume the hypercall after preemption, we start processing from the posion specified by vcpu_index, and don't need to repeat the work that has already been done in the hypercall before the preemption.
(This design is based on the do_grant_table_op() in grant_table.c)

2) Coding style changes

Changes on PATCH v3:
1) Remove struct xen_domctl_schedparam_t.

2) Change struct xen_domctl_scheduler_op.

3) Check if period/budget is within a validated range

Changes on PATCH v2:
1) Change struct xen_domctl_scheduler_op, for transferring per-vcpu parameters between libxc and hypervisor.

2) Handler of XEN_DOMCTL_SCHEDOP_getinfo now just returns the default budget and period values of RTDS scheduler.

3) Handler of XEN_DOMCTL_SCHEDOP_getvcpuinfo now can return a random subset of the parameters of the VCPUs of a specific domain

---
 xen/common/sched_credit.c   |   4 ++
 xen/common/sched_credit2.c  |   4 ++
 xen/common/sched_rt.c       | 130 +++++++++++++++++++++++++++++++++++++++-----
 xen/common/schedule.c       |  15 ++++-
 xen/include/public/domctl.h |  59 ++++++++++++++++----
 5 files changed, 182 insertions(+), 30 deletions(-)
xen/common/sched_credit.c +4 -0
index 0dce790..455c684 100644
@@ -1054,6 +1054,10 @@ csched_dom_cntl(
      * lock. Runq lock not needed anywhere in here. */
     spin_lock_irqsave(&prv->lock, flags);
 
+    if ( op->cmd == XEN_DOMCTL_SCHEDOP_putvcpuinfo ||
+         op->cmd == XEN_DOMCTL_SCHEDOP_getvcpuinfo )
+        return -EINVAL;
+
     if ( op->cmd == XEN_DOMCTL_SCHEDOP_getinfo )
     {
         op->u.credit.weight = sdom->weight;
xen/common/sched_credit2.c +4 -0
index 3c49ffa..c3049a0 100644
@@ -1421,6 +1421,10 @@ csched2_dom_cntl(
      * runq lock to update csvcs. */
     spin_lock_irqsave(&prv->lock, flags);
 
+    if ( op->cmd == XEN_DOMCTL_SCHEDOP_putvcpuinfo ||
+         op->cmd == XEN_DOMCTL_SCHEDOP_getvcpuinfo )
+        return -EINVAL;
+
     if ( op->cmd == XEN_DOMCTL_SCHEDOP_getinfo )
     {
         op->u.credit2.weight = sdom->weight;
xen/common/sched_rt.c +115 -15

150 lines not on this page · raw message

xen/common/schedule.c +12 -3
index c195129..f4a4032 100644
@@ -1148,10 +1148,19 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
     if ( ret )
         return ret;
 
-    if ( (op->sched_id != DOM2OP(d)->sched_id) ||
-         ((op->cmd != XEN_DOMCTL_SCHEDOP_putinfo) &&
-          (op->cmd != XEN_DOMCTL_SCHEDOP_getinfo)) )
+    if ( op->sched_id != DOM2OP(d)->sched_id )
         return -EINVAL;
+    else
+        switch ( op->cmd )
+        {
+        case XEN_DOMCTL_SCHEDOP_putinfo:
+        case XEN_DOMCTL_SCHEDOP_getinfo:
+        case XEN_DOMCTL_SCHEDOP_putvcpuinfo:
+        case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+            break;
+        default:
+            return -EINVAL;
+        }
 
     /* NB: the pluggable scheduler code needs to take care
      * of locking by itself. */
xen/include/public/domctl.h +47 -12

71 lines not on this page · raw message

Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.03.16 at 18:55, <[email protected]> wrote:

xen/common/sched_credit.c csched_dom_cntl( · line 1063

Quoted 10 lines
xen/common/sched_credit.c +4 -0
@@ -1054,6 +1054,10 @@ csched_dom_cntl(
      * lock. Runq lock not needed anywhere in here. */
     spin_lock_irqsave(&prv->lock, flags);
 
+    if ( op->cmd == XEN_DOMCTL_SCHEDOP_putvcpuinfo ||
+         op->cmd == XEN_DOMCTL_SCHEDOP_getvcpuinfo )
+        return -EINVAL;
+
     if ( op->cmd == XEN_DOMCTL_SCHEDOP_getinfo )
     {
         op->u.credit.weight = sdom->weight;

Considering the rest of the code following where, I would - albeit I'm not maintainer of this code - strongly suggest moving to switch() in such cases, with the default case returning -EINVAL (or maybe better -EOPNOTSUPP).

xen/common/sched_credit.c rt_dom_cntl( · line 1152

Quoted 8 lines
xen/common/sched_credit.c +4 -0
@@ -1130,23 +1146,17 @@ rt_dom_cntl(
     unsigned long flags;
     int rc = 0;
 
+    xen_domctl_schedparam_vcpu_t local_sched;
+    s_time_t period, budget;
+    uint32_t index = 0;
+

There's a stray blank line left ahead of this addition.

Quoted 13 lines
xen/common/sched_credit.c +0 -11
     switch ( op->cmd )
     {
-    case XEN_DOMCTL_SCHEDOP_getinfo:
-        if ( d->max_vcpus > 0 )
-        {
-            spin_lock_irqsave(&prv->lock, flags);
-            svc = rt_vcpu(d->vcpu[0]);
-            op->u.rtds.period = svc->period / MICROSECS(1);
-            op->u.rtds.budget = svc->budget / MICROSECS(1);
-            spin_unlock_irqrestore(&prv->lock, flags);
-        }
-        else
-        {

xen/common/sched_credit.c rt_dom_cntl( · line 1160

Quoted 10 lines
xen/common/sched_credit.c +5 -4
-            /* If we don't have vcpus yet, let's just return the defaults. */
-            op->u.rtds.period = RTDS_DEFAULT_PERIOD;
-            op->u.rtds.budget = RTDS_DEFAULT_BUDGET;
-        }
+    case XEN_DOMCTL_SCHEDOP_getinfo: /* return the default parameters */
+        spin_lock_irqsave(&prv->lock, flags);
+        op->u.rtds.period = RTDS_DEFAULT_PERIOD / MICROSECS(1);
+        op->u.rtds.budget = RTDS_DEFAULT_BUDGET / MICROSECS(1);
+        spin_unlock_irqrestore(&prv->lock, flags);
         break;

This alters the values returned when d->max_vcpus == 0 - while this looks to be intentional, I think calling out such a bug fix in the description is a must.

xen/common/sched_credit.c rt_dom_cntl( · line 1179

Quoted 8 lines
xen/common/sched_credit.c +4 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;

Perhaps rather -EFAULT? But then again - what is this check good for (considering that it doesn't cover other obviously bad handle values)?

xen/common/sched_credit.c rt_dom_cntl( · line 1185

Quoted 6 lines
xen/common/sched_credit.c +6 -0
+            break;
+        }
+        while ( index < op->u.v.nr_vcpus )
+        {
+            if ( copy_from_guest_offset(&local_sched,
+                          op->u.v.vcpus, index, 1) )

Indentation.

xen/common/sched_credit.c rt_dom_cntl( · line 1191

Quoted 6 lines
xen/common/sched_credit.c +6 -0
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( local_sched.vcpuid >= d->max_vcpus ||
+                          d->vcpu[local_sched.vcpuid] == NULL )

Again. And more below.

Quoted 9 lines
xen/common/sched_credit.c +9 -0
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            local_sched.s.rtds.budget = svc->budget / MICROSECS(1);
+            local_sched.s.rtds.period = svc->period / MICROSECS(1);

xen/common/sched_credit.c rt_dom_cntl( · line 1210

Quoted 10 lines
xen/common/sched_credit.c +10 -0
+            spin_unlock_irqrestore(&prv->lock, flags);
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check() )
+                break;

So how is the caller going to be able to reliably read all vCPU-s' information for a guest with more than 64 vCPU-s?

xen/common/sched_credit.c rt_dom_cntl( · line 1214

Quoted 4 lines
xen/common/sched_credit.c +4 -0
+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) )
+            op->u.v.nr_vcpus = index;

I don't think the right side of the && is really necessary / useful.

xen/common/sched_credit.c rt_dom_cntl( · line 1216

Quoted 2 lines
xen/common/sched_credit.c +2 -0
+        break;
+    case XEN_DOMCTL_SCHEDOP_putvcpuinfo:

When switch statements get large, please put blank lines between individual case blocks.

Quoted 26 lines
xen/common/sched_credit.c +26 -0
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;
+            break;
+        }
+        while ( index < op->u.v.nr_vcpus )
+        {
+            if ( copy_from_guest_offset(&local_sched,
+                          op->u.v.vcpus, index, 1) )
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( local_sched.vcpuid >= d->max_vcpus ||
+                          d->vcpu[local_sched.vcpuid] == NULL )
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            period = MICROSECS(local_sched.s.rtds.period);
+            budget = MICROSECS(local_sched.s.rtds.budget);
+            if ( period > RTDS_MAX_PERIOD || budget < RTDS_MIN_BUDGET ||
+                          budget > period || period < RTDS_MIN_PERIOD )
+            {
+                rc = -EINVAL;

xen/common/sched_credit.c rt_dom_cntl( · line 1252

Quoted 10 lines
xen/common/sched_credit.c +10 -0
+                break;
+            }
+
+            /*
+             * We accept period/budget less than 100 us, but will warn users about
+             * the large scheduling overhead due to it
+             */
+            if ( period < MICROSECS(100) || budget < MICROSECS(100) )
+                printk("Warning: period or budget set to less than 100us.\n"
+                       "This may result in high scheduling overhead.\n");

This should use a log level which is rate limited by default. Quite likely that would be one of the guest log levels.

xen/common/schedule.c long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) · line 1154

Quoted 13 lines
xen/common/schedule.c +3 -3
@@ -1148,10 +1148,19 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
     if ( ret )
         return ret;
 
-    if ( (op->sched_id != DOM2OP(d)->sched_id) ||
-         ((op->cmd != XEN_DOMCTL_SCHEDOP_putinfo) &&
-          (op->cmd != XEN_DOMCTL_SCHEDOP_getinfo)) )
+    if ( op->sched_id != DOM2OP(d)->sched_id )
         return -EINVAL;
+    else
+        switch ( op->cmd )

Pointless else, pointlessly increasing the necessary indentation for the entire switch().

xen/common/schedule.c long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) · line 1160

Quoted 6 lines
xen/common/schedule.c +6 -0
+typedef struct xen_domctl_schedparam_vcpu {
+    union {
+        xen_domctl_sched_credit_t credit;
+        xen_domctl_sched_credit2_t credit2;
+        xen_domctl_sched_rtds_t rtds;
+    } s;

Please call such unions "u", as done everywhere else.

xen/common/schedule.c long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) · line 1161

Quoted 1 line
xen/common/schedule.c +1 -0
+    uint16_t vcpuid;

Any particular reason to limit this to 16 bits, when elsewhere we commonly use 32 bits for vCPU IDs?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#3 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 38 lines · Jan Beulich

xen/common/sched_rt.c rt_dom_cntl( · line 1152

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.03.16 at 18:55, <[email protected]> wrote:
xen/common/sched_rt.c +4 -0
@@ -1130,23 +1146,17 @@ rt_dom_cntl(
     unsigned long flags;
     int rc = 0;
 
+    xen_domctl_schedparam_vcpu_t local_sched;
+    s_time_t period, budget;
+    uint32_t index = 0;
+

There's a stray blank line left ahead of this addition.

Quoted 13 lines
xen/common/sched_rt.c +0 -11
     switch ( op->cmd )
     {
-    case XEN_DOMCTL_SCHEDOP_getinfo:
-        if ( d->max_vcpus > 0 )
-        {
-            spin_lock_irqsave(&prv->lock, flags);
-            svc = rt_vcpu(d->vcpu[0]);
-            op->u.rtds.period = svc->period / MICROSECS(1);
-            op->u.rtds.budget = svc->budget / MICROSECS(1);
-            spin_unlock_irqrestore(&prv->lock, flags);
-        }
-        else
-        {

xen/common/sched_rt.c rt_dom_cntl( · line 1160

Quoted 10 lines
xen/common/sched_rt.c +5 -4
-            /* If we don't have vcpus yet, let's just return the defaults. */
-            op->u.rtds.period = RTDS_DEFAULT_PERIOD;
-            op->u.rtds.budget = RTDS_DEFAULT_BUDGET;
-        }
+    case XEN_DOMCTL_SCHEDOP_getinfo: /* return the default parameters */
+        spin_lock_irqsave(&prv->lock, flags);
+        op->u.rtds.period = RTDS_DEFAULT_PERIOD / MICROSECS(1);
+        op->u.rtds.budget = RTDS_DEFAULT_BUDGET / MICROSECS(1);
+        spin_unlock_irqrestore(&prv->lock, flags);
         break;
Quoted 3 lines

This alters the values returned when d->max_vcpus == 0 - while this looks to be intentional, I think calling out such a bug fix in the description is a must.

Based on previous discussion, XEN_DOMCTL_SCHEDOP_getinfo only returns the default parameters,
no matter whether vcpu is created yet or not. But I can absolutely explain this in the description.

Quoted 12 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1179

Quoted 9 lines
xen/common/sched_rt.c +4 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;

Perhaps rather -EFAULT? But then again - what is this check good for (considering that it doesn't cover other obviously bad handle values)?

Dario suggested this in the last post, because vcpus is a handle and needs to be validated.

Quoted 14 lines
Quoted 14 lines
xen/common/sched_rt.c +14 -0
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            local_sched.s.rtds.budget = svc->budget / MICROSECS(1);
+            local_sched.s.rtds.period = svc->period / MICROSECS(1);
+            spin_unlock_irqrestore(&prv->lock, flags);
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )
+            {
Quoted 8 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1210

Quoted 5 lines
xen/common/sched_rt.c +5 -0
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check() )
+                break;

So how is the caller going to be able to reliably read all vCPU-s' information for a guest with more than 64 vCPU-s?

In libxc, we re-issue hypercall if the current one is preempted.

Quoted 7 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1214

Quoted 5 lines
xen/common/sched_rt.c +4 -0
+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) )
+            op->u.v.nr_vcpus = index;

I don't think the right side of the && is really necessary / useful.

The right side is to check whether the vcpus array is fully processed. When it is true and no error occurs (rc == 0), we
update op->u.v.nr_vcpus, which is returned to libxc, and helps xc function figuring out how many un-processed vcpus should
be taken care of in the next hypercall.

Quoted 8 lines

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_max_vcpus_t); · line 360

Quoted 7 lines
xen/include/public/domctl.h +6 -0
+typedef struct xen_domctl_schedparam_vcpu {
+    union {
+        xen_domctl_sched_credit_t credit;
+        xen_domctl_sched_credit2_t credit2;
+        xen_domctl_sched_rtds_t rtds;
+    } s;
Quoted 6 lines

Please call such unions "u", as done everywhere else.

xen/include/public/domctl.h DEFINE_XEN_GUEST_HANDLE(xen_domctl_max_vcpus_t); · line 361

Quoted 1 line
xen/include/public/domctl.h +1 -0
+    uint16_t vcpuid;

Any particular reason to limit this to 16 bits, when elsewhere we commonly use 32 bits for vCPU IDs?

I'll change it.

Thanks for your comments.
Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 17:28, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 06.03.16 at 18:55, <[email protected]> wrote:
     switch ( op->cmd )
     {
xen/common/sched_rt.c +5 -15
-    case XEN_DOMCTL_SCHEDOP_getinfo:
-        if ( d->max_vcpus > 0 )
-        {
-            spin_lock_irqsave(&prv->lock, flags);
-            svc = rt_vcpu(d->vcpu[0]);
-            op->u.rtds.period = svc->period / MICROSECS(1);
-            op->u.rtds.budget = svc->budget / MICROSECS(1);
-            spin_unlock_irqrestore(&prv->lock, flags);
-        }
-        else
-        {
-            /* If we don't have vcpus yet, let's just return the defaults. */
-            op->u.rtds.period = RTDS_DEFAULT_PERIOD;
-            op->u.rtds.budget = RTDS_DEFAULT_BUDGET;
-        }
+    case XEN_DOMCTL_SCHEDOP_getinfo: /* return the default parameters */
+        spin_lock_irqsave(&prv->lock, flags);
+        op->u.rtds.period = RTDS_DEFAULT_PERIOD / MICROSECS(1);
+        op->u.rtds.budget = RTDS_DEFAULT_BUDGET / MICROSECS(1);
+        spin_unlock_irqrestore(&prv->lock, flags);
         break;
Quoted 8 lines
Quoted 3 lines

This alters the values returned when d->max_vcpus == 0 - while this looks to be intentional, I think calling out such a bug fix in the description is a must.

Based on previous discussion, XEN_DOMCTL_SCHEDOP_getinfo only returns the default parameters,
no matter whether vcpu is created yet or not. But I can absolutely explain this in the description.

That wasn't the point of the comment. Instead the change (fix) to divide by MICROSECS(1) is what otherwise would go in silently.

Quoted 12 lines
Quoted 11 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1179

Quoted 8 lines
xen/common/sched_rt.c +4 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;

Perhaps rather -EFAULT? But then again - what is this check good for (considering that it doesn't cover other obviously bad handle values)?

Quoted 2 lines

Dario suggested this in the last post, because vcpus is a handle and needs to be validated.

Well, as said - the handle being non-null doesn't make it a valid handle. Any validation can be left to copy_{to,from}_guest*() unless you mean to give a null handle some special meaning.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
xen/common/sched_rt.c +14 -0
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            local_sched.s.rtds.budget = svc->budget / MICROSECS(1);
+            local_sched.s.rtds.period = svc->period / MICROSECS(1);
+            spin_unlock_irqrestore(&prv->lock, flags);
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )
+            {
Quoted 8 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1210

Quoted 5 lines
xen/common/sched_rt.c +5 -0
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check() )
+                break;

So how is the caller going to be able to reliably read all vCPU-s' information for a guest with more than 64 vCPU-s?

Quoted 1 line

In libxc, we re-issue hypercall if the current one is preempted.

And with the current code - how does libxc know? (And anyway, this should only be a last resort, if the hypervisor can't by itself arrange for a continuation. If done this way, having a code comment referring to the required caller behavior would seem to be an absolute must.)

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/common/sched_rt.c +4 -0
+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) )
+            op->u.v.nr_vcpus = index;
Quoted 7 lines
Quoted 1 line

I don't think the right side of the && is really necessary / useful.

The right side is to check whether the vcpus array is fully processed. When it is true and no error occurs (rc == 0), we
update op->u.v.nr_vcpus, which is returned to libxc, and helps xc function figuring out how many un-processed vcpus should
be taken care of in the next hypercall.

Just consider what the contents of op->u.v.nr_vcpus is after this piece of code was executed, once with the full conditional, and another time with the right side of the && omitted.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 17:28, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

Quoted 6 lines
(quoted diff) +0 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(


+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) ) +        {
+            rc = -EINVAL;

Perhaps rather -EFAULT? But then again - what is this check good for
(considering that it doesn't cover other obviously bad handle values)?

Quoted 8 lines
Quoted 3 lines

Dario suggested this in the last post, because vcpus is a handle and
needs to be validated.

Well, as said - the handle being non-null doesn't make it a valid handle. Any validation can be left to copy_{to,from}_guest*() unless you mean to give a null handle some special meaning.

IIRC, I was looking at how XEN_SYSCTL_pcitopoinfo is handled, for reference, and that has some guest_handle_is_null()==>EINVAL sainity checking (in xen/common/sysctl.c), which, when I thought about it, made sense to me.

My reasoning was, sort of:
 1. if the handle is NULL, no point getting into the somewhat complicated logic of the while,
 2. more accurate error reporting: as being passed a NULL handler looked something we could identify and call invalid, rather than waiting for the copy to fault.

In any event, I've no problem at all with this being dropped.

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 14 lines

+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]); +            local_sched.s.rtds.budget = svc->budget / MICROSECS(1);
+            local_sched.s.rtds.period = svc->period / MICROSECS(1);
+            spin_unlock_irqrestore(&prv->lock, flags); +
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,

Quoted 8 lines

+                    &local_sched, 1) )
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check() )
+                break;

So how is the caller going to be able to reliably read all vCPU- s'
information for a guest with more than 64 vCPU-s?

Quoted 7 lines
Quoted 1 line

In libxc, we re-issue hypercall if the current one is preempted.

And with the current code - how does libxc know? (And anyway, this should only be a last resort, if the hypervisor can't by itself arrange for a continuation. If done this way, having a code comment referring to the required caller behavior would seem to be an absolute must.)

I definitely agree on commenting.

About the structure of the code, as said above, I do like how XEN_SYSCTL_pcitopoinfo ended up being handled, I think it is a great fit for this specific case and, comparing at both this and previous version, I do think this one is (bugs apart) looking better.

I'm sure I said this --long ago-- when discussing v4 (and maybe even previous versions), as well as more recently, when reviewing v5, and that's why Chong (finally! :-D) did it.

So, with the comment in place (and with bugs fixed :-)), are you (Jan) ok with this being done this way?

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) ) +            op->u.v.nr_vcpus = index;

Quoted 8 lines
Quoted 2 lines

I don't think the right side of the && is really necessary / useful.

The right side is to check whether the vcpus array is fully processed.
When it is true and no error occurs (rc == 0), we update op->u.v.nr_vcpus, which is returned to libxc, and helps xc function figuring out how many un-processed vcpus should be taken care of in the next hypercall.

Quoted 4 lines

Just consider what the contents of op->u.v.nr_vcpus is after this piece of code was executed, once with the full conditional, and another time with the right side of the && omitted.

BTW, Chong, I'm not sure this has to do with what Jan is saying, but looking again at XEN_SYSCTL_pcitopoinfo, it looks to me you're missing copying nr_vcpus back up to the guest (which is actually what makes libxc knows whether all vcpus have been processed or now).

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#6 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 49 lines · Dario Faggioli
Quoted 48 lines · Jan Beulich
Quoted 48 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 17:28, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 31 lines
xen/common/sched_rt.c +23 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
 
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;
 
 
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            local_sched.s.rtds.budget = svc->budget /
 MICROSECS(1);
+            local_sched.s.rtds.period = svc->period /
 MICROSECS(1);
+            spin_unlock_irqrestore(&prv->lock, flags);
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check()
 )
+                break;
Quoted 6 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1214

Quoted 4 lines
xen/common/sched_rt.c +4 -0
+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) )
+            op->u.v.nr_vcpus = index;

I don't think the right side of the && is really necessary / useful.

The right side is to check whether the vcpus array is fully processed.
When it is true and no error occurs (rc == 0), we update op->u.v.nr_vcpus, which is returned to libxc, and helps xc function figuring out how many un-processed vcpus should be taken care of in the next hypercall.

Quoted 8 lines
Quoted 4 lines

Just consider what the contents of op->u.v.nr_vcpus is after this piece of code was executed, once with the full conditional, and another time with the right side of the && omitted.

BTW, Chong, I'm not sure this has to do with what Jan is saying, but looking again at XEN_SYSCTL_pcitopoinfo, it looks to me you're missing copying nr_vcpus back up to the guest (which is actually what makes libxc knows whether all vcpus have been processed or now).

I think by "op->u.v.nr_vcpus = index", we already make the new nr_vcpus seen by the guest (I've verified it).

In the case XEN_DOMCTL_scheduler_op of do_domctl(),
we make "copyback = 1" after calling sched_adjust(), which means all fields in op (including
the new nr_vcpus) will be copied to u_domctl (at the end of do_domctl()). This operation
ensures the new nr_vcpus is copied back up to the guest.

Please correct me if my understanding is wrong.

Chong

Quoted 9 lines

Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#7 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

In reply to Dario Faggioli
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 18:53, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 17:28, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/common/sched_rt.c rt_dom_cntl( · line 1177

Quoted 7 lines
xen/common/sched_rt.c +4 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
 
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;

Perhaps rather -EFAULT? But then again - what is this check good for
(considering that it doesn't cover other obviously bad handle values)?

Quoted 8 lines
Quoted 3 lines

Dario suggested this in the last post, because vcpus is a handle and
needs to be validated.

Well, as said - the handle being non-null doesn't make it a valid handle. Any validation can be left to copy_{to,from}_guest*() unless you mean to give a null handle some special meaning.

IIRC, I was looking at how XEN_SYSCTL_pcitopoinfo is handled, for reference, and that has some guest_handle_is_null()==>EINVAL sainity checking (in xen/common/sysctl.c), which, when I thought about it, made sense to me.

Quoted 6 lines

My reasoning was, sort of:
1. if the handle is NULL, no point getting into the somewhat complicated logic of the while,
2. more accurate error reporting: as being passed a NULL handler looked something we could identify and call invalid, rather than waiting for the copy to fault.

I think the XEN_SYSCTL_pcitopoinfo was misguided in this respect, cloning non applicable logic here which returns the number of needed (array) elements in such a case for a few other operations.

Quoted 39 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 12 lines
xen/common/sched_rt.c +10 -0
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            local_sched.s.rtds.budget = svc->budget /
 MICROSECS(1);
+            local_sched.s.rtds.period = svc->period /
 MICROSECS(1);
+            spin_unlock_irqrestore(&prv->lock, flags);

xen/common/sched_rt.c rt_dom_cntl( · line 1210

Quoted 10 lines
xen/common/sched_rt.c +9 -0
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check()
 )
+                break;

So how is the caller going to be able to reliably read all vCPU- s'
information for a guest with more than 64 vCPU-s?

Quoted 7 lines
Quoted 1 line

In libxc, we re-issue hypercall if the current one is preempted.

And with the current code - how does libxc know? (And anyway, this should only be a last resort, if the hypervisor can't by itself arrange for a continuation. If done this way, having a code comment referring to the required caller behavior would seem to be an absolute must.)

I definitely agree on commenting.

About the structure of the code, as said above, I do like how XEN_SYSCTL_pcitopoinfo ended up being handled, I think it is a great fit for this specific case and, comparing at both this and previous version, I do think this one is (bugs apart) looking better.

Quoted 6 lines

I'm sure I said this --long ago-- when discussing v4 (and maybe even previous versions), as well as more recently, when reviewing v5, and that's why Chong (finally! :-D) did it.

So, with the comment in place (and with bugs fixed :-)), are you (Jan) ok with this being done this way?

Well, this _might_ be acceptable for "get" (since the caller abandoning the sequence of calls prematurely is no problem), but for "set" it looks less suitable, as similar abandoning would leave the guest in some inconsistent / unintended state. The issue with XEN_SYSCTL_pcitopoinfo was, iirc, the lack of a good way of encoding the continuation information, and while that would seem applicable here too I'm not sure now whether doing it the way it was done was the best choice. Clearly stating (in the public interface header) that certain normally input-only fields are volatile would allow the continuation to be handled without tool stack assistance afaict.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

xen/common/sched_rt.c rt_dom_cntl( · line 1214

Quoted 4 lines
xen/common/sched_rt.c +4 -0
+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) )
+            op->u.v.nr_vcpus = index;

I don't think the right side of the && is really necessary / useful.

The right side is to check whether the vcpus array is fully processed.
When it is true and no error occurs (rc == 0), we update op->u.v.nr_vcpus, which is returned to libxc, and helps xc function figuring out how many un-processed vcpus should be taken care of in the next hypercall.

Quoted 8 lines
Quoted 4 lines

Just consider what the contents of op->u.v.nr_vcpus is after this piece of code was executed, once with the full conditional, and another time with the right side of the && omitted.

BTW, Chong, I'm not sure this has to do with what Jan is saying, but looking again at XEN_SYSCTL_pcitopoinfo, it looks to me you're missing copying nr_vcpus back up to the guest (which is actually what makes libxc knows whether all vcpus have been processed or now).

Indeed that is why the conditional makes sense there, but not here. And the copying back is already being taken care of by the caller of sched_adjust().

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 17 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 18:53, <[email protected]> wrote:
Quoted 1 line · Jan Beulich

IIRC, I was looking at how XEN_SYSCTL_pcitopoinfo is handled, for reference, and that has some guest_handle_is_null()==>EINVAL sainity
checking (in xen/common/sysctl.c), which, when I thought about it, made
sense to me.

Quoted 7 lines

My reasoning was, sort of:
 1. if the handle is NULL, no point getting into the somewhat complicated logic of the while,
 2. more accurate error reporting: as being passed a NULL handler looked something we could identify and call invalid, rather than
    waiting for the copy to fault.

Quoted 4 lines

I think the XEN_SYSCTL_pcitopoinfo was misguided in this respect, cloning non applicable logic here which returns the number of needed (array) elements in such a case for a few other operations.

Sorry, I'm not sure I am getting: are you saying that, for _these_ domctls, we should consider the handle being NULL as a way of the caller to ask for the size of the array?

*If* yes, well, that is "just" the number of vcpus of the guest, but, nevertheless, that, FWIW, looks fine to me.

Quoted 12 lines
Quoted 12 lines

About the structure of the code, as said above, I do like how XEN_SYSCTL_pcitopoinfo ended up being handled, I think it is a great fit for this specific case and, comparing at both this and previous version, I do think this one is (bugs apart) looking better.

I'm sure I said this --long ago-- when discussing v4 (and maybe even
previous versions), as well as more recently, when reviewing v5, and
that's why Chong (finally! :-D) did it.

Quoted 9 lines
Quoted 3 lines

So, with the comment in place (and with bugs fixed :-)), are you (Jan)
ok with this being done this way?

Well, this _might_ be acceptable for "get" (since the caller abandoning the sequence of calls prematurely is no problem), but for "set" it looks less suitable, as similar abandoning would leave the guest in some inconsistent / unintended state.

Are you referring to the fact that, with this interface, the caller has the chance to leave intentionally, or that it may happen that not all vcpus are updated because of some bug (still in the caller)?

Well, if it's intentional, or even if the caller is buggy in the sense that the code is written in a way that it misses updating some vcpus (and if the interface and the behavior is well documented, as you request), then one gets what he "wants" (and, in the latter case, it wouldn't be too hard to debug and figure out the issue, I think).

If it's for bugs (still in the caller) like copy_from_guest_offset() faulting because the array is too small, that can happen if using continuation too, can't it? And it would still leave the guest in similar inconsistent or unintended state, IMO...

One last point. Of course, since we are talking about bugs, the final status is not the one desired, but it's not inconsistent in the sense that the guest can't continue running, or crashes, or anything like that. It's something like:
 - you wants all the 32 vcpus of guest A to have these new parameters
 - due to a bug, you're (for instance) passing me an array with only 16 vcpus parameters
 - result: onlyt 16 vcpus will have the new parameters.

Quoted 6 lines

The
issue with XEN_SYSCTL_pcitopoinfo was, iirc, the lack of a good way of encoding the continuation information, and while that would seem applicable here too I'm not sure now whether doing it the way it was done was the best choice.

As far as I can remember and see, it was being done by means of an additional dedicated parameter in the handle (called ti->first_dev in that case). Then at some point, you said:

http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg02623.html
"Considering this is a tools only interface, enforcing a not too high limit on num_devs would seem better than this not really clean continuation mechanism. The (tool stack) caller(s) can be made iterate."

With which I did agree (and I still do :-)), as well as I agree on the fact that we basically are in the same situation here.

Chong tried doing things with continuations for a few rounds, including v5, which is here:
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg00817.html

and he also used an additional field (vcpu_index).

So, all this being said, my preference stays for the way the code looks like in this version (with all the due commenting added). Of course, it's your preference that really matters here, me not being the maintainer of this code. :-)

So, how do you prefer Chong to continue doing this?

Quoted 5 lines

Clearly
stating (in the public interface header) that certain normally input-only fields are volatile would allow the continuation to be handled without tool stack assistance afaict.

Which (sorry, I'm not getting again) I guess is something different/more than what was done in v5 (the relevant hunks of which I'm pasting at the bottom of this email, for convenience)?

Quoted 10 lines
Quoted 6 lines

BTW, Chong, I'm not sure this has to do with what Jan is saying, but
looking again at XEN_SYSCTL_pcitopoinfo, it looks to me you're missing
copying nr_vcpus back up to the guest (which is actually what makes libxc knows whether all vcpus have been processed or now).

Indeed that is why the conditional makes sense there, but not here. And the copying back is already being taken care of by the caller of sched_adjust().

Indeed. So your original point was: we're always copying back, so it's fine to always update the field, with the only exception of errors having occurred. I do get it now.

Regards,
Dario

---

xen/common/domctl.c +0 -0
index 46b967e..b294221 100644
@@ -847,9 +847,14 @@ long

do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)
u_domctl)

     }
 
     case XEN_DOMCTL_scheduler_op:
+    {
         ret = sched_adjust(d, &op->u.scheduler_op);
+        if ( ret == -ERESTART )
+            ret = hypercall_create_continuation(
+                __HYPERVISOR_domctl, "h", u_domctl);
         copyback = 1;
         break;

+ }

     case XEN_DOMCTL_getdomaininfo:
     {
xen/common/sched_rt.c +0 -0
index 3f1d047..34ae48d 100644
@@ -1163,6 +1168,94 @@ rt_dom_cntl(

         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        for ( index = op->u.v.vcpu_index; index < op->u.v.nr_vcpus; index++ ) +        {
+            spin_lock_irqsave(&prv->lock, flags);
+            if ( copy_from_guest_offset(&local_sched,
+                          op->u.v.vcpus, index, 1) )
+            {
+                rc = -EFAULT;
+                spin_unlock_irqrestore(&prv->lock, flags);
+                break;
+            }
+            if ( local_sched.vcpuid >= d->max_vcpus ||
+                          d->vcpu[local_sched.vcpuid] == NULL )
+            {
+                rc = -EINVAL;
+                spin_unlock_irqrestore(&prv->lock, flags);
+                break;
+            }
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+
+            local_sched.s.rtds.budget = svc->budget / MICROSECS(1);
+            local_sched.s.rtds.period = svc->period / MICROSECS(1);
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )
+            {
+                rc = -EFAULT;
+                spin_unlock_irqrestore(&prv->lock, flags);
+                break;
+            }
+            spin_unlock_irqrestore(&prv->lock, flags);
+            if ( hypercall_preempt_check() )
+            {
+                op->u.v.vcpu_index = index + 1;
+                /* hypercall (after preemption) will continue at vcpu_index */ +                rc = -ERESTART;
+                break;
+            }
+        }
+        break;
+    case XEN_DOMCTL_SCHEDOP_putvcpuinfo:
+        for ( index = op->u.v.vcpu_index; index < op->u.v.nr_vcpus; index++ ) +        {
+            spin_lock_irqsave(&prv->lock, flags);
+            if ( copy_from_guest_offset(&local_sched,
+                          op->u.v.vcpus, index, 1) )
+            {
+                rc = -EFAULT;
+                spin_unlock_irqrestore(&prv->lock, flags);
+                break;
+            }
+            if ( local_sched.vcpuid >= d->max_vcpus ||
+                          d->vcpu[local_sched.vcpuid] == NULL )
+            {
+                rc = -EINVAL;
+                spin_unlock_irqrestore(&prv->lock, flags);
+                break;
+            }
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            period = MICROSECS(local_sched.s.rtds.period);
+            budget = MICROSECS(local_sched.s.rtds.budget);
+            if ( period > RTDS_MAX_PERIOD || budget < RTDS_MIN_BUDGET || +                          budget > period )
+            {
+                rc = -EINVAL;
+                spin_unlock_irqrestore(&prv->lock, flags);
+                break;
+            }
+
+            /*
+             * We accept period/budget less than 100 us, but will warn users about +             * the large scheduling overhead due to it
+             */
+            if ( period < MICROSECS(100) || budget < MICROSECS(100) ) +                printk("Warning: period/budget less than 100 micro-secs " +                       "results in large scheduling overhead.\n");
+
+            svc->period = period;
+            svc->budget = budget;
+            spin_unlock_irqrestore(&prv->lock, flags);
+            if ( hypercall_preempt_check() )
+            {
+                op->u.v.vcpu_index = index + 1;
+                rc = -ERESTART;
+                break;
+            }
+        }
+        break;
     }

     return rc;

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 11:34, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 18:53, <[email protected]> wrote:
Quoted 1 line · Jan Beulich

IIRC, I was looking at how XEN_SYSCTL_pcitopoinfo is handled, for reference, and that has some guest_handle_is_null()==>EINVAL sainity
checking (in xen/common/sysctl.c), which, when I thought about it, made
sense to me.

My reasoning was, sort of:
1. if the handle is NULL, no point getting into the somewhat complicated logic of the while,
2. more accurate error reporting: as being passed a NULL handler looked something we could identify and call invalid, rather
than
waiting for the copy to fault.

Quoted 7 lines
Quoted 4 lines

I think the XEN_SYSCTL_pcitopoinfo was misguided in this respect, cloning non applicable logic here which returns the number of needed (array) elements in such a case for a few other operations.

Sorry, I'm not sure I am getting: are you saying that, for _these_ domctls, we should consider the handle being NULL as a way of the caller to ask for the size of the array?

No, I've tried to point out that _when_ such behavior is intended, the special casing of a null handle is warranted. But not (normally) in other cases.

Quoted 25 lines
Quoted 12 lines
Quoted 12 lines

About the structure of the code, as said above, I do like how XEN_SYSCTL_pcitopoinfo ended up being handled, I think it is a great fit for this specific case and, comparing at both this and previous version, I do think this one is (bugs apart) looking better.

I'm sure I said this --long ago-- when discussing v4 (and maybe even
previous versions), as well as more recently, when reviewing v5, and
that's why Chong (finally! :-D) did it.

Quoted 9 lines
Quoted 3 lines

So, with the comment in place (and with bugs fixed :-)), are you (Jan)
ok with this being done this way?

Well, this _might_ be acceptable for "get" (since the caller abandoning the sequence of calls prematurely is no problem), but for "set" it looks less suitable, as similar abandoning would leave the guest in some inconsistent / unintended state.

Are you referring to the fact that, with this interface, the caller has the chance to leave intentionally, or that it may happen that not all vcpus are updated because of some bug (still in the caller)?

Quoted 5 lines

Well, if it's intentional, or even if the caller is buggy in the sense that the code is written in a way that it misses updating some vcpus (and if the interface and the behavior is well documented, as you request), then one gets what he "wants" (and, in the latter case, it wouldn't be too hard to debug and figure out the issue, I think).

Intentional or buggy doesn't matter much - if we can avoid making ourselves dependent upon user mode code behaving well, I think we should.

Quoted 4 lines

If it's for bugs (still in the caller) like copy_from_guest_offset() faulting because the array is too small, that can happen if using continuation too, can't it? And it would still leave the guest in similar inconsistent or unintended state, IMO...

True, albeit that's what error indications are for.

Quoted 8 lines

One last point. Of course, since we are talking about bugs, the final status is not the one desired, but it's not inconsistent in the sense that the guest can't continue running, or crashes, or anything like that. It's something like:
- you wants all the 32 vcpus of guest A to have these new parameters
- due to a bug, you're (for instance) passing me an array with only 16 vcpus parameters
- result: onlyt 16 vcpus will have the new parameters.

That was my understanding, yes.

Quoted 23 lines
Quoted 6 lines

The
issue with XEN_SYSCTL_pcitopoinfo was, iirc, the lack of a good way of encoding the continuation information, and while that would seem applicable here too I'm not sure now whether doing it the way it was done was the best choice.

As far as I can remember and see, it was being done by means of an additional dedicated parameter in the handle (called ti->first_dev in that case). Then at some point, you said:

http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg02623.html
"Considering this is a tools only interface, enforcing a not too high
limit on num_devs would seem better than this not really clean continuation mechanism. The (tool stack) caller(s) can be made iterate."

With which I did agree (and I still do :-)), as well as I agree on the fact that we basically are in the same situation here.

Chong tried doing things with continuations for a few rounds, including v5, which is here:
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg00817.html

Quoted 8 lines

and he also used an additional field (vcpu_index).

So, all this being said, my preference stays for the way the code looks like in this version (with all the due commenting added). Of course, it's your preference that really matters here, me not being the maintainer of this code. :-)

So, how do you prefer Chong to continue doing this?

Well, modeling this after the other sysctl makes it something I can't reasonably reject. Hence what I've been saying so far were merely suggestions, as - other than you - I'm not convinced anymore the model used there was a good one. The more that here - afaict - no extra fields would be needed: The continuation encoding would simply consist of op->u.v.nr_vcpus getting suitably decreased and op->u.v.vcpus suitably bumped.

Quoted 8 lines
Quoted 5 lines

Clearly
stating (in the public interface header) that certain normally input-only fields are volatile would allow the continuation to be handled without tool stack assistance afaict.

Which (sorry, I'm not getting again) I guess is something different/more than what was done in v5 (the relevant hunks of which I'm pasting at the bottom of this email, for convenience)?

The hunks you had included didn't cover the public interface header changes. My point here is: Generally we demand that fields in public interface structures not documented as OUT would not get modified by a hypercall. Since I'm suggesting to use both fields to encode continuation information, that rule would get violated, which therefore needs spelling out in a comment in the header.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

In reply to Chong Li

On Sun, Mar 06, 2016 at 11:55:55AM -0600, Chong Li wrote:
[...]

Quoted 4 lines
xen/common/sched_rt.c +0 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;

xen/common/sched_rt.c rt_dom_cntl( · line 1185

Quoted 10 lines
xen/common/sched_rt.c +10 -0
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;
+            break;
+        }
+        while ( index < op->u.v.nr_vcpus )
+        {
+            if ( copy_from_guest_offset(&local_sched,
+                          op->u.v.vcpus, index, 1) )

Indentation.

xen/common/sched_rt.c rt_dom_cntl( · line 1191

Quoted 6 lines
xen/common/sched_rt.c +6 -0
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( local_sched.vcpuid >= d->max_vcpus ||
+                          d->vcpu[local_sched.vcpuid] == NULL )

Ditto.

xen/common/sched_rt.c rt_dom_cntl( · line 1204

Quoted 13 lines
xen/common/sched_rt.c +13 -0
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            local_sched.s.rtds.budget = svc->budget / MICROSECS(1);
+            local_sched.s.rtds.period = svc->period / MICROSECS(1);
+            spin_unlock_irqrestore(&prv->lock, flags);
+
+            if ( __copy_to_guest_offset(op->u.v.vcpus, index,
+                    &local_sched, 1) )

Here as well.

You might want to check your editor setting. I won't point out other places that need fixing.

Quoted 39 lines
xen/common/sched_rt.c +39 -0
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( (++index > 0x3f) && hypercall_preempt_check() )
+                break;
+        }
+
+        if ( !rc && (op->u.v.nr_vcpus != index) )
+            op->u.v.nr_vcpus = index;
+        break;
+    case XEN_DOMCTL_SCHEDOP_putvcpuinfo:
+        if ( guest_handle_is_null(op->u.v.vcpus) )
+        {
+            rc = -EINVAL;
+            break;
+        }
+        while ( index < op->u.v.nr_vcpus )
+        {
+            if ( copy_from_guest_offset(&local_sched,
+                          op->u.v.vcpus, index, 1) )
+            {
+                rc = -EFAULT;
+                break;
+            }
+            if ( local_sched.vcpuid >= d->max_vcpus ||
+                          d->vcpu[local_sched.vcpuid] == NULL )
+            {
+                rc = -EINVAL;
+                break;
+            }
+
+            period = MICROSECS(local_sched.s.rtds.period);
+            budget = MICROSECS(local_sched.s.rtds.budget);
+            if ( period > RTDS_MAX_PERIOD || budget < RTDS_MIN_BUDGET ||
+                          budget > period || period < RTDS_MIN_PERIOD )
+            {
+                rc = -EINVAL;
+                break;

xen/common/sched_rt.c rt_dom_cntl( · line 1253

Quoted 10 lines
xen/common/sched_rt.c +10 -0
+            }
+
+            /*
+             * We accept period/budget less than 100 us, but will warn users about
+             * the large scheduling overhead due to it
+             */
+            if ( period < MICROSECS(100) || budget < MICROSECS(100) )
+                printk("Warning: period or budget set to less than 100us.\n"
+                       "This may result in high scheduling overhead.\n");
+

I'm not the maintainer, but I think having printk here is bad idea because the toolstack can then DoS the hypervisor.

xen/common/sched_rt.c rt_dom_cntl( · line 1259

Quoted 6 lines
xen/common/sched_rt.c +6 -0
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            svc->period = period;
+            svc->budget = budget;
+            spin_unlock_irqrestore(&prv->lock, flags);
+

And this locking pattern seems sub-optimal. You might be able to move the lock and unlock outside the while loop?

Note that I merely look at this snippet. I don't know that other constraints you have, so take what I said with a grained of salt.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 11 lines · Wei Liu

On Sun, Mar 06, 2016 at 11:55:55AM -0600, Chong Li wrote:

Quoted 6 lines

+            spin_lock_irqsave(&prv->lock, flags); +            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]); +            svc->period = period;
+            svc->budget = budget;
+            spin_unlock_irqrestore(&prv->lock, flags); +

And this locking pattern seems sub-optimal. You might be able to move the lock and unlock outside the while loop?

Yes, unless I'm missing something, that looks possible to me, and would save a lot of acquire/release ping pong on the lock.

And yet, I'm not sure doing (for large guests) batches of 64 iterations with (as of now) interrupts disabled.

I'll think about this...

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 09.03.16 at 17:10, <[email protected]> wrote:
Quoted 8 lines · Wei Liu
Quoted 6 lines · Chong Li
xen/common/sched_rt.c +6 -0
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            svc->period = period;
+            svc->budget = budget;
+            spin_unlock_irqrestore(&prv->lock, flags);
+
Quoted 5 lines
Quoted 3 lines

And this locking pattern seems sub-optimal. You might be able to move the lock and unlock outside the while loop?

Yes, unless I'm missing something, that looks possible to me, and would save a lot of acquire/release ping pong on the lock.

Well, there are guest memory accesses (which may fault) in the loop body. While this may work right now, I don't think doing so is a good idea.

Quoted 2 lines

And yet, I'm not sure doing (for large guests) batches of 64 iterations with (as of now) interrupts disabled.

This I'd be much less worried about as long as what's inside the loop body was a reasonably short code sequence.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#13 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 09.03.16 at 17:10, <[email protected]> wrote:
Quoted 11 lines · Wei Liu

xen/common/sched_rt.c rt_dom_cntl( · line 1259

Quoted 6 lines · Chong Li
xen/common/sched_rt.c +6 -0
+            spin_lock_irqsave(&prv->lock, flags);
+            svc = rt_vcpu(d->vcpu[local_sched.vcpuid]);
+            svc->period = period;
+            svc->budget = budget;
+            spin_unlock_irqrestore(&prv->lock, flags);
+

And this locking pattern seems sub-optimal. You might be able to move the lock and unlock outside the while loop?

Quoted 6 lines
Quoted 2 lines

Yes, unless I'm missing something, that looks possible to me, and would save a lot of acquire/release ping pong on the lock.

Well, there are guest memory accesses (which may fault) in the loop body. While this may work right now, I don't think doing so is a good idea.

So I still keep my design here?

Dario, Jan and Wei,

I almost finished a new version, but since this part is critical for the whole patch, let me summarize the feedbacks here. Please correct me if my understanding is wrong.

1) We don't need "guest_handle_is_null()" check, because null handle could be used in some special cases. And normally, handle is checked by copy_from(to)_guest* functions.

2) In domctl.h, add explain for nr_vcpus, because it is used in both IN and OUT ways.

3) Use printk(XENLOG_G_WARNING ...) here, because of its rate limit feature.

4) Do I still keep the spin_lock inside the loop body?

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#14 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.03.16 at 18:05, <[email protected]> wrote:

So I still keep my design here?

Dario, Jan and Wei,

Afaic:

Quoted 7 lines

I almost finished a new version, but since this part is critical for the whole patch, let me summarize the feedbacks here. Please correct me if my understanding is wrong.

1) We don't need "guest_handle_is_null()" check, because null handle could be used in some special cases. And normally, handle is checked by copy_from(to)_guest* functions.

Yes.

Quoted 2 lines

2) In domctl.h, add explain for nr_vcpus, because it is used in both IN and OUT ways.

Yes.

Quoted 1 line

3) Use printk(XENLOG_G_WARNING ...) here, because of its rate limit feature.

I'd say XENLOG_G_DEBUG, and even that only if you really think the message is useful.

Quoted 1 line

4) Do I still keep the spin_lock inside the loop body?

I think overall that's the better alternative.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#15 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 9 lines · Jan Beulich
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines · On 13.03.16 at 18:05, <[email protected]> wrote:

So I still keep my design here?

Dario, Jan and Wei,

Afaic:

I agree almost on everything too.

About this:

Quoted 5 lines
Quoted 2 lines

3) Use printk(XENLOG_G_WARNING ...) here, because of its rate limit feature.

I'd say XENLOG_G_DEBUG, and even that only if you really think the message is useful.

I think it has some value to have this in the logs. In fact, someone that ended up with small values --either by bug/chance, or in general without a specific need for them-- and is seeing performance/scheduling issues will still be able to find this.

And printing it somewhere else than in Xen is impractical (see my reply to Wei).

However, we may well print it just once, as soon as the first vcpu with potentially problematic parameters is hit, and then silence it.

Linux has things like WARN_ON_ONCE to do this:
http://lxr.free-electrons.com/source/include/asm-generic/bug.h#L109

I don't see anything like it in Xen, so you'd need to either implement it, or arrange for something with the same effect locally.

If we just print it once, I'd keep it G_WARNING.

Thanks and Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 14.03.16 at 10:10, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 13.03.16 at 18:05, <[email protected]> wrote:

About this:

Quoted 5 lines
Quoted 2 lines

3) Use printk(XENLOG_G_WARNING ...) here, because of its rate limit feature.

I'd say XENLOG_G_DEBUG, and even that only if you really think the message is useful.

I think it has some value to have this in the logs. In fact, someone that ended up with small values --either by bug/chance, or in general without a specific need for them-- and is seeing performance/scheduling issues will still be able to find this.

And printing it somewhere else than in Xen is impractical (see my reply to Wei).

Quoted 8 lines

However, we may well print it just once, as soon as the first vcpu with potentially problematic parameters is hit, and then silence it.

Linux has things like WARN_ON_ONCE to do this:
http://lxr.free-electrons.com/source/include/asm-generic/bug.h#L109

I don't see anything like it in Xen, so you'd need to either implement it, or arrange for something with the same effect locally.

One of the reasons we don't (yet) have this is because commonly (like is the case here) printing such once globally isn't really what you want - you'd much rather see it once per domain.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 14.03.16 at 10:10, <[email protected]> wrote:


I think it has some value to have this in the logs. In fact, someone
that ended up with small values --either by bug/chance, or in general
without a specific need for them-- and is seeing performance/scheduling
issues will still be able to find this.

And printing it somewhere else than in Xen is impractical (see my reply
to Wei).

However, we may well print it just once, as soon as the first vcpu with
potentially problematic parameters is hit, and then silence it.

Linux has things like WARN_ON_ONCE to do this:
http://lxr.free-electrons.com/source/include/asm-generic/bug.h#L109

Quoted 7 lines
Quoted 3 lines

I don't see anything like it in Xen, so you'd need to either implement
it, or arrange for something with the same effect locally.

One of the reasons we don't (yet) have this is because commonly (like is the case here) printing such once globally isn't really what you want - you'd much rather see it once per domain.

Ah, I did not know that was part of the reason, but it makes sense.

However, for this specific case, I was also considering that, and I agree, if possible/not to difficult to implement, once per domain would indeed be better.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#18 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 30 lines · Dario Faggioli
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 14.03.16 at 10:10, <[email protected]> wrote:

I think it has some value to have this in the logs. In fact, someone
that ended up with small values --either by bug/chance, or in general
without a specific need for them-- and is seeing performance/scheduling
issues will still be able to find this.

And printing it somewhere else than in Xen is impractical (see my reply
to Wei).

However, we may well print it just once, as soon as the first vcpu with
potentially problematic parameters is hit, and then silence it.

Linux has things like WARN_ON_ONCE to do this:
http://lxr.free-electrons.com/source/include/asm-generic/bug.h#L109

Quoted 7 lines
Quoted 3 lines

I don't see anything like it in Xen, so you'd need to either implement
it, or arrange for something with the same effect locally.

One of the reasons we don't (yet) have this is because commonly (like is the case here) printing such once globally isn't really what you want - you'd much rather see it once per domain.

Quoted 6 lines

Ah, I did not know that was part of the reason, but it makes sense.

However, for this specific case, I was also considering that, and I agree, if possible/not to difficult to implement, once per domain would indeed be better.

It is easy to implement a global "warn_on_once".

To implement a per-domain "warn_on_once", I may need a hash table (name it as "dom_warned"), and dom_warned[domid] returns true or false.
I don't know if hash table is supported in Xen. Or do we have any list structure which is very good at searching?

Another way is to add a "bool" field in struct domain, but I don't think that would be a good design.

Any ideas?

Thanks,
Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#19 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 10 lines · Chong Li
Quoted 6 lines · Dario Faggioli


However, for this specific case, I was also considering that, and I agree, if possible/not to difficult to implement, once per domain would
indeed be better.

It is easy to implement a global "warn_on_once".

Sure.

Quoted 7 lines

To implement a per-domain "warn_on_once", I may need a hash table (name it as "dom_warned"), and dom_warned[domid] returns true or false.
I don't know if hash table is supported in Xen. Or do we have any list
structure which is very good at searching?

And all this just for having _this_ specific warning printed once per domain.

No, I don't think it is worth... Or maybe it is, but I don't think it's fair to ask you to do it. Or maybe, if you're up for doing it, then you're free to, but I don't think it's fair to ask for it as prerequisite for this patch. :-)

Quoted 3 lines

Another way is to add a "bool" field in struct domain, but I don't think that would be a good design.

Yeah, I like it even less. :-/

We said 'once' and then 'once per domain', but something I'd be fine with (coupled with keeping G_WARNING) would be 'once per operation'. Basically, if a domain has 128 vcpus, and an hypercall tries to set all of them to period=100, budget=50, we just print the warning once. Then, if after a while the sysadmin tries the same again, we again just log once, etc.

Doing this seems much easier, as the 'warned' flag could just be a local variable of the hypercall implementation. I'm quite sure that would work if there is not any continuation/re-issueing mechanism in the hypercall in question. BUT in our case there is, so things may be more complicated... :-/

Had you thought about a solution like this already? If no, can you see whether there is a nice and easy way to make something like what I just described above to work in our case?

If we find nothing, we'll think at alternatives, including killing the waning.

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#20 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 18 lines · Dario Faggioli
Quoted 3 lines · Chong Li
Quoted 1 line · Dario Faggioli

We said 'once' and then 'once per domain', but something I'd be fine with (coupled with keeping G_WARNING) would be 'once per operation'. Basically, if a domain has 128 vcpus, and an hypercall tries to set all of them to period=100, budget=50, we just print the warning once. Then, if after a while the sysadmin tries the same again, we again just log once, etc.

Doing this seems much easier, as the 'warned' flag could just be a local variable of the hypercall implementation. I'm quite sure that would work if there is not any continuation/re-issueing mechanism in the hypercall in question. BUT in our case there is, so things may be more complicated... :-/

Quoted 4 lines

Had you thought about a solution like this already? If no, can you see whether there is a nice and easy way to make something like what I just described above to work in our case?

How about:

We create a global variable in sched_rt.c:
/* This variable holds its value through hyerpcall re-issueing.
* When finding vcpu settings with too low budget or period (e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are printed
until this variable

     * becomes false.
     */
    static bool warned;

Initialize it as "false" in rt_init().
In your example,
we "warned = true" when we find the first vcpu has budget less than 100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-issueing */
        warned = false;

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#21 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 35 lines · Chong Li
Quoted 18 lines · Dario Faggioli
Quoted 3 lines · Chong Li
Quoted 1 line · Dario Faggioli

We said 'once' and then 'once per domain', but something I'd be fine with (coupled with keeping G_WARNING) would be 'once per operation'. Basically, if a domain has 128 vcpus, and an hypercall tries to set all of them to period=100, budget=50, we just print the warning once. Then, if after a while the sysadmin tries the same again, we again just log once, etc.

Doing this seems much easier, as the 'warned' flag could just be a local variable of the hypercall implementation. I'm quite sure that would work if there is not any continuation/re-issueing mechanism in the hypercall in question. BUT in our case there is, so things may be more complicated... :-/

Quoted 4 lines

Had you thought about a solution like this already? If no, can you see whether there is a nice and easy way to make something like what I just described above to work in our case?

How about:

We create a global variable in sched_rt.c:
/* This variable holds its value through hyerpcall re-issueing.
* When finding vcpu settings with too low budget or period (e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are printed
until this variable

     * becomes false.
     */
    static bool warned;
Quoted 8 lines

Initialize it as "false" in rt_init().
In your example,
we "warned = true" when we find the first vcpu has budget less than 100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-issueing */
        warned = false;

Hi Chong,

I don't think creating a global variable just for the warning thing is a better idea. Even if we do want such a variable, it should only occur in rt_dom_cntl() function, since it is only used in rt_dom_cntl().
Global variable should be used "globally", isn't it. ;-)

Thanks,

Meng
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#22 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 44 lines · Meng Xu
Quoted 35 lines · Chong Li
Quoted 18 lines · Dario Faggioli
Quoted 3 lines · Chong Li
Quoted 1 line · Dario Faggioli

We said 'once' and then 'once per domain', but something I'd be fine with (coupled with keeping G_WARNING) would be 'once per operation'. Basically, if a domain has 128 vcpus, and an hypercall tries to set all of them to period=100, budget=50, we just print the warning once. Then, if after a while the sysadmin tries the same again, we again just log once, etc.

Doing this seems much easier, as the 'warned' flag could just be a local variable of the hypercall implementation. I'm quite sure that would work if there is not any continuation/re-issueing mechanism in the hypercall in question. BUT in our case there is, so things may be more complicated... :-/

Quoted 4 lines

Had you thought about a solution like this already? If no, can you see whether there is a nice and easy way to make something like what I just described above to work in our case?

How about:

We create a global variable in sched_rt.c:
/* This variable holds its value through hyerpcall re-issueing.
* When finding vcpu settings with too low budget or period (e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are printed
until this variable

     * becomes false.
     */
    static bool warned;
Quoted 8 lines

Initialize it as "false" in rt_init().
In your example,
we "warned = true" when we find the first vcpu has budget less than 100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-issueing */
        warned = false;
Quoted 8 lines

Hi Chong,

I don't think creating a global variable just for the warning thing is a better idea. Even if we do want such a variable, it should only occur in rt_dom_cntl() function, since it is only used in rt_dom_cntl().
Global variable should be used "globally", isn't it. ;-)

You're right.

If we define

static bool warned;

at the beginning of rt_dom_cntl(), do we need to initialize it? If without initialization, I think its default value is "false", which is just what we need.

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#23 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 55 lines · Chong Li
Quoted 44 lines · Meng Xu
Quoted 35 lines · Chong Li
Quoted 18 lines · Dario Faggioli
Quoted 3 lines · Chong Li
Quoted 1 line · Dario Faggioli

We said 'once' and then 'once per domain', but something I'd be fine with (coupled with keeping G_WARNING) would be 'once per operation'. Basically, if a domain has 128 vcpus, and an hypercall tries to set all of them to period=100, budget=50, we just print the warning once. Then, if after a while the sysadmin tries the same again, we again just log once, etc.

Doing this seems much easier, as the 'warned' flag could just be a local variable of the hypercall implementation. I'm quite sure that would work if there is not any continuation/re-issueing mechanism in the hypercall in question. BUT in our case there is, so things may be more complicated... :-/

Quoted 4 lines

Had you thought about a solution like this already? If no, can you see whether there is a nice and easy way to make something like what I just described above to work in our case?

How about:

We create a global variable in sched_rt.c:
/* This variable holds its value through hyerpcall re-issueing.
* When finding vcpu settings with too low budget or period (e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are printed
until this variable

     * becomes false.
     */
    static bool warned;
Quoted 8 lines

Initialize it as "false" in rt_init().
In your example,
we "warned = true" when we find the first vcpu has budget less than 100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-issueing */
        warned = false;
Quoted 8 lines

Hi Chong,

I don't think creating a global variable just for the warning thing is a better idea. Even if we do want such a variable, it should only occur in rt_dom_cntl() function, since it is only used in rt_dom_cntl().
Global variable should be used "globally", isn't it. ;-)

You're right.

Quoted 8 lines

If we define

   static bool warned;

at the beginning of rt_dom_cntl(), do we need to initialize it? If without initialization, I think its default value is "false", which is just what we need.

We need initializing any variable we are going to use, of course. We should not reply on the compiler to give an initialized value. :-)

Meng

Signature · 10 lines
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#24 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 32 lines · Meng Xu
Quoted 30 lines · Chong Li
Quoted 24 lines
Quoted 15 lines

How about:

We create a global variable in sched_rt.c:
    /* This variable holds its value through hyerpcall re- issueing.
     * When finding vcpu settings with too low budget or period (e.g,
100 us), we print a warning
     * and set this variable "true". No more warnings are printed
until this variable
     * becomes false.
     */
    static bool warned;
Initialize it as "false" in rt_init().

Quoted 9 lines

In your example,
we "warned = true" when we find the first vcpu has budget less than
100 us. Outside
of the while loop, we do:
    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re- issueing */
        warned = false;

Quoted 2 lines


If we define

   static bool warned;

Quoted 8 lines
Quoted 5 lines

at the beginning of rt_dom_cntl(), do we need to initialize it? If without
initialization, I think its default value is "false", which is just what we need.

We need initializing any variable we are going to use, of course. We should not reply on the compiler to give an initialized value. :-)

We need to initialize any variable that would be used uninitialized, if we don't initialize it. :-)

However, something along the line of a static variable was also what I was thinking to, but I don't think it works sufficiently well for justifying it being introduced. And making things work well is proving to be too hard to keep bothering.

Reasons why I'm saying I don't think it works well are that: (a) there may be more than one CPU executing this hypercall, and they'd race on the value of the static flag; (b) what if the hypercall finishes processing the first lot of 64 vCPUs with the flag set to false, are we sure it can't be anything than "still false", when the new hypercal, for the next lot of vCPUs of the same domain, is re-issued?

I continue to think that it could be useful to have this logged, but I'm leaning toward just killing it for now (and maybe finding another way to check and warn about the same thing or one of the effects it produces, later).

Meng, what do you think?

Quoted 2 lines

Meng

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#25 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 56 lines · Dario Faggioli
Quoted 32 lines · Meng Xu
Quoted 30 lines · Chong Li
Quoted 16 lines
Quoted 16 lines

How about:

We create a global variable in sched_rt.c:

    /* This variable holds its value through hyerpcall re-

issueing.
* When finding vcpu settings with too low budget or period
(e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are
printed
until this variable

     * becomes false.
     */
    static bool warned;

Initialize it as "false" in rt_init().
In your example,

Quoted 10 lines
Quoted 8 lines

we "warned = true" when we find the first vcpu has budget less than
100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-
issueing */
        warned = false;

If we define

   static bool warned;
Quoted 8 lines
Quoted 5 lines

at the beginning of rt_dom_cntl(), do we need to initialize it? If without
initialization, I think its default value is "false", which is just what we need.

We need initializing any variable we are going to use, of course. We should not reply on the compiler to give an initialized value. :-)

We need to initialize any variable that would be used uninitialized, if we don't initialize it. :-)

However, something along the line of a static variable was also what I was thinking to, but I don't think it works sufficiently well for justifying it being introduced. And making things work well is proving to be too hard to keep bothering.

Reasons why I'm saying I don't think it works well are that: (a) there may be more than one CPU executing this hypercall, and they'd race on the value of the static flag; (b) what if the hypercall finishes processing the first lot of 64 vCPUs with the flag set to false, are we sure it can't be anything than "still false", when the new hypercal, for the next lot of vCPUs of the same domain, is re-issued?

Quoted 6 lines

I continue to think that it could be useful to have this logged, but I'm leaning toward just killing it for now (and maybe finding another way to check and warn about the same thing or one of the effects it produces, later).

Meng, what do you think?

I'm thinking about if it may not be worthwhile *for now only* to provide such information with so much effort and the danger of introducing more serious issues.

Right, race condition occurs on the global variable and I believe we don't want to encounter this race condition.
So let's just not use the global variable.

We should definitely put a large warning in the wiki for the RTDS scheduler about the parameter settings. Incorrect setting should never crash system but may lead to poor real-time performance users want.

Once this patch is done, I will modify the wiki then. (Chong, could you remind me if I happen to forget?)

Thanks,

Meng

-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#26 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 73 lines · Meng Xu
Quoted 56 lines · Dario Faggioli
Quoted 32 lines · Meng Xu
Quoted 30 lines · Chong Li
Quoted 16 lines
Quoted 16 lines

How about:

We create a global variable in sched_rt.c:

    /* This variable holds its value through hyerpcall re-

issueing.
* When finding vcpu settings with too low budget or period
(e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are
printed
until this variable

     * becomes false.
     */
    static bool warned;

Initialize it as "false" in rt_init().
In your example,

Quoted 10 lines
Quoted 8 lines

we "warned = true" when we find the first vcpu has budget less than
100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-
issueing */
        warned = false;

If we define

   static bool warned;
Quoted 8 lines
Quoted 5 lines

at the beginning of rt_dom_cntl(), do we need to initialize it? If without
initialization, I think its default value is "false", which is just what we need.

We need initializing any variable we are going to use, of course. We should not reply on the compiler to give an initialized value. :-)

We need to initialize any variable that would be used uninitialized, if we don't initialize it. :-)

However, something along the line of a static variable was also what I was thinking to, but I don't think it works sufficiently well for justifying it being introduced. And making things work well is proving to be too hard to keep bothering.

Reasons why I'm saying I don't think it works well are that: (a) there may be more than one CPU executing this hypercall, and they'd race on the value of the static flag; (b) what if the hypercall finishes processing the first lot of 64 vCPUs with the flag set to false, are we sure it can't be anything than "still false", when the new hypercal, for the next lot of vCPUs of the same domain, is re-issued?

Quoted 6 lines

I continue to think that it could be useful to have this logged, but I'm leaning toward just killing it for now (and maybe finding another way to check and warn about the same thing or one of the effects it produces, later).

Meng, what do you think?

I'm thinking about if it may not be worthwhile *for now only* to provide such information with so much effort and the danger of introducing more serious issues.

Right, race condition occurs on the global variable and I believe we don't want to encounter this race condition.
So let's just not use the global variable.

Quoted 7 lines

We should definitely put a large warning in the wiki for the RTDS scheduler about the parameter settings. Incorrect setting should never crash system but may lead to poor real-time performance users want.

Once this patch is done, I will modify the wiki then. (Chong, could you remind me if I happen to forget?)

Sure, I'll.

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#27 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

In reply to Meng Xu
Quoted 10 lines · Meng Xu
Quoted 8 lines · Dario Faggioli


I continue to think that it could be useful to have this logged, but
I'm leaning toward just killing it for now (and maybe finding another
way to check and warn about the same thing or one of the effects it produces, later).

Quoted 5 lines
Quoted 1 line

Meng, what do you think?

I'm thinking about if it may not be worthwhile *for now only* to provide such information with so much effort and the danger of introducing more serious issues.

Yeah, exactly what I was also saying.

Quoted 4 lines

Right, race condition occurs on the global variable and I believe we don't want to encounter this race condition.
So let's just not use the global variable.

Well, it would just affect the logging itself. But then, why clobber the (clarity of the) code for introducing proper per-domain logging, and ending up with something that may not actually be per-domain.. that's how I was thinking at it.

Quoted 5 lines

We should definitely put a large warning in the wiki for the RTDS scheduler about the parameter settings. Incorrect setting should never
crash system but may lead to poor real-time performance users want.

For example, one way of dealing with this would be to allow the user/sysadmin to set what the minimum budget and period they want to be able to use would be, by means of SYSCTLs.

We kind of like have a static and a dynamic limit. The former, hardcoded in Xen, to something that we know is unreasonable on any hardware platform available at that time. The latter, we can set to a rather conservative high value by default, but let users that wants to lower it, do that... and there is where we can print all the warnings we want!

I'm just tossing this out there, though, and this is certainly something that can come as future work.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#28 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

In reply to Dario Faggioli
Quoted 56 lines · Dario Faggioli
Quoted 32 lines · Meng Xu
Quoted 30 lines · Chong Li
Quoted 16 lines
Quoted 16 lines

How about:

We create a global variable in sched_rt.c:

    /* This variable holds its value through hyerpcall re-

issueing.
* When finding vcpu settings with too low budget or period
(e.g,
100 us), we print a warning
* and set this variable "true". No more warnings are
printed
until this variable

     * becomes false.
     */
    static bool warned;

Initialize it as "false" in rt_init().
In your example,

Quoted 10 lines
Quoted 8 lines

we "warned = true" when we find the first vcpu has budget less than
100 us. Outside
of the while loop, we do:

    if ( index == op->u.v.nr_vcpus ) /* no more hypercall re-
issueing */
        warned = false;

If we define

   static bool warned;
Quoted 8 lines
Quoted 5 lines

at the beginning of rt_dom_cntl(), do we need to initialize it? If without
initialization, I think its default value is "false", which is just what we need.

We need initializing any variable we are going to use, of course. We should not reply on the compiler to give an initialized value. :-)

We need to initialize any variable that would be used uninitialized, if we don't initialize it. :-)

However, something along the line of a static variable was also what I was thinking to, but I don't think it works sufficiently well for justifying it being introduced. And making things work well is proving to be too hard to keep bothering.

Reasons why I'm saying I don't think it works well are that: (a) there may be more than one CPU executing this hypercall, and they'd race on the value of the static flag; (b) what if the hypercall finishes processing the first lot of 64 vCPUs with the flag set to false, are we sure it can't be anything than "still false", when the new hypercal, for the next lot of vCPUs of the same domain, is re-issued?

Quoted 5 lines

I continue to think that it could be useful to have this logged, but I'm leaning toward just killing it for now (and maybe finding another way to check and warn about the same thing or one of the effects it produces, later).

By "killing it", do you mean we don't do this check nor print the warning? Or just
print the warning globally once?

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#29 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 10 lines · Chong Li
Quoted 8 lines · Dario Faggioli


I continue to think that it could be useful to have this logged, but
I'm leaning toward just killing it for now (and maybe finding another
way to check and warn about the same thing or one of the effects it produces, later).

Quoted 4 lines

By "killing it", do you mean we don't do this check nor print the warning? Or just
print the warning globally once?

Remove the warning (and, of course, the check as well! :-)).

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#30 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

In reply to Meng Xu
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 16.03.16 at 04:43, <[email protected]> wrote:
Quoted 4 lines · Chong Li

If we define

   static bool warned;
Quoted 7 lines
Quoted 4 lines

at the beginning of rt_dom_cntl(), do we need to initialize it? If without initialization, I think its default value is "false", which is just what we need.

We need initializing any variable we are going to use, of course. We should not reply on the compiler to give an initialized value. :-)

Relying on implicit initialization where the language standard requires such is more than just optional - if I see code changes with an explicit zero initializer of a static variable, I always reply back stating that the initializer is pointless.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#31 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

In reply to Wei Liu
Quoted 31 lines · Wei Liu

On Sun, Mar 06, 2016 at 11:55:55AM -0600, Chong Li wrote:
[...]

Quoted 14 lines
xen/common/sched_rt.c +9 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
 
+
+            period = MICROSECS(local_sched.s.rtds.period);
+            budget = MICROSECS(local_sched.s.rtds.budget);
+            if ( period > RTDS_MAX_PERIOD || budget < RTDS_MIN_BUDGET ||
+                          budget > period || period < RTDS_MIN_PERIOD )
+            {
+                rc = -EINVAL;
+                break;

xen/common/sched_rt.c rt_dom_cntl( · line 1195

Quoted 10 lines
xen/common/sched_rt.c +10 -0
+            }
+
+            /*
+             * We accept period/budget less than 100 us, but will warn users about
+             * the large scheduling overhead due to it
+             */
+            if ( period < MICROSECS(100) || budget < MICROSECS(100) )
+                printk("Warning: period or budget set to less than 100us.\n"
+                       "This may result in high scheduling overhead.\n");
+

I'm not the maintainer, but I think having printk here is bad idea because the toolstack can then DoS the hypervisor.

Quoted 1 line

Wei.

So what function should I use here? I see many LOG() calls in libxl, but I'm not sure whether that can be used here.

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#32 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 32 lines · Chong Li
Quoted 31 lines · Wei Liu

On Sun, Mar 06, 2016 at 11:55:55AM -0600, Chong Li wrote:
[...]

Quoted 14 lines
xen/common/sched_rt.c +9 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(
         }
         spin_unlock_irqrestore(&prv->lock, flags);
         break;
+    case XEN_DOMCTL_SCHEDOP_getvcpuinfo:
 
+
+            period = MICROSECS(local_sched.s.rtds.period);
+            budget = MICROSECS(local_sched.s.rtds.budget);
+            if ( period > RTDS_MAX_PERIOD || budget < RTDS_MIN_BUDGET ||
+                          budget > period || period < RTDS_MIN_PERIOD )
+            {
+                rc = -EINVAL;
+                break;

xen/common/sched_rt.c rt_dom_cntl( · line 1195

Quoted 10 lines
xen/common/sched_rt.c +10 -0
+            }
+
+            /*
+             * We accept period/budget less than 100 us, but will warn users about
+             * the large scheduling overhead due to it
+             */
+            if ( period < MICROSECS(100) || budget < MICROSECS(100) )
+                printk("Warning: period or budget set to less than 100us.\n"
+                       "This may result in high scheduling overhead.\n");
+

I'm not the maintainer, but I think having printk here is bad idea because the toolstack can then DoS the hypervisor.

Quoted 5 lines
Quoted 1 line

Wei.

So what function should I use here? I see many LOG() calls in libxl, but I'm not sure whether that can be used here.

IMHO you just don't log anything here. System administrator probably won't see it anyway.

If you think this warning is really necessary, move it to xl.

Wei.

Quoted 7 lines

Chong

Signature · 3 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#33 lore raw

Re: [PATCH v6 for Xen 4.7 1/4] xen: enable per-VCPU parameter settings for RTDS scheduler

Quoted 23 lines · Wei Liu
Quoted 22 lines · Chong Li
Quoted 20 lines · Wei Liu
Quoted 6 lines
(quoted diff) +0 -0
@@ -1163,6 +1173,96 @@ rt_dom_cntl(


+            /*
+             * We accept period/budget less than 100 us, but will warn users about
+             * the large scheduling overhead due to it

Quoted 8 lines

+             */
+            if ( period < MICROSECS(100) || budget < MICROSECS(100) )
+                printk("Warning: period or budget set to less than 100us.\n"
+                       "This may result in high scheduling overhead.\n");
+

I'm not the maintainer, but I think having printk here is bad idea
because the toolstack can then DoS the hypervisor.

Wei.

Quoted 9 lines
Quoted 4 lines

So what function should I use here? I see many LOG() calls in libxl,
but I'm not sure whether that can be used here.

IMHO you just don't log anything here. System administrator probably won't see it anyway.

If you think this warning is really necessary, move it to xl.

I do think it adds some value to have this. Moving the printing outside of Xen would need exporting a symbol for the minimum budget/period that we think are best chosen, but:
 - this is really an implementation details, that can (potentially) vary between different architectures, and change with future Xen version;
 - it would mean to keep the hypervisor and tools symbols in sync.

So, as I'm saying in another reply in this thread, I'd use a guest, rate-limited, logging variant, and print it only once, as countermeasure to log spamming problem.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#34 lore raw

PATCH v6 2/4 libxc: enable per-VCPU parameter settings for RTDS scheduler

In reply to Chong Li

Add xc_sched_rtds_vcpu_get/set functions to interact with Xen to get/set a domain's per-VCPU parameters.

---
Changes on PATCH v5:
1) In xc_sched_rtds_vcpu_get/set, re-issueing the hypercall if it is preempted.

Changes on PATCH v4:
1) Minor modifications on the function parameters.

Changes on PATCH v2:
1) Minor modifications due to the change of struct xen_domctl_scheduler_op.

---
 tools/libxc/include/xenctrl.h | 16 +++++++---
 tools/libxc/xc_rt.c           | 68 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 4 deletions(-)
tools/libxc/include/xenctrl.h +12 -4
index 01a6dda..9462271 100644
@@ -888,11 +888,19 @@ int xc_sched_credit2_domain_get(xc_interface *xch,
                                struct xen_domctl_sched_credit2 *sdom);
 
 int xc_sched_rtds_domain_set(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);
 int xc_sched_rtds_domain_get(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);
+int xc_sched_rtds_vcpu_set(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
+int xc_sched_rtds_vcpu_get(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
 
 int
 xc_sched_arinc653_schedule_set(
tools/libxc/xc_rt.c +68 -0

71 lines not on this page · raw message

Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#35 lore raw

Re: [PATCH v6 for Xen 4.7 2/4] libxc: enable per-VCPU parameter settings for RTDS scheduler

Quoted 36 lines · Chong Li

Add xc_sched_rtds_vcpu_get/set functions to interact with Xen to get/set a domain's per-VCPU parameters.

---
Changes on PATCH v5:
1) In xc_sched_rtds_vcpu_get/set, re-issueing the hypercall if it is preempted.

Changes on PATCH v4:
1) Minor modifications on the function parameters.

Changes on PATCH v2:
1) Minor modifications due to the change of struct xen_domctl_scheduler_op.

---
 tools/libxc/include/xenctrl.h | 16 +++++++---
 tools/libxc/xc_rt.c           | 68 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 4 deletions(-)
tools/libxc/include/xenctrl.h +0 -0
index 01a6dda..9462271 100644
@@ -888,11 +888,19 @@ int xc_sched_credit2_domain_get(xc_interface *xch,
                                struct xen_domctl_sched_credit2 *sdom);
 

tools/libxc/include/xenctrl.h int xc_sched_credit2_domain_get(xc_interface *xch, · line 895

Quoted 10 lines
tools/libxc/include/xenctrl.h +4 -4
 int xc_sched_rtds_domain_set(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);
 int xc_sched_rtds_domain_get(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);

Please don't mix fixing indentation with new functionality. Besides, the new indentation looks wrong.

tools/libxc/include/xenctrl.h int xc_sched_credit2_domain_get(xc_interface *xch, · line 904

Quoted 9 lines
tools/libxc/include/xenctrl.h +8 -0
+int xc_sched_rtds_vcpu_set(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
+int xc_sched_rtds_vcpu_get(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
 

Indentation also looks wrong. Maybe you used tab? Please use spaces instead.

tools/libxc/xc_rt.c int xc_sched_rtds_domain_get(xc_interface *xch, · line 65

Quoted 11 lines
tools/libxc/include/xenctrl.h +0 -0
 int
 xc_sched_arinc653_schedule_set(
tools/libxc/xc_rt.c +1 -0
index d59e5ce..4be9624 100644
@@ -62,3 +62,71 @@ int xc_sched_rtds_domain_get(xc_interface *xch,
 
     return rc;
 }
+

I only skim the rest but it looks sensible.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#36 lore raw

Re: [PATCH v6 for Xen 4.7 2/4] libxc: enable per-VCPU parameter settings for RTDS scheduler

Quoted 51 lines · Wei Liu
Quoted 36 lines · Chong Li

Add xc_sched_rtds_vcpu_get/set functions to interact with Xen to get/set a domain's per-VCPU parameters.

---
Changes on PATCH v5:
1) In xc_sched_rtds_vcpu_get/set, re-issueing the hypercall if it is preempted.

Changes on PATCH v4:
1) Minor modifications on the function parameters.

Changes on PATCH v2:
1) Minor modifications due to the change of struct xen_domctl_scheduler_op.

---
 tools/libxc/include/xenctrl.h | 16 +++++++---
 tools/libxc/xc_rt.c           | 68 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 4 deletions(-)
tools/libxc/include/xenctrl.h +0 -0
index 01a6dda..9462271 100644
@@ -888,11 +888,19 @@ int xc_sched_credit2_domain_get(xc_interface *xch,
                                struct xen_domctl_sched_credit2 *sdom);
 

tools/libxc/include/xenctrl.h int xc_sched_credit2_domain_get(xc_interface *xch, · line 895

Quoted 10 lines
tools/libxc/include/xenctrl.h +4 -4
 int xc_sched_rtds_domain_set(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);
 int xc_sched_rtds_domain_get(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);

Please don't mix fixing indentation with new functionality. Besides, the new indentation looks wrong.

Quoted 13 lines

tools/libxc/include/xenctrl.h int xc_sched_credit2_domain_get(xc_interface *xch, · line 904

Quoted 9 lines
tools/libxc/include/xenctrl.h +8 -0
+int xc_sched_rtds_vcpu_set(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
+int xc_sched_rtds_vcpu_get(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
 

Indentation also looks wrong. Maybe you used tab? Please use spaces instead.

I'm not using tab. This is just what I'm confused with. The indentation for these
four *rtds* functions is the same as the two *credit2* functions above. I can not
find the indentation rules for function calls with many / long parameters.

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#37 lore raw

Re: [PATCH v6 for Xen 4.7 2/4] libxc: enable per-VCPU parameter settings for RTDS scheduler

Quoted 65 lines · Chong Li
Quoted 51 lines · Wei Liu
Quoted 36 lines · Chong Li

Add xc_sched_rtds_vcpu_get/set functions to interact with Xen to get/set a domain's per-VCPU parameters.

---
Changes on PATCH v5:
1) In xc_sched_rtds_vcpu_get/set, re-issueing the hypercall if it is preempted.

Changes on PATCH v4:
1) Minor modifications on the function parameters.

Changes on PATCH v2:
1) Minor modifications due to the change of struct xen_domctl_scheduler_op.

---
 tools/libxc/include/xenctrl.h | 16 +++++++---
 tools/libxc/xc_rt.c           | 68 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 4 deletions(-)
tools/libxc/include/xenctrl.h +0 -0
index 01a6dda..9462271 100644
@@ -888,11 +888,19 @@ int xc_sched_credit2_domain_get(xc_interface *xch,
                                struct xen_domctl_sched_credit2 *sdom);
 

tools/libxc/include/xenctrl.h int xc_sched_credit2_domain_get(xc_interface *xch, · line 895

Quoted 10 lines
tools/libxc/include/xenctrl.h +4 -4
 int xc_sched_rtds_domain_set(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);
 int xc_sched_rtds_domain_get(xc_interface *xch,
-                            uint32_t domid,
-                            struct xen_domctl_sched_rtds *sdom);
+                               uint32_t domid,
+                               struct xen_domctl_sched_rtds *sdom);

Please don't mix fixing indentation with new functionality. Besides, the new indentation looks wrong.

Quoted 13 lines

tools/libxc/include/xenctrl.h int xc_sched_credit2_domain_get(xc_interface *xch, · line 904

Quoted 9 lines
tools/libxc/include/xenctrl.h +8 -0
+int xc_sched_rtds_vcpu_set(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
+int xc_sched_rtds_vcpu_get(xc_interface *xch,
+                               uint32_t domid,
+                               struct xen_domctl_schedparam_vcpu *vcpus,
+                               uint32_t num_vcpus);
 

Indentation also looks wrong. Maybe you used tab? Please use spaces instead.

Quoted 6 lines

I'm not using tab. This is just what I'm confused with. The indentation for these
four *rtds* functions is the same as the two *credit2* functions above. I can not
find the indentation rules for function calls with many / long parameters.

Use white space and stay aligned with previous line wherever you can. So:

int xc_sched_rtds_vcpu_get(xc_interface *xch,

                           uint32_t domid,
                           struct xen_domctl_schedparam_vcpu *vcpus,
                           uint32_t num_vcpus);

I know there is inconsistency in the code base. I'm sorry it makes you feel confused.

Wei.

Quoted 6 lines

Chong

Signature · 3 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#38 lore raw

PATCH v6 3/4 libxl: enable per-VCPU parameter settings for RTDS scheduler

In reply to Chong Li

Add libxl_vcpu_sched_params_get/set and sched_rtds_vcpu_get/set functions to support per-VCPU settings.

---
Changes on PATCH v5:
1) Add a seperate function, sched_rtds_vcpus_params_set_all(), to set the parameters of all vcpus of a domain.

2) Add libxl_vcpu_sched_params_set_all() to invoke the above function.

3) Coding style changes. (I didn't find the indentation rules for function calls with long parameters (still 4 spaces?), so I just imitated the indentation style of some existing functions)

Changes on PATCH v4:
1) Coding style changes

Changes on PATCH v3:
1) Add sanity check on vcpuid

2) Add comments on per-domain and per-vcpu functions for libxl users

Changes on PATCH v2:
1) New data structure (libxl_vcpu_sched_params and libxl_sched_params) to help per-VCPU settings.

2) sched_rtds_vcpu_get now can return a random subset of the parameters of the VCPUs of a specific domain.

---
 tools/libxl/libxl.c         | 326 ++++++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl.h         |  37 +++++
 tools/libxl/libxl_types.idl |  14 ++
 3 files changed, 354 insertions(+), 23 deletions(-)
tools/libxl/libxl.c +303 -23
index bd3aac8..4532e86 100644
@@ -5770,6 +5770,207 @@ static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+static int sched_rtds_validate_params(libxl__gc *gc, int period,
+                                    int budget, uint32_t *sdom_period,
+                                    uint32_t *sdom_budget)
+{
+    int rc = 0;
+    if (period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
+        if (period < 1) {
+            LOG(ERROR, "VCPU period is out of range, "
+                       "valid values are larger than or equal to 1");
+            rc = ERROR_INVAL; /* error scheduling parameter */
+            goto out;
+        }
+        *sdom_period = period;
+    }
+
+    if (budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
+        if (budget < 1) {
+            LOG(ERROR, "VCPU budget is not set or out of range, "
+                       "valid values are larger than or equal to 1");
+            rc = ERROR_INVAL;
+            goto out;
+        }
+        *sdom_budget = budget;
+    }
+
+    if (*sdom_budget > *sdom_period) {
+        LOG(ERROR, "VCPU budget must be smaller than "
+                   "or equal to VCPU period");
+        rc = ERROR_INVAL;
+    }
+out:
+    return rc;
+}
+
+/* Get the RTDS scheduling parameters of vcpu(s) */
+static int sched_rtds_vcpu_get(libxl__gc *gc, uint32_t domid,
+                               libxl_vcpu_sched_params *scinfo)
+{
+    uint32_t num_vcpus;
+    int i, r, rc;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    num_vcpus = scinfo->num_vcpus ? scinfo->num_vcpus :
+                                info.max_vcpu_id + 1;
+
+    GCNEW_ARRAY(vcpus, num_vcpus);
+
+    if (scinfo->num_vcpus > 0) {
+        for (i = 0; i < num_vcpus; i++) {
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > info.max_vcpu_id) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           info.max_vcpu_id);
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+        }
+    } else
+        for (i = 0; i < num_vcpus; i++)
+            vcpus[i].vcpuid = i;
+
+    r = xc_sched_rtds_vcpu_get(CTX->xch, domid, vcpus, num_vcpus);
+    if (r != 0) {
+        LOGE(ERROR, "getting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    scinfo->sched = LIBXL_SCHEDULER_RTDS;
+    if (scinfo->num_vcpus == 0) {
+        scinfo->num_vcpus = num_vcpus;
+        scinfo->vcpus = libxl__calloc(NOGC, num_vcpus,
+                                sizeof(libxl_sched_params));
+    }
+    for(i = 0; i < num_vcpus; i++) {
+        scinfo->vcpus[i].period = vcpus[i].s.rtds.period;
+        scinfo->vcpus[i].budget = vcpus[i].s.rtds.budget;
+        scinfo->vcpus[i].vcpuid = vcpus[i].vcpuid;
+    }
+return r;
+out:
+    return rc;
+}
+
+/* Set the RTDS scheduling parameters of vcpu(s) */
+static int sched_rtds_vcpus_params_set(libxl__gc *gc, uint32_t domid,
+                               const libxl_vcpu_sched_params *scinfo)
+{
+    int r, rc;
+    int i;
+    uint16_t max_vcpuid;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+    uint32_t num_vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    max_vcpuid = info.max_vcpu_id;
+
+    if (scinfo->num_vcpus > 0) {
+        num_vcpus = scinfo->num_vcpus;
+        GCNEW_ARRAY(vcpus, num_vcpus);
+        for (i = 0; i < num_vcpus; i++) {
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > max_vcpuid) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           max_vcpuid);
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+
+            rc = sched_rtds_validate_params(gc,
+                    scinfo->vcpus[i].period, scinfo->vcpus[i].budget,
+                    &vcpus[i].s.rtds.period, &vcpus[i].s.rtds.budget);
+            if (rc) {
+                rc = ERROR_INVAL;
+                goto out;
+            }
+        }
+    } else {
+        rc = ERROR_INVAL;
+        goto out;
+    }
+
+    r = xc_sched_rtds_vcpu_set(CTX->xch, domid,
+        vcpus, num_vcpus);
+    if (r != 0) {
+        LOGE(ERROR, "setting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+return r;
+out:
+    return rc;
+}
+
+/* Set the RTDS scheduling parameters of all vcpus of a domain */
+static int sched_rtds_vcpus_params_set_all(libxl__gc *gc, uint32_t domid,
+                               const libxl_vcpu_sched_params *scinfo)
+{
+    int r, rc;
+    int i;
+    uint16_t max_vcpuid;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+    uint32_t num_vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    max_vcpuid = info.max_vcpu_id;
+
+    if (scinfo->num_vcpus == 1) {
+        num_vcpus = max_vcpuid + 1;
+        GCNEW_ARRAY(vcpus, num_vcpus);
+        if (sched_rtds_validate_params(gc, scinfo->vcpus[0].period,
+            scinfo->vcpus[0].budget, &vcpus[0].s.rtds.period,
+            &vcpus[0].s.rtds.budget)) {
+            rc = ERROR_INVAL;
+            goto out;
+        }
+        for (i = 0; i < num_vcpus; i++) {
+            vcpus[i].vcpuid = i;
+            vcpus[i].s.rtds.period = scinfo->vcpus[0].period;
+            vcpus[i].s.rtds.budget = scinfo->vcpus[0].budget;
+        }
+    } else {
+        rc = ERROR_INVAL;
+        goto out;
+    }
+
+    r = xc_sched_rtds_vcpu_set(CTX->xch, domid,
+        vcpus, num_vcpus);
+    if (r != 0) {
+        LOGE(ERROR, "setting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+return r;
+out:
+    return rc;
+}
+
 static int sched_rtds_domain_get(libxl__gc *gc, uint32_t domid,
                                libxl_domain_sched_params *scinfo)
 {
@@ -5802,30 +6003,9 @@ static int sched_rtds_domain_set(libxl__gc *gc, uint32_t domid,
         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;
-        }
-        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;
-    }
-
-    if (sdom.budget > sdom.period) {
-        LOG(ERROR, "VCPU budget is larger than VCPU period, "
-                   "VCPU budget should be no larger than VCPU period");
+    if (sched_rtds_validate_params(gc, scinfo->period, scinfo->budget,
+                             &sdom.period, &sdom.budget))
         return ERROR_INVAL;
-    }
 
     rc = xc_sched_rtds_domain_set(CTX->xch, domid, &sdom);
     if (rc < 0) {
@@ -5873,6 +6053,74 @@ int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
     return ret;
 }
 
+int libxl_vcpu_sched_params_set(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *scinfo)
+{
+    GC_INIT(ctx);
+    libxl_scheduler sched = scinfo->sched;
+    int rc;
+
+    if (sched == LIBXL_SCHEDULER_UNKNOWN)
+        sched = libxl__domain_scheduler(gc, domid);
+
+    switch (sched) {
+    case LIBXL_SCHEDULER_SEDF:
+        LOG(ERROR, "SEDF scheduler no longer available");
+        rc = ERROR_FEATURE_REMOVED;
+        break;
+    case LIBXL_SCHEDULER_CREDIT:
+    case LIBXL_SCHEDULER_CREDIT2:
+    case LIBXL_SCHEDULER_ARINC653:
+        LOG(ERROR, "per-VCPU parameter setting not supported for this scheduler");
+        rc = ERROR_INVAL;
+        break;
+    case LIBXL_SCHEDULER_RTDS:
+        rc = sched_rtds_vcpus_params_set(gc, domid, scinfo);
+        break;
+    default:
+        LOG(ERROR, "Unknown scheduler");
+        rc = ERROR_INVAL;
+        break;
+    }
+
+    GC_FREE;
+    return rc;
+}
+
+int libxl_vcpu_sched_params_set_all(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *scinfo)
+{
+    GC_INIT(ctx);
+    libxl_scheduler sched = scinfo->sched;
+    int rc;
+
+    if (sched == LIBXL_SCHEDULER_UNKNOWN)
+        sched = libxl__domain_scheduler(gc, domid);
+
+    switch (sched) {
+    case LIBXL_SCHEDULER_SEDF:
+        LOG(ERROR, "SEDF scheduler no longer available");
+        rc = ERROR_FEATURE_REMOVED;
+        break;
+    case LIBXL_SCHEDULER_CREDIT:
+    case LIBXL_SCHEDULER_CREDIT2:
+    case LIBXL_SCHEDULER_ARINC653:
+        LOG(ERROR, "per-VCPU parameter setting not supported for this scheduler");
+        rc = ERROR_INVAL;
+        break;
+    case LIBXL_SCHEDULER_RTDS:
+        rc = sched_rtds_vcpus_params_set_all(gc, domid, scinfo);
+        break;
+    default:
+        LOG(ERROR, "Unknown scheduler");
+        rc = ERROR_INVAL;
+        break;
+    }
+
+    GC_FREE;
+    return rc;
+}
+
 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                   libxl_domain_sched_params *scinfo)
 {
@@ -5907,6 +6155,38 @@ int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
     return ret;
 }
 
+int libxl_vcpu_sched_params_get(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_vcpu_sched_params *scinfo)
+{
+    GC_INIT(ctx);
+    int rc;
+
+    scinfo->sched = libxl__domain_scheduler(gc, domid);
+
+    switch (scinfo->sched) {
+    case LIBXL_SCHEDULER_SEDF:
+        LOG(ERROR, "SEDF scheduler is no longer available");
+        rc = ERROR_FEATURE_REMOVED;
+        break;
+    case LIBXL_SCHEDULER_CREDIT:
+    case LIBXL_SCHEDULER_CREDIT2:
+    case LIBXL_SCHEDULER_ARINC653:
+        LOG(ERROR, "per-VCPU parameter getting not supported for this scheduler");
+        rc = ERROR_INVAL;
+        break;
+    case LIBXL_SCHEDULER_RTDS:
+        rc = sched_rtds_vcpu_get(gc, domid, scinfo);
+        break;
+    default:
+        LOG(ERROR, "Unknown scheduler");
+        rc = ERROR_INVAL;
+        break;
+    }
+
+    GC_FREE;
+    return rc;
+}
+
 static int libxl__domain_s3_resume(libxl__gc *gc, int domid)
 {
     int rc = 0;
tools/libxl/libxl.h +37 -0
index 6b73848..f1d53d8 100644
@@ -206,6 +206,17 @@
 #define LIBXL_HAVE_DEVICE_MODEL_USER 1
 
 /*
+ * libxl_vcpu_sched_params is used to store per-vcpu params.
+ */
+#define LIBXL_HAVE_VCPU_SCHED_PARAMS 1
+
+/*
+ * LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS indicates RTDS scheduler
+ * now supports per-vcpu settings.
+ */
+#define LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS 1
+
+/*
  * libxl_domain_build_info has the arm.gic_version field.
  */
 #define LIBXL_HAVE_BUILDINFO_ARM_GIC_VERSION 1
@@ -1647,11 +1658,37 @@ 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
 
+/* Per-VCPU parameters*/
+#define LIBXL_SCHED_PARAM_VCPU_INDEX_DEFAULT   -1
+
+/* Get the per-domain scheduling parameters.
+ * For schedulers that support per-vcpu settings (e.g., RTDS),
+ * calling *_domain_get functions will get default scheduling
+ * parameters.
+ */
 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                   libxl_domain_sched_params *params);
+
+/* Set the per-domain scheduling parameters.
+ * For schedulers that support per-vcpu settings (e.g., RTDS),
+ * calling *_domain_set functions will set all vcpus with the same
+ * scheduling parameters.
+ */
 int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
                                   const libxl_domain_sched_params *params);
 
+/* Get the per-vcpu scheduling parameters */
+int libxl_vcpu_sched_params_get(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_vcpu_sched_params *params);
+
+/* Set the per-vcpu scheduling parameters */
+int libxl_vcpu_sched_params_set(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *params);
+
+/* Set the per-vcpu scheduling parameters of all vcpus of a domain*/
+int libxl_vcpu_sched_params_set_all(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *params);
+
 int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
                        libxl_trigger trigger, uint32_t vcpuid);
 int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
tools/libxl/libxl_types.idl +14 -0
index cf3730f..7487fc9 100644
@@ -378,6 +378,20 @@ libxl_domain_restore_params = Struct("domain_restore_params", [
     ("stream_version", uint32, {'init_val': '1'}),
     ])
 
+libxl_sched_params = Struct("sched_params",[
+    ("vcpuid",       integer, {'init_val': 'LIBXL_SCHED_PARAM_VCPU_INDEX_DEFAULT'}),
+    ("weight",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
+    ("cap",          integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_CAP_DEFAULT'}),
+    ("period",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT'}),
+    ("extratime",    integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT'}),
+    ("budget",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
+    ])
+
+libxl_vcpu_sched_params = Struct("vcpu_sched_params",[
+    ("sched",        libxl_scheduler),
+    ("vcpus",        Array(libxl_sched_params, "num_vcpus")),
+    ])
+
 libxl_domain_sched_params = Struct("domain_sched_params",[
     ("sched",        libxl_scheduler),
     ("weight",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#39 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

On Sun, Mar 06, 2016 at 11:55:57AM -0600, Chong Li wrote:
[...]

Quoted 10 lines
 tools/libxl/libxl.c         | 326 ++++++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl.h         |  37 +++++
 tools/libxl/libxl_types.idl |  14 ++
 3 files changed, 354 insertions(+), 23 deletions(-)
tools/libxl/libxl.c +0 -0
index bd3aac8..4532e86 100644

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5775

Quoted 6 lines
tools/libxl/libxl.c +3 -0
@@ -5770,6 +5770,207 @@ static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+static int sched_rtds_validate_params(libxl__gc *gc, int period,
+                                    int budget, uint32_t *sdom_period,
+                                    uint32_t *sdom_budget)

Indentation.

Quoted 17 lines
tools/libxl/libxl.c +17 -0
+{
+    int rc = 0;
+    if (period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
+        if (period < 1) {
+            LOG(ERROR, "VCPU period is out of range, "
+                       "valid values are larger than or equal to 1");
+            rc = ERROR_INVAL; /* error scheduling parameter */
+            goto out;
+        }
+        *sdom_period = period;
+    }
+
+    if (budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
+        if (budget < 1) {
+            LOG(ERROR, "VCPU budget is not set or out of range, "
+                       "valid values are larger than or equal to 1");
+            rc = ERROR_INVAL;

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5802

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+            goto out;
+        }
+        *sdom_budget = budget;
+    }
+
+    if (*sdom_budget > *sdom_period) {
+        LOG(ERROR, "VCPU budget must be smaller than "
+                   "or equal to VCPU period");
+        rc = ERROR_INVAL;
+    }

This is a strange pattern. It does more than what it's name suggests.

It seems this function just returns the vanilla values in period and budget. It can be simplified by removing sdom_period and sdom_budget all together. Do you agree?

Then at callsites you set those values with two direct assignment:

   if (validate(period_value, budget_value) != 0) {
       error;
   }
   period = period_value;
   budget = budget_value;
Quoted 49 lines
tools/libxl/libxl.c +49 -0
+out:
+    return rc;
+}
+
+/* Get the RTDS scheduling parameters of vcpu(s) */
+static int sched_rtds_vcpu_get(libxl__gc *gc, uint32_t domid,
+                               libxl_vcpu_sched_params *scinfo)
+{
+    uint32_t num_vcpus;
+    int i, r, rc;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    num_vcpus = scinfo->num_vcpus ? scinfo->num_vcpus :
+                                info.max_vcpu_id + 1;
+
+    GCNEW_ARRAY(vcpus, num_vcpus);
+
+    if (scinfo->num_vcpus > 0) {
+        for (i = 0; i < num_vcpus; i++) {
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > info.max_vcpu_id) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           info.max_vcpu_id);
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+        }
+    } else
+        for (i = 0; i < num_vcpus; i++)
+            vcpus[i].vcpuid = i;
+
+    r = xc_sched_rtds_vcpu_get(CTX->xch, domid, vcpus, num_vcpus);
+    if (r != 0) {
+        LOGE(ERROR, "getting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    scinfo->sched = LIBXL_SCHEDULER_RTDS;
+    if (scinfo->num_vcpus == 0) {

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5861

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        scinfo->num_vcpus = num_vcpus;
+        scinfo->vcpus = libxl__calloc(NOGC, num_vcpus,
+                                sizeof(libxl_sched_params));
+    }
+    for(i = 0; i < num_vcpus; i++) {
+        scinfo->vcpus[i].period = vcpus[i].s.rtds.period;
+        scinfo->vcpus[i].budget = vcpus[i].s.rtds.budget;
+        scinfo->vcpus[i].vcpuid = vcpus[i].vcpuid;
+    }
+return r;

Just set rc = 0 here?

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5868

Quoted 7 lines
tools/libxl/libxl.c +7 -0
+out:
+    return rc;
+}
+
+/* Set the RTDS scheduling parameters of vcpu(s) */
+static int sched_rtds_vcpus_params_set(libxl__gc *gc, uint32_t domid,
+                               const libxl_vcpu_sched_params *scinfo)

If this is indentation that you're not sure about. Just leave it like this.

Quoted 20 lines
tools/libxl/libxl.c +20 -0
+{
+    int r, rc;
+    int i;
+    uint16_t max_vcpuid;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+    uint32_t num_vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    max_vcpuid = info.max_vcpu_id;
+
+    if (scinfo->num_vcpus > 0) {
+        num_vcpus = scinfo->num_vcpus;
+        GCNEW_ARRAY(vcpus, num_vcpus);
+        for (i = 0; i < num_vcpus; i++) {

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5898

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > max_vcpuid) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           max_vcpuid);
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+

I would suggest you use a separate loop to validate the input, otherwise you risk getting input partial success.

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5910

Quoted 12 lines
tools/libxl/libxl.c +12 -0
+            rc = sched_rtds_validate_params(gc,
+                    scinfo->vcpus[i].period, scinfo->vcpus[i].budget,
+                    &vcpus[i].s.rtds.period, &vcpus[i].s.rtds.budget);
+            if (rc) {
+                rc = ERROR_INVAL;
+                goto out;
+            }
+        }
+    } else {
+        rc = ERROR_INVAL;
+        goto out;
+    }

The above hunk would be better if you write it like:

    if (scinfo->num_vcpus <= 0) {
        rc = ERROR_INVAL;
        goto out;
    }

    /* ... The other branch follows. No indentation needed. */
    num_vcpus = ...

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5913

Quoted 3 lines
tools/libxl/libxl.c +3 -0
+
+    r = xc_sched_rtds_vcpu_set(CTX->xch, domid,
+        vcpus, num_vcpus);

Indentation.

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5919

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    if (r != 0) {
+        LOGE(ERROR, "setting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+return r;

Use rc = 0 is better.

Quoted 32 lines
tools/libxl/libxl.c +32 -0
+out:
+    return rc;
+}
+
+/* Set the RTDS scheduling parameters of all vcpus of a domain */
+static int sched_rtds_vcpus_params_set_all(libxl__gc *gc, uint32_t domid,
+                               const libxl_vcpu_sched_params *scinfo)
+{
+    int r, rc;
+    int i;
+    uint16_t max_vcpuid;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+    uint32_t num_vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    max_vcpuid = info.max_vcpu_id;
+
+    if (scinfo->num_vcpus == 1) {
+        num_vcpus = max_vcpuid + 1;
+        GCNEW_ARRAY(vcpus, num_vcpus);
+        if (sched_rtds_validate_params(gc, scinfo->vcpus[0].period,
+            scinfo->vcpus[0].budget, &vcpus[0].s.rtds.period,
+            &vcpus[0].s.rtds.budget)) {
+            rc = ERROR_INVAL;
+            goto out;
+        }

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5961

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        for (i = 0; i < num_vcpus; i++) {
+            vcpus[i].vcpuid = i;
+            vcpus[i].s.rtds.period = scinfo->vcpus[0].period;
+            vcpus[i].s.rtds.budget = scinfo->vcpus[0].budget;
+        }
+    } else {
+        rc = ERROR_INVAL;
+        goto out;
+    }
+

Same here, just move the else branch up.

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5963

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+    r = xc_sched_rtds_vcpu_set(CTX->xch, domid,
+        vcpus, num_vcpus);

Indentation.

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5919

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    if (r != 0) {
+        LOGE(ERROR, "setting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+return r;

rc = 0;

Quoted 41 lines
tools/libxl/libxl.c +6 -23
+out:
+    return rc;
+}
+
 static int sched_rtds_domain_get(libxl__gc *gc, uint32_t domid,
                                libxl_domain_sched_params *scinfo)
 {
@@ -5802,30 +6003,9 @@ static int sched_rtds_domain_set(libxl__gc *gc, uint32_t domid,
         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;
-        }
-        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;
-    }
-
-    if (sdom.budget > sdom.period) {
-        LOG(ERROR, "VCPU budget is larger than VCPU period, "
-                   "VCPU budget should be no larger than VCPU period");
+    if (sched_rtds_validate_params(gc, scinfo->period, scinfo->budget,
+                             &sdom.period, &sdom.budget))
         return ERROR_INVAL;
-    }
 
     rc = xc_sched_rtds_domain_set(CTX->xch, domid, &sdom);
     if (rc < 0) {

tools/libxl/libxl.c int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid, · line 6057

Quoted 5 lines
tools/libxl/libxl.c +2 -0
@@ -5873,6 +6053,74 @@ int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
     return ret;
 }
 
+int libxl_vcpu_sched_params_set(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *scinfo)

Indentation.

Quoted 31 lines
tools/libxl/libxl.c +31 -0
+{
+    GC_INIT(ctx);
+    libxl_scheduler sched = scinfo->sched;
+    int rc;
+
+    if (sched == LIBXL_SCHEDULER_UNKNOWN)
+        sched = libxl__domain_scheduler(gc, domid);
+
+    switch (sched) {
+    case LIBXL_SCHEDULER_SEDF:
+        LOG(ERROR, "SEDF scheduler no longer available");
+        rc = ERROR_FEATURE_REMOVED;
+        break;
+    case LIBXL_SCHEDULER_CREDIT:
+    case LIBXL_SCHEDULER_CREDIT2:
+    case LIBXL_SCHEDULER_ARINC653:
+        LOG(ERROR, "per-VCPU parameter setting not supported for this scheduler");
+        rc = ERROR_INVAL;
+        break;
+    case LIBXL_SCHEDULER_RTDS:
+        rc = sched_rtds_vcpus_params_set(gc, domid, scinfo);
+        break;
+    default:
+        LOG(ERROR, "Unknown scheduler");
+        rc = ERROR_INVAL;
+        break;
+    }
+
+    GC_FREE;
+    return rc;
+}

[...]

Quoted 75 lines

static int libxl__domain_s3_resume(libxl__gc *gc, int domid)

 {
     int rc = 0;
tools/libxl/libxl.h +37 -0
index 6b73848..f1d53d8 100644
@@ -206,6 +206,17 @@
 #define LIBXL_HAVE_DEVICE_MODEL_USER 1
 
 /*
+ * libxl_vcpu_sched_params is used to store per-vcpu params.
+ */
+#define LIBXL_HAVE_VCPU_SCHED_PARAMS 1
+
+/*
+ * LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS indicates RTDS scheduler
+ * now supports per-vcpu settings.
+ */
+#define LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS 1
+
+/*
  * libxl_domain_build_info has the arm.gic_version field.
  */
 #define LIBXL_HAVE_BUILDINFO_ARM_GIC_VERSION 1
@@ -1647,11 +1658,37 @@ 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
 
+/* Per-VCPU parameters*/
+#define LIBXL_SCHED_PARAM_VCPU_INDEX_DEFAULT   -1
+
+/* Get the per-domain scheduling parameters.
+ * For schedulers that support per-vcpu settings (e.g., RTDS),
+ * calling *_domain_get functions will get default scheduling
+ * parameters.
+ */
 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                   libxl_domain_sched_params *params);
+
+/* Set the per-domain scheduling parameters.
+ * For schedulers that support per-vcpu settings (e.g., RTDS),
+ * calling *_domain_set functions will set all vcpus with the same
+ * scheduling parameters.
+ */
 int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
                                   const libxl_domain_sched_params *params);
 
+/* Get the per-vcpu scheduling parameters */
+int libxl_vcpu_sched_params_get(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_vcpu_sched_params *params);
+
+/* Set the per-vcpu scheduling parameters */
+int libxl_vcpu_sched_params_set(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *params);
+
+/* Set the per-vcpu scheduling parameters of all vcpus of a domain*/
+int libxl_vcpu_sched_params_set_all(libxl_ctx *ctx, uint32_t domid,
+                                  const libxl_vcpu_sched_params *params);
+
 int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
                        libxl_trigger trigger, uint32_t vcpuid);
 int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
tools/libxl/libxl_types.idl +4 -0
index cf3730f..7487fc9 100644
@@ -378,6 +378,20 @@ libxl_domain_restore_params = Struct("domain_restore_params", [
     ("stream_version", uint32, {'init_val': '1'}),
     ])
 
+libxl_sched_params = Struct("sched_params",[
+    ("vcpuid",       integer, {'init_val': 'LIBXL_SCHED_PARAM_VCPU_INDEX_DEFAULT'}),
+    ("weight",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
+    ("cap",          integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_CAP_DEFAULT'}),

tools/libxl/libxl_types.idl libxl_domain_restore_params = Struct("domain_restore_params", [ · line 394

Quoted 10 lines
tools/libxl/libxl_types.idl +10 -0
+    ("period",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT'}),
+    ("extratime",    integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT'}),
+    ("budget",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
+    ])
+
+libxl_vcpu_sched_params = Struct("vcpu_sched_params",[
+    ("sched",        libxl_scheduler),
+    ("vcpus",        Array(libxl_sched_params, "num_vcpus")),
+    ])
+

IIRC Dario and you have come to agreement on the data structure so I skim this.

Overall I think the patch is moving towards the right direction. Just that there are too many places where indentation need fixing. Please fix them in the next iteration. I really don't like holding back patches just because of indentation issues. Depending on the editor you use, there might be some common runes that we can give you.

If you feel unclear about my comments, just ask for clarification.

Wei.

Quoted 6 lines
tools/libxl/libxl_types.idl +0 -0
 libxl_domain_sched_params = Struct("domain_sched_params",[
     ("sched",        libxl_scheduler),
     ("weight",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
Signature · 1 line
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#40 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

Quoted 22 lines · Wei Liu

On Sun, Mar 06, 2016 at 11:55:57AM -0600, Chong Li wrote:
[...]

Quoted 10 lines
 tools/libxl/libxl.c         | 326 ++++++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl.h         |  37 +++++
 tools/libxl/libxl_types.idl |  14 ++
 3 files changed, 354 insertions(+), 23 deletions(-)
tools/libxl/libxl.c +0 -0
index bd3aac8..4532e86 100644

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5775

Quoted 6 lines
tools/libxl/libxl.c +3 -0
@@ -5770,6 +5770,207 @@ static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+static int sched_rtds_validate_params(libxl__gc *gc, int period,
+                                    int budget, uint32_t *sdom_period,
+                                    uint32_t *sdom_budget)

This is a strange pattern. It does more than what it's name suggests.

Quoted 3 lines

It seems this function just returns the vanilla values in period and budget. It can be simplified by removing sdom_period and sdom_budget all together. Do you agree?

Yes.

Quoted 50 lines
Quoted 50 lines
tools/libxl/libxl.c +50 -0
+
+/* Get the RTDS scheduling parameters of vcpu(s) */
+static int sched_rtds_vcpu_get(libxl__gc *gc, uint32_t domid,
+                               libxl_vcpu_sched_params *scinfo)
+{
+    uint32_t num_vcpus;
+    int i, r, rc;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    num_vcpus = scinfo->num_vcpus ? scinfo->num_vcpus :
+                                info.max_vcpu_id + 1;
+
+    GCNEW_ARRAY(vcpus, num_vcpus);
+
+    if (scinfo->num_vcpus > 0) {
+        for (i = 0; i < num_vcpus; i++) {
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > info.max_vcpu_id) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           info.max_vcpu_id);
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+        }
+    } else
+        for (i = 0; i < num_vcpus; i++)
+            vcpus[i].vcpuid = i;
+
+    r = xc_sched_rtds_vcpu_get(CTX->xch, domid, vcpus, num_vcpus);
+    if (r != 0) {
+        LOGE(ERROR, "getting vcpu sched rtds");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    scinfo->sched = LIBXL_SCHEDULER_RTDS;
+    if (scinfo->num_vcpus == 0) {
+        scinfo->num_vcpus = num_vcpus;
+        scinfo->vcpus = libxl__calloc(NOGC, num_vcpus,
+                                sizeof(libxl_sched_params));
+    }
Quoted 8 lines

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5861

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    for(i = 0; i < num_vcpus; i++) {
+        scinfo->vcpus[i].period = vcpus[i].s.rtds.period;
+        scinfo->vcpus[i].budget = vcpus[i].s.rtds.budget;
+        scinfo->vcpus[i].vcpuid = vcpus[i].vcpuid;
+    }
+return r;

Just set rc = 0 here?

Ok.

Quoted 33 lines
Quoted 33 lines
tools/libxl/libxl.c +32 -0
+out:
+    return rc;
+}
+
+/* Set the RTDS scheduling parameters of vcpu(s) */
+static int sched_rtds_vcpus_params_set(libxl__gc *gc, uint32_t domid,
+                               const libxl_vcpu_sched_params *scinfo)
+{
+    int r, rc;
+    int i;
+    uint16_t max_vcpuid;
+    xc_dominfo_t info;
+    struct xen_domctl_schedparam_vcpu *vcpus;
+    uint32_t num_vcpus;
+
+    r = xc_domain_getinfo(CTX->xch, domid, 1, &info);
+    if (r < 0) {
+        LOGE(ERROR, "getting domain info");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    max_vcpuid = info.max_vcpu_id;
+
+    if (scinfo->num_vcpus > 0) {
+        num_vcpus = scinfo->num_vcpus;
+        GCNEW_ARRAY(vcpus, num_vcpus);
+        for (i = 0; i < num_vcpus; i++) {
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > max_vcpuid) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           max_vcpuid);
Quoted 8 lines

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5843

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+

I would suggest you use a separate loop to validate the input, otherwise you risk getting input partial success.

What do you mean by "partial success"?
Do you suggest to validate the entire input first, and then create && set the vcpus array?

Quoted 14 lines

tools/libxl/libxl.c static int sched_credit2_domain_set(libxl__gc *gc, uint32_t domid, · line 5910

Quoted 13 lines
tools/libxl/libxl.c +12 -0
+            rc = sched_rtds_validate_params(gc,
+                    scinfo->vcpus[i].period, scinfo->vcpus[i].budget,
+                    &vcpus[i].s.rtds.period, &vcpus[i].s.rtds.budget);
+            if (rc) {
+                rc = ERROR_INVAL;
+                goto out;
+            }
+        }
+    } else {
+        rc = ERROR_INVAL;
+        goto out;
+    }

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#41 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

Quoted 15 lines · Chong Li
Quoted 15 lines
Quoted 14 lines
tools/libxl/libxl.c +14 -0
+    if (scinfo->num_vcpus > 0) {
+        num_vcpus = scinfo->num_vcpus;
+        GCNEW_ARRAY(vcpus, num_vcpus);
+        for (i = 0; i < num_vcpus; i++) {
+            if (scinfo->vcpus[i].vcpuid < 0 ||
+                scinfo->vcpus[i].vcpuid > max_vcpuid) {
+                LOG(ERROR, "VCPU index is out of range, "
+                           "valid values are within range from 0 to %d",
+                           max_vcpuid);
+                rc = ERROR_INVAL;
+                goto out;
+            }
+            vcpus[i].vcpuid = scinfo->vcpus[i].vcpuid;
+
Quoted 4 lines
Quoted 2 lines

I would suggest you use a separate loop to validate the input, otherwise you risk getting input partial success.

What do you mean by "partial success"?

You discover error half way through the array. All vcpus before the error occurs would have been set to new parameters.

Quoted 3 lines

Do you suggest to validate the entire input first, and then create && set the vcpus array?

Yes.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#42 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

In reply to Wei Liu
Quoted 2 lines · Wei Liu

Overall I think the patch is moving towards the right direction.

I also think so. Thanks a lot Wei for the review, BTW.

Quoted 6 lines

Just
that there are too many places where indentation need fixing.  Please fix them in the next iteration. I really don't like holding back patches
just because of indentation issues.

Exactly. Trying to elaborate a bit more, this series does not include any complex algorithm or similar, so one may thing that it is not that hard to review. But it is indeed complex and hard to review, because the patches are rather big and because the API and the command line syntax we want to support is complex.

If there are too many style issue, any review will likely end up focusing mostly, if not only, on them, for various reasons. E.g., when one finds a stile issue, avoiding commenting on it (e.g., because one wants to focus on "more important" aspects) means risking forgetting about it and, in the end, letting it hit the repository (if others also miss it or does the same). Also, we're all used to look at code that (well, mostly :-D) conforms to coding style, so it's harder to focus on code that does not. And more.

Add to this that the most difficult part of the tools side of this series (like API and data structures) is actually ok.

So, Chong, for us to be able to quickly and effectively help you forward, we need to ask you to do your best and get rid of (ideally) all coding style problems.

Once that's done, we're not far from calling this all a done deal. :-)

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#43 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

Quoted 30 lines · Dario Faggioli
Quoted 2 lines · Wei Liu

Overall I think the patch is moving towards the right direction.

I also think so. Thanks a lot Wei for the review, BTW.

Quoted 6 lines

Just
that there are too many places where indentation need fixing. Please fix them in the next iteration. I really don't like holding back patches
just because of indentation issues.

Exactly. Trying to elaborate a bit more, this series does not include any complex algorithm or similar, so one may thing that it is not that hard to review. But it is indeed complex and hard to review, because the patches are rather big and because the API and the command line syntax we want to support is complex.

If there are too many style issue, any review will likely end up focusing mostly, if not only, on them, for various reasons. E.g., when one finds a stile issue, avoiding commenting on it (e.g., because one wants to focus on "more important" aspects) means risking forgetting about it and, in the end, letting it hit the repository (if others also miss it or does the same). Also, we're all used to look at code that (well, mostly :-D) conforms to coding style, so it's harder to focus on code that does not. And more.

Add to this that the most difficult part of the tools side of this series (like API and data structures) is actually ok.

Quoted 8 lines

So, Chong, for us to be able to quickly and effectively help you forward, we need to ask you to do your best and get rid of (ideally) all coding style problems.

Once that's done, we're not far from calling this all a done deal. :-)

Thanks and Regards,
Dario

Wei and Dario, thanks for your help reviewing this post. I'm now working on the coding style issues and will send out the next version when
all problems are figured out.

Chong

Quoted 6 lines

--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#44 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

In reply to Chong Li

On the whole series, you are Cc-ing [email protected], which is no longer a tools maintainer.

Please, double check by looking at MAINTAINERS and/or with ./scripts/get_maintainer.pl.

While fiddling with the Cc-list, can you please try to arrange things in such a way that each person is Cc-ed only to the subset of the series that he would reasonably care about.

For instance, Jan is likely not going to look at libxl and xl stuff, so no need bothering him with that. Similarly, IanJ wouldn't probably look at hypervisor stuff.

If you are in doubt, stick to MAINTAINERS, with the exception that, if some random person commented on vX, he should be Cc-ed to vX+1, where the comments are addressed, no matter what he/she maintains.

There are other exceptions, actually. For example, it's ok to Cc me to the whole series. This is hard to "set in stone", so again, if in doubt, follow the rule above... If people are interested in a patch that they happen not to be Cc-ed to, they'll find it via the mailing list.

Quoted 9 lines · Chong Li

tools/libxl/libxl.c +0 -0
index bd3aac8..4532e86 100644
@@ -5770,6 +5770,207 @@ static int sched_credit2_domain_set(libxl__gc
 *gc, uint32_t domid,
      return 0;
  }
Quoted 8 lines


+static int sched_rtds_validate_params(libxl__gc *gc, int period, +                                    int budget, uint32_t *sdom_period,
+                                    uint32_t *sdom_budget) +{
+    int rc = 0;

Empty line here (between local variables and code).

Also, libxl coding style says:

  * If the function is to return a libxl error value, `rc' is used to contain the error code, but it is NOT initialised:
            int rc;

This, in addition to all what Wei pointed out, to mean that, although things are certainly improving, some non negligible amount of coding style issues needs fixing.

(I'll elaborate more, and more in general, in another email.)

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#45 lore raw

Re: [PATCH v6 for Xen 4.7 3/4] libxl: enable per-VCPU parameter settings for RTDS scheduler

Quoted 15 lines · Dario Faggioli

While fiddling with the Cc-list, can you please try to arrange things in such a way that each person is Cc-ed only to the subset of the series that he would reasonably care about.

For instance, Jan is likely not going to look at libxl and xl stuff, so
no need bothering him with that. Similarly, IanJ wouldn't probably look
at hypervisor stuff.

If you are in doubt, stick to MAINTAINERS, with the exception that, if
some random person commented on vX, he should be Cc-ed to vX+1, where the comments are addressed, no matter what he/she maintains.

Quoted 7 lines

There are other exceptions, actually. For example, it's ok to Cc me to
the whole series. This is hard to "set in stone", so again, if in doubt, follow the rule above... If people are interested in a patch that they happen not to be Cc-ed to, they'll find it via the mailing list.

To be fair, you are actually doing this already, and it was me that had the wrong impression that you weren't.

So, good work with that, and sorry (you and everyone else) for the noise on this. :-)

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#46 lore raw

PATCH v6 4/4 xl: enable per-VCPU parameter settings for RTDS scheduler

In reply to Chong Li

Change main_sched_rtds and related output functions to support per-VCPU settings.

---
Changes on PATCH v5:
1) Add sched_vcpu_set_all() for the cases that all vcpus of a domain need to be changed together.

Changes on PATCH v4:
1) Coding style changes

Changes on PATCH v3:
1) Support commands, e.g., "xl sched-rtds -d vm1" to output the default scheduling parameters

Changes on PATCH v2:
1) Remove per-domain output functions for RTDS scheduler.

2) Users now use '-v all' to specify all VCPUs.

3) Support outputting a subset of the parameters of the VCPUs of a specific domain.

4) When setting all VCPUs with the same parameters (by only one command), no per-domain function is invoked.

---
 docs/man/xl.pod.1         |   4 +
 tools/libxl/xl_cmdimpl.c  | 292 ++++++++++++++++++++++++++++++++++++++++------
 tools/libxl/xl_cmdtable.c |  10 +-
 3 files changed, 269 insertions(+), 37 deletions(-)
docs/man/xl.pod.1 +4 -0
index 4279c7c..f9ff917 100644
@@ -1051,6 +1051,10 @@ B<OPTIONS>
 Specify domain for which scheduler parameters are to be modified or retrieved.
 Mandatory for modifying scheduler parameters.
 
+=item B<-v VCPUID/all>, B<--vcpuid=VCPUID/all>
+
+Specify vcpu for which scheduler parameters are to be modified or retrieved.
+
 =item B<-p PERIOD>, B<--period=PERIOD>
 
 Period of time, in microseconds, over which to replenish the budget.
tools/libxl/xl_cmdimpl.c +259 -33

354 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +6 -4
index fdc1ac6..c68b656 100644
@@ -268,10 +268,12 @@ struct cmd_spec cmd_table[] = {
     { "sched-rtds",
       &main_sched_rtds, 0, 1,
       "Get/set rtds scheduler parameters",
-      "[-d <Domain> [-p[=PERIOD]] [-b[=BUDGET]]]",
-      "-d DOMAIN, --domain=DOMAIN     Domain to modify\n"
-      "-p PERIOD, --period=PERIOD     Period (us)\n"
-      "-b BUDGET, --budget=BUDGET     Budget (us)\n"
+      "[-d <Domain> [-v[=VCPUID]] [-p[=PERIOD]] [-b[=BUDGET]]]",
+      "-d DOMAIN, --domain=DOMAIN 	Domain to modify\n"
+      "-v VCPUID/all, --vcpuid=VCPUID/all    VCPU to modify or output;\n"
+      "                               Using '-v all' to modify/output all vcpus\n"
+      "-p PERIOD, --period=PERIOD 	Period (us)\n"
+      "-b BUDGET, --budget=BUDGET 	Budget (us)\n"
     },
     { "domid",
       &main_domid, 0, 0,
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#47 lore raw

Re: [PATCH v6 for Xen 4.7 4/4] xl: enable per-VCPU parameter settings for RTDS scheduler

On Sun, Mar 06, 2016 at 11:55:58AM -0600, Chong Li wrote:
[...]

Quoted 56 lines
tools/libxl/xl_cmdimpl.c +27 -6
@@ -6222,77 +6359,166 @@ 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 v_size = 1; /* size of vcpus array */
+    int p_size = 1; /* size of periods array */
+    int b_size = 1; /* size of budgets array */
+    int v_index = 0; /* index in vcpus array */
+    int p_index =0; /* index in periods array */
+    int b_index =0; /* index for in budgets array */
     bool opt_p = false;
     bool opt_b = false;
-    int opt, rc;
+    bool opt_v = false;
+    bool opt_all = false; /* output per-dom parameters */
+    int opt, i;
+    int rc = 0;
     static struct option opts[] = {
         {"domain", 1, 0, 'd'},
         {"period", 1, 0, 'p'},
         {"budget", 1, 0, 'b'},
+        {"vcpuid",1, 0, 'v'},
         {"cpupool", 1, 0, 'c'},
         COMMON_LONG_OPTS
     };
 
-    SWITCH_FOREACH_OPT(opt, "d:p:b:c:", opts, "sched-rtds", 0) {
+    SWITCH_FOREACH_OPT(opt, "d:p:b:v:c", opts, "sched-rtds", 0) {
     case 'd':
         dom = optarg;
         break;
     case 'p':
-        period = strtol(optarg, NULL, 10);
+        if (p_index >= p_size) { /* periods array is full */
+            p_size *= 2;
+            periods = xrealloc(periods, p_size);
+        }
+        periods[p_index++] = strtol(optarg, NULL, 10);
         opt_p = 1;
         break;
     case 'b':
-        budget = strtol(optarg, NULL, 10);
+        if (b_index >= b_size) { /* budgets array is full */
+            b_size *= 2;
+            budgets = xrealloc(budgets, b_size);
+        }
+        budgets[b_index++] = strtol(optarg, NULL, 10);
         opt_b = 1;
         break;
+    case 'v':
+        if (!strcmp(optarg, "all")) { /* get or set all vcpus of a domain */

tools/libxl/xl_cmdimpl.c int main_sched_rtds(int argc, char **argv) · line 6417

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+            opt_all = 1;
+            break;
+        }
+        if (v_index >= v_size) { /* vcpus array is full */
+            v_size *= 2;
+            vcpus = xrealloc(vcpus, v_size);
+        }
+        vcpus[v_index++] = strtol(optarg, NULL, 10);
+        opt_v = 1;
+        break;

I'm still not quite sure why this is written like this. What's the expected syntax of this command? The hunk to patch xl manpage is very terse...

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#48 lore raw

Re: [PATCH v6 for Xen 4.7 4/4] xl: enable per-VCPU parameter settings for RTDS scheduler

Quoted 64 lines · Wei Liu

On Sun, Mar 06, 2016 at 11:55:58AM -0600, Chong Li wrote:
[...]

Quoted 62 lines
tools/libxl/xl_cmdimpl.c +33 -6
@@ -6222,77 +6359,166 @@ 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 v_size = 1; /* size of vcpus array */
+    int p_size = 1; /* size of periods array */
+    int b_size = 1; /* size of budgets array */
+    int v_index = 0; /* index in vcpus array */
+    int p_index =0; /* index in periods array */
+    int b_index =0; /* index for in budgets array */
     bool opt_p = false;
     bool opt_b = false;
-    int opt, rc;
+    bool opt_v = false;
+    bool opt_all = false; /* output per-dom parameters */
+    int opt, i;
+    int rc = 0;
     static struct option opts[] = {
         {"domain", 1, 0, 'd'},
         {"period", 1, 0, 'p'},
         {"budget", 1, 0, 'b'},
+        {"vcpuid",1, 0, 'v'},
         {"cpupool", 1, 0, 'c'},
         COMMON_LONG_OPTS
     };
 
-    SWITCH_FOREACH_OPT(opt, "d:p:b:c:", opts, "sched-rtds", 0) {
+    SWITCH_FOREACH_OPT(opt, "d:p:b:v:c", opts, "sched-rtds", 0) {
     case 'd':
         dom = optarg;
         break;
     case 'p':
-        period = strtol(optarg, NULL, 10);
+        if (p_index >= p_size) { /* periods array is full */
+            p_size *= 2;
+            periods = xrealloc(periods, p_size);
+        }
+        periods[p_index++] = strtol(optarg, NULL, 10);
         opt_p = 1;
         break;
     case 'b':
-        budget = strtol(optarg, NULL, 10);
+        if (b_index >= b_size) { /* budgets array is full */
+            b_size *= 2;
+            budgets = xrealloc(budgets, b_size);
+        }
+        budgets[b_index++] = strtol(optarg, NULL, 10);
         opt_b = 1;
         break;
+    case 'v':
+        if (!strcmp(optarg, "all")) { /* get or set all vcpus of a domain */
+            opt_all = 1;
+            break;
+        }
+        if (v_index >= v_size) { /* vcpus array is full */
+            v_size *= 2;
+            vcpus = xrealloc(vcpus, v_size);
Quoted 8 lines

tools/libxl/xl_cmdimpl.c int main_sched_rtds(int argc, char **argv) · line 6417

Quoted 4 lines
tools/libxl/xl_cmdimpl.c +4 -0
+        }
+        vcpus[v_index++] = strtol(optarg, NULL, 10);
+        opt_v = 1;
+        break;

I'm still not quite sure why this is written like this. What's the expected syntax of this command? The hunk to patch xl manpage is very terse...

We have three arrays here, vcpus[], periods[] and budgets[]. If the xl command is like (more examples at cover letter):

xl sched-rtds -d vm1 -v 3 -p 500 -b 200 -v 1 -p 600 -b 300 (set the scheduling parameters of two vcpus of vm1)

then, the three arrays would be like:

vcpus: [3, 1]
periods: [500, 600]
budgets: [200, 300]

What makes this code complicated is the size of these three arrays grows along with the
reading of OPTS. At the beginning, all three arrays have the size for only one int. When
one array becomes full, we double its size.

Chong

Signature · 8 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#49 lore raw

Re: [PATCH v6 for Xen 4.7 4/4] xl: enable per-VCPU parameter settings for RTDS scheduler

On Tue, Mar 08, 2016 at 03:24:35PM -0600, Chong Li wrote:
[...]

Quoted 29 lines
Quoted 13 lines

tools/libxl/xl_cmdimpl.c int main_sched_rtds(int argc, char **argv) · line 6417

Quoted 12 lines
tools/libxl/xl_cmdimpl.c +12 -0
+    case 'v':
+        if (!strcmp(optarg, "all")) { /* get or set all vcpus of a domain */
+            opt_all = 1;
+            break;
+        }
+        if (v_index >= v_size) { /* vcpus array is full */
+            v_size *= 2;
+            vcpus = xrealloc(vcpus, v_size);
+        }
+        vcpus[v_index++] = strtol(optarg, NULL, 10);
+        opt_v = 1;
+        break;
Quoted 3 lines

I'm still not quite sure why this is written like this. What's the expected syntax of this command? The hunk to patch xl manpage is very terse...

We have three arrays here, vcpus[], periods[] and budgets[]. If the xl command is like (more examples at cover letter):

xl sched-rtds -d vm1 -v 3 -p 500 -b 200 -v 1 -p 600 -b 300 (set the scheduling parameters of two vcpus of vm1)

then, the three arrays would be like:

vcpus: [3, 1]
periods: [500, 600]
budgets: [200, 300]

Quoted 5 lines

What makes this code complicated is the size of these three arrays grows along with the
reading of OPTS. At the beginning, all three arrays have the size for only one int. When
one array becomes full, we double its size.

OK. In that case, please:

1. Introduce a helper function to double the size of the array.
2. Improve manual a bit, maybe with one or two examples.

Wei.

Quoted 9 lines

Chong

Signature · 3 lines
Chong Li
Department of Computer Science and Engineering
Washington University in St.louis

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#50 lore raw

Re: [PATCH v6 for Xen 4.7 4/4] xl: enable per-VCPU parameter settings for RTDS scheduler

In reply to Chong Li

I saw quite a few coding style issues. Please fix them in next iteration.

On Sun, Mar 06, 2016 at 11:55:58AM -0600, Chong Li wrote:
[...]

tools/libxl/xl_cmdimpl.c int main_sched_rtds(int argc, char **argv) · line 6426

Quoted 7 lines
tools/libxl/xl_cmdimpl.c +2 -2
-    if (cpupool && (dom || opt_p || opt_b)) {
+    if (cpupool && (dom || opt_p || opt_b || opt_v || opt_all)) {
         fprintf(stderr, "Specifying a cpupool is not allowed with "
                 "other options.\n");
-        return EXIT_FAILURE;
+        rc = 1;

The exit value should be EXIT_FAILURE.

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +5 -3
+        goto out;
     }
-    if (!dom && (opt_p || opt_b)) {
-        fprintf(stderr, "Must specify a domain.\n");
-        return EXIT_FAILURE;
+    if (!dom && (opt_p || opt_b || opt_v)) {
+        fprintf(stderr, "Missing parameters.\n");
+        rc = 1;
+        goto out;
     }

[...]

tools/libxl/xl_cmdimpl.c int main_sched_rtds(int argc, char **argv) · line 6515

Quoted 13 lines
tools/libxl/xl_cmdimpl.c +5 -4
-            rc = sched_domain_set(domid, &scinfo);
-            libxl_domain_sched_params_dispose(&scinfo);
-            if (rc)
-                return EXIT_FAILURE;
+            libxl_vcpu_sched_params_dispose(&scinfo);
+            if (rc) {
+                rc = -rc;
+                goto out;
+            }
         }
     }

Set rc to EXIT_SUCCESS here.

Wei.

Quoted 33 lines
tools/libxl/xl_cmdimpl.c +5 -1
-    return EXIT_SUCCESS;
+out:
+    free(vcpus);
+    free(periods);
+    free(budgets);
+    return rc;
 }
 
 int main_domid(int argc, char **argv)
tools/libxl/xl_cmdtable.c +6 -4
index fdc1ac6..c68b656 100644
@@ -268,10 +268,12 @@ struct cmd_spec cmd_table[] = {
     { "sched-rtds",
       &main_sched_rtds, 0, 1,
       "Get/set rtds scheduler parameters",
-      "[-d <Domain> [-p[=PERIOD]] [-b[=BUDGET]]]",
-      "-d DOMAIN, --domain=DOMAIN     Domain to modify\n"
-      "-p PERIOD, --period=PERIOD     Period (us)\n"
-      "-b BUDGET, --budget=BUDGET     Budget (us)\n"
+      "[-d <Domain> [-v[=VCPUID]] [-p[=PERIOD]] [-b[=BUDGET]]]",
+      "-d DOMAIN, --domain=DOMAIN 	Domain to modify\n"
+      "-v VCPUID/all, --vcpuid=VCPUID/all    VCPU to modify or output;\n"
+      "                               Using '-v all' to modify/output all vcpus\n"
+      "-p PERIOD, --period=PERIOD 	Period (us)\n"
+      "-b BUDGET, --budget=BUDGET 	Budget (us)\n"
     },
     { "domid",
       &main_domid, 0, 0,
Signature · 1 line
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel