Skip to contentSkip to conversation

Introduce rt real-time scheduler for Xen

PATCH Superseded Meng Xu 5 participants 24 messages Sep 7, 2014 – Sep 11, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Meng Xu

author
#0 lore raw

This serie of patches adds rt real-time scheduler to Xen.

In summary, It supports:
1) Preemptive Global Earliest Deadline First scheduling policy by using a global RunQ for the scheduler;
2) Assign/display VCPUs' parameters of each domain (All VCPUs of each domain have the same period and budget);
3) Supports CPU Pool
Note:
a) Although the toolstack only allows users to set the paramters of all VCPUs of the same domain to the same number, the scheduler supports to schedule VCPUs with different parameters of the same domain. In Xen 4.6, we plan to support assign/display each VCPU's parameters of each domain.
b) Parameters of a domain at tool stack is in microsecond, instead of millisecond.

Compared with the PATCH v1, this set of patch has the following modifications:
a) Toolstack only allows users to set the parameters of all VCPUs of the same domain to be the same value; Toostack only displays the VCPUs' period and budget of a domain. (In PATCH v1, toolstack can assign/display each VCPU's parameters of each domain, but because it is hard to reach an agreement with the libxl interface for this functionality, we decide to delay this functionality to Xen 4.6 after the scheduler is merged into Xen 4.5.)
b) Miscellous modification of the scheduler in sched_rt.c based on Dario's detailed comments.
c) Code style correction in libxl.

-----------------------------------------------------------------------------------------------------------------------------
TODO after Xen 4.5:
a) Burn budget in finer granularity instead of 1ms; [medium]
b) Use separate timer per vcpu for each vcpu's budget replenishment, instead of scanning the full runqueue every now and then [medium]
c) Handle time stolen from domU by hypervisor. When it runs on a machine with many sockets and lots of cores, the spin-lock for global RunQ used in rt scheduler could eat up time from domU, which could make domU have less budget than it requires. [not sure about difficulty right now] (Thank Konrad Rzeszutek to point this out in the XenSummit. :-))
d) Toolstack supports assiging/display each VCPU's parameters of each domain.

-----------------------------------------------------------------------------------------------------------------------------
The design of this rt scheduler is as follows:
This scheduler follows the Preemptive Global Earliest Deadline First (EDF) theory in real-time field.
At any scheduling point, the VCPU with earlier deadline has higher priority. The scheduler always picks the highest priority VCPU to run on a feasible PCPU.
A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is idle or has a lower-priority VCPU running on it.)

Each VCPU has a dedicated period and budget.
The deadline of a VCPU is at the end of each of its periods;
A VCPU has its budget replenished at the beginning of each of its periods; While scheduled, a VCPU burns its budget.
The VCPU needs to finish its budget before its deadline in each period; The VCPU discards its unused budget at the end of each of its periods. If a VCPU runs out of budget in a period, it has to wait until next period.

Each VCPU is implemented as a deferable server.
When a VCPU has a task running on it, its budget is continuously burned; When a VCPU has no task but with budget left, its budget is preserved.

Queue scheme: A global runqueue for each CPU pool.
The runqueue holds all runnable VCPUs.
VCPUs in the runqueue are divided into two parts: with and without budget. At the first part, VCPUs are sorted based on EDF priority scheme.

Note: cpumask and cpupool is supported.

If you are intersted in the details of the design and evaluation of this rt scheduler, please refer to our paper "Real-Time Multi-Core Virtual Machine Scheduling in Xen" (http://www.cis.upenn.edu/~mengxu/emsoft14/emsoft14.pdf), which will be published in EMSOFT14. This paper has the following details:
a) Desgin of this scheduler;
b) Measurement of the implementation overhead, e.g., scheduler overhead, context switch overhead, etc.
c) Comparison of this rt scheduler and credit scheduler in terms of the real-time performance.

If you are interested in other real-time schedulers in Xen, please refer to the RT-Xen project's website (https://sites.google.com/site/realtimexen/). It also supports Preemptive Global Rate Monotonic schedulers.
-----------------------------------------------------------------------------------------------------------------------------
One scenario to show the functionality of this rt scheduler is as follows:
//list the domains
#xl list
Name ID Mem VCPUs State Time(s)

Domain-0                                     0  3344     4     r-----     146.1
vm1                                          1   512     2     r-----     155.1

//list VCPUs' parameters of each domain in cpu pools using rt scheduler #xl sched-rt
Cpupool Pool-0: sched=EDF
Name ID Period Budget

Domain-0                             0     10000      4000
vm1                                  1     10000      4000

//set VCPUs' parameters of each domain to new value
xl sched-rt -d Domain-0 -p 20000 -b 10000
//Now all vcpus of Domain-0 have period 20000us and budget 10000us. #xl sched-rt
Cpupool Pool-0: sched=EDF
Name ID Period Budget

Domain-0                             0     20000     10000
vm1                                  1     10000      4000

// list cpupool information
#xl cpupool-list
Name CPUs Sched Active Domain count
Pool-0 4 rt_ds y 2
#xl cpupool-list -c
Name CPU list
Pool-0 0,1,2,3

//create a cpupool test
#xl cpupool-cpu-remove Pool-0 3
#xl cpupool-cpu-remove Pool-0 2
#xl cpupool-create name=\"test\" sched=\"rt_ds\"
#xl cpupool-cpu-add test 3
#xl cpupool-cpu-add test 2
#xl cpupool-list
Name CPUs Sched Active Domain count

Pool-0               2     rt_ds       y          2
test                 2     rt_ds       y          0

//migrate vm1 from cpupool Pool-0 to cpupool test. #xl cpupool-migrate vm1 test

//now vm1 is in cpupool test

# xl sched-rt
pupool Pool-0: sched=EDF
Name                                ID    Period    Budget
Domain-0                             0     20000     10000
Cpupool test: sched=EDF                 
Name                                ID    Period    Budget
vm1                                  1     10000      4000

-----------------------------------------------------------------------------------------------------------------------------
Any comment, question, and concerns are more than welcome! :-)

Thank you very much!

Best,

Meng

[PATCH v2 1/4] xen: add real time scheduler rt
[PATCH v2 2/4] libxc: add rt scheduler
[PATCH v2 3/4] libxl: add rt scheduler
[PATCH v2 4/4] xl: introduce rt scheduler

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

author
#1 lore raw

PATCH v2 1/4 xen: add real time scheduler rt

This scheduler follows the Preemptive Global Earliest Deadline First (EDF) theory in real-time field.
At any scheduling point, the VCPU with earlier deadline has higher priority. The scheduler always picks the highest priority VCPU to run on a feasible PCPU.
A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is idle or has a lower-priority VCPU running on it.)

Each VCPU has a dedicated period and budget.
The deadline of a VCPU is at the end of each of its periods;
A VCPU has its budget replenished at the beginning of each of its periods; While scheduled, a VCPU burns its budget.
The VCPU needs to finish its budget before its deadline in each period; The VCPU discards its unused budget at the end of each of its periods. If a VCPU runs out of budget in a period, it has to wait until next period.

Each VCPU is implemented as a deferable server.
When a VCPU has a task running on it, its budget is continuously burned; When a VCPU has no task but with budget left, its budget is preserved.

Queue scheme: A global runqueue for each CPU pool.
The runqueue holds all runnable VCPUs.
VCPUs in the runqueue are divided into two parts: with and without budget. At the first part, VCPUs are sorted based on EDF priority scheme.

Note: cpumask and cpupool is supported.

This is an experimental scheduler.

---
 xen/common/Makefile         |    1 +
 xen/common/sched_rt.c       | 1146 +++++++++++++++++++++++++++++++++++++++++++
 xen/common/schedule.c       |    1 +
 xen/include/public/domctl.h |    6 +
 xen/include/public/trace.h  |    1 +
 xen/include/xen/sched-if.h  |    1 +
 6 files changed, 1156 insertions(+)
 create mode 100644 xen/common/sched_rt.c
xen/common/Makefile +1 -0
index 3683ae3..5a23aa4 100644
@@ -26,6 +26,7 @@ obj-y += sched_credit.o
 obj-y += sched_credit2.o
 obj-y += sched_sedf.o
 obj-y += sched_arinc653.o
+obj-y += sched_rt.o
 obj-y += schedule.o
 obj-y += shutdown.o
 obj-y += softirq.o
xen/common/sched_rt.c new file +1146 -0

1,146 lines not on this page · raw message

xen/common/schedule.c +1 -0
index 73cc2ea..dc4f749 100644
@@ -69,6 +69,7 @@ static const struct scheduler *schedulers[] = {
     &sched_credit_def,
     &sched_credit2_def,
     &sched_arinc653_def,
+    &sched_rt_ds_def,
 };
 
 static struct scheduler __read_mostly ops;
xen/include/public/domctl.h +6 -0
index 69a8b44..11654d0 100644
@@ -347,6 +347,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_max_vcpus_t);
 #define XEN_SCHEDULER_CREDIT   5
 #define XEN_SCHEDULER_CREDIT2  6
 #define XEN_SCHEDULER_ARINC653 7
+#define XEN_SCHEDULER_RT_DS    8
+
 /* Set or get info? */
 #define XEN_DOMCTL_SCHEDOP_putinfo 0
 #define XEN_DOMCTL_SCHEDOP_getinfo 1
@@ -368,6 +370,10 @@ struct xen_domctl_scheduler_op {
         struct xen_domctl_sched_credit2 {
             uint16_t weight;
         } credit2;
+        struct xen_domctl_sched_rt{
+            uint32_t period;
+            uint32_t budget;
+        } rt;
     } u;
 };
 typedef struct xen_domctl_scheduler_op xen_domctl_scheduler_op_t;
xen/include/public/trace.h +1 -0
index cfcf4aa..87340c4 100644
@@ -77,6 +77,7 @@
 #define TRC_SCHED_CSCHED2  1
 #define TRC_SCHED_SEDF     2
 #define TRC_SCHED_ARINC653 3
+#define TRC_SCHED_RT       4
 
 /* Per-scheduler tracing */
 #define TRC_SCHED_CLASS_EVT(_c, _e) \
xen/include/xen/sched-if.h +1 -0
index 4164dff..04d81dc 100644
@@ -169,6 +169,7 @@ extern const struct scheduler sched_sedf_def;
 extern const struct scheduler sched_credit_def;
 extern const struct scheduler sched_credit2_def;
 extern const struct scheduler sched_arinc653_def;
+extern const struct scheduler sched_rt_ds_def;
 
 
 struct cpupool
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

Interface comments on the first pass; I'll dig into the algorithm more on the second pass.

xen/common/schedule.c static const struct scheduler *schedulers[] = { · line 72

Quoted 9 lines · Meng Xu
xen/common/schedule.c +1 -0
index 73cc2ea..dc4f749 100644
@@ -69,6 +69,7 @@ static const struct scheduler *schedulers[] = {
      &sched_credit_def,
      &sched_credit2_def,
      &sched_arinc653_def,
+    &sched_rt_ds_def,

I think it would be nicer to leave the _ out of the middle -- just call this the "rtds" server (here and elsewhere).

Quoted 17 lines
xen/common/schedule.c +0 -0
  };
 
  static struct scheduler __read_mostly ops;
xen/include/public/domctl.h +2 -0
index 69a8b44..11654d0 100644
@@ -347,6 +347,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_max_vcpus_t);
  #define XEN_SCHEDULER_CREDIT   5
  #define XEN_SCHEDULER_CREDIT2  6
  #define XEN_SCHEDULER_ARINC653 7
+#define XEN_SCHEDULER_RT_DS    8
+
  /* Set or get info? */
  #define XEN_DOMCTL_SCHEDOP_putinfo 0
  #define XEN_DOMCTL_SCHEDOP_getinfo 1

xen/include/public/domctl.h struct xen_domctl_scheduler_op { · line 376

Quoted 7 lines
xen/include/public/domctl.h +4 -0
@@ -368,6 +370,10 @@ struct xen_domctl_scheduler_op {
          struct xen_domctl_sched_credit2 {
              uint16_t weight;
          } credit2;
+        struct xen_domctl_sched_rt{
+            uint32_t period;
+            uint32_t budget;
+        } rt;

I'm not sure if you meant to leave this as "rt" instead of "rtds", but I don't think we can assume that every other server is going to expose "period" and "budget": the sEDF scheduler had "slice" instead, for instance. I would prefer this to be "xen_domctl_sched_rtds".

xen/include/public/trace.h line 80

Quoted 12 lines
xen/include/public/domctl.h +0 -0
      } u;
  };
  typedef struct xen_domctl_scheduler_op xen_domctl_scheduler_op_t;
xen/include/public/trace.h +1 -0
index cfcf4aa..87340c4 100644
@@ -77,6 +77,7 @@
  #define TRC_SCHED_CSCHED2  1
  #define TRC_SCHED_SEDF     2
  #define TRC_SCHED_ARINC653 3
+#define TRC_SCHED_RT       4

TRC_SCHED_RTDS

-George

#3 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

In reply to Meng Xu
Quoted 341 lines · Meng Xu

This scheduler follows the Preemptive Global Earliest Deadline First (EDF) theory in real-time field.
At any scheduling point, the VCPU with earlier deadline has higher priority. The scheduler always picks the highest priority VCPU to run on a feasible PCPU.
A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is idle or has a lower-priority VCPU running on it.)

Each VCPU has a dedicated period and budget.
The deadline of a VCPU is at the end of each of its periods;
A VCPU has its budget replenished at the beginning of each of its periods; While scheduled, a VCPU burns its budget.
The VCPU needs to finish its budget before its deadline in each period; The VCPU discards its unused budget at the end of each of its periods. If a VCPU runs out of budget in a period, it has to wait until next period.

Each VCPU is implemented as a deferable server.
When a VCPU has a task running on it, its budget is continuously burned; When a VCPU has no task but with budget left, its budget is preserved.

Queue scheme: A global runqueue for each CPU pool.
The runqueue holds all runnable VCPUs.
VCPUs in the runqueue are divided into two parts: with and without budget. At the first part, VCPUs are sorted based on EDF priority scheme.

Note: cpumask and cpupool is supported.

This is an experimental scheduler.

---
  xen/common/Makefile         |    1 +
  xen/common/sched_rt.c       | 1146 +++++++++++++++++++++++++++++++++++++++++++
  xen/common/schedule.c       |    1 +
  xen/include/public/domctl.h |    6 +
  xen/include/public/trace.h  |    1 +
  xen/include/xen/sched-if.h  |    1 +
  6 files changed, 1156 insertions(+)

create mode 100644 xen/common/sched_rt.c

xen/common/Makefile +1 -0
index 3683ae3..5a23aa4 100644
@@ -26,6 +26,7 @@ obj-y += sched_credit.o
  obj-y += sched_credit2.o
  obj-y += sched_sedf.o
  obj-y += sched_arinc653.o
+obj-y += sched_rt.o
  obj-y += schedule.o
  obj-y += shutdown.o
  obj-y += softirq.o
xen/common/sched_rt.c new file +282 -0
new file mode 100644
index 0000000..412f8b1
@@ -0,0 +1,1146 @@
+/******************************************************************************
+ * Preemptive Global Earliest Deadline First  (EDF) scheduler for Xen
+ * EDF scheduling is a real-time scheduling algorithm used in embedded field.
+ *
+ * by Sisu Xi, 2013, Washington University in Saint Louis
+ * and Meng Xu, 2014, University of Pennsylvania
+ *
+ * based on the code of credit Scheduler
+ */
+
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/sched.h>
+#include <xen/domain.h>
+#include <xen/delay.h>
+#include <xen/event.h>
+#include <xen/time.h>
+#include <xen/perfc.h>
+#include <xen/sched-if.h>
+#include <xen/softirq.h>
+#include <asm/atomic.h>
+#include <xen/errno.h>
+#include <xen/trace.h>
+#include <xen/cpu.h>
+#include <xen/keyhandler.h>
+#include <xen/trace.h>
+#include <xen/guest_access.h>
+
+/*
+ * TODO:
+ *
+ * Migration compensation and resist like credit2 to better use cache;
+ * Lock Holder Problem, using yield?
+ * Self switch problem: VCPUs of the same domain may preempt each other;
+ */
+
+/*
+ * Design:
+ *
+ * This scheduler follows the Preemptive Global Earliest Deadline First (EDF)
+ * theory in real-time field.
+ * At any scheduling point, the VCPU with earlier deadline has higher priority.
+ * The scheduler always picks highest priority VCPU to run on a feasible PCPU.
+ * A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is idle or
+ * has a lower-priority VCPU running on it.)
+ *
+ * Each VCPU has a dedicated period and budget.
+ * The deadline of a VCPU is at the end of each of its periods;
+ * A VCPU has its budget replenished at the beginning of each of its periods;
+ * While scheduled, a VCPU burns its budget.
+ * The VCPU needs to finish its budget before its deadline in each period;
+ * The VCPU discards its unused budget at the end of each of its periods.
+ * If a VCPU runs out of budget in a period, it has to wait until next period.
+ *
+ * Each VCPU is implemented as a deferable server.
+ * When a VCPU has a task running on it, its budget is continuously burned;
+ * When a VCPU has no task but with budget left, its budget is preserved.
+ *
+ * Queue scheme: A global runqueue for each CPU pool.
+ * The runqueue holds all runnable VCPUs.
+ * VCPUs in the runqueue are divided into two parts:
+ * with and without remaining budget.
+ * At the first part, VCPUs are sorted based on EDF priority scheme.
+ *
+ * Note: cpumask and cpupool is supported.
+ */
+
+/*
+ * Locking:
+ * A global system lock is used to protect the RunQ.
+ * The global lock is referenced by schedule_data.schedule_lock
+ * from all physical cpus.
+ *
+ * The lock is already grabbed when calling wake/sleep/schedule/ functions
+ * in schedule.c
+ *
+ * The functions involes RunQ and needs to grab locks are:
+ *    vcpu_insert, vcpu_remove, context_saved, __runq_insert
+ */
+
+
+/*
+ * Default parameters:
+ * Period and budget in default is 10 and 4 ms, respectively
+ */
+#define RT_DS_DEFAULT_PERIOD     (MICROSECS(10000))
+#define RT_DS_DEFAULT_BUDGET     (MICROSECS(4000))
+
+/*
+ * Flags
+ */
+/*
+ * RT_scheduled: Is this vcpu either running on, or context-switching off,
+ * a phyiscal cpu?
+ * + Accessed only with Runqueue lock held.
+ * + Set when chosen as next in rt_schedule().
+ * + Cleared after context switch has been saved in rt_context_saved()
+ * + Checked in vcpu_wake to see if we can add to the Runqueue, or if we should
+ *   set RT_delayed_runq_add
+ * + Checked to be false in runq_insert.
+ */
+#define __RT_scheduled            1
+#define RT_scheduled (1<<__RT_scheduled)
+/*
+ * RT_delayed_runq_add: Do we need to add this to the Runqueueu once it'd done
+ * being context switching out?
+ * + Set when scheduling out in rt_schedule() if prev is runable
+ * + Set in rt_vcpu_wake if it finds RT_scheduled set
+ * + Read in rt_context_saved(). If set, it adds prev to the Runqueue and
+ *   clears the bit.
+ */
+#define __RT_delayed_runq_add     2
+#define RT_delayed_runq_add (1<<__RT_delayed_runq_add)
+
+/*
+ * Debug only. Used to printout debug information
+ */
+#define printtime()\
+        ({s_time_t now = NOW(); \
+          printk("%u : %3ld.%3ldus : %-19s\n",smp_processor_id(),\
+          now/MICROSECS(1), now%MICROSECS(1)/1000, __func__);} )
+
+/*
+ * rt tracing events ("only" 512 available!). Check
+ * include/public/trace.h for more details.
+ */
+#define TRC_RT_TICKLE           TRC_SCHED_CLASS_EVT(RT, 1)
+#define TRC_RT_RUNQ_PICK        TRC_SCHED_CLASS_EVT(RT, 2)
+#define TRC_RT_BUDGET_BURN      TRC_SCHED_CLASS_EVT(RT, 3)
+#define TRC_RT_BUDGET_REPLENISH TRC_SCHED_CLASS_EVT(RT, 4)
+#define TRC_RT_SCHED_TASKLET    TRC_SCHED_CLASS_EVT(RT, 5)
+#define TRC_RT_VCPU_DUMP        TRC_SCHED_CLASS_EVT(RT, 6)
+
+/*
+ * Systme-wide private data, include a global RunQueue
+ * Global lock is referenced by schedule_data.schedule_lock from all
+ * physical cpus. It can be grabbed via vcpu_schedule_lock_irq()
+ */
+struct rt_private {
+    spinlock_t lock;           /* The global coarse grand lock */
+    struct list_head sdom;     /* list of availalbe domains, used for dump */
+    struct list_head runq;     /* Ordered list of runnable VMs */
+    struct rt_vcpu *flag_vcpu; /* position of the first depleted vcpu */
+    cpumask_t cpus;            /* cpumask_t of available physical cpus */
+    cpumask_t tickled;         /* cpus been tickled */
+};
+
+/*
+ * Virtual CPU
+ */
+struct rt_vcpu {
+    struct list_head runq_elem; /* On the runqueue list */
+    struct list_head sdom_elem; /* On the domain VCPU list */
+
+    /* Up-pointers */
+    struct rt_dom *sdom;
+    struct vcpu *vcpu;
+
+    /* VCPU parameters, in nanoseconds */
+    s_time_t period;
+    s_time_t budget;
+
+    /* VCPU current infomation in nanosecond */
+    s_time_t cur_budget;        /* current budget */
+    s_time_t last_start;        /* last start time */
+    s_time_t cur_deadline;      /* current deadline for EDF */
+
+    unsigned flags;             /* mark __RT_scheduled, etc.. */
+};
+
+/*
+ * Domain
+ */
+struct rt_dom {
+    struct list_head vcpu;      /* link its VCPUs */
+    struct list_head sdom_elem; /* link list on rt_priv */
+    struct domain *dom;         /* pointer to upper domain */
+};
+
+/*
+ * Useful inline functions
+ */
+static inline struct rt_private *RT_PRIV(const struct scheduler *ops)
+{
+    return ops->sched_data;
+}
+
+static inline struct rt_vcpu *RT_VCPU(const struct vcpu *vcpu)
+{
+    return vcpu->sched_priv;
+}
+
+static inline struct rt_dom *RT_DOM(const struct domain *dom)
+{
+    return dom->sched_priv;
+}
+
+static inline struct list_head *RUNQ(const struct scheduler *ops)
+{
+    return &RT_PRIV(ops)->runq;
+}
+
+/*
+ * RunQueue helper functions
+ */
+static int
+__vcpu_on_runq(const struct rt_vcpu *svc)
+{
+   return !list_empty(&svc->runq_elem);
+}
+
+static struct rt_vcpu *
+__runq_elem(struct list_head *elem)
+{
+    return list_entry(elem, struct rt_vcpu, runq_elem);
+}
+
+/*
+ * Debug related code, dump vcpu/cpu information
+ */
+static void
+rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    char cpustr[1024];
+    cpumask_t *cpupool_mask;
+
+    ASSERT(svc != NULL);
+    /* flag vcpu */
+    if( svc->sdom == NULL )
+        return;
+
+    cpumask_scnprintf(cpustr, sizeof(cpustr), svc->vcpu->cpu_hard_affinity);
+    printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime"),"
+           " cur_b=%"PRI_stime" cur_d=%"PRI_stime" last_start=%"PRI_stime
+           " onR=%d runnable=%d cpu_hard_affinity=%s ",
+            svc->vcpu->domain->domain_id,
+            svc->vcpu->vcpu_id,
+            svc->vcpu->processor,
+            svc->period,
+            svc->budget,
+            svc->cur_budget,
+            svc->cur_deadline,
+            svc->last_start,
+            __vcpu_on_runq(svc),
+            vcpu_runnable(svc->vcpu),
+            cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpupool_mask = cpupool_scheduler_cpumask(svc->vcpu->domain->cpupool);
+    cpumask_scnprintf(cpustr, sizeof(cpustr), cpupool_mask);
+    printk("cpupool=%s ", cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpumask_scnprintf(cpustr, sizeof(cpustr), &prv->cpus);
+    printk("prv->cpus=%s\n", cpustr);
+
+    /* TRACE */
+    {
+        struct {
+            unsigned dom:16,vcpu:16;
+            unsigned processor;
+            unsigned cur_budget_lo, cur_budget_hi;
+            unsigned cur_deadline_lo, cur_deadline_hi;
+            unsigned is_vcpu_on_runq:16,is_vcpu_runnable:16;
+        } d;
+        d.dom = svc->vcpu->domain->domain_id;
+        d.vcpu = svc->vcpu->vcpu_id;
+        d.processor = svc->vcpu->processor;
+        d.cur_budget_lo = (unsigned) svc->cur_budget;
+        d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+        d.cur_deadline_lo = (unsigned) svc->cur_deadline;
+        d.cur_deadline_hi = (unsigned) (svc->cur_deadline >> 32);
+        d.is_vcpu_on_runq = __vcpu_on_runq(svc);
+        d.is_vcpu_runnable = vcpu_runnable(svc->vcpu);
+        trace_var(TRC_RT_VCPU_DUMP, 1,
+                  sizeof(d),
+                  (unsigned char *)&d);
+    }
+}
+
+static void
+rt_dump_pcpu(const struct scheduler *ops, int cpu)

xen/common/sched_rt.c line 292

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+{
+    struct rt_vcpu *svc = RT_VCPU(curr_on_cpu(cpu));
+
+    printtime();
+    rt_dump_vcpu(ops, svc);
+}
+
+/*
+ * should not need lock here. only showing stuff
+ */

This isn't true -- you're walking both the runqueue and the lists of domains and vcpus, each of which may change under your feet.

Quoted 44 lines
xen/common/sched_rt.c new file +44 -0
+static void
+rt_dump(const struct scheduler *ops)
+{
+    struct list_head *iter_sdom, *iter_svc, *runq, *iter;
+    struct rt_private *prv = RT_PRIV(ops);
+    struct rt_vcpu *svc;
+    unsigned int cpu = 0;
+
+    printtime();
+
+    printk("PCPU info:\n");
+    for_each_cpu(cpu, &prv->cpus)
+        rt_dump_pcpu(ops, cpu);
+
+    printk("Global RunQueue info:\n");
+    runq = RUNQ(ops);
+    list_for_each( iter, runq )
+    {
+        svc = __runq_elem(iter);
+        rt_dump_vcpu(ops, svc);
+    }
+
+    printk("Domain info:\n");
+    list_for_each( iter_sdom, &prv->sdom )
+    {
+        struct rt_dom *sdom;
+        sdom = list_entry(iter_sdom, struct rt_dom, sdom_elem);
+        printk("\tdomain: %d\n", sdom->dom->domain_id);
+
+        list_for_each( iter_svc, &sdom->vcpu )
+        {
+            svc = list_entry(iter_svc, struct rt_vcpu, sdom_elem);
+            rt_dump_vcpu(ops, svc);
+        }
+    }
+
+    printk("\n");
+}
+
+/*
+ * update deadline and budget when deadline is in the past,
+ * it need to be updated to the deadline of the current period
+ */
+static void

xen/common/sched_rt.c line 346

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+rt_update_helper(s_time_t now, struct rt_vcpu *svc)
+{
+    s_time_t diff = now - svc->cur_deadline;
+
+    if ( diff >= 0 )
+    {
+        /* now can be later for several periods */
+        long count = ( diff/svc->period ) + 1;
+        svc->cur_deadline += count * svc->period;
+        svc->cur_budget = svc->budget;

In the common case, don't we expect diff/svc->period to be a small number, like 0 or 1? If so, since division and multiplication are so expensive, it might make more sense to make this a while() loop:

while (now - svc_cur_deadline > 0 )
{
svc->cur_deadline += svc->period;
count++;
}
if ( count ) {
svc->cur_budget = svc->budget;
[tracing code]
}

And similarly for the other 64-bit division Dario was asking about below?

I probably wouldn't make this a precondition of going in.

Quoted 50 lines
xen/common/sched_rt.c new file +50 -0
+
+        /* TRACE */
+        {
+            struct {
+                unsigned dom:16,vcpu:16;
+                unsigned cur_budget_lo, cur_budget_hi;
+            } d;
+            d.dom = svc->vcpu->domain->domain_id;
+            d.vcpu = svc->vcpu->vcpu_id;
+            d.cur_budget_lo = (unsigned) svc->cur_budget;
+            d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+            trace_var(TRC_RT_BUDGET_REPLENISH, 1,
+                      sizeof(d),
+                      (unsigned char *) &d);
+        }
+
+        return;
+    }
+}
+
+static inline void
+__runq_remove(struct rt_vcpu *svc)
+{
+    if ( __vcpu_on_runq(svc) )
+        list_del_init(&svc->runq_elem);
+}
+
+/*
+ * Insert svc in the RunQ according to EDF: vcpus with smaller deadlines
+ * goes first.
+ */
+static void
+__runq_insert(const struct scheduler *ops, struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    spinlock_t *schedule_lock;
+
+    schedule_lock = per_cpu(schedule_data, svc->vcpu->processor).schedule_lock;
+    ASSERT( spin_is_locked(schedule_lock) );
+
+    ASSERT( !__vcpu_on_runq(svc) );
+
+    /* svc still has budget */
+    if ( svc->cur_budget > 0 )
+    {
+        list_for_each(iter, runq)
+        {
+            struct rt_vcpu * iter_svc = __runq_elem(iter);

xen/common/sched_rt.c line 406

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+            if ( iter_svc->cur_budget == 0 ||
+                 svc->cur_deadline <= iter_svc->cur_deadline )
+                    break;
+         }
+        list_add_tail(&svc->runq_elem, iter);
+     }
+    else
+    {
+        list_add(&svc->runq_elem, &prv->flag_vcpu->runq_elem);
+    }

OK, this thing with the "flag vcpu" seems a bit weird. Why not just have two queues -- a runq and a depletedq. You don't need to have another function; you just add it to depleted_runq rather than runq in __runq_insert(). Then you don't have to have this "cur_budget==0" stuff. The only extra code you'd have is (I think) in __repl_update().

Quoted 158 lines
xen/common/sched_rt.c new file +158 -0
+}
+
+/*
+ * Init/Free related code
+ */
+static int
+rt_init(struct scheduler *ops)
+{
+    struct rt_private *prv = xzalloc(struct rt_private);
+
+    printk("Initializing RT scheduler\n" \
+           " WARNING: This is experimental software in development.\n" \
+           " Use at your own risk.\n");
+
+    if ( prv == NULL )
+        return -ENOMEM;
+
+    spin_lock_init(&prv->lock);
+    INIT_LIST_HEAD(&prv->sdom);
+    INIT_LIST_HEAD(&prv->runq);
+
+    prv->flag_vcpu = xzalloc(struct rt_vcpu);
+    prv->flag_vcpu->cur_budget = 0;
+    prv->flag_vcpu->sdom = NULL; /* distinguish this vcpu with others */
+    list_add(&prv->flag_vcpu->runq_elem, &prv->runq);
+
+    cpumask_clear(&prv->cpus);
+    cpumask_clear(&prv->tickled);
+
+    ops->sched_data = prv;
+
+    printtime();
+    printk("\n");
+
+    return 0;
+}
+
+static void
+rt_deinit(const struct scheduler *ops)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+
+    printtime();
+    printk("\n");
+    xfree(prv->flag_vcpu);
+    xfree(prv);
+}
+
+/*
+ * Point per_cpu spinlock to the global system lock;
+ * All cpu have same global system lock
+ */
+static void *
+rt_alloc_pdata(const struct scheduler *ops, int cpu)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+
+    cpumask_set_cpu(cpu, &prv->cpus);
+
+    per_cpu(schedule_data, cpu).schedule_lock = &prv->lock;
+
+    printtime();
+    printk("%s total cpus: %d", __func__, cpumask_weight(&prv->cpus));
+    /* 1 indicates alloc. succeed in schedule.c */
+    return (void *)1;
+}
+
+static void
+rt_free_pdata(const struct scheduler *ops, void *pcpu, int cpu)
+{
+    struct rt_private * prv = RT_PRIV(ops);
+    cpumask_clear_cpu(cpu, &prv->cpus);
+}
+
+static void *
+rt_alloc_domdata(const struct scheduler *ops, struct domain *dom)
+{
+    unsigned long flags;
+    struct rt_dom *sdom;
+    struct rt_private * prv = RT_PRIV(ops);
+
+    sdom = xzalloc(struct rt_dom);
+    if ( sdom == NULL )
+    {
+        printk("%s, xzalloc failed\n", __func__);
+        return NULL;
+    }
+
+    INIT_LIST_HEAD(&sdom->vcpu);
+    INIT_LIST_HEAD(&sdom->sdom_elem);
+    sdom->dom = dom;
+
+    /* spinlock here to insert the dom */
+    spin_lock_irqsave(&prv->lock, flags);
+    list_add_tail(&sdom->sdom_elem, &(prv->sdom));
+    spin_unlock_irqrestore(&prv->lock, flags);
+
+    return sdom;
+}
+
+static void
+rt_free_domdata(const struct scheduler *ops, void *data)
+{
+    unsigned long flags;
+    struct rt_dom *sdom = data;
+    struct rt_private *prv = RT_PRIV(ops);
+
+    spin_lock_irqsave(&prv->lock, flags);
+    list_del_init(&sdom->sdom_elem);
+    spin_unlock_irqrestore(&prv->lock, flags);
+    xfree(data);
+}
+
+static int
+rt_dom_init(const struct scheduler *ops, struct domain *dom)
+{
+    struct rt_dom *sdom;
+
+    /* IDLE Domain does not link on rt_private */
+    if ( is_idle_domain(dom) )
+        return 0;
+
+    sdom = rt_alloc_domdata(ops, dom);
+    if ( sdom == NULL )
+    {
+        printk("%s, failed\n", __func__);
+        return -ENOMEM;
+    }
+    dom->sched_priv = sdom;
+
+    return 0;
+}
+
+static void
+rt_dom_destroy(const struct scheduler *ops, struct domain *dom)
+{
+    rt_free_domdata(ops, RT_DOM(dom));
+}
+
+static void *
+rt_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd)
+{
+    struct rt_vcpu *svc;
+    s_time_t now = NOW();
+
+    /* Allocate per-VCPU info */
+    svc = xzalloc(struct rt_vcpu);
+    if ( svc == NULL )
+    {
+        printk("%s, xzalloc failed\n", __func__);
+        return NULL;
+    }
+
+    INIT_LIST_HEAD(&svc->runq_elem);
+    INIT_LIST_HEAD(&svc->sdom_elem);
+    svc->flags = 0U;
+    svc->sdom = dd;
+    svc->vcpu = vc;

xen/common/sched_rt.c line 574

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+    svc->last_start = 0;
+
+    svc->period = RT_DS_DEFAULT_PERIOD;
+    if ( !is_idle_vcpu(vc) )
+        svc->budget = RT_DS_DEFAULT_BUDGET;
+
+    rt_update_helper(now, svc);
+
+    /* Debug only: dump new vcpu's info */
+    rt_dump_vcpu(ops, svc);

Having these rt_dump_vcpu() things all over the place is a non-starter. You're going to have to take all these out except the one in rt_dump().

Quoted 100 lines
xen/common/sched_rt.c new file +100 -0
+
+    return svc;
+}
+
+static void
+rt_free_vdata(const struct scheduler *ops, void *priv)
+{
+    struct rt_vcpu *svc = priv;
+
+    /* Debug only: dump freed vcpu's info */
+    rt_dump_vcpu(ops, svc);
+    xfree(svc);
+}
+
+/*
+ * This function is called in sched_move_domain() in schedule.c
+ * When move a domain to a new cpupool.
+ * It inserts vcpus of moving domain to the scheduler's RunQ in
+ * dest. cpupool; and insert rt_vcpu svc to scheduler-specific
+ * vcpu list of the dom
+ */
+static void
+rt_vcpu_insert(const struct scheduler *ops, struct vcpu *vc)
+{
+    struct rt_vcpu *svc = RT_VCPU(vc);
+
+    /* Debug only: dump info of vcpu to insert */
+    rt_dump_vcpu(ops, svc);
+
+    /* not addlocate idle vcpu to dom vcpu list */
+    if ( is_idle_vcpu(vc) )
+        return;
+
+    if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && !vc->is_running )
+        __runq_insert(ops, svc);
+
+    /* add rt_vcpu svc to scheduler-specific vcpu list of the dom */
+    list_add_tail(&svc->sdom_elem, &svc->sdom->vcpu);
+}
+
+/*
+ * Remove rt_vcpu svc from the old scheduler in source cpupool; and
+ * Remove rt_vcpu svc from scheduler-specific vcpu list of the dom
+ */
+static void
+rt_vcpu_remove(const struct scheduler *ops, struct vcpu *vc)
+{
+    struct rt_vcpu * const svc = RT_VCPU(vc);
+    struct rt_dom * const sdom = svc->sdom;
+
+    rt_dump_vcpu(ops, svc);
+
+    BUG_ON( sdom == NULL );
+    BUG_ON( __vcpu_on_runq(svc) );
+
+    if ( __vcpu_on_runq(svc) )
+        __runq_remove(svc);
+
+    if ( !is_idle_vcpu(vc) )
+        list_del_init(&svc->sdom_elem);
+}
+
+/*
+ * Pick a valid CPU for the vcpu vc
+ * Valid CPU of a vcpu is intesection of vcpu's affinity
+ * and available cpus
+ */
+static int
+rt_cpu_pick(const struct scheduler *ops, struct vcpu *vc)
+{
+    cpumask_t cpus;
+    cpumask_t *online;
+    int cpu;
+    struct rt_private * prv = RT_PRIV(ops);
+
+    online = cpupool_scheduler_cpumask(vc->domain->cpupool);
+    cpumask_and(&cpus, &prv->cpus, online);
+    cpumask_and(&cpus, &cpus, vc->cpu_hard_affinity);
+
+    cpu = cpumask_test_cpu(vc->processor, &cpus)
+            ? vc->processor
+            : cpumask_cycle(vc->processor, &cpus);
+    ASSERT( !cpumask_empty(&cpus) && cpumask_test_cpu(cpu, &cpus) );
+
+    return cpu;
+}
+
+/*
+ * Burn budget in nanosecond granularity
+ */
+static void
+burn_budgets(const struct scheduler *ops, struct rt_vcpu *svc, s_time_t now)
+{
+    s_time_t delta;
+
+    /* don't burn budget for idle VCPU */
+    if ( is_idle_vcpu(svc->vcpu) )
+        return;
+
+    rt_update_helper(now, svc);

xen/common/sched_rt.c line 684

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+
+    /* not burn budget when vcpu miss deadline */
+    if ( now >= svc->cur_deadline )
+        return;
+
+    /* burn at nanoseconds level */
+    delta = now - svc->last_start;
+    /*
+     * delta < 0 only happens in nested virtualization;
+     * TODO: how should we handle delta < 0 in a better way?

I think what I did in credit2 was just

if(delta < 0) delta = 0;

What you're doing here basically takes away an entire budget when the time goes backwards for whatever reason. Much better, it seems to me, to just give the vcpu some "free" time and deal with it. :-)

Quoted 113 lines
xen/common/sched_rt.c new file +113 -0
+     */
+    if ( delta < 0 )
+    {
+        printk("%s, ATTENTION: now is behind last_start! delta = %ld",
+                __func__, delta);
+        rt_dump_vcpu(ops, svc);
+        svc->last_start = now;
+        svc->cur_budget = 0;
+        return;
+    }
+
+    if ( svc->cur_budget == 0 )
+        return;
+
+    svc->cur_budget -= delta;
+    if ( svc->cur_budget < 0 )
+        svc->cur_budget = 0;
+
+    /* TRACE */
+    {
+        struct {
+            unsigned dom:16, vcpu:16;
+            unsigned cur_budget_lo;
+            unsigned cur_budget_hi;
+            int delta;
+        } d;
+        d.dom = svc->vcpu->domain->domain_id;
+        d.vcpu = svc->vcpu->vcpu_id;
+        d.cur_budget_lo = (unsigned) svc->cur_budget;
+        d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+        d.delta = delta;
+        trace_var(TRC_RT_BUDGET_BURN, 1,
+                  sizeof(d),
+                  (unsigned char *) &d);
+    }
+}
+
+/*
+ * RunQ is sorted. Pick first one within cpumask. If no one, return NULL
+ * lock is grabbed before calling this function
+ */
+static struct rt_vcpu *
+__runq_pick(const struct scheduler *ops, cpumask_t mask)
+{
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    struct rt_vcpu *svc = NULL;
+    struct rt_vcpu *iter_svc = NULL;
+    cpumask_t cpu_common;
+    cpumask_t *online;
+    struct rt_private * prv = RT_PRIV(ops);
+
+    list_for_each(iter, runq)
+    {
+        iter_svc = __runq_elem(iter);
+
+        /* flag vcpu */
+        if(iter_svc->sdom == NULL)
+            break;
+
+        /* mask cpu_hard_affinity & cpupool & priv->cpus */
+        online = cpupool_scheduler_cpumask(iter_svc->vcpu->domain->cpupool);
+        cpumask_and(&cpu_common, online, &prv->cpus);
+        cpumask_and(&cpu_common, &cpu_common, iter_svc->vcpu->cpu_hard_affinity);
+        cpumask_and(&cpu_common, &mask, &cpu_common);
+        if ( cpumask_empty(&cpu_common) )
+            continue;
+
+        ASSERT( iter_svc->cur_budget > 0 );
+
+        svc = iter_svc;
+        break;
+    }
+
+    /* TRACE */
+    {
+        if( svc != NULL )
+        {
+            struct {
+                unsigned dom:16, vcpu:16;
+                unsigned cur_deadline_lo, cur_deadline_hi;
+                unsigned cur_budget_lo, cur_budget_hi;
+            } d;
+            d.dom = svc->vcpu->domain->domain_id;
+            d.vcpu = svc->vcpu->vcpu_id;
+            d.cur_deadline_lo = (unsigned) svc->cur_deadline;
+            d.cur_deadline_hi = (unsigned) (svc->cur_deadline >> 32);
+            d.cur_budget_lo = (unsigned) svc->cur_budget;
+            d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+            trace_var(TRC_RT_RUNQ_PICK, 1,
+                      sizeof(d),
+                      (unsigned char *) &d);
+        }
+        else
+            trace_var(TRC_RT_RUNQ_PICK, 1, 0, NULL);
+    }
+
+    return svc;
+}
+
+/*
+ * Update vcpu's budget and sort runq by insert the modifed vcpu back to runq
+ * lock is grabbed before calling this function
+ */
+static void
+__repl_update(const struct scheduler *ops, s_time_t now)
+{
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    struct list_head *tmp;
+    struct rt_vcpu *svc = NULL;
+
+    list_for_each_safe(iter, tmp, runq)

xen/common/sched_rt.c line 807

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+    {
+        svc = __runq_elem(iter);
+
+        /* not update flag_vcpu's budget */
+        if(svc->sdom == NULL)
+            continue;
+
+        rt_update_helper(now, svc);
+        /* reinsert the vcpu if its deadline is updated */
+        if ( now >= 0 )

Uum, when is this ever not going to be >= 0? The comment here seems completely inaccurate...

Also, it seems like you could make this a bit more efficient by pulling the check into this loop itself, rather than putting it in the helper function. Since the queue is sorted by deadline, you could stop processing once you reach one for which now < cur_deadline, since you know all subsequent ones will even later than this one.

Of course, that wouldn't take care of the depleted ones, but if those were already on a separate queue, you'd be OK. :-)

Right, past time for me to go home... I've given a quick scan over the other things and nothing jumped out at me, but I'll come back to it again tomorrow and see how we fare.

Overall, the code was pretty clean, and easy for me to read -- very much like credit1 and credit2, so thanks. :-)

-George

#4 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

Quoted 12 lines · George Dunlap
Quoted 10 lines · Meng Xu
xen/common/sched_rt.c new file +10 -0
+/*
+ * update deadline and budget when deadline is in the past,
+ * it need to be updated to the deadline of the current period
+ */
+static void
+rt_update_helper(s_time_t now, struct rt_vcpu *svc)
+{
+    s_time_t diff = now - svc->cur_deadline;
+
+    if ( diff >= 0 )
Quoted 9 lines

xen/common/sched_rt.c line 346

Quoted 5 lines
xen/common/sched_rt.c new file +5 -0
+    {
+        /* now can be later for several periods */
+        long count = ( diff/svc->period ) + 1;
+        svc->cur_deadline += count * svc->period;
+        svc->cur_budget = svc->budget;

In the common case, don't we expect diff/svc->period to be a small number, like 0 or 1?

In general, yes. The only exception is when cur_deadline is set for the first time. In that case, now can be arbitrary large and cur_deadline will always be 0, so quite a few iterations may be required, possibly taking longer than the div and the mult.

That is not an hot path anyway, so either approach would be fine in that case. For all the other occurrences, the while{} approach is an absolute win-win, IMO.

Quoted 13 lines

If so, since division and multiplication are so expensive, it might make more sense to make this a while() loop:

  while (now - svc_cur_deadline > 0 )
  {
   svc->cur_deadline += svc->period;
   count++;
  }
  if ( count ) {
   svc->cur_budget = svc->budget;
   [tracing code]
  }
Quoted 2 lines

And similarly for the other 64-bit division Dario was asking about below?

Hehe, this is, I think, the third or fourth time I say I'd like this to be turned into a while! :-D

If it were me doing this, I'd go for something like this:

  static void
  rt_update_helper(s_time_t now, struct rt_vcpu *svc)
  {
      if ( svc->cur_deadline > now )
          return;
      do
          svc->cur_deadline += svc->period;
      while ( svc->cur_deadline <= now );
      svc->cur_budget = svc->budget;

      [tracing]

}

Or even just the do {} while (and below), and have the check at the call sites (as George is also saying below).

Quoted 2 lines

I probably wouldn't make this a precondition of going in.

No, I'm not strict about this either, we can do it later. I don't think it's a big or a too disruptive change, though. :-)

Quoted 28 lines
Quoted 28 lines
xen/common/sched_rt.c new file +28 -0
+
+        /* TRACE */
+        {
+            struct {
+                unsigned dom:16,vcpu:16;
+                unsigned cur_budget_lo, cur_budget_hi;
+            } d;
+            d.dom = svc->vcpu->domain->domain_id;
+            d.vcpu = svc->vcpu->vcpu_id;
+            d.cur_budget_lo = (unsigned) svc->cur_budget;
+            d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+            trace_var(TRC_RT_BUDGET_REPLENISH, 1,
+                      sizeof(d),
+                      (unsigned char *) &d);
+        }
+
+        return;
+    }
+}
+
+static inline void
+__runq_remove(struct rt_vcpu *svc)
+{
+    if ( __vcpu_on_runq(svc) )
+        list_del_init(&svc->runq_elem);
+}
+
+/*
Quoted 9 lines

xen/common/sched_rt.c line 382

Quoted 8 lines

+ * Insert svc in the RunQ according to EDF: vcpus with smaller deadlines
+ * goes first.
+ */

xen/common/sched_rt.c new file +5 -0
+static void
+__runq_insert(const struct scheduler *ops, struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);

Oh, BTW, George, what do you think about these? The case, I mean. Since now they're static inlines, I've been telling Meng to turn the function names lower case.

This is, of course, a minor thing, but since we're saying the are not major issues... :-)

Quoted 3 lines

Overall, the code was pretty clean, and easy for me to read -- very much like credit1 and credit2, so thanks. :-)

Yep, indeed!

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

#5 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

Quoted 22 lines · Dario Faggioli
Quoted 12 lines · George Dunlap
Quoted 10 lines · Meng Xu
xen/common/sched_rt.c new file +10 -0
+/*
+ * update deadline and budget when deadline is in the past,
+ * it need to be updated to the deadline of the current period
+ */
+static void
+rt_update_helper(s_time_t now, struct rt_vcpu *svc)
+{
+    s_time_t diff = now - svc->cur_deadline;
+
+    if ( diff >= 0 )
Quoted 9 lines

xen/common/sched_rt.c line 346

Quoted 5 lines
xen/common/sched_rt.c new file +5 -0
+    {
+        /* now can be later for several periods */
+        long count = ( diff/svc->period ) + 1;
+        svc->cur_deadline += count * svc->period;
+        svc->cur_budget = svc->budget;

In the common case, don't we expect diff/svc->period to be a small number, like 0 or 1?

Quoted 4 lines

In general, yes. The only exception is when cur_deadline is set for the first time. In that case, now can be arbitrary large and cur_deadline will always be 0, so quite a few iterations may be required, possibly taking longer than the div and the mult.

Right, well we should be able to special-case zero. Is there any reason, if cur_deadline == 0, not to just set cur_deadline=now + svc->period? I can see a reason why after skipping several periods you'd want the future periods "lined up with" previous periods. But is there a need to have all the periods lined up from the beginning of time?

Quoted 4 lines
Quoted 2 lines

And similarly for the other 64-bit division Dario was asking about below?

Hehe, this is, I think, the third or fourth time I say I'd like this to be turned into a while! :-D

Well, if you've asked for it several times, we should probably make it a precondition of going in then.

Quoted 8 lines

If it were me doing this, I'd go for something like this:

  static void
  rt_update_helper(s_time_t now, struct rt_vcpu *svc)
  {
      if ( svc->cur_deadline > now )
          return;
Quoted 7 lines
      do
          svc->cur_deadline += svc->period;
      while ( svc->cur_deadline <= now );
      svc->cur_budget = svc->budget;

      [tracing]

}

Yes, that looks even cleaner. :-)

Quoted 10 lines
Quoted 4 lines

xen/common/sched_rt.c line 382

Quoted 3 lines
xen/common/sched_rt.c new file +3 -0
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);

Oh, BTW, George, what do you think about these? The case, I mean. Since now they're static inlines, I've been telling Meng to turn the function names lower case.

This is, of course, a minor thing, but since we're saying the are not major issues... :-)

Yes, static inlines need to be lower case.

-George

#6 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

2014-09-09 7:31 GMT-04:00 George Dunlap <[email protected]>:

Quoted 29 lines
Quoted 22 lines · Dario Faggioli
Quoted 12 lines · George Dunlap
Quoted 10 lines · Meng Xu
xen/common/sched_rt.c new file +10 -0
+/*
+ * update deadline and budget when deadline is in the past,
+ * it need to be updated to the deadline of the current period
+ */
+static void
+rt_update_helper(s_time_t now, struct rt_vcpu *svc)
+{
+    s_time_t diff = now - svc->cur_deadline;
+
+    if ( diff >= 0 )
Quoted 9 lines

xen/common/sched_rt.c line 346

Quoted 5 lines
xen/common/sched_rt.c new file +5 -0
+    {
+        /* now can be later for several periods */
+        long count = ( diff/svc->period ) + 1;
+        svc->cur_deadline += count * svc->period;
+        svc->cur_budget = svc->budget;

In the common case, don't we expect diff/svc->period to be a small number, like 0 or 1?

Quoted 4 lines

In general, yes. The only exception is when cur_deadline is set for the first time. In that case, now can be arbitrary large and cur_deadline will always be 0, so quite a few iterations may be required, possibly taking longer than the div and the mult.

Quoted 7 lines

Right, well we should be able to special-case zero. Is there any reason, if cur_deadline == 0, not to just set cur_deadline=now + svc->period? I can see a reason why after skipping several periods you'd want the future periods "lined up with" previous periods. But is there a need to have all the periods lined up from the beginning of time?

Actually, no need to line up all vcpus from the beginning of time. This just makes the scheduler more deterministic since everytime when we boot the system, we know all vcpus are lined up to the beginning of time. When a vcpu is created, its cur_deadline can be now + svc->period.

I'm personally fine with either way. (very slightly prefer the line up way because it is more deterministic, but not so prefer. :-))

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

And similarly for the other 64-bit division Dario was asking about below?

Hehe, this is, I think, the third or fourth time I say I'd like this to be turned into a while! :-D

Well, if you've asked for it several times, we should probably make it a precondition of going in then.

I will modify this for sure in the next version. Didn't realize this was stressed for many times. Sorry Dario for bothering you. :-(

Quoted 23 lines
Quoted 9 lines

If it were me doing this, I'd go for something like this:

  static void
  rt_update_helper(s_time_t now, struct rt_vcpu *svc)
  {
      if ( svc->cur_deadline > now )
          return;
Quoted 7 lines
      do
          svc->cur_deadline += svc->period;
      while ( svc->cur_deadline <= now );
      svc->cur_budget = svc->budget;

      [tracing]

}

Yes, that looks even cleaner. :-)

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
xen/common/sched_rt.c new file +3 -0
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);
Quoted 8 lines
Quoted 6 lines

Oh, BTW, George, what do you think about these? The case, I mean. Since now they're static inlines, I've been telling Meng to turn the function names lower case.

This is, of course, a minor thing, but since we're saying the are not major issues... :-)

Yes, static inlines need to be lower case.

Roger and will change to lower case then.

Thanks,

Meng

Signature · 4 lines
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
#7 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

In reply to Dario Faggioli

Hi George and Dario,

2014-09-09 5:42 GMT-04:00 Dario Faggioli <[email protected]>:

Quoted 63 lines · George Dunlap
Quoted 12 lines · Meng Xu
Quoted 11 lines
xen/common/sched_rt.c new file +10 -0
+/*
+ * update deadline and budget when deadline is in the past,
+ * it need to be updated to the deadline of the current period
+ */
+static void
+rt_update_helper(s_time_t now, struct rt_vcpu *svc)
+{
+    s_time_t diff = now - svc->cur_deadline;
+
+    if ( diff >= 0 )
Quoted 9 lines

xen/common/sched_rt.c line 346

Quoted 5 lines
xen/common/sched_rt.c new file +5 -0
+    {
+        /* now can be later for several periods */
+        long count = ( diff/svc->period ) + 1;
+        svc->cur_deadline += count * svc->period;
+        svc->cur_budget = svc->budget;

In the common case, don't we expect diff/svc->period to be a small number, like 0 or 1?

In general, yes. The only exception is when cur_deadline is set for the first time. In that case, now can be arbitrary large and cur_deadline will always be 0, so quite a few iterations may be required, possibly taking longer than the div and the mult.

That is not an hot path anyway, so either approach would be fine in that case. For all the other occurrences, the while{} approach is an absolute win-win, IMO.

Quoted 13 lines

If so, since division and multiplication are so expensive, it might make more sense to make this a while() loop:

  while (now - svc_cur_deadline > 0 )
  {
   svc->cur_deadline += svc->period;
   count++;
  }
  if ( count ) {
   svc->cur_budget = svc->budget;
   [tracing code]
  }
Quoted 2 lines

And similarly for the other 64-bit division Dario was asking about below?

Hehe, this is, I think, the third or fourth time I say I'd like this to be turned into a while! :-D

If it were me doing this, I'd go for something like this:

  static void
  rt_update_helper(s_time_t now, struct rt_vcpu *svc)
  {
      if ( svc->cur_deadline > now )
          return;
      do
          svc->cur_deadline += svc->period;
      while ( svc->cur_deadline <= now );
      svc->cur_budget = svc->budget;

      [tracing]
Quoted 4 lines

}

Or even just the do {} while (and below), and have the check at the call sites (as George is also saying below).

I see the point and will change them for the next version. Thank you very much! :-)

Quoted 47 lines
Quoted 3 lines

I probably wouldn't make this a precondition of going in.

No, I'm not strict about this either, we can do it later. I don't think it's a big or a too disruptive change, though. :-)

Quoted 28 lines
Quoted 28 lines
xen/common/sched_rt.c new file +28 -0
+
+        /* TRACE */
+        {
+            struct {
+                unsigned dom:16,vcpu:16;
+                unsigned cur_budget_lo, cur_budget_hi;
+            } d;
+            d.dom = svc->vcpu->domain->domain_id;
+            d.vcpu = svc->vcpu->vcpu_id;
+            d.cur_budget_lo = (unsigned) svc->cur_budget;
+            d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+            trace_var(TRC_RT_BUDGET_REPLENISH, 1,
+                      sizeof(d),
+                      (unsigned char *) &d);
+        }
+
+        return;
+    }
+}
+
+static inline void
+__runq_remove(struct rt_vcpu *svc)
+{
+    if ( __vcpu_on_runq(svc) )
+        list_del_init(&svc->runq_elem);
+}
+
+/*
Quoted 9 lines

xen/common/sched_rt.c line 382

Quoted 8 lines

+ * Insert svc in the RunQ according to EDF: vcpus with smaller deadlines
+ * goes first.
+ */

xen/common/sched_rt.c new file +5 -0
+static void
+__runq_insert(const struct scheduler *ops, struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);

Oh, BTW, George, what do you think about these? The case, I mean. Since now they're static inlines, I've been telling Meng to turn the function names lower case.

Quoted 7 lines

This is, of course, a minor thing, but since we're saying the are not major issues... :-)

Quoted 3 lines

Overall, the code was pretty clean, and easy for me to read -- very much like credit1 and credit2, so thanks. :-)

Yep, indeed!

Yes, it is. :-)

Thank you very much for your helpful comments and advice! I will incorporate them in the next version.

Best,

Meng
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania

#8 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

In reply to George Dunlap

2014-09-08 14:44 GMT-04:00 George Dunlap <[email protected]>:

Quoted 367 lines · Meng Xu
Quoted 366 lines

This scheduler follows the Preemptive Global Earliest Deadline First (EDF) theory in real-time field.
At any scheduling point, the VCPU with earlier deadline has higher priority. The scheduler always picks the highest priority VCPU to run on a feasible PCPU.
A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is idle or has a lower-priority VCPU running on it.)

Each VCPU has a dedicated period and budget.
The deadline of a VCPU is at the end of each of its periods;
A VCPU has its budget replenished at the beginning of each of its periods; While scheduled, a VCPU burns its budget.
The VCPU needs to finish its budget before its deadline in each period; The VCPU discards its unused budget at the end of each of its periods. If a VCPU runs out of budget in a period, it has to wait until next period.

Each VCPU is implemented as a deferable server.
When a VCPU has a task running on it, its budget is continuously burned; When a VCPU has no task but with budget left, its budget is preserved.

Queue scheme: A global runqueue for each CPU pool.
The runqueue holds all runnable VCPUs.
VCPUs in the runqueue are divided into two parts: with and without budget. At the first part, VCPUs are sorted based on EDF priority scheme.

Note: cpumask and cpupool is supported.

This is an experimental scheduler.

---
  xen/common/Makefile         |    1 +
  xen/common/sched_rt.c       | 1146
+++++++++++++++++++++++++++++++++++++++++++
  xen/common/schedule.c       |    1 +
  xen/include/public/domctl.h |    6 +
  xen/include/public/trace.h  |    1 +
  xen/include/xen/sched-if.h  |    1 +
  6 files changed, 1156 insertions(+)

create mode 100644 xen/common/sched_rt.c

xen/common/Makefile +1 -0
index 3683ae3..5a23aa4 100644
@@ -26,6 +26,7 @@ obj-y += sched_credit.o
  obj-y += sched_credit2.o
  obj-y += sched_sedf.o
  obj-y += sched_arinc653.o
+obj-y += sched_rt.o
  obj-y += schedule.o
  obj-y += shutdown.o
  obj-y += softirq.o
xen/common/sched_rt.c new file +3 -0
new file mode 100644
index 0000000..412f8b1
@@ -0,0 +1,1146 @@
 
+/******************************************************************************
+ * Preemptive Global Earliest Deadline First  (EDF) scheduler for Xen
+ * EDF scheduling is a real-time scheduling algorithm used in embedded

field.
+ *
+ * by Sisu Xi, 2013, Washington University in Saint Louis
+ * and Meng Xu, 2014, University of Pennsylvania
+ *
+ * based on the code of credit Scheduler
+ */

xen/common/sched_rt.c new file +32 -0
+
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/sched.h>
+#include <xen/domain.h>
+#include <xen/delay.h>
+#include <xen/event.h>
+#include <xen/time.h>
+#include <xen/perfc.h>
+#include <xen/sched-if.h>
+#include <xen/softirq.h>
+#include <asm/atomic.h>
+#include <xen/errno.h>
+#include <xen/trace.h>
+#include <xen/cpu.h>
+#include <xen/keyhandler.h>
+#include <xen/trace.h>
+#include <xen/guest_access.h>
+
+/*
+ * TODO:
+ *
+ * Migration compensation and resist like credit2 to better use cache;
+ * Lock Holder Problem, using yield?
+ * Self switch problem: VCPUs of the same domain may preempt each other;
+ */
+
+/*
+ * Design:
+ *
+ * This scheduler follows the Preemptive Global Earliest Deadline First

(EDF)
+ * theory in real-time field.
+ * At any scheduling point, the VCPU with earlier deadline has higher priority.
+ * The scheduler always picks highest priority VCPU to run on a feasible PCPU.
+ * A PCPU is feasible if the VCPU can run on this PCPU and (the PCPU is idle or
+ * has a lower-priority VCPU running on it.)
+ *
+ * Each VCPU has a dedicated period and budget.
+ * The deadline of a VCPU is at the end of each of its periods;
+ * A VCPU has its budget replenished at the beginning of each of its periods;
+ * While scheduled, a VCPU burns its budget.
+ * The VCPU needs to finish its budget before its deadline in each period;
+ * The VCPU discards its unused budget at the end of each of its periods.
+ * If a VCPU runs out of budget in a period, it has to wait until next period.
+ *
+ * Each VCPU is implemented as a deferable server.
+ * When a VCPU has a task running on it, its budget is continuously burned;
+ * When a VCPU has no task but with budget left, its budget is preserved.
+ *
+ * Queue scheme: A global runqueue for each CPU pool.
+ * The runqueue holds all runnable VCPUs.
+ * VCPUs in the runqueue are divided into two parts:
+ * with and without remaining budget.
+ * At the first part, VCPUs are sorted based on EDF priority scheme.
+ *
+ * Note: cpumask and cpupool is supported.
+ */

xen/common/sched_rt.c new file +8 -0
+
+/*
+ * Locking:
+ * A global system lock is used to protect the RunQ.
+ * The global lock is referenced by schedule_data.schedule_lock
+ * from all physical cpus.
+ *
+ * The lock is already grabbed when calling wake/sleep/schedule/

functions
+ * in schedule.c
+ *
+ * The functions involes RunQ and needs to grab locks are:
+ * vcpu_insert, vcpu_remove, context_saved, __runq_insert
+ */

xen/common/sched_rt.c new file +14 -0
+
+
+/*
+ * Default parameters:
+ * Period and budget in default is 10 and 4 ms, respectively
+ */
+#define RT_DS_DEFAULT_PERIOD     (MICROSECS(10000))
+#define RT_DS_DEFAULT_BUDGET     (MICROSECS(4000))
+
+/*
+ * Flags
+ */
+/*
+ * RT_scheduled: Is this vcpu either running on, or context-switching

off,
+ * a phyiscal cpu?
+ * + Accessed only with Runqueue lock held.
+ * + Set when chosen as next in rt_schedule().
+ * + Cleared after context switch has been saved in rt_context_saved()
+ * + Checked in vcpu_wake to see if we can add to the Runqueue, or if we should
+ * set RT_delayed_runq_add
+ * + Checked to be false in runq_insert.
+ */

xen/common/sched_rt.c new file +4 -0
+#define __RT_scheduled            1
+#define RT_scheduled (1<<__RT_scheduled)
+/*
+ * RT_delayed_runq_add: Do we need to add this to the Runqueueu once it'd

done
+ * being context switching out?
+ * + Set when scheduling out in rt_schedule() if prev is runable
+ * + Set in rt_vcpu_wake if it finds RT_scheduled set
+ * + Read in rt_context_saved(). If set, it adds prev to the Runqueue and
+ * clears the bit.
+ */

xen/common/sched_rt.c new file +30 -0
+#define __RT_delayed_runq_add     2
+#define RT_delayed_runq_add (1<<__RT_delayed_runq_add)
+
+/*
+ * Debug only. Used to printout debug information
+ */
+#define printtime()\
+        ({s_time_t now = NOW(); \
+          printk("%u : %3ld.%3ldus : %-19s\n",smp_processor_id(),\
+          now/MICROSECS(1), now%MICROSECS(1)/1000, __func__);} )
+
+/*
+ * rt tracing events ("only" 512 available!). Check
+ * include/public/trace.h for more details.
+ */
+#define TRC_RT_TICKLE           TRC_SCHED_CLASS_EVT(RT, 1)
+#define TRC_RT_RUNQ_PICK        TRC_SCHED_CLASS_EVT(RT, 2)
+#define TRC_RT_BUDGET_BURN      TRC_SCHED_CLASS_EVT(RT, 3)
+#define TRC_RT_BUDGET_REPLENISH TRC_SCHED_CLASS_EVT(RT, 4)
+#define TRC_RT_SCHED_TASKLET    TRC_SCHED_CLASS_EVT(RT, 5)
+#define TRC_RT_VCPU_DUMP        TRC_SCHED_CLASS_EVT(RT, 6)
+
+/*
+ * Systme-wide private data, include a global RunQueue
+ * Global lock is referenced by schedule_data.schedule_lock from all
+ * physical cpus. It can be grabbed via vcpu_schedule_lock_irq()
+ */
+struct rt_private {
+    spinlock_t lock;           /* The global coarse grand lock */
+    struct list_head sdom;     /* list of availalbe domains, used for

dump */

xen/common/sched_rt.c new file +92 -0
+    struct list_head runq;     /* Ordered list of runnable VMs */
+    struct rt_vcpu *flag_vcpu; /* position of the first depleted vcpu */
+    cpumask_t cpus;            /* cpumask_t of available physical cpus */
+    cpumask_t tickled;         /* cpus been tickled */
+};
+
+/*
+ * Virtual CPU
+ */
+struct rt_vcpu {
+    struct list_head runq_elem; /* On the runqueue list */
+    struct list_head sdom_elem; /* On the domain VCPU list */
+
+    /* Up-pointers */
+    struct rt_dom *sdom;
+    struct vcpu *vcpu;
+
+    /* VCPU parameters, in nanoseconds */
+    s_time_t period;
+    s_time_t budget;
+
+    /* VCPU current infomation in nanosecond */
+    s_time_t cur_budget;        /* current budget */
+    s_time_t last_start;        /* last start time */
+    s_time_t cur_deadline;      /* current deadline for EDF */
+
+    unsigned flags;             /* mark __RT_scheduled, etc.. */
+};
+
+/*
+ * Domain
+ */
+struct rt_dom {
+    struct list_head vcpu;      /* link its VCPUs */
+    struct list_head sdom_elem; /* link list on rt_priv */
+    struct domain *dom;         /* pointer to upper domain */
+};
+
+/*
+ * Useful inline functions
+ */
+static inline struct rt_private *RT_PRIV(const struct scheduler *ops)
+{
+    return ops->sched_data;
+}
+
+static inline struct rt_vcpu *RT_VCPU(const struct vcpu *vcpu)
+{
+    return vcpu->sched_priv;
+}
+
+static inline struct rt_dom *RT_DOM(const struct domain *dom)
+{
+    return dom->sched_priv;
+}
+
+static inline struct list_head *RUNQ(const struct scheduler *ops)
+{
+    return &RT_PRIV(ops)->runq;
+}
+
+/*
+ * RunQueue helper functions
+ */
+static int
+__vcpu_on_runq(const struct rt_vcpu *svc)
+{
+   return !list_empty(&svc->runq_elem);
+}
+
+static struct rt_vcpu *
+__runq_elem(struct list_head *elem)
+{
+    return list_entry(elem, struct rt_vcpu, runq_elem);
+}
+
+/*
+ * Debug related code, dump vcpu/cpu information
+ */
+static void
+rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    char cpustr[1024];
+    cpumask_t *cpupool_mask;
+
+    ASSERT(svc != NULL);
+    /* flag vcpu */
+    if( svc->sdom == NULL )
+        return;
+
+    cpumask_scnprintf(cpustr, sizeof(cpustr),

svc->vcpu->cpu_hard_affinity);

xen/common/sched_rt.c new file +54 -0
+    printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime"),"
+           " cur_b=%"PRI_stime" cur_d=%"PRI_stime" last_start=%"PRI_stime
+           " onR=%d runnable=%d cpu_hard_affinity=%s ",
+            svc->vcpu->domain->domain_id,
+            svc->vcpu->vcpu_id,
+            svc->vcpu->processor,
+            svc->period,
+            svc->budget,
+            svc->cur_budget,
+            svc->cur_deadline,
+            svc->last_start,
+            __vcpu_on_runq(svc),
+            vcpu_runnable(svc->vcpu),
+            cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpupool_mask = cpupool_scheduler_cpumask(svc->vcpu->domain->cpupool);
+    cpumask_scnprintf(cpustr, sizeof(cpustr), cpupool_mask);
+    printk("cpupool=%s ", cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpumask_scnprintf(cpustr, sizeof(cpustr), &prv->cpus);
+    printk("prv->cpus=%s\n", cpustr);
+
+    /* TRACE */
+    {
+        struct {
+            unsigned dom:16,vcpu:16;
+            unsigned processor;
+            unsigned cur_budget_lo, cur_budget_hi;
+            unsigned cur_deadline_lo, cur_deadline_hi;
+            unsigned is_vcpu_on_runq:16,is_vcpu_runnable:16;
+        } d;
+        d.dom = svc->vcpu->domain->domain_id;
+        d.vcpu = svc->vcpu->vcpu_id;
+        d.processor = svc->vcpu->processor;
+        d.cur_budget_lo = (unsigned) svc->cur_budget;
+        d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+        d.cur_deadline_lo = (unsigned) svc->cur_deadline;
+        d.cur_deadline_hi = (unsigned) (svc->cur_deadline >> 32);
+        d.is_vcpu_on_runq = __vcpu_on_runq(svc);
+        d.is_vcpu_runnable = vcpu_runnable(svc->vcpu);
+        trace_var(TRC_RT_VCPU_DUMP, 1,
+                  sizeof(d),
+                  (unsigned char *)&d);
+    }
+}
+
+static void
+rt_dump_pcpu(const struct scheduler *ops, int cpu)
+{
+    struct rt_vcpu *svc = RT_VCPU(curr_on_cpu(cpu));
+
+    printtime();
+    rt_dump_vcpu(ops, svc);
+}
Quoted 8 lines

xen/common/sched_rt.c line 292

Quoted 4 lines
xen/common/sched_rt.c new file +4 -0
+
+/*
+ * should not need lock here. only showing stuff
+ */

This isn't true -- you're walking both the runqueue and the lists of domains and vcpus, each of which may change under your feet.

I see. So even when I only read (and never write) the runqueue, I still need to use the lock. I can add the lock in these dumps.

Quoted 61 lines
Quoted 61 lines
xen/common/sched_rt.c new file +40 -0
+
+        /* TRACE */
+        {
+            struct {
+                unsigned dom:16,vcpu:16;
+                unsigned cur_budget_lo, cur_budget_hi;
+            } d;
+            d.dom = svc->vcpu->domain->domain_id;
+            d.vcpu = svc->vcpu->vcpu_id;
+            d.cur_budget_lo = (unsigned) svc->cur_budget;
+            d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+            trace_var(TRC_RT_BUDGET_REPLENISH, 1,
+                      sizeof(d),
+                      (unsigned char *) &d);
+        }
+
+        return;
+    }
+}
+
+static inline void
+__runq_remove(struct rt_vcpu *svc)
+{
+    if ( __vcpu_on_runq(svc) )
+        list_del_init(&svc->runq_elem);
+}
+
+/*
+ * Insert svc in the RunQ according to EDF: vcpus with smaller deadlines
+ * goes first.
+ */
+static void
+__runq_insert(const struct scheduler *ops, struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    spinlock_t *schedule_lock;
+
+    schedule_lock = per_cpu(schedule_data,

svc->vcpu->processor).schedule_lock;

xen/common/sched_rt.c new file +19 -0
+    ASSERT( spin_is_locked(schedule_lock) );
+
+    ASSERT( !__vcpu_on_runq(svc) );
+
+    /* svc still has budget */
+    if ( svc->cur_budget > 0 )
+    {
+        list_for_each(iter, runq)
+        {
+            struct rt_vcpu * iter_svc = __runq_elem(iter);
+            if ( iter_svc->cur_budget == 0 ||
+                 svc->cur_deadline <= iter_svc->cur_deadline )
+                    break;
+         }
+        list_add_tail(&svc->runq_elem, iter);
+     }
+    else
+    {
+        list_add(&svc->runq_elem, &prv->flag_vcpu->runq_elem);
Quoted 8 lines
Quoted 1 line

+ }

OK, this thing with the "flag vcpu" seems a bit weird. Why not just have two queues -- a runq and a depletedq. You don't need to have another function; you just add it to depleted_runq rather than runq in __runq_insert(). Then you don't have to have this "cur_budget==0" stuff. The only extra code you'd have is (I think) in __repl_update().

I may need to add some other code, like the static inline function DEPLETEDQ() to get the depletedq from struct rt_private, and the DepletedQ's helper functions, like __vcpu_on_depletedq, etc. But these codes are not big, so Yes, I will change it to two queues in the next version.

Quoted 29 lines
Quoted 15 lines
xen/common/sched_rt.c new file +6 -0
+
+/*
+ * Burn budget in nanosecond granularity
+ */
+static void
+burn_budgets(const struct scheduler *ops, struct rt_vcpu *svc, s_time_t

now)

xen/common/sched_rt.c new file +8 -0
+{
+    s_time_t delta;
+
+    /* don't burn budget for idle VCPU */
+    if ( is_idle_vcpu(svc->vcpu) )
+        return;
+
+    rt_update_helper(now, svc);

xen/common/sched_rt.c line 684

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+
+    /* not burn budget when vcpu miss deadline */
+    if ( now >= svc->cur_deadline )
+        return;
+
+    /* burn at nanoseconds level */
+    delta = now - svc->last_start;
+    /*
+     * delta < 0 only happens in nested virtualization;
+     * TODO: how should we handle delta < 0 in a better way?

I think what I did in credit2 was just

Quoted 5 lines

if(delta < 0) delta = 0;

What you're doing here basically takes away an entire budget when the time goes backwards for whatever reason. Much better, it seems to me, to just give the vcpu some "free" time and deal with it. :-)

I can remove svc->cur_budget = 0 to not set the vcpu's budget to 0. If this vcpu has some budget left during this period and has higher priority, it should be able to run.
So I will remove svc->cur_budget = 0.

Quoted 21 lines
Quoted 21 lines
xen/common/sched_rt.c new file +3 -0
+
+/*
+ * Update vcpu's budget and sort runq by insert the modifed vcpu back to

runq
+ * lock is grabbed before calling this function
+ */

xen/common/sched_rt.c new file +15 -0
+static void
+__repl_update(const struct scheduler *ops, s_time_t now)
+{
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    struct list_head *tmp;
+    struct rt_vcpu *svc = NULL;
+
+    list_for_each_safe(iter, tmp, runq)
+    {
+        svc = __runq_elem(iter);
+
+        /* not update flag_vcpu's budget */
+        if(svc->sdom == NULL)
+            continue;
Quoted 8 lines

xen/common/sched_rt.c line 807

Quoted 4 lines
xen/common/sched_rt.c new file +4 -0
+
+        rt_update_helper(now, svc);
+        /* reinsert the vcpu if its deadline is updated */
+        if ( now >= 0 )

Uum, when is this ever not going to be >= 0? The comment here seems completely inaccurate...

My bad. This is incorrect. :-( It should be diff (which is now-svc->cur_deadline) >= 0. Sorry. Will change in the next patch.

Quoted 9 lines

Also, it seems like you could make this a bit more efficient by pulling the check into this loop itself, rather than putting it in the helper function. Since the queue is sorted by deadline, you could stop processing once you reach one for which now < cur_deadline, since you know all subsequent ones will even later than this one.

Of course, that wouldn't take care of the depleted ones, but if those were already on a separate queue, you'd be OK. :-)

Sure! Will do that.

Quoted 4 lines

Right, past time for me to go home... I've given a quick scan over the other things and nothing jumped out at me, but I'll come back to it again tomorrow and see how we fare.

Thank you so much for your comments and time! I really appreciate it and will tackle these comments in the next version asap.

Thanks!

Meng

-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania

#9 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

In reply to Meng Xu

xen/common/sched_rt.c line 123

Quoted 12 lines · Meng Xu
xen/common/sched_rt.c new file +8 -0
new file mode 100644
index 0000000..412f8b1
 
+/*
+ * Debug only. Used to printout debug information
+ */
+#define printtime()\
+        ({s_time_t now = NOW(); \
+          printk("%u : %3ld.%3ldus : %-19s\n",smp_processor_id(),\
+          now/MICROSECS(1), now%MICROSECS(1)/1000, __func__);} )
+

You probably don't need this. As I said yesterday, you can keep it in an out-of-series debug commit/patch.

xen/common/sched_rt.c line 133

Quoted 11 lines
xen/common/sched_rt.c new file +10 -0
+/*
+ * rt tracing events ("only" 512 available!). Check
+ * include/public/trace.h for more details.
+ */
+#define TRC_RT_TICKLE           TRC_SCHED_CLASS_EVT(RT, 1)
+#define TRC_RT_RUNQ_PICK        TRC_SCHED_CLASS_EVT(RT, 2)
+#define TRC_RT_BUDGET_BURN      TRC_SCHED_CLASS_EVT(RT, 3)
+#define TRC_RT_BUDGET_REPLENISH TRC_SCHED_CLASS_EVT(RT, 4)
+#define TRC_RT_SCHED_TASKLET    TRC_SCHED_CLASS_EVT(RT, 5)
+#define TRC_RT_VCPU_DUMP        TRC_SCHED_CLASS_EVT(RT, 6)

Ditto about the uselessness of TRC_RT_VCPU_DUMP.

Also, as already said, RTDS here and everywhere else.

xen/common/sched_rt.c line 143

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+
+/*
+ * Systme-wide private data, include a global RunQueue
+ * Global lock is referenced by schedule_data.schedule_lock from all 
+ * physical cpus. It can be grabbed via vcpu_schedule_lock_irq()
+ */
+struct rt_private {
+    spinlock_t lock;           /* The global coarse grand lock */
+    struct list_head sdom;     /* list of availalbe domains, used for dump */
+    struct list_head runq;     /* Ordered list of runnable VMs */

runnable vcpus ?

Quoted 15 lines
xen/common/sched_rt.c new file +13 -0
+    struct rt_vcpu *flag_vcpu; /* position of the first depleted vcpu */
+    cpumask_t cpus;            /* cpumask_t of available physical cpus */
+    cpumask_t tickled;         /* cpus been tickled */
+};
 
+/*
+ * Debug related code, dump vcpu/cpu information
+ */
+static void
+rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    char cpustr[1024];
+    cpumask_t *cpupool_mask;

xen/common/sched_rt.c line 237

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+
+    ASSERT(svc != NULL);
+    /* flag vcpu */
+    if( svc->sdom == NULL )
+        return;
+
+    cpumask_scnprintf(cpustr, sizeof(cpustr), svc->vcpu->cpu_hard_affinity);
+    printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime"),"
+           " cur_b=%"PRI_stime" cur_d=%"PRI_stime" last_start=%"PRI_stime
+           " onR=%d runnable=%d cpu_hard_affinity=%s ",

How does this come up in the console? Should we break it with a '\n' somewhere? It looks rather long...

Quoted 42 lines
xen/common/sched_rt.c new file +41 -0
+            svc->vcpu->domain->domain_id,
+            svc->vcpu->vcpu_id,
+            svc->vcpu->processor,
+            svc->period,
+            svc->budget,
+            svc->cur_budget,
+            svc->cur_deadline,
+            svc->last_start,
+            __vcpu_on_runq(svc),
+            vcpu_runnable(svc->vcpu),
+            cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpupool_mask = cpupool_scheduler_cpumask(svc->vcpu->domain->cpupool);
+    cpumask_scnprintf(cpustr, sizeof(cpustr), cpupool_mask);
+    printk("cpupool=%s ", cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpumask_scnprintf(cpustr, sizeof(cpustr), &prv->cpus);
+    printk("prv->cpus=%s\n", cpustr);
+    
+    /* TRACE */
+    {
+        struct {
+            unsigned dom:16,vcpu:16;
+            unsigned processor;
+            unsigned cur_budget_lo, cur_budget_hi;
+            unsigned cur_deadline_lo, cur_deadline_hi;
+            unsigned is_vcpu_on_runq:16,is_vcpu_runnable:16;
+        } d;
+        d.dom = svc->vcpu->domain->domain_id;
+        d.vcpu = svc->vcpu->vcpu_id;
+        d.processor = svc->vcpu->processor;
+        d.cur_budget_lo = (unsigned) svc->cur_budget;
+        d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+        d.cur_deadline_lo = (unsigned) svc->cur_deadline;
+        d.cur_deadline_hi = (unsigned) (svc->cur_deadline >> 32);
+        d.is_vcpu_on_runq = __vcpu_on_runq(svc);
+        d.is_vcpu_runnable = vcpu_runnable(svc->vcpu);
+        trace_var(TRC_RT_VCPU_DUMP, 1,
+                  sizeof(d),
+                  (unsigned char *)&d);
+    }

xen/common/sched_rt.c line 338

Quoted 10 lines
xen/common/sched_rt.c new file +9 -0
+}
+
 
+/*
+ * update deadline and budget when deadline is in the past,
+ * it need to be updated to the deadline of the current period 
+ */
+static void
+rt_update_helper(s_time_t now, struct rt_vcpu *svc)
+{

While you're reworking this function, I'd also consider a different name like 'rt_update_deadline', or 'rt_update_bandwidth', or something else (it's the _helper part I don't like).

Quoted 28 lines
xen/common/sched_rt.c new file +28 -0
+    s_time_t diff = now - svc->cur_deadline;
+
+    if ( diff >= 0 ) 
+    {
+        /* now can be later for several periods */
+        long count = ( diff/svc->period ) + 1;
+        svc->cur_deadline += count * svc->period;
+        svc->cur_budget = svc->budget;
+
+        /* TRACE */
+        {
+            struct {
+                unsigned dom:16,vcpu:16;
+                unsigned cur_budget_lo, cur_budget_hi;
+            } d;
+            d.dom = svc->vcpu->domain->domain_id;
+            d.vcpu = svc->vcpu->vcpu_id;
+            d.cur_budget_lo = (unsigned) svc->cur_budget;
+            d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+            trace_var(TRC_RT_BUDGET_REPLENISH, 1,
+                      sizeof(d),
+                      (unsigned char *) &d);
+        }
+
+        return;
+    }
+}
+

xen/common/sched_rt.c line 376

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+static inline void
+__runq_remove(struct rt_vcpu *svc)
+{
+    if ( __vcpu_on_runq(svc) )
+        list_del_init(&svc->runq_elem);
+}
+
+/*
+ * Insert svc in the RunQ according to EDF: vcpus with smaller deadlines
+ * goes first.

go

And if it was me that wrote 'goes', apologies for that. :-D

Quoted 10 lines

+ */

xen/common/sched_rt.c new file +8 -0
+static void
+__runq_insert(const struct scheduler *ops, struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    spinlock_t *schedule_lock;
+    

This empty line above seems to be actually empty, but looking more

carefully, it does contain 4 spaces, doesn't it?

If that's the case, avoid doing this, i.e., make sure that empty lines are actually empty. :-D

Looking at each patch with `git show' should highlight occurrences of this phenomenon, as well as of any trailing white space, by marking them in red.

xen/common/sched_rt.c line 388

Quoted 3 lines
xen/common/sched_rt.c new file +3 -0
+    schedule_lock = per_cpu(schedule_data, svc->vcpu->processor).schedule_lock;
+    ASSERT( spin_is_locked(schedule_lock) );
+    

As of now, the only lock around is prv->lock, isn't it? So this per_cpu(xxx) is a complex way to get to prv->lock, or am I missing something.

In credit, the pre-inited set of locks are actually used "as they are", while in credit2, there is some remapping going on, but there is more than one lock anyway. That's why you find things like the above in those two schedulers. Here, you should not need anything like that, (as you do everywhere else) just go ahead and use prv->lock.

Of course, that does not mean you don't need the lock remapping in rt_alloc_pdata(). That code looks ok to me, just adapt this bit above, as, like this, it makes things harder to understand.

Or am I overlooking something?

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+    ASSERT( !__vcpu_on_runq(svc) );
+
+    /* svc still has budget */
+    if ( svc->cur_budget > 0 ) 
+    {
+        list_for_each(iter, runq) 
+        {
+            struct rt_vcpu * iter_svc = __runq_elem(iter);
+            if ( iter_svc->cur_budget == 0 ||
+                 svc->cur_deadline <= iter_svc->cur_deadline )

xen/common/sched_rt.c line 408

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+                    break;
+         }
+        list_add_tail(&svc->runq_elem, iter);
+     }
+    else 
+    {
+        list_add(&svc->runq_elem, &prv->flag_vcpu->runq_elem);
+    }
+}
+

I agree with George about the queue splitting.

xen/common/sched_rt.c line 450

Quoted 8 lines
xen/common/sched_rt.c new file +7 -0
+static void
+rt_deinit(const struct scheduler *ops)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+
+    printtime();
+    printk("\n");

As said, when removing all the calls to rt_dump_vcpu, also remove both the definition and all these calls to printtime(), they're of very few value, IMO.

Quoted 7 lines
xen/common/sched_rt.c new file +5 -0
+    xfree(prv->flag_vcpu);
+    xfree(prv);
+}
 
+static void *
+rt_alloc_domdata(const struct scheduler *ops, struct domain *dom)

xen/common/sched_rt.c line 492

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+{
+    unsigned long flags;
+    struct rt_dom *sdom;
+    struct rt_private * prv = RT_PRIV(ops);
+
+    sdom = xzalloc(struct rt_dom);
+    if ( sdom == NULL ) 
+    {
+        printk("%s, xzalloc failed\n", __func__);
+        return NULL;

Just `return NULL', the printk() is pretty useless. Failures like this, will be identified, without the need of it.

Quoted 31 lines
xen/common/sched_rt.c new file +30 -0
+    }
+
+    INIT_LIST_HEAD(&sdom->vcpu);
+    INIT_LIST_HEAD(&sdom->sdom_elem);
+    sdom->dom = dom;
+
+    /* spinlock here to insert the dom */
+    spin_lock_irqsave(&prv->lock, flags);
+    list_add_tail(&sdom->sdom_elem, &(prv->sdom));
+    spin_unlock_irqrestore(&prv->lock, flags);
+
+    return sdom;
+}
 
+static void *
+rt_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd)
+{
+    struct rt_vcpu *svc;
+    s_time_t now = NOW();
+
+    /* Allocate per-VCPU info */
+    svc = xzalloc(struct rt_vcpu);
+    if ( svc == NULL ) 
+    {
+        printk("%s, xzalloc failed\n", __func__);
+        return NULL;
+    }
+
+    INIT_LIST_HEAD(&svc->runq_elem);
+    INIT_LIST_HEAD(&svc->sdom_elem);
+    svc->flags = 0U;

xen/common/sched_rt.c line 572

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+    svc->sdom = dd;
+    svc->vcpu = vc;
+    svc->last_start = 0;
+
+    svc->period = RT_DS_DEFAULT_PERIOD;
+    if ( !is_idle_vcpu(vc) )
+        svc->budget = RT_DS_DEFAULT_BUDGET;
+
+    rt_update_helper(now, svc);
+

And one more point in favour of pulling the check out of the helper. In fact, in this case (independently whether you want to keep the division, because it's the first time we set the deadline, or use the while loop), you don't need to check if the deadline is in the past... You already know it is!! :-D

That would mean you can just call rt_update_helper(), without further checking, not here, neither inside the helper. Faster, but that does not matter much in this case. Cleaner, and that _always_ does. :-)

xen/common/sched_rt.c line 667

Quoted 13 lines
xen/common/sched_rt.c new file +11 -0
+    /* Debug only: dump new vcpu's info */
+    rt_dump_vcpu(ops, svc);
+
+    return svc;
+}
 
+/*
+ * Burn budget in nanosecond granularity
+ */
+static void
+burn_budgets(const struct scheduler *ops, struct rt_vcpu *svc, s_time_t now) 
+{

burn_budget()? I mean, why the trailing 's'?

(yes, this is a very minor thing.)

xen/common/sched_rt.c line 679

Quoted 12 lines
xen/common/sched_rt.c new file +12 -0
+    s_time_t delta;
+
+    /* don't burn budget for idle VCPU */
+    if ( is_idle_vcpu(svc->vcpu) ) 
+        return;
+
+    rt_update_helper(now, svc);
+
+    /* not burn budget when vcpu miss deadline */
+    if ( now >= svc->cur_deadline )
+        return;
+

How this can be true?

Unless I'm missing something, in rt_update_helper(), if the deadline is behind now, you move it ahead of it (and replenish the budget). Here you check again whether the deadline is behind now, which should not be possible, as you just took care of that... Isn't it so?

Considering both mine and George's suggestion, if you rework the helper and move the check out of it, then this one is fine (and you just call the helper if the condition is verified). If you don't want to do that, then I guess you can have the helper returning 0|1 depending on whether or not the update happened, and use such value here, for deciding whether to bail or not.

I think I'd prefer the former (pulling the check out of the helper).

Quoted 38 lines
xen/common/sched_rt.c new file +38 -0
+    /* burn at nanoseconds level */
+    delta = now - svc->last_start;
+    /* 
+     * delta < 0 only happens in nested virtualization;
+     * TODO: how should we handle delta < 0 in a better way? 
+     */
+    if ( delta < 0 ) 
+    {
+        printk("%s, ATTENTION: now is behind last_start! delta = %ld",
+                __func__, delta);
+        rt_dump_vcpu(ops, svc);
+        svc->last_start = now;
+        svc->cur_budget = 0;
+        return;
+    }
+
+    if ( svc->cur_budget == 0 ) 
+        return;
+
+    svc->cur_budget -= delta;
+    if ( svc->cur_budget < 0 ) 
+        svc->cur_budget = 0;
+
+    /* TRACE */
+    {
+        struct {
+            unsigned dom:16, vcpu:16;
+            unsigned cur_budget_lo;
+            unsigned cur_budget_hi;
+            int delta;
+        } d;
+        d.dom = svc->vcpu->domain->domain_id;
+        d.vcpu = svc->vcpu->vcpu_id;
+        d.cur_budget_lo = (unsigned) svc->cur_budget;
+        d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+        d.delta = delta;
+        trace_var(TRC_RT_BUDGET_BURN, 1,
+                  sizeof(d),

xen/common/sched_rt.c line 727

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+                  (unsigned char *) &d);
+    }
+}
+
+/* 
+ * RunQ is sorted. Pick first one within cpumask. If no one, return NULL
+ * lock is grabbed before calling this function 
+ */
+static struct rt_vcpu *
+__runq_pick(const struct scheduler *ops, cpumask_t mask)

cpumask_t *mask

would be better, I think.

Quoted 15 lines
xen/common/sched_rt.c new file +14 -0
+/*
+ * Update vcpu's budget and sort runq by insert the modifed vcpu back to runq
+ * lock is grabbed before calling this function 
+ */
+static void
+__repl_update(const struct scheduler *ops, s_time_t now)
+{
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    struct list_head *tmp;
+    struct rt_vcpu *svc = NULL;
+
+    list_for_each_safe(iter, tmp, runq) 
+    {

xen/common/sched_rt.c line 808

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+        svc = __runq_elem(iter);
+
+        /* not update flag_vcpu's budget */
+        if(svc->sdom == NULL)
+            continue;
+
+        rt_update_helper(now, svc);
+        /* reinsert the vcpu if its deadline is updated */
+        if ( now >= 0 )
+        {

This is wrong, and I saw you noticed this already.

Quoted 13 lines
xen/common/sched_rt.c new file +13 -0
+            __runq_remove(svc);
+            __runq_insert(ops, svc);
+        }
+    }
+}
+
+/* 
+ * schedule function for rt scheduler.
+ * The lock is already grabbed in schedule.c, no need to lock here 
+ */
+static struct task_slice
+rt_schedule(const struct scheduler *ops, s_time_t now, bool_t tasklet_work_scheduled)
+{

xen/common/sched_rt.c line 831

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+    const int cpu = smp_processor_id();
+    struct rt_private * prv = RT_PRIV(ops);
+    struct rt_vcpu * const scurr = RT_VCPU(current);
+    struct rt_vcpu * snext = NULL;
+    struct task_slice ret = { .migrated = 0 };
+
+    /* clear ticked bit now that we've been scheduled */
+    if ( cpumask_test_cpu(cpu, &prv->tickled) )
+        cpumask_clear_cpu(cpu, &prv->tickled);
+

Is the test important? cpumask operations may be quite expensive, and I think always clearing is better than always testing and sometimes (rather often, I think) clear.

I'm open to other views on this, though. :-)

xen/common/sched_rt.c

Quoted 8 lines
xen/common/sched_rt.c new file +6 -0
+    /* burn_budget would return for IDLE VCPU */
+    burn_budgets(ops, scurr, now);
+
+    __repl_update(ops, now);
 
+/*
+ * Pick a vcpu on a cpu to kick out to place the running candidate

Rather than 'Pick a vcpu on a cpu to kick out...', I'd say 'Pick a cpu where to run a vcpu, possibly kicking out the vcpu running there'.

Right. For this round, I tried, while looking at the patch, as hard as I could to concentrate on the algorithm, and on how the Xen scheduling framework is being used here. As a result, I confirm my previous impression that this code is in a fair state and that, as an experimental and in-development feature, it could well be checked in soon (as far as comments are addressed, of course :-D ).

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

#10 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

Hi Dario,

Thank you very much for your comments! I will just comment on the points that needs clarification and will solve all of these comments.

Quoted 14 lines
Quoted 14 lines
xen/common/sched_rt.c new file +14 -0
+/*
+ * Debug related code, dump vcpu/cpu information
+ */
+static void
+rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    char cpustr[1024];
+    cpumask_t *cpupool_mask;
+
+    ASSERT(svc != NULL);
+    /* flag vcpu */
+    if( svc->sdom == NULL )
+        return;
Quoted 8 lines

xen/common/sched_rt.c line 237

Quoted 6 lines
xen/common/sched_rt.c new file +5 -0
+
+    cpumask_scnprintf(cpustr, sizeof(cpustr), svc->vcpu->cpu_hard_affinity);
+    printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime"),"
+           " cur_b=%"PRI_stime" cur_d=%"PRI_stime" last_start=%"PRI_stime
+           " onR=%d runnable=%d cpu_hard_affinity=%s ",

How does this come up in the console? Should we break it with a '\n' somewhere? It looks rather long...

Some information is not so useful here, such as the period and budget of the vcpu, which can be displayed by using the tool stack. I can remove some of them to make this line shorter. I will remove svc->budget, svc->period and prv->cpus.

Quoted 63 lines
Quoted 53 lines
xen/common/sched_rt.c new file +52 -0
+            svc->vcpu->domain->domain_id,
+            svc->vcpu->vcpu_id,
+            svc->vcpu->processor,
+            svc->period,
+            svc->budget,
+            svc->cur_budget,
+            svc->cur_deadline,
+            svc->last_start,
+            __vcpu_on_runq(svc),
+            vcpu_runnable(svc->vcpu),
+            cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpupool_mask = cpupool_scheduler_cpumask(svc->vcpu->domain->cpupool);
+    cpumask_scnprintf(cpustr, sizeof(cpustr), cpupool_mask);
+    printk("cpupool=%s ", cpustr);
+    memset(cpustr, 0, sizeof(cpustr));
+    cpumask_scnprintf(cpustr, sizeof(cpustr), &prv->cpus);
+    printk("prv->cpus=%s\n", cpustr);
+
+    /* TRACE */
+    {
+        struct {
+            unsigned dom:16,vcpu:16;
+            unsigned processor;
+            unsigned cur_budget_lo, cur_budget_hi;
+            unsigned cur_deadline_lo, cur_deadline_hi;
+            unsigned is_vcpu_on_runq:16,is_vcpu_runnable:16;
+        } d;
+        d.dom = svc->vcpu->domain->domain_id;
+        d.vcpu = svc->vcpu->vcpu_id;
+        d.processor = svc->vcpu->processor;
+        d.cur_budget_lo = (unsigned) svc->cur_budget;
+        d.cur_budget_hi = (unsigned) (svc->cur_budget >> 32);
+        d.cur_deadline_lo = (unsigned) svc->cur_deadline;
+        d.cur_deadline_hi = (unsigned) (svc->cur_deadline >> 32);
+        d.is_vcpu_on_runq = __vcpu_on_runq(svc);
+        d.is_vcpu_runnable = vcpu_runnable(svc->vcpu);
+        trace_var(TRC_RT_VCPU_DUMP, 1,
+                  sizeof(d),
+                  (unsigned char *)&d);
+    }
+}
+
 
+ */
+static void
+__runq_insert(const struct scheduler *ops, struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    struct list_head *runq = RUNQ(ops);
+    struct list_head *iter;
+    spinlock_t *schedule_lock;
+
Quoted 1 line

This empty line above seems to be actually empty, but looking more

carefully, it does contain 4 spaces, doesn't it?

If that's the case, avoid doing this, i.e., make sure that empty lines are actually empty. :-D

Looking at each patch with `git show' should highlight occurrences of this phenomenon, as well as of any trailing white space, by marking them in red.

Quoted 6 lines

xen/common/sched_rt.c line 388

Quoted 3 lines
xen/common/sched_rt.c new file +3 -0
+    schedule_lock = per_cpu(schedule_data, svc->vcpu->processor).schedule_lock;
+    ASSERT( spin_is_locked(schedule_lock) );
+

As of now, the only lock around is prv->lock, isn't it? So this per_cpu(xxx) is a complex way to get to prv->lock, or am I missing something.

Yes. It's the only lock right now. When I split the RunQ to two
queues: RunQ, DepletedQ, I can still use one lock, (but probably two locks are more efficient?)

Quoted 7 lines

In credit, the pre-inited set of locks are actually used "as they are", while in credit2, there is some remapping going on, but there is more than one lock anyway. That's why you find things like the above in those two schedulers. Here, you should not need anything like that, (as you do everywhere else) just go ahead and use prv->lock.

Quoted 5 lines

Of course, that does not mean you don't need the lock remapping in rt_alloc_pdata(). That code looks ok to me, just adapt this bit above, as, like this, it makes things harder to understand.

Or am I overlooking something?

I think you didn't overlook anything. I will refer to credit2 to see how it is using multiple locks, since it's likely we will have two locks here.

Quoted 11 lines

xen/common/sched_rt.c line 667

Quoted 7 lines
xen/common/sched_rt.c new file +6 -0
+/*
+ * Burn budget in nanosecond granularity
+ */
+static void
+burn_budgets(const struct scheduler *ops, struct rt_vcpu *svc, s_time_t now)
+{

burn_budget()? I mean, why the trailing 's'?

(yes, this is a very minor thing.)

Quoted 13 lines

xen/common/sched_rt.c line 679

Quoted 12 lines
xen/common/sched_rt.c new file +12 -0
+    s_time_t delta;
+
+    /* don't burn budget for idle VCPU */
+    if ( is_idle_vcpu(svc->vcpu) )
+        return;
+
+    rt_update_helper(now, svc);
+
+    /* not burn budget when vcpu miss deadline */
+    if ( now >= svc->cur_deadline )
+        return;
+

How this can be true?

You are right! After rt_update_helper(), this should be always true. Will change as you said and preferred. :-)

Quoted 38 lines

Unless I'm missing something, in rt_update_helper(), if the deadline is behind now, you move it ahead of it (and replenish the budget). Here you check again whether the deadline is behind now, which should not be possible, as you just took care of that... Isn't it so?

Considering both mine and George's suggestion, if you rework the helper and move the check out of it, then this one is fine (and you just call the helper if the condition is verified). If you don't want to do that, then I guess you can have the helper returning 0|1 depending on whether or not the update happened, and use such value here, for deciding whether to bail or not.

I think I'd prefer the former (pulling the check out of the helper).

Quoted 7 lines
xen/common/sched_rt.c new file +7 -0
+/*
+ * schedule function for rt scheduler.
+ * The lock is already grabbed in schedule.c, no need to lock here
+ */
+static struct task_slice
+rt_schedule(const struct scheduler *ops, s_time_t now, bool_t tasklet_work_scheduled)
+{

xen/common/sched_rt.c line 831

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+    const int cpu = smp_processor_id();
+    struct rt_private * prv = RT_PRIV(ops);
+    struct rt_vcpu * const scurr = RT_VCPU(current);
+    struct rt_vcpu * snext = NULL;
+    struct task_slice ret = { .migrated = 0 };
+
+    /* clear ticked bit now that we've been scheduled */
+    if ( cpumask_test_cpu(cpu, &prv->tickled) )
+        cpumask_clear_cpu(cpu, &prv->tickled);
+

Is the test important? cpumask operations may be quite expensive, and I think always clearing is better than always testing and sometimes (rather often, I think) clear.

Quoted 1 line

I'm open to other views on this, though. :-)

I think we can just clear it, unless clear is much more expensive than test. If no objection, I will just clear it in the next version.

Quoted 7 lines

Right. For this round, I tried, while looking at the patch, as hard as I could to concentrate on the algorithm, and on how the Xen scheduling framework is being used here. As a result, I confirm my previous impression that this code is in a fair state and that, as an experimental and in-development feature, it could well be checked in soon (as far as comments are addressed, of course :-D ).

I will solve all of these comments this week and try my best to release the next version at the weekend. (Well, if not, it should be early next week. Many simple things to change and modify. :-) )

Thank you very much!

Best,

Meng

-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania

#11 lore raw

Re: [PATCH v2 1/4] xen: add real time scheduler rt

Quoted 23 lines · Meng Xu
Quoted 14 lines
Quoted 14 lines
xen/common/sched_rt.c new file +14 -0
+/*
+ * Debug related code, dump vcpu/cpu information
+ */
+static void
+rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    char cpustr[1024];
+    cpumask_t *cpupool_mask;
+
+    ASSERT(svc != NULL);
+    /* flag vcpu */
+    if( svc->sdom == NULL )
+        return;
Quoted 8 lines

xen/common/sched_rt.c line 237

Quoted 6 lines
xen/common/sched_rt.c new file +5 -0
+
+    cpumask_scnprintf(cpustr, sizeof(cpustr), svc->vcpu->cpu_hard_affinity);
+    printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime"),"
+           " cur_b=%"PRI_stime" cur_d=%"PRI_stime" last_start=%"PRI_stime
+           " onR=%d runnable=%d cpu_hard_affinity=%s ",

How does this come up in the console? Should we break it with a '\n' somewhere? It looks rather long...

Quoted 5 lines

Some information is not so useful here, such as the period and budget of the vcpu, which can be displayed by using the tool stack. I can remove some of them to make this line shorter. I will remove svc->budget, svc->period and prv->cpus.

Well, as you wish... A '\n' (and perhaps some more formatting with '\t'-s, etch) would be fine too, IMO.

Quoted 22 lines
Quoted 6 lines

xen/common/sched_rt.c line 388

Quoted 3 lines
xen/common/sched_rt.c new file +3 -0
+    schedule_lock = per_cpu(schedule_data, svc->vcpu->processor).schedule_lock;
+    ASSERT( spin_is_locked(schedule_lock) );
+

As of now, the only lock around is prv->lock, isn't it? So this per_cpu(xxx) is a complex way to get to prv->lock, or am I missing something.

Yes. It's the only lock right now. When I split the RunQ to two
queues: RunQ, DepletedQ, I can still use one lock, (but probably two locks are more efficient?)

Quoted 11 lines

In credit, the pre-inited set of locks are actually used "as they are", while in credit2, there is some remapping going on, but there is more than one lock anyway. That's why you find things like the above in those two schedulers. Here, you should not need anything like that, (as you do everywhere else) just go ahead and use prv->lock.

Of course, that does not mean you don't need the lock remapping in rt_alloc_pdata(). That code looks ok to me, just adapt this bit above, as, like this, it makes things harder to understand.

Quoted 6 lines
Quoted 1 line

Or am I overlooking something?

I think you didn't overlook anything. I will refer to credit2 to see how it is using multiple locks, since it's likely we will have two locks here.

I don't think you do. I mentioned credit2 only to make it clear why notation like the one above is required there, and to highlight that it is _not_ required in your case.

Even if you start using 2 queues, one for runnable and one for depleted vcpus, access to both can well be serialized by the same lock. In fact, in quite a few places, you'd need moving vcpus from one queue to the other, i.e., you'd be forced to take both of the locks anyway.

I do think that using separate queues may improve scalability, and adopting a different locking strategy could make that happen, but I just won't do that right now, at this point of the release cycle. For now, the two queue approach will "just" make the code easier to read, understand and hack, which is already something really important, especially for an experimental feature.

So, IMO, just replace the line above with a simple "&prv->lock" and get done with it, without adding any more locks, or changing the locking logic.

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 v2 1/4] xen: add real time scheduler rt

2014-09-11 4:44 GMT-04:00 Dario Faggioli <[email protected]>:

Quoted 24 lines · Meng Xu
Quoted 23 lines
Quoted 22 lines
Quoted 10 lines
xen/common/sched_rt.c new file +9 -0
+/*
+ * Debug related code, dump vcpu/cpu information
+ */
+static void
+rt_dump_vcpu(const struct scheduler *ops, const struct rt_vcpu *svc)
+{
+    struct rt_private *prv = RT_PRIV(ops);
+    char cpustr[1024];
+    cpumask_t *cpupool_mask;

xen/common/sched_rt.c line 237

Quoted 10 lines
xen/common/sched_rt.c new file +10 -0
+
+    ASSERT(svc != NULL);
+    /* flag vcpu */
+    if( svc->sdom == NULL )
+        return;
+
+    cpumask_scnprintf(cpustr, sizeof(cpustr), svc->vcpu->cpu_hard_affinity);
+    printk("[%5d.%-2u] cpu %u, (%"PRI_stime", %"PRI_stime"),"
+           " cur_b=%"PRI_stime" cur_d=%"PRI_stime" last_start=%"PRI_stime
+           " onR=%d runnable=%d cpu_hard_affinity=%s ",

How does this come up in the console? Should we break it with a '\n' somewhere? It looks rather long...

Quoted 7 lines
Quoted 5 lines

Some information is not so useful here, such as the period and budget of the vcpu, which can be displayed by using the tool stack. I can remove some of them to make this line shorter. I will remove svc->budget, svc->period and prv->cpus.

Well, as you wish... A '\n' (and perhaps some more formatting with '\t'-s, etch) would be fine too, IMO.

Got it! Thanks!

Quoted 45 lines
Quoted 23 lines
Quoted 7 lines

xen/common/sched_rt.c line 388

Quoted 4 lines
xen/common/sched_rt.c new file +3 -0
+    schedule_lock = per_cpu(schedule_data, svc->vcpu->processor).schedule_lock;
+    ASSERT( spin_is_locked(schedule_lock) );
+

As of now, the only lock around is prv->lock, isn't it? So this per_cpu(xxx) is a complex way to get to prv->lock, or am I missing something.

Yes. It's the only lock right now. When I split the RunQ to two
queues: RunQ, DepletedQ, I can still use one lock, (but probably two locks are more efficient?)

Quoted 11 lines

In credit, the pre-inited set of locks are actually used "as they are", while in credit2, there is some remapping going on, but there is more than one lock anyway. That's why you find things like the above in those two schedulers. Here, you should not need anything like that, (as you do everywhere else) just go ahead and use prv->lock.

Of course, that does not mean you don't need the lock remapping in rt_alloc_pdata(). That code looks ok to me, just adapt this bit above, as, like this, it makes things harder to understand.

Quoted 6 lines
Quoted 1 line

Or am I overlooking something?

I think you didn't overlook anything. I will refer to credit2 to see how it is using multiple locks, since it's likely we will have two locks here.

I don't think you do. I mentioned credit2 only to make it clear why notation like the one above is required there, and to highlight that it is _not_ required in your case.

Even if you start using 2 queues, one for runnable and one for depleted vcpus, access to both can well be serialized by the same lock. In fact, in quite a few places, you'd need moving vcpus from one queue to the other, i.e., you'd be forced to take both of the locks anyway.

I do think that using separate queues may improve scalability, and adopting a different locking strategy could make that happen, but I just won't do that right now, at this point of the release cycle. For now, the two queue approach will "just" make the code easier to read, understand and hack, which is already something really important, especially for an experimental feature.

Quoted 4 lines

So, IMO, just replace the line above with a simple "&prv->lock" and get done with it, without adding any more locks, or changing the locking logic.

I agree with you totally. Sure! I will use one lock then. :-)

Best,

Meng

-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania

author
#13 lore raw

PATCH v2 2/4 libxc: add rt scheduler

In reply to Meng Xu

Add xc_sched_rt_* functions to interact with Xen to set/get domain's parameters for rt scheduler.
Note: VCPU's information (period, budget) is in microsecond (us).

---
 tools/libxc/Makefile  |    1 +
 tools/libxc/xc_rt.c   |   65 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h |    7 ++++++
 3 files changed, 73 insertions(+)
 create mode 100644 tools/libxc/xc_rt.c
tools/libxc/Makefile +1 -0
index 3b04027..8db0d97 100644
@@ -20,6 +20,7 @@ CTRL_SRCS-y       += xc_sedf.c
 CTRL_SRCS-y       += xc_csched.c
 CTRL_SRCS-y       += xc_csched2.c
 CTRL_SRCS-y       += xc_arinc653.c
+CTRL_SRCS-y       += xc_rt.c
 CTRL_SRCS-y       += xc_tbuf.c
 CTRL_SRCS-y       += xc_pm.c
 CTRL_SRCS-y       += xc_cpu_hotplug.c
tools/libxc/xc_rt.c new file +65 -0

65 lines not on this page · raw message

tools/libxc/xenctrl.h +7 -0
index 1c8aa42..a61b2a7 100644
@@ -875,6 +875,13 @@ int xc_sched_credit2_domain_get(xc_interface *xch,
                                uint32_t domid,
                                struct xen_domctl_sched_credit2 *sdom);
 
+int xc_sched_rt_domain_set(xc_interface *xch,
+                          uint32_t domid,
+                          struct xen_domctl_sched_rt *sdom);
+int xc_sched_rt_domain_get(xc_interface *xch,
+                          uint32_t domid,
+                          struct xen_domctl_sched_rt *sdom);
+
 int
 xc_sched_arinc653_schedule_set(
     xc_interface *xch,
Signature · 1 line
1.7.9.5
#14 lore raw

Re: [PATCH v2 2/4] libxc: add rt scheduler

Quoted 3 lines · Meng Xu

Add xc_sched_rt_* functions to interact with Xen to set/get domain's parameters for rt scheduler.
Note: VCPU's information (period, budget) is in microsecond (us).

s/rt/rtds/g; and it looks good to me.

-George

Quoted 111 lines
---
  tools/libxc/Makefile  |    1 +
  tools/libxc/xc_rt.c   |   65 +++++++++++++++++++++++++++++++++++++++++++++++++
  tools/libxc/xenctrl.h |    7 ++++++
  3 files changed, 73 insertions(+)

create mode 100644 tools/libxc/xc_rt.c

tools/libxc/Makefile +1 -0
index 3b04027..8db0d97 100644
@@ -20,6 +20,7 @@ CTRL_SRCS-y       += xc_sedf.c
  CTRL_SRCS-y       += xc_csched.c
  CTRL_SRCS-y       += xc_csched2.c
  CTRL_SRCS-y       += xc_arinc653.c
+CTRL_SRCS-y       += xc_rt.c
  CTRL_SRCS-y       += xc_tbuf.c
  CTRL_SRCS-y       += xc_pm.c
  CTRL_SRCS-y       += xc_cpu_hotplug.c
tools/libxc/xc_rt.c new file +65 -0
new file mode 100644
index 0000000..e62f745
@@ -0,0 +1,65 @@
+/****************************************************************************
+ *
+ *        File: xc_rt.c
+ *      Author: Sisu Xi
+ *              Meng Xu
+ *
+ * Description: XC Interface to the rt scheduler
+ * Note: VCPU's parameter (period, budget) is in microsecond (us).
+ *       All VCPUs of the same domain have same period and budget.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "xc_private.h"
+
+int xc_sched_rt_domain_set(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_sched_rt *sdom)
+{
+    int rc;
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_scheduler_op;
+    domctl.domain = (domid_t) domid;
+    domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_RT_DS;
+    domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
+    domctl.u.scheduler_op.u.rt.period = sdom->period;
+    domctl.u.scheduler_op.u.rt.budget = sdom->budget;
+
+    rc = do_domctl(xch, &domctl);
+
+    return rc;
+}
+
+int xc_sched_rt_domain_get(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_sched_rt *sdom)
+{
+    int rc;
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_scheduler_op;
+    domctl.domain = (domid_t) domid;
+    domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_RT_DS;
+    domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
+
+    rc = do_domctl(xch, &domctl);
+
+    if ( rc == 0 )
+        *sdom = domctl.u.scheduler_op.u.rt;
+
+    return rc;
+}
tools/libxc/xenctrl.h +7 -0
index 1c8aa42..a61b2a7 100644
@@ -875,6 +875,13 @@ int xc_sched_credit2_domain_get(xc_interface *xch,
                                 uint32_t domid,
                                 struct xen_domctl_sched_credit2 *sdom);
 
+int xc_sched_rt_domain_set(xc_interface *xch,
+                          uint32_t domid,
+                          struct xen_domctl_sched_rt *sdom);
+int xc_sched_rt_domain_get(xc_interface *xch,
+                          uint32_t domid,
+                          struct xen_domctl_sched_rt *sdom);
+
  int
  xc_sched_arinc653_schedule_set(
      xc_interface *xch,
Acked-by on v2 2/4
#15 lore raw

Re: [PATCH v2 2/4] libxc: add rt scheduler

In reply to Meng Xu
Quoted 6 lines · Meng Xu

Add xc_sched_rt_* functions to interact with Xen to set/get domain's parameters for rt scheduler.
Note: VCPU's information (period, budget) is in microsecond (us).

These looks like correct bindings of the hypercall to me, so if the h/visor side folks are happy with the interface:

Reviewed-by on v2 2/4
#16 lore raw

Re: [PATCH v2 2/4] libxc: add rt scheduler

In reply to Meng Xu
Quoted 6 lines · Meng Xu

Add xc_sched_rt_* functions to interact with Xen to set/get domain's parameters for rt scheduler.
Note: VCPU's information (period, budget) is in microsecond (us).

This looks fine.

With the scheduler name properly updated (as George is saying, and as pointed out below):

Quoted 26 lines
tools/libxc/xc_rt.c new file +20 -0
new file mode 100644
index 0000000..e62f745
@@ -0,0 +1,65 @@
+/****************************************************************************
+ *
+ *        File: xc_rt.c
+ *      Author: Sisu Xi 
+ *              Meng Xu
+ *
+ * Description: XC Interface to the rt scheduler
+ * Note: VCPU's parameter (period, budget) is in microsecond (us).
+ *       All VCPUs of the same domain have same period and budget.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *

tools/libxc/xc_rt.c line 30

Quoted 10 lines
tools/libxc/xc_rt.c new file +10 -0
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "xc_private.h"
+
+int xc_sched_rt_domain_set(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_sched_rt *sdom)

xen_domctl_sched_rtds

tools/libxc/xc_rt.c line 37

Quoted 7 lines
tools/libxc/xc_rt.c new file +7 -0
+{
+    int rc;
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_scheduler_op;
+    domctl.domain = (domid_t) domid;
+    domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_RT_DS;

RTDS

tools/libxc/xc_rt.c line 39

Quoted 2 lines
tools/libxc/xc_rt.c new file +2 -0
+    domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
+    domctl.u.scheduler_op.u.rt.period = sdom->period;

rtds

tools/libxc/xc_rt.c line 40

Quoted 1 line
tools/libxc/xc_rt.c new file +1 -0
+    domctl.u.scheduler_op.u.rt.budget = sdom->budget;

rtds

tools/libxc/xc_rt.c line 49

Quoted 9 lines
tools/libxc/xc_rt.c new file +9 -0
+
+    rc = do_domctl(xch, &domctl);
+
+    return rc;
+}
+
+int xc_sched_rt_domain_get(xc_interface *xch,
+                           uint32_t domid,
+                           struct xen_domctl_sched_rt *sdom)

rtds

tools/libxc/xc_rt.c line 37

Quoted 7 lines
tools/libxc/xc_rt.c new file +7 -0
+{
+    int rc;
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_scheduler_op;
+    domctl.domain = (domid_t) domid;
+    domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_RT_DS;

RTDS

tools/libxc/xc_rt.c line 62

Quoted 6 lines
tools/libxc/xc_rt.c new file +6 -0
+    domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
+
+    rc = do_domctl(xch, &domctl);
+
+    if ( rc == 0 )
+        *sdom = domctl.u.scheduler_op.u.rt;

rtds

tools/libxc/xc_rt.c line 45

Quoted 4 lines
tools/libxc/xc_rt.c new file +3 -0
+
+    return rc;
+}

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
#17 lore raw

PATCH v2 3/4 libxl: add rt scheduler

In reply to Meng Xu

Add libxl functions to set/get domain's parameters for rt scheduler
Note: VCPU's information (period, budget) is in microsecond (us).

---
 tools/libxl/libxl.c         |   75 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h         |    1 +
 tools/libxl/libxl_types.idl |    2 ++
 3 files changed, 78 insertions(+)
tools/libxl/libxl.c +75 -0
index 2ae5fca..6840c92 100644
@@ -5155,6 +5155,75 @@ static int sched_sedf_domain_set(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+static int sched_rt_domain_get(libxl__gc *gc, uint32_t domid,
+                               libxl_domain_sched_params *scinfo)
+{
+    struct xen_domctl_sched_rt sdom;
+    int rc;
+
+    rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);
+    if (rc != 0) {
+        LOGE(ERROR, "getting domain sched rt");
+        return ERROR_FAIL;
+    }
+
+    libxl_domain_sched_params_init(scinfo);
+    
+    scinfo->sched = LIBXL_SCHEDULER_RT_DS;
+    scinfo->period = sdom.period;
+    scinfo->budget = sdom.budget;
+    
+    return 0;
+}
+
+#define SCHED_RT_DS_VCPU_PERIOD_UINT_MAX    4294967295U /* 2^32 - 1 us */
+#define SCHED_RT_DS_VCPU_BUDGET_UINT_MAX    SCHED_RT_DS_VCPU_PERIOD_UINT_MAX
+
+static int sched_rt_domain_set(libxl__gc *gc, uint32_t domid,
+                               const libxl_domain_sched_params *scinfo)
+{
+    struct xen_domctl_sched_rt sdom;
+    int rc;
+ 
+    rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);
+
+    if (scinfo->period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
+        if (scinfo->period < 1 ||
+            scinfo->period > SCHED_RT_DS_VCPU_PERIOD_UINT_MAX) {
+            LOG(ERROR, "VCPU period is not set or out of range, "
+                       "valid values are within range from 0 to %u",
+                       SCHED_RT_DS_VCPU_PERIOD_UINT_MAX);
+            return ERROR_INVAL;
+        }
+        sdom.period = scinfo->period;
+    }
+
+    if (scinfo->budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
+        if (scinfo->budget < 1 ||
+            scinfo->budget > SCHED_RT_DS_VCPU_BUDGET_UINT_MAX) {
+            LOG(ERROR, "VCPU budget is not set or out of range, "
+                       "valid values are within range from 0 to %u",
+                       SCHED_RT_DS_VCPU_BUDGET_UINT_MAX);
+            return ERROR_INVAL;
+        }
+        sdom.budget = scinfo->budget;
+    }
+
+    if (sdom.budget > sdom.period) {
+        LOG(ERROR, "VCPU budget is larger than VCPU period, "
+                   "VCPU budget should be no larger than VCPU period");
+        return ERROR_INVAL;
+    }
+
+    rc = xc_sched_rt_domain_set(CTX->xch, domid, &sdom);
+    if (rc < 0) {
+        LOGE(ERROR, "setting domain sched rt");
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
 int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
                                   const libxl_domain_sched_params *scinfo)
 {
@@ -5178,6 +5247,9 @@ int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
     case LIBXL_SCHEDULER_ARINC653:
         ret=sched_arinc653_domain_set(gc, domid, scinfo);
         break;
+    case LIBXL_SCHEDULER_RT_DS:
+        ret=sched_rt_domain_set(gc, domid, scinfo);
+        break;
     default:
         LOG(ERROR, "Unknown scheduler");
         ret=ERROR_INVAL;
@@ -5208,6 +5280,9 @@ int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
     case LIBXL_SCHEDULER_CREDIT2:
         ret=sched_credit2_domain_get(gc, domid, scinfo);
         break;
+    case LIBXL_SCHEDULER_RT_DS:
+        ret=sched_rt_domain_get(gc, domid, scinfo);
+        break;
     default:
         LOG(ERROR, "Unknown scheduler");
         ret=ERROR_INVAL;
tools/libxl/libxl.h +1 -0
index 460207b..dbe736c 100644
@@ -1280,6 +1280,7 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
 #define LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT     -1
 #define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT   -1
 #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT     -1
 
 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                   libxl_domain_sched_params *params);
tools/libxl/libxl_types.idl +2 -0
index 931c9e9..72f24fe 100644
@@ -153,6 +153,7 @@ libxl_scheduler = Enumeration("scheduler", [
     (5, "credit"),
     (6, "credit2"),
     (7, "arinc653"),
+    (8, "rt_ds"),
     ])
 
 # Consistent with SHUTDOWN_* in sched.h (apart from UNKNOWN)
@@ -315,6 +316,7 @@ libxl_domain_sched_params = Struct("domain_sched_params",[
     ("slice",        integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT'}),
     ("latency",      integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT'}),
     ("extratime",    integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT'}),
+    ("budget",       integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
     ])
 
 libxl_domain_build_info = Struct("domain_build_info",[
Signature · 1 line
1.7.9.5
#18 lore raw

Re: [PATCH v2 3/4] libxl: add rt scheduler

Quoted 32 lines · Meng Xu

Add libxl functions to set/get domain's parameters for rt scheduler
Note: VCPU's information (period, budget) is in microsecond (us).

---
  tools/libxl/libxl.c         |   75 +++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/libxl.h         |    1 +
  tools/libxl/libxl_types.idl |    2 ++
  3 files changed, 78 insertions(+)
tools/libxl/libxl.c +13 -0
index 2ae5fca..6840c92 100644
@@ -5155,6 +5155,75 @@ static int sched_sedf_domain_set(libxl__gc *gc, uint32_t domid,
      return 0;
  }
 
+static int sched_rt_domain_get(libxl__gc *gc, uint32_t domid,
+                               libxl_domain_sched_params *scinfo)
+{
+    struct xen_domctl_sched_rt sdom;
+    int rc;
+
+    rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);
+    if (rc != 0) {
+        LOGE(ERROR, "getting domain sched rt");
+        return ERROR_FAIL;
+    }
+
+    libxl_domain_sched_params_init(scinfo);

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

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+
+    scinfo->sched = LIBXL_SCHEDULER_RT_DS;
+    scinfo->period = sdom.period;
+    scinfo->budget = sdom.budget;
+
+    return 0;
+}
+
+#define SCHED_RT_DS_VCPU_PERIOD_UINT_MAX    4294967295U /* 2^32 - 1 us */
+#define SCHED_RT_DS_VCPU_BUDGET_UINT_MAX    SCHED_RT_DS_VCPU_PERIOD_UINT_MAX

I think what Dario was looking for was this:

#define SCHED_RT_DS_VCPU_PERIOD_MAX UINT_MAX

I.e., use the already-defined #defines with meaningful names (line UINT_MAX), and avoid open-coding (i.e., typing out a "magic" number, like 429....U).

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

Quoted 8 lines
tools/libxl/libxl.c +8 -0
+
+static int sched_rt_domain_set(libxl__gc *gc, uint32_t domid,
+                               const libxl_domain_sched_params *scinfo)
+{
+    struct xen_domctl_sched_rt sdom;
+    int rc;
+
+    rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);

You need to check the return value here and bail out on an error.

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

Quoted 4 lines
tools/libxl/libxl.c +4 -0
+
+    if (scinfo->period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
+        if (scinfo->period < 1 ||
+            scinfo->period > SCHED_RT_DS_VCPU_PERIOD_UINT_MAX) {

...but this isn't right anyway, right? scinfo->period is a signed integer. You shouldn't be comparing it to an unsigned int; and this can never be false anyway, because even if it's automatically cast to be unsigned, the type isn't big enough to be bigger than UINT_MAX anyway.

If period is allowed to be anything up to INT_MAX, then there's no need to check the upper bound. Checking to make sure it's >= 1 should be sufficient. Then you can just get rid of the #defines above.

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

Quoted 11 lines
tools/libxl/libxl.c +11 -0
+            LOG(ERROR, "VCPU period is not set or out of range, "
+                       "valid values are within range from 0 to %u",
+                       SCHED_RT_DS_VCPU_PERIOD_UINT_MAX);
+            return ERROR_INVAL;
+        }
+        sdom.period = scinfo->period;
+    }
+
+    if (scinfo->budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
+        if (scinfo->budget < 1 ||
+            scinfo->budget > SCHED_RT_DS_VCPU_BUDGET_UINT_MAX) {

Same here.

Quoted 63 lines
tools/libxl/libxl.c +29 -0
+            LOG(ERROR, "VCPU budget is not set or out of range, "
+                       "valid values are within range from 0 to %u",
+                       SCHED_RT_DS_VCPU_BUDGET_UINT_MAX);
+            return ERROR_INVAL;
+        }
+        sdom.budget = scinfo->budget;
+    }
+
+    if (sdom.budget > sdom.period) {
+        LOG(ERROR, "VCPU budget is larger than VCPU period, "
+                   "VCPU budget should be no larger than VCPU period");
+        return ERROR_INVAL;
+    }
+
+    rc = xc_sched_rt_domain_set(CTX->xch, domid, &sdom);
+    if (rc < 0) {
+        LOGE(ERROR, "setting domain sched rt");
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
  int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
                                    const libxl_domain_sched_params *scinfo)
  {
@@ -5178,6 +5247,9 @@ int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
      case LIBXL_SCHEDULER_ARINC653:
          ret=sched_arinc653_domain_set(gc, domid, scinfo);
          break;
+    case LIBXL_SCHEDULER_RT_DS:
+        ret=sched_rt_domain_set(gc, domid, scinfo);
+        break;
      default:
          LOG(ERROR, "Unknown scheduler");
          ret=ERROR_INVAL;
@@ -5208,6 +5280,9 @@ int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
      case LIBXL_SCHEDULER_CREDIT2:
          ret=sched_credit2_domain_get(gc, domid, scinfo);
          break;
+    case LIBXL_SCHEDULER_RT_DS:
+        ret=sched_rt_domain_get(gc, domid, scinfo);
+        break;
      default:
          LOG(ERROR, "Unknown scheduler");
          ret=ERROR_INVAL;
tools/libxl/libxl.h +1 -0
index 460207b..dbe736c 100644
@@ -1280,6 +1280,7 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
  #define LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT     -1
  #define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT   -1
  #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT     -1
 
  int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                    libxl_domain_sched_params *params);
tools/libxl/libxl_types.idl +0 -0
index 931c9e9..72f24fe 100644

tools/libxl/libxl_types.idl libxl_scheduler = Enumeration("scheduler", [ · line 156

Quoted 4 lines
tools/libxl/libxl_types.idl +1 -0
@@ -153,6 +153,7 @@ libxl_scheduler = Enumeration("scheduler", [
      (5, "credit"),
      (6, "credit2"),
      (7, "arinc653"),
+    (8, "rt_ds"),

rtds

Other than that, looks good.

-George

#19 lore raw

Re: [PATCH v2 3/4] libxl: add rt scheduler

2014-09-08 11:19 GMT-04:00 George Dunlap <[email protected]>:

Quoted 50 lines · Meng Xu
Quoted 44 lines

Add libxl functions to set/get domain's parameters for rt scheduler
Note: VCPU's information (period, budget) is in microsecond (us).

---
  tools/libxl/libxl.c         |   75
+++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/libxl.h         |    1 +
  tools/libxl/libxl_types.idl |    2 ++
  3 files changed, 78 insertions(+)
tools/libxl/libxl.c +22 -0
index 2ae5fca..6840c92 100644
@@ -5155,6 +5155,75 @@ static int sched_sedf_domain_set(libxl__gc *gc,
 uint32_t domid,
      return 0;
  }
  +static int sched_rt_domain_get(libxl__gc *gc, uint32_t domid,
+                               libxl_domain_sched_params *scinfo)
+{
+    struct xen_domctl_sched_rt sdom;
+    int rc;
+
+    rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);
+    if (rc != 0) {
+        LOGE(ERROR, "getting domain sched rt");
+        return ERROR_FAIL;
+    }
+
+    libxl_domain_sched_params_init(scinfo);
+
+    scinfo->sched = LIBXL_SCHEDULER_RT_DS;
+    scinfo->period = sdom.period;
+    scinfo->budget = sdom.budget;
+
+    return 0;
+}
+
+#define SCHED_RT_DS_VCPU_PERIOD_UINT_MAX    4294967295U /* 2^32 - 1 us */
+#define SCHED_RT_DS_VCPU_BUDGET_UINT_MAX
Quoted 1 line

SCHED_RT_DS_VCPU_PERIOD_UINT_MAX

I think what Dario was looking for was this:

Quoted 5 lines

#define SCHED_RT_DS_VCPU_PERIOD_MAX UINT_MAX

I.e., use the already-defined #defines with meaningful names (line UINT_MAX), and avoid open-coding (i.e., typing out a "magic" number, like 429....U).

Ah, I see. I misunderstood. :-( Thank you very much, George, for clarification! :-)

Quoted 12 lines

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

Quoted 9 lines
tools/libxl/libxl.c +8 -0
+
+static int sched_rt_domain_set(libxl__gc *gc, uint32_t domid,
+                               const libxl_domain_sched_params *scinfo)
+{
+    struct xen_domctl_sched_rt sdom;
+    int rc;
+
+    rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);

You need to check the return value here and bail out on an error.

Right, will do.

Quoted 7 lines

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

Quoted 5 lines
tools/libxl/libxl.c +4 -0
+
+    if (scinfo->period != LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT) {
+        if (scinfo->period < 1 ||
+            scinfo->period > SCHED_RT_DS_VCPU_PERIOD_UINT_MAX) {
Quoted 8 lines

...but this isn't right anyway, right? scinfo->period is a signed integer. You shouldn't be comparing it to an unsigned int; and this can never be false anyway, because even if it's automatically cast to be unsigned, the type isn't big enough to be bigger than UINT_MAX anyway.

If period is allowed to be anything up to INT_MAX, then there's no need to check the upper bound. Checking to make sure it's >= 1 should be sufficient. Then you can just get rid of the #defines above.

I see and will change it as you said.

Quoted 14 lines

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

Quoted 12 lines
tools/libxl/libxl.c +11 -0
+            LOG(ERROR, "VCPU period is not set or out of range, "
+                       "valid values are within range from 0 to %u",
+                       SCHED_RT_DS_VCPU_PERIOD_UINT_MAX);
+            return ERROR_INVAL;
+        }
+        sdom.period = scinfo->period;
+    }
+
+    if (scinfo->budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT) {
+        if (scinfo->budget < 1 ||
+            scinfo->budget > SCHED_RT_DS_VCPU_BUDGET_UINT_MAX) {
Quoted 1 line

Same here.

Will change, Thanks!

Quoted 67 lines
Quoted 67 lines
tools/libxl/libxl.c +23 -0
+            LOG(ERROR, "VCPU budget is not set or out of range, "
+                       "valid values are within range from 0 to %u",
+                       SCHED_RT_DS_VCPU_BUDGET_UINT_MAX);
+            return ERROR_INVAL;
+        }
+        sdom.budget = scinfo->budget;
+    }
+
+    if (sdom.budget > sdom.period) {
+        LOG(ERROR, "VCPU budget is larger than VCPU period, "
+                   "VCPU budget should be no larger than VCPU period");
+        return ERROR_INVAL;
+    }
+
+    rc = xc_sched_rt_domain_set(CTX->xch, domid, &sdom);
+    if (rc < 0) {
+        LOGE(ERROR, "setting domain sched rt");
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
  int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
                                    const libxl_domain_sched_params

*scinfo)
{

tools/libxl/libxl.c +3 -0
@@ -5178,6 +5247,9 @@ int libxl_domain_sched_params_set(libxl_ctx *ctx,
 uint32_t domid,
      case LIBXL_SCHEDULER_ARINC653:
          ret=sched_arinc653_domain_set(gc, domid, scinfo);
          break;
+    case LIBXL_SCHEDULER_RT_DS:
+        ret=sched_rt_domain_set(gc, domid, scinfo);
+        break;
      default:
          LOG(ERROR, "Unknown scheduler");
          ret=ERROR_INVAL;
tools/libxl/libxl.c +3 -0
@@ -5208,6 +5280,9 @@ int libxl_domain_sched_params_get(libxl_ctx *ctx,
 uint32_t domid,
      case LIBXL_SCHEDULER_CREDIT2:
          ret=sched_credit2_domain_get(gc, domid, scinfo);
          break;
+    case LIBXL_SCHEDULER_RT_DS:
+        ret=sched_rt_domain_get(gc, domid, scinfo);
+        break;
      default:
          LOG(ERROR, "Unknown scheduler");
          ret=ERROR_INVAL;
tools/libxl/libxl.h +1 -0
index 460207b..dbe736c 100644
@@ -1280,6 +1280,7 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx,
 uint32_t poolid,
  #define LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT     -1
  #define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT   -1
  #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT     -1
    int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
                                    libxl_domain_sched_params *params);
tools/libxl/libxl_types.idl +0 -0
index 931c9e9..72f24fe 100644
Quoted 9 lines

tools/libxl/libxl_types.idl libxl_scheduler = Enumeration("scheduler", [ · line 156

Quoted 5 lines
tools/libxl/libxl_types.idl +1 -0
@@ -153,6 +153,7 @@ libxl_scheduler = Enumeration("scheduler", [
      (5, "credit"),
      (6, "credit2"),
      (7, "arinc653"),
+    (8, "rt_ds"),

rtds

Roger, will change very rt_ds to rtds then. :-P

Thanks,

Meng

Signature · 4 lines
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
author
#20 lore raw

PATCH v2 4/4 xl: introduce rt scheduler

In reply to Meng Xu

Add xl command for rt scheduler
Note: VCPU's parameter (period, budget) is in microsecond (us).

---
 docs/man/xl.pod.1         |   34 +++++++++++++
 tools/libxl/xl.h          |    1 +
 tools/libxl/xl_cmdimpl.c  |  119 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |    8 +++
 4 files changed, 162 insertions(+)
docs/man/xl.pod.1 +34 -0
index 9d1c2a5..c2532cb 100644
@@ -1035,6 +1035,40 @@ Restrict output to domains in the specified cpupool.
 
 =back
 
+=item B<sched-rt> [I<OPTIONS>]
+
+Set or get rt (Real Time) scheduler parameters. This rt scheduler applies 
+Preemptive Global Earliest Deadline First real-time scheduling algorithm to 
+schedule VCPUs in the system. Each VCPU has a dedicated period and budget.
+VCPUs in the same domain have the same period and budget (in Xen 4.5).
+While scheduled, a VCPU burns its budget. 
+A VCPU has its budget replenished at the beginning of each of its periods;
+The VCPU discards its unused budget at the end of its periods.
+
+B<OPTIONS>
+
+=over 4
+
+=item B<-d DOMAIN>, B<--domain=DOMAIN>
+
+Specify domain for which scheduler parameters are to be modified or retrieved.
+Mandatory for modifying scheduler parameters.
+
+=item B<-p PERIOD>, B<--period=PERIOD>
+
+A VCPU replenish its budget in every period. Time unit is millisecond.
+
+=item B<-b BUDGET>, B<--budget=BUDGET>
+
+A VCPU has BUDGET amount of time to run for each period. 
+Time unit is millisecond.
+
+=item B<-c CPUPOOL>, B<--cpupool=CPUPOOL>
+
+Restrict output to domains in the specified cpupool.
+
+=back
+
 =back
 
 =head1 CPUPOOLS COMMANDS
tools/libxl/xl.h +1 -0
index 10a2e66..51b634a 100644
@@ -67,6 +67,7 @@ int main_memset(int argc, char **argv);
 int main_sched_credit(int argc, char **argv);
 int main_sched_credit2(int argc, char **argv);
 int main_sched_sedf(int argc, char **argv);
+int main_sched_rt(int argc, char **argv);
 int main_domid(int argc, char **argv);
 int main_domname(int argc, char **argv);
 int main_rename(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +119 -0

131 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +8 -0
index 7b7fa92..0c0e06e 100644
@@ -277,6 +277,14 @@ struct cmd_spec cmd_table[] = {
       "                               --period/--slice)\n"
       "-c CPUPOOL, --cpupool=CPUPOOL  Restrict output to CPUPOOL"
     },
+    { "sched-rt",
+      &main_sched_rt, 0, 1,
+      "Get/set rt 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"
+    },
     { "domid",
       &main_domid, 0, 0,
       "Convert a domain name to domain id",
Signature · 1 line
1.7.9.5
#21 lore raw

Re: [PATCH v2 4/4] xl: introduce rt scheduler

Quoted 17 lines · Meng Xu

Add xl command for rt scheduler
Note: VCPU's parameter (period, budget) is in microsecond (us).

---
  docs/man/xl.pod.1         |   34 +++++++++++++
  tools/libxl/xl.h          |    1 +
  tools/libxl/xl_cmdimpl.c  |  119 +++++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/xl_cmdtable.c |    8 +++
  4 files changed, 162 insertions(+)
docs/man/xl.pod.1 +0 -0
index 9d1c2a5..c2532cb 100644

docs/man/xl.pod.1 Restrict output to domains in the specified cpupool. · line 1038

Quoted 4 lines
docs/man/xl.pod.1 +1 -0
@@ -1035,6 +1035,40 @@ Restrict output to domains in the specified cpupool.
 
  =back
 
+=item B<sched-rt> [I<OPTIONS>]

sched-rtds, I think.

docs/man/xl.pod.1 Restrict output to domains in the specified cpupool. · line 1046

Quoted 8 lines
docs/man/xl.pod.1 +8 -0
+
+Set or get rt (Real Time) scheduler parameters. This rt scheduler applies
+Preemptive Global Earliest Deadline First real-time scheduling algorithm to
+schedule VCPUs in the system. Each VCPU has a dedicated period and budget.
+VCPUs in the same domain have the same period and budget (in Xen 4.5).
+While scheduled, a VCPU burns its budget.
+A VCPU has its budget replenished at the beginning of each of its periods;
+The VCPU discards its unused budget at the end of its periods.

I think I would say, "A VCPU has its budget replenished at the beginning of each period; unused budget is discarded at the end of each period."

docs/man/xl.pod.1 Restrict output to domains in the specified cpupool. · line 1059

Quoted 13 lines
docs/man/xl.pod.1 +13 -0
+
+B<OPTIONS>
+
+=over 4
+
+=item B<-d DOMAIN>, B<--domain=DOMAIN>
+
+Specify domain for which scheduler parameters are to be modified or retrieved.
+Mandatory for modifying scheduler parameters.
+
+=item B<-p PERIOD>, B<--period=PERIOD>
+
+A VCPU replenish its budget in every period. Time unit is millisecond.

I think I'd say: "Period of time, in milliseconds, over which to replenish the budget."

docs/man/xl.pod.1 Restrict output to domains in the specified cpupool. · line 1064

Quoted 5 lines
docs/man/xl.pod.1 +5 -0
+
+=item B<-b BUDGET>, B<--budget=BUDGET>
+
+A VCPU has BUDGET amount of time to run for each period.
+Time unit is millisecond.

"Amount of time, in milliseconds, that the VCPU will be allowed to run every period."

Quoted 15 lines
docs/man/xl.pod.1 +7 -0
+
+=item B<-c CPUPOOL>, B<--cpupool=CPUPOOL>
+
+Restrict output to domains in the specified cpupool.
+
+=back
+
  =back
 
  =head1 CPUPOOLS COMMANDS
tools/libxl/xl.h +0 -0
index 10a2e66..51b634a 100644

tools/libxl/xl.h int main_memset(int argc, char **argv); · line 70

Quoted 4 lines
tools/libxl/xl.h +1 -0
@@ -67,6 +67,7 @@ int main_memset(int argc, char **argv);
  int main_sched_credit(int argc, char **argv);
  int main_sched_credit2(int argc, char **argv);
  int main_sched_sedf(int argc, char **argv);
+int main_sched_rt(int argc, char **argv);

main_sched_rtds

Quoted 15 lines
tools/libxl/xl.h +0 -0
  int main_domid(int argc, char **argv);
  int main_domname(int argc, char **argv);
  int main_rename(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +4 -0
index e6b9615..92037b1 100644
@@ -5212,6 +5212,47 @@ static int sched_sedf_domain_output(
      return 0;
  }
 
+static int sched_rt_domain_output(
+    int domid)
+{
+    char *domname;

tools/libxl/xl_cmdimpl.c static int sched_sedf_domain_output( · line 5228

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+    libxl_domain_sched_params scinfo;
+    int rc = 0;
+
+    if (domid < 0) {
+        printf("%-33s %4s %9s %9s\n", "Name", "ID", "Period", "Budget");
+        return 0;
+    }
+
+    libxl_domain_sched_params_init(&scinfo);
+    rc = sched_domain_get(LIBXL_SCHEDULER_RT_DS, domid, &scinfo);

Hmm, the other callers of sched_domain_get() don't call libxl_domain_sched_params_init(); but reading through libxl.h looks like that's actually a mistake:

* ...the user must
* always call the "init" function before using a type, even if the
* variable is simply being passed by reference as an out parameter
* to a libxl function.

Meng, would you be willing to put on your "to-do list" to send a follow-up patch to clean this up?

I think what should probably actually be done is that sched_domain_get() should call libxl_domain_sched_params_init() before calling libxl_domain_sched_params_get(). But I'm sure IanJ will have opinions on that.

Quoted 12 lines
tools/libxl/xl_cmdimpl.c +12 -0
+    if (rc)
+        goto out;
+
+    domname = libxl_domid_to_name(ctx, domid);
+    printf("%-33s %4d %9d %9d\n",
+        domname,
+        domid,
+        scinfo.period,
+        scinfo.budget);
+    free(domname);
+
+out:

tools/libxl/xl_cmdimpl.c static int sched_sedf_domain_output( · line 5250

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+    libxl_domain_sched_params_dispose(&scinfo);
+    return rc;
+}
+
+static int sched_rt_pool_output(uint32_t poolid)
+{
+    char *poolname;
+
+    poolname = libxl_cpupoolid_to_name(ctx, poolid);
+    printf("Cpupool %s: sched=EDF\n", poolname);

Should we change this to "RTDS"?

Quoted 13 lines
tools/libxl/xl_cmdimpl.c +6 -0
+
+    free(poolname);
+    return 0;
+}
+
  static int sched_default_pool_output(uint32_t poolid)
  {
      char *poolname;
@@ -5579,6 +5620,84 @@ int main_sched_sedf(int argc, char **argv)
      return 0;
  }
 
+/*

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

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+ * <nothing>            : List all domain paramters and sched params
+ * -d [domid]           : List domain params for domain
+ * -d [domid] [params]  : Set domain params for domain
+ */
+int main_sched_rt(int argc, char **argv)
+{
+    const char *dom = NULL;
+    const char *cpupool = NULL;
+    int period = 10, opt_p = 0; /* period is in microsecond */
+    int budget = 4, opt_b = 0; /* budget is in microsecond */

We might as well make opt_p and opt_b of type "bool".

Why are you setting the values for period and budget here? It looks like they're either never used (if either one or both are not set on the command line), or they're clobbered (when both are set).

If gcc doesn't complain, just leave them uninitizlized. If it does complian, then just initialize them to 0 -- that will make sure that it returns an error if there ever *is* a path which doesn't actually set the value.

Quoted 26 lines
tools/libxl/xl_cmdimpl.c +26 -0
+    int opt, rc;
+    static struct option opts[] = {
+        {"domain", 1, 0, 'd'},
+        {"period", 1, 0, 'p'},
+        {"budget", 1, 0, 'b'},
+        {"cpupool", 1, 0, 'c'},
+        COMMON_LONG_OPTS,
+        {0, 0, 0, 0}
+    };
+
+    SWITCH_FOREACH_OPT(opt, "d:p:b:c:h", opts, "sched-rt", 0) {
+    case 'd':
+        dom = optarg;
+        break;
+    case 'p':
+        period = strtol(optarg, NULL, 10);
+        opt_p = 1;
+        break;
+    case 'b':
+        budget = strtol(optarg, NULL, 10);
+        opt_b = 1;
+        break;
+    case 'c':
+        cpupool = optarg;
+        break;
+    }

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

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+
+    if (cpupool && (dom || opt_p || opt_b)) {
+        fprintf(stderr, "Specifying a cpupool is not allowed with other options.\n");
+        return 1;
+    }
+    if (!dom && (opt_p || opt_b)) {
+        fprintf(stderr, "Must specify a domain.\n");
+        return 1;
+    }
+    if ((opt_p || opt_b) && (opt_p + opt_b != 2)) {

Maybe, "if (opt_p != opt_b)"?

Quoted 39 lines
tools/libxl/xl_cmdimpl.c +31 -0
+        fprintf(stderr, "Must specify period and budget\n");
+        return 1;
+    }
+
+    if (!dom) { /* list all domain's rt scheduler info */
+        return -sched_domain_output(LIBXL_SCHEDULER_RT_DS,
+                                    sched_rt_domain_output,
+                                    sched_rt_pool_output,
+                                    cpupool);
+    } else {
+        uint32_t domid = find_domain(dom);
+        if (!opt_p && !opt_b) { /* output rt scheduler info */
+            sched_rt_domain_output(-1);
+            return -sched_rt_domain_output(domid);
+        } else { /* set rt scheduler paramaters */
+            libxl_domain_sched_params scinfo;
+            libxl_domain_sched_params_init(&scinfo);
+            scinfo.sched = LIBXL_SCHEDULER_RT_DS;
+            scinfo.period = period;
+            scinfo.budget = budget;
+
+            rc = sched_domain_set(domid, &scinfo);
+            libxl_domain_sched_params_dispose(&scinfo);
+            if (rc)
+                return -rc;
+        }
+    }
+
+    return 0;
+}
+
  int main_domid(int argc, char **argv)
  {
      uint32_t domid;
tools/libxl/xl_cmdtable.c +0 -0
index 7b7fa92..0c0e06e 100644

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 280

Quoted 4 lines
tools/libxl/xl_cmdtable.c +1 -0
@@ -277,6 +277,14 @@ struct cmd_spec cmd_table[] = {
        "                               --period/--slice)\n"
        "-c CPUPOOL, --cpupool=CPUPOOL  Restrict output to CPUPOOL"
      },
+    { "sched-rt",

sched-rtds

Right, starting to get close. :-)

-George

Quoted 10 lines
tools/libxl/xl_cmdtable.c +7 -0
+      &main_sched_rt, 0, 1,
+      "Get/set rt 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"
+    },
      { "domid",
        &main_domid, 0, 0,
        "Convert a domain name to domain id",
#22 lore raw

Re: [PATCH v2 4/4] xl: introduce rt scheduler

Quoted 14 lines · George Dunlap

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 280

Quoted 9 lines · Meng Xu
tools/libxl/xl_cmdtable.c +1 -0
index 7b7fa92..0c0e06e 100644
@@ -277,6 +277,14 @@ struct cmd_spec cmd_table[] = {
        "                               --period/--slice)\n"
        "-c CPUPOOL, --cpupool=CPUPOOL  Restrict output to CPUPOOL"
      },
+    { "sched-rt",

sched-rtds

Quoted 4 lines

Right, starting to get close. :-)

-George

So, Meng, I've just skimmed George's comment to patches 3 and 4, and I agree with all the points he makes.

I'll have a closer look and see if I've got any other comments on my own, but not before I've looked carefully and commented at the new version of patch 1.

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

#23 lore raw

Re: [PATCH v2 4/4] xl: introduce rt scheduler

In reply to George Dunlap

2014-09-08 12:06 GMT-04:00 George Dunlap <[email protected]>:

Quoted 15 lines · Meng Xu
Quoted 14 lines

Add xl command for rt scheduler
Note: VCPU's parameter (period, budget) is in microsecond (us).

---
  docs/man/xl.pod.1         |   34 +++++++++++++
  tools/libxl/xl.h          |    1 +
  tools/libxl/xl_cmdimpl.c  |  119
+++++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/xl_cmdtable.c |    8 +++
  4 files changed, 162 insertions(+)
Quoted 11 lines
Quoted 8 lines
docs/man/xl.pod.1 +0 -0
index 9d1c2a5..c2532cb 100644
@@ -1035,6 +1035,40 @@ Restrict output to domains in the specified

cpupool.
=back
+=item B<sched-rt> [I<OPTIONS>]

sched-rtds, I think.

OK. Then the command we provide will be "xl sched-rtds". I will modify them.

Quoted 31 lines
Quoted 15 lines
  int main_domid(int argc, char **argv);
  int main_domname(int argc, char **argv);
  int main_rename(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +3 -0
index e6b9615..92037b1 100644
@@ -5212,6 +5212,47 @@ static int sched_sedf_domain_output(
      return 0;
  }
  +static int sched_rt_domain_output(
+    int domid)
+{
+    char *domname;

tools/libxl/xl_cmdimpl.c static int sched_sedf_domain_output( · line 5227

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+    libxl_domain_sched_params scinfo;
+    int rc = 0;
+
+    if (domid < 0) {
+        printf("%-33s %4s %9s %9s\n", "Name", "ID", "Period", "Budget");
+        return 0;
+    }
+
+    libxl_domain_sched_params_init(&scinfo);
+    rc = sched_domain_get(LIBXL_SCHEDULER_RT_DS, domid, &scinfo);

Hmm, the other callers of sched_domain_get() don't call libxl_domain_sched_params_init(); but reading through libxl.h looks like that's actually a mistake:

Quoted 8 lines

* ...the user must
* always call the "init" function before using a type, even if the
* variable is simply being passed by reference as an out parameter
* to a libxl function.

Meng, would you be willing to put on your "to-do list" to send a follow-up patch to clean this up?

Sure! I'm happy to do that! Noted and will do after finishing the next version of the rt scheduler stuff. :-)

Quoted 22 lines

I think what should probably actually be done is that sched_domain_get() should call libxl_domain_sched_params_init() before calling libxl_domain_sched_params_get(). But I'm sure IanJ will have opinions on that.

Quoted 17 lines
tools/libxl/xl_cmdimpl.c +17 -0
+    if (rc)
+        goto out;
+
+    domname = libxl_domid_to_name(ctx, domid);
+    printf("%-33s %4d %9d %9d\n",
+        domname,
+        domid,
+        scinfo.period,
+        scinfo.budget);
+    free(domname);
+
+out:
+    libxl_domain_sched_params_dispose(&scinfo);
+    return rc;
+}
+
+static int sched_rt_pool_output(uint32_t poolid)
Quoted 8 lines

tools/libxl/xl_cmdimpl.c static int sched_sedf_domain_output( · line 5250

Quoted 5 lines
tools/libxl/xl_cmdimpl.c +5 -0
+{
+    char *poolname;
+
+    poolname = libxl_cpupoolid_to_name(ctx, poolid);
+    printf("Cpupool %s: sched=EDF\n", poolname);

Should we change this to "RTDS"?

Maybe yes, if we want to distinguish RTDS with other RT schedulers with different server mechanisms. (I will change it to RTDS if no one objects to it.)

Quoted 27 lines
Quoted 13 lines
tools/libxl/xl_cmdimpl.c +5 -0
+
+    free(poolname);
+    return 0;
+}
+
  static int sched_default_pool_output(uint32_t poolid)
  {
      char *poolname;
@@ -5579,6 +5620,84 @@ int main_sched_sedf(int argc, char **argv)
      return 0;
  }
  +/*

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

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+ * <nothing>            : List all domain paramters and sched params
+ * -d [domid]           : List domain params for domain
+ * -d [domid] [params]  : Set domain params for domain
+ */
+int main_sched_rt(int argc, char **argv)
+{
+    const char *dom = NULL;
+    const char *cpupool = NULL;
+    int period = 10, opt_p = 0; /* period is in microsecond */
+    int budget = 4, opt_b = 0; /* budget is in microsecond */

We might as well make opt_p and opt_b of type "bool".

Quoted 8 lines

Why are you setting the values for period and budget here? It looks like they're either never used (if either one or both are not set on the command line), or they're clobbered (when both are set).

If gcc doesn't complain, just leave them uninitizlized. If it does complian, then just initialize them to 0 -- that will make sure that it returns an error if there ever *is* a path which doesn't actually set the value.

OK. Will leave them uninitialized.

Quoted 34 lines
Quoted 34 lines
tools/libxl/xl_cmdimpl.c +31 -0
+    int opt, rc;
+    static struct option opts[] = {
+        {"domain", 1, 0, 'd'},
+        {"period", 1, 0, 'p'},
+        {"budget", 1, 0, 'b'},
+        {"cpupool", 1, 0, 'c'},
+        COMMON_LONG_OPTS,
+        {0, 0, 0, 0}
+    };
+
+    SWITCH_FOREACH_OPT(opt, "d:p:b:c:h", opts, "sched-rt", 0) {
+    case 'd':
+        dom = optarg;
+        break;
+    case 'p':
+        period = strtol(optarg, NULL, 10);
+        opt_p = 1;
+        break;
+    case 'b':
+        budget = strtol(optarg, NULL, 10);
+        opt_b = 1;
+        break;
+    case 'c':
+        cpupool = optarg;
+        break;
+    }
+
+    if (cpupool && (dom || opt_p || opt_b)) {
+        fprintf(stderr, "Specifying a cpupool is not allowed with other
 options.\n");
+        return 1;
+    }
Quoted 8 lines

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

Quoted 5 lines
tools/libxl/xl_cmdimpl.c +5 -0
+    if (!dom && (opt_p || opt_b)) {
+        fprintf(stderr, "Must specify a domain.\n");
+        return 1;
+    }
+    if ((opt_p || opt_b) && (opt_p + opt_b != 2)) {

Maybe, "if (opt_p != opt_b)"?

This is better! :-)

Quoted 49 lines
Quoted 41 lines
tools/libxl/xl_cmdimpl.c +31 -0
+        fprintf(stderr, "Must specify period and budget\n");
+        return 1;
+    }
+
+    if (!dom) { /* list all domain's rt scheduler info */
+        return -sched_domain_output(LIBXL_SCHEDULER_RT_DS,
+                                    sched_rt_domain_output,
+                                    sched_rt_pool_output,
+                                    cpupool);
+    } else {
+        uint32_t domid = find_domain(dom);
+        if (!opt_p && !opt_b) { /* output rt scheduler info */
+            sched_rt_domain_output(-1);
+            return -sched_rt_domain_output(domid);
+        } else { /* set rt scheduler paramaters */
+            libxl_domain_sched_params scinfo;
+            libxl_domain_sched_params_init(&scinfo);
+            scinfo.sched = LIBXL_SCHEDULER_RT_DS;
+            scinfo.period = period;
+            scinfo.budget = budget;
+
+            rc = sched_domain_set(domid, &scinfo);
+            libxl_domain_sched_params_dispose(&scinfo);
+            if (rc)
+                return -rc;
+        }
+    }
+
+    return 0;
+}
+
  int main_domid(int argc, char **argv)
  {
      uint32_t domid;
tools/libxl/xl_cmdtable.c +0 -0
index 7b7fa92..0c0e06e 100644

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 280

Quoted 4 lines
tools/libxl/xl_cmdtable.c +1 -0
@@ -277,6 +277,14 @@ struct cmd_spec cmd_table[] = {
        "                               --period/--slice)\n"
        "-c CPUPOOL, --cpupool=CPUPOOL  Restrict output to CPUPOOL"
      },
+    { "sched-rt",

sched-rtds

Quoted 2 lines

Right, starting to get close. :-)

Thank you so much for your helpful comments! :-)

Best,

Meng

-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania