Skip to contentSkip to conversation

New credit, experimental, v1

ED George Dunlap 1 participant 1 message Jun 18, 2009 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

A couple of things are clear from the previous discussion, and from other work on the scheduler: the 10ms granularity of credit charging is much too rough for latency-sensitive workloads. The next version of the scheduler will be keeping track of credits more precisely.

That alone won't fix it, however. The credit scheduler is still designed to cross between UNDER and OVER on a regular basis, and to discriminate against VMs which go into OVER.

For a while I worked on different algorithms that were similar in nature. However, I kept running up against some fundamental limitations.

Credit1's method of "active" vs "inactive" works well if VMs fall directly into those two camps, and are not interactive: active VMs burn all the credits they get, inactive VMs don't get credits but hardly need any cpu. But a number of VMs fall into the middle.

(Starting now is where I'm a lot less sure of what I'm saying, and expect to hear that I'm mistaken, or I've missed something.)

If VMs are allowed to accumulate credit, then some VMs will continually gain credit. Credit1 solved this by capping credit, and actually discarding it when a VM reached the cap. The problems with this have been discussed before. If you don't discard the credit, however, then the "stable state" of the system is for all VMs to have max credit, and cpu will effectively fall back to round-robin. (Briefly, if all VMs have MAX_CREDITS, and we assign up to 30ms of credit every 30ms, allowing extra credit from one VM to flow into another VM, then after burning some combination of credits, all VMs will be filled up to their max.)

I experimented for a while with the idea of discarding credits and assigning new credits from scratch every 100ms. The problem with this was again dealing with assigning credits not burned by some VMs "fairly" (i.e., by weight) to other VMs. The fundamental limitation is that we can't know ahead of time how much a VM will want to use. Even past performance isn't a good measure: just because a VM *didn't* run didnt' mean it *wouldn't* have run given the chance.

* Dynamic retroactive earning

The solution I'm presenting now is actually very simple computationally. However, it has some very subtle side-effects.

The algortihm is this:

* Set everyone's credits according to their weights, scaled so that the total amount of assigned credit can be burned up in 50-100ms.

* Then, burn credits as a fixed rate, running the VM with the highest amount of credits first.

* If a vcpu comes to the front of a queue that has zero credits (i.e., if there are no runnable VMs with credits), then assign credits again; but do not *add* credits, merely *set* them proportional to their weights; any unused credit is effectively discarded.

Here are some of the attributes of this algorithm:

* The credit assignment will effectively divide time into "earning periods".

* The amount of credit added into the system each earning period is equal to the amount burned. So overall system credit and overall system burn will be the same.

* Assigning fixed credit but varying the time at which it is delivered effectively changes the effective rate of earning. However, because the thing that varies the rate of earning happens at the end rather than the beginning, the time at which credits are assigned effectively retoractively sets the rate of earning for that earning period. (Think carefully about this for a bit.)

So this effectively addresses the two problems we had before: adding too much credit into the system (because earn == burn always), and not knowing in advance how much credit a VM would use, because we set the effective rate of earning not at the beginning, but at the end.

* Assigning credit when we first have a vcpu without credit. This scales everyone's earning rate, and discards the credits of those who don't use all of theirs, while making sure that those who do use all of their credits get time proportional to their weight.

A couple of conditions are required to make this algorithm work properly in the mix of burn and wake-and-sleep workloads. First, the "time slice" given to a "burn" VM must be a fraction (1/2 at most, probably preferrably less) than the amount of credit that VM has.

Anyway, take a look, give it a spin, and let me know what you think. I'm still working on the wake latency properties. But scp to an HVM domU, in competition with spinners, works pretty well for me, and scales well with setting weight. Test some other latency-sensitive workloads and let me know how it fares. I still have some more things to tweak, but I wanted to get the basic idea out there so people could discuss it / ask questions / give feedback / turn up workload or situations where it fails miserably.

I should make it clear, this is totally an early design prototype. Still needs work; some ugly hacks; scant attention paid to efficient algorithms; promised features (such as cap, reservation) missing.

-George

xen/common/Makefile +1 -0
diff -r f72d26c00002 xen/common/Makefile
@@ -13,6 +13,7 @@
 obj-y += page_alloc.o
 obj-y += rangeset.o
 obj-y += sched_credit.o
+obj-y += sched_credit2.o
 obj-y += sched_sedf.o
 obj-y += schedule.o
 obj-y += shutdown.o
xen/common/sched_credit2.c new file +1076 -0

1,076 lines not on this page · raw message

xen/common/schedule.c +2 -0
diff -r f72d26c00002 xen/common/schedule.c
@@ -58,9 +58,11 @@
 
 extern struct scheduler sched_sedf_def;
 extern struct scheduler sched_credit_def;
+extern struct scheduler sched_credit2_def;
 static struct scheduler *schedulers[] = { 
     &sched_sedf_def,
     &sched_credit_def,
+    &sched_credit2_def,
     NULL
 };
 
xen/include/public/domctl.h +4 -0
diff -r f72d26c00002 xen/include/public/domctl.h
@@ -297,6 +297,7 @@
 /* Scheduler types. */
 #define XEN_SCHEDULER_SEDF     4
 #define XEN_SCHEDULER_CREDIT   5
+#define XEN_SCHEDULER_CREDIT2  6
 /* Set or get info? */
 #define XEN_DOMCTL_SCHEDOP_putinfo 0
 #define XEN_DOMCTL_SCHEDOP_getinfo 1
@@ -315,6 +316,9 @@
             uint16_t weight;
             uint16_t cap;
         } credit;
+        struct xen_domctl_sched_credit2 {
+            uint16_t weight;
+        } credit2;
     } u;
 };
 typedef struct xen_domctl_scheduler_op xen_domctl_scheduler_op_t;
xen/include/public/trace.h +1 -0
diff -r f72d26c00002 xen/include/public/trace.h
@@ -53,6 +53,7 @@
 #define TRC_HVM_HANDLER   0x00082000   /* various HVM handlers      */
 
 #define TRC_SCHED_MIN       0x00021000   /* Just runstate changes */
+#define TRC_SCHED_CLASS     0x00022000   /* Scheduler-specific    */
 #define TRC_SCHED_VERBOSE   0x00028000   /* More inclusive scheduling */
 
 /* Trace events per class */
tools/libxc/Makefile +1 -0
diff -r 31161e9da095 tools/libxc/Makefile
@@ -17,6 +17,7 @@
 CTRL_SRCS-y       += xc_private.c
 CTRL_SRCS-y       += xc_sedf.c
 CTRL_SRCS-y       += xc_csched.c
+CTRL_SRCS-y       += xc_csched2.c
 CTRL_SRCS-y       += xc_tbuf.c
 CTRL_SRCS-y       += xc_pm.c
 CTRL_SRCS-y       += xc_cpu_hotplug.c
tools/libxc/xc_csched2.c new file +50 -0

50 lines not on this page · raw message

tools/libxc/xenctrl.h +8 -0
diff -r 31161e9da095 tools/libxc/xenctrl.h
@@ -468,6 +468,14 @@
                                uint32_t domid,
                                struct xen_domctl_sched_credit *sdom);
 
+int xc_sched_credit2_domain_set(int xc_handle,
+                               uint32_t domid,
+                               struct xen_domctl_sched_credit2 *sdom);
+
+int xc_sched_credit2_domain_get(int xc_handle,
+                               uint32_t domid,
+                               struct xen_domctl_sched_credit2 *sdom);
+
 /**
  * This function sends a trigger to a domain.
  *
tools/python/xen/lowlevel/xc/xc.c +58 -0

76 lines not on this page · raw message

tools/python/xen/xend/XendAPI.py +1 -2
diff -r 31161e9da095 tools/python/xen/xend/XendAPI.py
@@ -1595,8 +1595,7 @@
         if 'weight' in xeninfo.info['vcpus_params'] \
            and 'cap' in xeninfo.info['vcpus_params']:
             weight = xeninfo.info['vcpus_params']['weight']
-            cap = xeninfo.info['vcpus_params']['cap']
-            xendom.domain_sched_credit_set(xeninfo.getDomid(), weight, cap)
+            xendom.domain_sched_credit2_set(xeninfo.getDomid(), weight)
 
     def VM_set_VCPUs_number_live(self, _, vm_ref, num):
         dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
tools/python/xen/xend/XendDomain.py +54 -0

60 lines not on this page · raw message

tools/python/xen/xend/XendDomainInfo.py +4 -0
diff -r 31161e9da095 tools/python/xen/xend/XendDomainInfo.py
@@ -474,6 +474,10 @@
                     xendomains.domain_sched_credit_set(self.getDomid(),
                                                        self.getWeight(),
                                                        self.getCap())
+                elif xennode.xenschedinfo() == 'credit2':
+                    xendomains.domain_sched_credit2_set(self.getDomid(),
+                                                        self.getWeight())
+
             except:
                 log.exception('VM start failed')
                 self.destroy()
tools/python/xen/xend/XendNode.py +4 -0
diff -r 31161e9da095 tools/python/xen/xend/XendNode.py
@@ -678,6 +678,8 @@
             return 'sedf'
         elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
             return 'credit'
+        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT2:
+            return 'credit2'
         else:
             return 'unknown'
 
@@ -874,6 +876,8 @@
             return 'sedf'
         elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
             return 'credit'
+        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT2:
+            return 'credit2'
         else:
             return 'unknown'
 
tools/python/xen/xend/XendVMMetrics.py +1 -0
diff -r 31161e9da095 tools/python/xen/xend/XendVMMetrics.py
@@ -129,6 +129,7 @@
                 params_live['cpumap%i' % i] = \
                     ",".join(map(str, info['cpumap']))
 
+                # FIXME: credit2??
             params_live.update(xc.sched_credit_domain_get(domid))
             
             return params_live
tools/python/xen/xend/server/SrvDomain.py +14 -0
diff -r 31161e9da095 tools/python/xen/xend/server/SrvDomain.py
@@ -162,6 +162,20 @@
         val = fn(req.args, {'dom': self.dom.getName()})
         return val
 
+    def op_domain_sched_credit2_get(self, _, req):
+        fn = FormFn(self.xd.domain_sched_credit2_get,
+                    [['dom', 'str']])
+        val = fn(req.args, {'dom': self.dom.getName()})
+        return val
+
+
+    def op_domain_sched_credit2_set(self, _, req):
+        fn = FormFn(self.xd.domain_sched_credit2_set,
+                    [['dom', 'str'],
+                     ['weight', 'int']])
+        val = fn(req.args, {'dom': self.dom.getName()})
+        return val
+
     def op_maxmem_set(self, _, req):
         return self.call(self.dom.setMemoryMaximum,
                          [['memory', 'int']],
tools/python/xen/xm/main.py +82 -0

112 lines not on this page · raw message

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