Skip to contentSkip to conversation

Credit2 scheduler prototype

RFC PATCH In review George Dunlap 3 participants 11 messages Dec 7, 2009 – Jan 29, 2010 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Credit2 scheduler prototype

I'm attaching patches for the rudimentary new credit2 scheduler which I discussed at the Summit. It's definitely still at a developmental stage, but it's in a state where people should be able to contribute now.

I've put up a wiki page to help coordinate development here:
http://wiki.xensource.com/xenwiki/Credit2_Scheduler_Development

Some caveats:
* There is no inter-socket load balancing. This is one of the work items to be done.
* It works on my 2-core box, but deadlocks on my 4-core box; cause still to be determined.

The wiki page lists a number of semi-independent lines of development that people can take. Let me know if you're interested in any of them, and if you have any questions, and I can elaborate.

Keir (and everyone), I think at this point it would be a good idea to start a credit2 development branch in ext/ so we can keep a revision history. Thoughts?

-George

xen/arch/x86/domain.c +10 -4
diff -r 23d34c3ba4b7 xen/arch/x86/domain.c
@@ -1426,9 +1426,9 @@
 
     set_current(next);
 
-    if ( (per_cpu(curr_vcpu, cpu) == next) || is_idle_vcpu(next) )
+    if ( (per_cpu(curr_vcpu, cpu) == next) /* || is_idle_vcpu(next) */)
     {
-        local_irq_enable();
+        ;//local_irq_enable();
     }
     else
     {
@@ -1445,9 +1445,8 @@
                 write_efer(efer | EFER_SCE);
         }
 #endif
-
         /* Re-enable interrupts before restoring state which may fault. */
-        local_irq_enable();
+        //local_irq_enable();
 
         if ( !is_hvm_vcpu(next) )
         {
@@ -1458,6 +1457,13 @@
 
     context_saved(prev);
 
+    local_irq_enable();
+
+    /* If we've deadlocked somehow and temporarily made a VM unrunnable,
+     * clear the bit and call wake. */
+    if ( test_and_clear_bit(_VPF_deadlock, &prev->pause_flags ) )
+         vcpu_wake(prev);
+
     if (prev != next)
         update_runstate_area(next);
 
xen/arch/x86/nmi.c +2 -3
diff -r 23d34c3ba4b7 xen/arch/x86/nmi.c
@@ -391,7 +391,6 @@
     u32 id = cpu_physical_id(cpu);
 
     printk("Triggering NMI on APIC ID %x\n", id);
-    debugtrace_dump();
 
     local_irq_disable();
     apic_wait_icr_idle();
@@ -426,11 +425,12 @@
         if ( this_cpu(alert_counter) == 5*nmi_hz )
         {
             console_force_unlock();
+            spin_lock(&panic_lock);
             printk("Watchdog timer detects that CPU%d is stuck!\n",
                    smp_processor_id());
-            spin_lock(&panic_lock);
             show_execution_state(regs);
             debugtrace_dump();
+            spin_unlock(&panic_lock);
             atomic_inc(&all_panic);
             {
                 int cpu;
@@ -441,7 +441,6 @@
                     do_nmi_trigger_cpu(cpu);
                 }
             }
-            spin_unlock(&panic_lock);
             while(1);
             //fatal_trap(TRAP_nmi, regs);
         }
xen/common/Makefile +1 -0
diff -r 23d34c3ba4b7 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 +992 -0

992 lines not on this page · raw message

xen/common/schedule.c +2 -0
diff -r 23d34c3ba4b7 xen/common/schedule.c
@@ -58,9 +58,11 @@
 
 extern const struct scheduler sched_sedf_def;
 extern const struct scheduler sched_credit_def;
+extern const struct scheduler sched_credit2_def;
 static const struct scheduler *__initdata schedulers[] = {
     &sched_sedf_def,
     &sched_credit_def,
+    &sched_credit2_def,
     NULL
 };
 
xen/include/public/domctl.h +4 -0
diff -r 23d34c3ba4b7 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 23d34c3ba4b7 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 */
xen/include/xen/sched.h +2 -0
diff -r 23d34c3ba4b7 xen/include/xen/sched.h
@@ -530,6 +530,8 @@
  /* VCPU affinity has changed: migrating to a new CPU. */
 #define _VPF_migrating       3
 #define VPF_migrating        (1UL<<_VPF_migrating)
+#define _VPF_deadlock        4
+#define VPF_deadlock        (1UL<<_VPF_migrating)
 
 static inline int vcpu_runnable(struct vcpu *v)
 {
tools/libxc/Makefile +1 -0
diff -r d2f0843a38e4 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 d2f0843a38e4 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 d2f0843a38e4 tools/python/xen/xend/XendAPI.py
@@ -1613,8 +1613,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 d2f0843a38e4 tools/python/xen/xend/XendDomainInfo.py
@@ -2640,6 +2640,10 @@
             XendDomain.instance().domain_sched_credit_set(self.getDomid(),
                                                           self.getWeight(),
                                                           self.getCap())
+        elif XendNode.instance().xenschedinfo() == 'credit2':
+            from xen.xend import XendDomain
+            XendDomain.instance().domain_sched_credit2_set(self.getDomid(),
+                                                           self.getWeight())
 
     def _initDomain(self):
         log.debug('XendDomainInfo.initDomain: %s %s',
tools/python/xen/xend/XendNode.py +4 -0
diff -r d2f0843a38e4 tools/python/xen/xend/XendNode.py
@@ -679,6 +679,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 d2f0843a38e4 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 d2f0843a38e4 tools/python/xen/xend/server/SrvDomain.py
@@ -163,6 +163,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

#1 lore raw
Quoted 3 lines · George Dunlap

Keir (and everyone), I think at this point it would be a good idea to start a credit2 development branch in ext/ so we can keep a revision history. Thoughts?

Sounds like a reasonable idea, if you don't think it suitable just to check into mainline as the non-default scheduler.

-- Keir

#2 lore raw

My main concern is that sharing the runqueue between cores requires some changes to the core context switch code. The kinks aren't 100% worked out yet, so there's a risk that there will be an impact on the correctness of the credit1 scheduler.

If you want to go that route, we should probably talk about the changes we want to the context switch path first, and check that in as a separate patch, before checking in the core scheduler code.

Or we could just check it in and sort it out as things go, since this is -unstable. :-)

Thoughts?

Either way I'll write up an e-mail describing some of the scheduler path changes I'd like to see.

-George

Quoted 18 lines · Keir Fraser
Quoted 3 lines · George Dunlap

Keir (and everyone), I think at this point it would be a good idea to start a credit2 development branch in ext/ so we can keep a revision history.  Thoughts?

Sounds like a reasonable idea, if you don't think it suitable just to check into mainline as the non-default scheduler.

 -- Keir

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

#3 lore raw
Quoted 4 lines · George Dunlap

My main concern is that sharing the runqueue between cores requires some changes to the core context switch code. The kinks aren't 100% worked out yet, so there's a risk that there will be an impact on the correctness of the credit1 scheduler.

Ah, if that's the problem with selecting a vcpu which happens to still be 'is_running' then I had some ideas how you could deal with that within the credit2 scheduler. If you see such a vcpu when searching the runqueue, ignore it, but set VPF_migrating. You'll then get a 'pick_cpu' callback when descheduling of the vcpu is completed. That should play nice with the lazy context switch logic while keeping things work conserving.

-- Keir

#4 lore raw

Keir,

What do you think of the attached patches?

The first implements something like what you suggest below, but instead of using a sort of "hack" with VPF_migrate, it makes a proper "context_saved" SCHED_OP callback.

The second addresses the fact that when sharing runqueues, v->processor may change quickly without an explicit migrate.

The last two are the credit2 hypervisor and tool patches, which use these two changes (for reference).

I think these patches should be basically NOOP for the existing schedulers, so as far as I'm concerned they're ready to be merged as soon as you're happy with them.

Peace,
-George

Quoted 14 lines · Keir Fraser
Quoted 4 lines · George Dunlap

My main concern is that sharing the runqueue between cores requires some changes to the core context switch code. The kinks aren't 100% worked out yet, so there's a risk that there will be an impact on the correctness of the credit1 scheduler.

Ah, if that's the problem with selecting a vcpu which happens to still be 'is_running' then I had some ideas how you could deal with that within the credit2 scheduler. If you see such a vcpu when searching the runqueue, ignore it, but set VPF_migrating. You'll then get a 'pick_cpu' callback when descheduling of the vcpu is completed. That should play nice with the lazy context switch logic while keeping things work conserving.

Quoted 9 lines

 -- Keir

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

Add context_saved scheduler callback.

Because credit2 shares a runqueue between several cpus, it needs to know when a scheduled-out process has finally been context-switched away so that it can be added to the runqueue again. (Otherwise it may be grabbed by another processor before the context has been properly saved.)

xen/common/schedule.c +2 -0
diff -r c44b7b9b6306 xen/common/schedule.c
@@ -877,6 +877,8 @@
     /* Check for migration request /after/ clearing running flag. */
     smp_mb();
 
+    SCHED_OP(context_saved, prev);
+
     if ( unlikely(test_bit(_VPF_migrating, &prev->pause_flags)) )
         vcpu_migrate(prev);
 }
xen/include/xen/sched-if.h +1 -0
diff -r c44b7b9b6306 xen/include/xen/sched-if.h
@@ -69,6 +69,7 @@
 
     void         (*sleep)          (struct vcpu *);
     void         (*wake)           (struct vcpu *);
+    void         (*context_saved)  (struct vcpu *);
 
     struct task_slice (*do_schedule) (s_time_t);
 

Safely change next->processor if necessary.

Credit2's shared runqueue means that a vcpu may switch from one pcpu to another without an explicit migration. We need to change v->processor to match. However, this must be done with the current v->processor schedule lock held. To avoid deadlock, do this after we've released the current processor's schedule lock.

xen/common/schedule.c +22 -0
diff -r 669448fb9d0c xen/common/schedule.c
@@ -305,6 +305,23 @@
     vcpu_wake(v);
 }
 
+/* Safely change v->processor when running on a different cpu sharing the same runqueue */
+static void __vcpu_processor_sync(struct vcpu *next)
+{
+    unsigned long flags;
+    int old_cpu;
+    int this_cpu = smp_processor_id();
+
+    vcpu_schedule_lock_irqsave(next, flags);
+
+    /* Switch to new CPU, then unlock old CPU. */
+    old_cpu = next->processor;
+    next->processor = this_cpu;
+
+    spin_unlock_irqrestore(
+        &per_cpu(schedule_data, old_cpu).schedule_lock, flags);
+}
+
 /*
  * Force a VCPU through a deschedule/reschedule path.
  * For example, using this when setting the periodic timer period means that
@@ -852,6 +869,11 @@
 
     spin_unlock_irq(&sd->schedule_lock);
 
+    /* Safely change v->processor if necessary.  Do this after
+     * releasing this cpu's lock to avoid deadlock. */
+    if ( next->processor != smp_processor_id() )
+        __vcpu_processor_sync(next);
+
     perfc_incr(sched_ctx);
 
     stop_timer(&prev->periodic_timer);
xen/common/Makefile +1 -0
diff -r 7bd1dd9fb30f 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 +1037 -0

1,037 lines not on this page · raw message

xen/common/schedule.c +2 -0
diff -r 7bd1dd9fb30f xen/common/schedule.c
@@ -58,9 +58,11 @@
 
 extern const struct scheduler sched_sedf_def;
 extern const struct scheduler sched_credit_def;
+extern const struct scheduler sched_credit2_def;
 static const struct scheduler *__initdata schedulers[] = {
     &sched_sedf_def,
     &sched_credit_def,
+    &sched_credit2_def,
     NULL
 };
 
xen/include/public/domctl.h +4 -0
diff -r 7bd1dd9fb30f xen/include/public/domctl.h
@@ -295,6 +295,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
@@ -313,6 +314,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 7bd1dd9fb30f 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 63531e640828 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 63531e640828 tools/libxc/xenctrl.h
@@ -469,6 +469,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 63531e640828 tools/python/xen/xend/XendAPI.py
@@ -1626,8 +1626,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 63531e640828 tools/python/xen/xend/XendDomainInfo.py
@@ -2719,6 +2719,10 @@
             XendDomain.instance().domain_sched_credit_set(self.getDomid(),
                                                           self.getWeight(),
                                                           self.getCap())
+        elif XendNode.instance().xenschedinfo() == 'credit2':
+            from xen.xend import XendDomain
+            XendDomain.instance().domain_sched_credit2_set(self.getDomid(),
+                                                           self.getWeight())
 
     def _initDomain(self):
         log.debug('XendDomainInfo.initDomain: %s %s',
tools/python/xen/xend/XendNode.py +4 -0
diff -r 63531e640828 tools/python/xen/xend/XendNode.py
@@ -760,6 +760,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'
 
@@ -961,6 +963,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 63531e640828 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 63531e640828 tools/python/xen/xend/server/SrvDomain.py
@@ -163,6 +163,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

#5 lore raw
Quoted 3 lines · George Dunlap

The first implements something like what you suggest below, but instead of using a sort of "hack" with VPF_migrate, it makes a proper "context_saved" SCHED_OP callback.

I thought using the vcpu_migrate() path might work well since you presumably have logic there to pick a new cpu which is relatively unloaded, making the cpu which tried to schedule the vcpu but had to idle instead a prime candidate. So rather than having to implement a new callback hook, you'd get to leverage the pick_cpu hook for free?

Quoted 2 lines

The second addresses the fact that when sharing runqueues, v->processor may change quickly without an explicit migrate.

I can't think of a better solution for this one.

-- Keir

#6 lore raw
Quoted 11 lines · Keir Fraser
Quoted 3 lines · George Dunlap

The first implements something like what you suggest below, but instead of using a sort of "hack" with VPF_migrate, it makes a proper "context_saved" SCHED_OP callback.

I thought using the vcpu_migrate() path might work well since you presumably have logic there to pick a new cpu which is relatively unloaded, making the cpu which tried to schedule the vcpu but had to idle instead a prime candidate. So rather than having to implement a new callback hook, you'd get to leverage the pick_cpu hook for free?

Hmm, not sure that actually gives us the leverage we need to solve all the races. If you look at sched_credit2.c (in the credit2-hypervisor patch), you'll see I added two flags to the private vcpu struct: one to indicate that the vcpu has (or may have) context somewhere on a cpu, and thus can't be added to the runqueue; another to indicate that when the first flag is cleared, it should be added to the runqueue. In the current implementation, the first flag is set and cleared every time a vcpu is scheduled or descheduled, whether it needs to be added to the runqueue after context_saved() or not.

[NB that the current global lock will eventually be replaced with per-runqueue locks.]

In particular, one of the races without the first flag looks like this (brackets indicate physical cpu):
[0] lock cpu0 schedule lock
[0] lock credit2 runqueue lock
[0] Take vX off runqueue; vX->processor == 1
[0] unlock credit2 runqueue lock
[1] vcpu_wake(vX) lock cpu1 schedule lock
[1] finds vX->running false, adds it to the runqueue
[1] unlock cpu1 schedule_lock
[0] vX->running=1
[0] unlock cpu0 schedule lock
[0] lock cpu1 schedule lock (vX->cpu == 1)
[0] vX->cpu = 0
[0] unlock cpu1 schedule lock
[1] takes vX from the runqueue, finds vX->running is true *ERROR*

I guess the real problem here is that vX->running is set even though the vX->processor schedule lock isn't held, causing a race with vcpu_wake(). In the other schedulers this can't happen, since it takes an explicit migrate to change processors. In the attached patches, csched2 operations serialize on the runqueue lock, fixing that particular race.

Can't think of a better solution off the top of my head; I'll give it some thought.

-George

#7 lore raw
Quoted 12 lines · George Dunlap

[NB that the current global lock will eventually be replaced with per-runqueue locks.]

In particular, one of the races without the first flag looks like this (brackets indicate physical cpu):
[0] lock cpu0 schedule lock
[0] lock credit2 runqueue lock
[0] Take vX off runqueue; vX->processor == 1
[0] unlock credit2 runqueue lock
[1] vcpu_wake(vX) lock cpu1 schedule lock
[1] finds vX->running false, adds it to the runqueue
[1] unlock cpu1 schedule_lock

Actually, hang on. Doesn't this issue, and the one that your second patch addresses, go away if we change the schedule_lock granularity to match runqueue granularity? That would seem pretty sensible, and could be implemented with a schedule_lock(cpu) scheduler hook, returning a spinlock_t*, and a some easy scheduler code changes.

If we do that, do you then even need separate private per-runqueue locks? (Just an extra thought).

-- Keir

#8 lore raw
Quoted 17 lines · Keir Fraser
Quoted 13 lines · George Dunlap

[NB that the current global lock will eventually be replaced with per-runqueue locks.]

In particular, one of the races without the first flag looks like this (brackets indicate physical cpu):
[0] lock cpu0 schedule lock
[0] lock credit2 runqueue lock
[0] Take vX off runqueue; vX->processor == 1
[0] unlock credit2 runqueue lock
[1] vcpu_wake(vX) lock cpu1 schedule lock
[1] finds vX->running false, adds it to the runqueue
[1] unlock cpu1 schedule_lock

Quoted 9 lines

Actually, hang on. Doesn't this issue, and the one that your second patch addresses, go away if we change the schedule_lock granularity to match runqueue granularity? That would seem pretty sensible, and could be implemented with a schedule_lock(cpu) scheduler hook, returning a spinlock_t*, and a some easy scheduler code changes.

If we do that, do you then even need separate private per-runqueue locks? (Just an extra thought).

Hmm.... can't see anything wrong with it. It would make the whole locking discipline thing a lot simpler. It would, AFAICT, remove the need for private per-runqueue locks, which make it a lot harder to avoid deadlock without these sorts of strange tricks. :-)

I'll think about it, and probably give it a spin to see how it works out.

-George

#9 lore raw

George,

With your patches and sched=credit2, xen crashes on a failed assertion :
(XEN) ****************************************
(XEN) Panic on CPU 1:
(XEN) Assertion '_spin_is_locked(&(*({ unsigned long __ptr; __asm__ ("" : "=r"(* (XEN)

Is this version supposed to work (or is it just some reference code) ?

thanks
dulloor

Quoted 44 lines · George Dunlap
Quoted 19 lines · Keir Fraser
Quoted 4 lines · George Dunlap

[NB that the current global lock will eventually be replaced with per-runqueue locks.]

Quoted 10 lines

In particular, one of the races without the first flag looks like this (brackets indicate physical cpu):
[0] lock cpu0 schedule lock
[0] lock credit2 runqueue lock
[0] Take vX off runqueue; vX->processor == 1
[0] unlock credit2 runqueue lock
[1] vcpu_wake(vX) lock cpu1 schedule lock
[1] finds vX->running false, adds it to the runqueue
[1] unlock cpu1 schedule_lock

Quoted 9 lines

Actually, hang on. Doesn't this issue, and the one that your second patch addresses, go away if we change the schedule_lock granularity to match runqueue granularity? That would seem pretty sensible, and could be implemented with a schedule_lock(cpu) scheduler hook, returning a spinlock_t*, and a some easy scheduler code changes.

If we do that, do you then even need separate private per-runqueue locks? (Just an extra thought).

Hmm.... can't see anything wrong with it.  It would make the whole locking discipline thing a lot simpler.  It would, AFAICT, remove the need for private per-runqueue locks, which make it a lot harder to avoid deadlock without these sorts of strange tricks. :-)

I'll think about it, and probably give it a spin to see how it works out.

-George

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

#10 lore raw

Since it's an assertion, I assume you ran it with debug=y?

I'm definitely changing some assumptions with this, so it's not a surprise that some assertions trigger.

I'm working on a modified version based on the discussion we had here; I'll post a patch (tested with debug=y) when I'm done.

-George

Quoted 66 lines · Dulloor

George,

With your patches and sched=credit2, xen crashes on a failed assertion :
(XEN) ****************************************
(XEN) Panic on CPU 1:
(XEN) Assertion '_spin_is_locked(&(*({ unsigned long __ptr; __asm__ ("" : "=r"(* (XEN)

Is this version supposed to work (or is it just some reference code) ?

thanks
dulloor

Quoted 35 lines · George Dunlap
Quoted 19 lines · Keir Fraser
Quoted 4 lines · George Dunlap

[NB that the current global lock will eventually be replaced with per-runqueue locks.]

Quoted 10 lines

In particular, one of the races without the first flag looks like this (brackets indicate physical cpu):
[0] lock cpu0 schedule lock
[0] lock credit2 runqueue lock
[0] Take vX off runqueue; vX->processor == 1
[0] unlock credit2 runqueue lock
[1] vcpu_wake(vX) lock cpu1 schedule lock
[1] finds vX->running false, adds it to the runqueue
[1] unlock cpu1 schedule_lock

Quoted 9 lines

Actually, hang on. Doesn't this issue, and the one that your second patch addresses, go away if we change the schedule_lock granularity to match runqueue granularity? That would seem pretty sensible, and could be implemented with a schedule_lock(cpu) scheduler hook, returning a spinlock_t*, and a some easy scheduler code changes.

If we do that, do you then even need separate private per-runqueue locks? (Just an extra thought).

Hmm.... can't see anything wrong with it.  It would make the whole locking discipline thing a lot simpler.  It would, AFAICT, remove the need for private per-runqueue locks, which make it a lot harder to avoid deadlock without these sorts of strange tricks. :-)

Quoted 9 lines

I'll think about it, and probably give it a spin to see how it works out.

-George

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

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