Scheduler interface changes for credit2
RFC PATCH 1/1 Scheduler interface changes for credit2
The two attached patches change the scheduler interface to allow credit2 to have several cpus share the same runqueue. The patches should have almost no impact on the current schedulers. The patches and their reasonings are below. I've also attached the patches for the prototype credit2 scheduler, for reference.
* Add a context swich callback (sched-context_switch-callback.diff)
Add a callback to tell a scheduler that a vcpu has been completely context-switched off a cpu.
When sharing a runqueue, we can't put a scheduled-out vcpu back on the runqueue until it's been completely de-scheduled, because it may be grabbed by another processor before it's ready. This callback allows a scheduler to detect when a vcpu on its way out is completely off the processor, so that it can put the vcpu on the runqueue.
* Allow sharing of locks between cpus (sched-spin_lock-pointers.diff)
Have per-cpu pointers, initialized to per-cpu locks, which the scheduler may change during its init to reconfigure locking granularity.
There are a number of race conditions having to do with updating of v->is_running and v->processor, all having to do with the fact that vcpus may change cpus without an explicit migrate. Furthermore, the scheduler needs runqueues to be covered by a lock as well. The cleanest way to solve all of these is to have the scheduler lock and the runqueue lock coincide.
* Add a "scheduler" trace class (trace-sched-class.diff) Uses defined on a per-scheduler basis
I've been running parallel kernel compiles on a 16-way box (2x4x2) for several hours now without deadlocks or BUG()s. As far as I'm concerned, with these changes, credit2 is now ready to be checked in, as long as it's not set to the default scheduler.
All of the above:
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
@@ -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
@@ -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 );
xen/arch/ia64/vmx/vmmu.c +3 -3
@@ -394,7 +394,7 @@if (cpu != current->processor)return ;local_irq_save (flags); -if (!spin_trylock (&per_cpu (schedule_data, cpu).schedule_lock)) +if (!spin_trylock (per_cpu (schedule_data, cpu).schedule_lock)) goto bail2;if (v->processor != cpu) goto bail1;
@@ -416,7 +416,7 @@ia64_dv_serialize_data (); args->vcpu =NULL ; bail1: -spin_unlock (&per_cpu (schedule_data, cpu).schedule_lock); +spin_unlock (per_cpu (schedule_data, cpu).schedule_lock); bail2:local_irq_restore (flags); }
@@ -446,7 +446,7 @@ do { cpu = v->processor; if (cpu != current->processor) { - spin_barrier(&per_cpu(schedule_data, cpu).schedule_lock); + spin_barrier(per_cpu(schedule_data, cpu).schedule_lock); /* Flush VHPT on remote processors. */ smp_call_function_single(cpu, &ptc_ga_remote_func, &args, 1); } else {
xen/common/sched_credit.c +4 -4
@@ -770,7 +770,7 @@ spc->runq_sort_last = sort_epoch; -spin_lock_irqsave (&per_cpu (schedule_data, cpu).schedule_lock, flags); +spin_lock_irqsave (per_cpu (schedule_data, cpu).schedule_lock, flags); runq = &spc->runq; elem = runq->next;
@@ -795,7 +795,7 @@ elem = next; } -spin_unlock_irqrestore (&per_cpu (schedule_data, cpu).schedule_lock, flags); +spin_unlock_irqrestore (per_cpu (schedule_data, cpu).schedule_lock, flags); } static void
@@ -1110,7 +1110,7 @@* cause a deadlock if the peer CPU is also load balancing and trying * to lock this CPU. */ -if ( !spin_trylock (&per_cpu (schedule_data, peer_cpu).schedule_lock) ) +if ( !spin_trylock (per_cpu (schedule_data, peer_cpu).schedule_lock) ) {CSCHED_STAT_CRANK (steal_trylock_failed);continue ;
@@ -1120,7 +1120,7 @@* Any work over there to steal? */ speer =csched_runq_steal (peer_cpu, cpu, snext->pri); -spin_unlock (&per_cpu (schedule_data, peer_cpu).schedule_lock); +spin_unlock (per_cpu (schedule_data, peer_cpu).schedule_lock);if ( speer !=NULL )return speer; }
xen/common/schedule.c +10 -8
@@ -108,7 +108,7 @@s_time_t delta;ASSERT (v->runstate.state != new_state); -ASSERT (spin_is_locked (&per_cpu (schedule_data,v->processor).schedule_lock)); +ASSERT (spin_is_locked (per_cpu (schedule_data,v->processor).schedule_lock));trace_runstate_change (v, new_state);
@@ -299,7 +299,7 @@ old_cpu = v->processor; v->processor =SCHED_OP (pick_cpu, v);spin_unlock_irqrestore ( - &per_cpu (schedule_data, old_cpu).schedule_lock, flags); +per_cpu (schedule_data, old_cpu).schedule_lock, flags);/* Wake on new CPU. */ vcpu_wake (v);
@@ -806,7 +806,7 @@ sd = &this_cpu (schedule_data); -spin_lock_irq (&sd->schedule_lock); +spin_lock_irq (sd->schedule_lock);stop_timer (&sd->s_timer);
@@ -822,7 +822,7 @@if (unlikely (prev == next) ) { -spin_unlock_irq (&sd->schedule_lock); +spin_unlock_irq (sd->schedule_lock);trace_continue_running (next);return continue_running (prev); }
@@ -850,7 +850,7 @@ASSERT (!next->is_running); next->is_running =1 ; -spin_unlock_irq (&sd->schedule_lock); +spin_unlock_irq (sd->schedule_lock);perfc_incr (sched_ctx);
@@ -922,7 +922,9 @@for_each_possible_cpu ( i ) { -spin_lock_init (&per_cpu (schedule_data, i).schedule_lock); +spin_lock_init (&per_cpu (schedule_data, i)._lock); +per_cpu (schedule_data, i).schedule_lock + = &per_cpu (schedule_data, i)._lock;init_timer (&per_cpu (schedule_data, i).s_timer, s_timer_fn,NULL , i); }
@@ -956,10 +958,10 @@for_each_online_cpu ( i ) { -spin_lock (&per_cpu (schedule_data, i).schedule_lock); +spin_lock (per_cpu (schedule_data, i).schedule_lock);printk ("CPU[%02d] " , i);SCHED_OP (dump_cpu_state, i); -spin_unlock (&per_cpu (schedule_data, i).schedule_lock); +spin_unlock (per_cpu (schedule_data, i).schedule_lock); }local_irq_restore (flags);
xen/include/xen/sched-if.h +47 -4
73 lines not on this page · raw message
xen/include/public/trace.h +1 -0
@@ -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/common/Makefile +1 -0
@@ -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 +1121 -0
1,121 lines not on this page · raw message
xen/common/schedule.c +2 -0
@@ -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
@@ -303,6 +303,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
@@ -321,6 +322,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 ;
tools/libxc/Makefile +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Keir, any thoughts? Does this seem like a reasonable approach?
Thanks,
-George
Quoted 41 lines · George Dunlap
The two attached patches change the scheduler interface to allow credit2 to have several cpus share the same runqueue. The patches should have almost no impact on the current schedulers. The patches and their reasonings are below. I've also attached the patches for the prototype credit2 scheduler, for reference.
* Add a context swich callback (sched-context_switch-callback.diff)
Add a callback to tell a scheduler that a vcpu has been completely context-switched off a cpu.
When sharing a runqueue, we can't put a scheduled-out vcpu back on the runqueue until it's been completely de-scheduled, because it may be grabbed by another processor before it's ready. This callback allows a scheduler to detect when a vcpu on its way out is completely off the processor, so that it can put the vcpu on the runqueue.
* Allow sharing of locks between cpus (sched-spin_lock-pointers.diff)
Have per-cpu pointers, initialized to per-cpu locks, which the scheduler may change during its init to reconfigure locking granularity.
There are a number of race conditions having to do with updating of
v->is_runningandv->processor, all having to do with the fact that vcpus may change cpus without an explicit migrate. Furthermore, the scheduler needs runqueues to be covered by a lock as well. The cleanest way to solve all of these is to have the scheduler lock and the runqueue lock coincide.* Add a "scheduler" trace class (trace-sched-class.diff) Uses defined on a per-scheduler basis
I've been running parallel kernel compiles on a 16-way box (2x4x2) for several hours now without deadlocks or BUG()s. As far as I'm concerned, with these changes, credit2 is now ready to be checked in, as long as it's not set to the default scheduler.
All of the above:
Signed-off-by George Dunlap <[email protected]>
They're all fine, even probably sched-context_switch-callback.diff, which I suppose is your new alternative to having vcpus-which-arent-yet-schedulable left on the shared runqueue? I suppose, although I reckon it could still be done another way and using the vcpu_migrate logic, that this is a smaller and neater way to do it really.
All this are apply-able after 4.0.
-- Keir
Quoted 48 lines · George Dunlap
Keir, any thoughts? Does this seem like a reasonable approach?
Thanks,
-GeorgeQuoted 41 lines · George Dunlap
The two attached patches change the scheduler interface to allow credit2 to have several cpus share the same runqueue. The patches should have almost no impact on the current schedulers. The patches and their reasonings are below. I've also attached the patches for the prototype credit2 scheduler, for reference.
* Add a context swich callback (sched-context_switch-callback.diff)
Add a callback to tell a scheduler that a vcpu has been completely context-switched off a cpu.
When sharing a runqueue, we can't put a scheduled-out vcpu back on the runqueue until it's been completely de-scheduled, because it may be grabbed by another processor before it's ready. This callback allows a scheduler to detect when a vcpu on its way out is completely off the processor, so that it can put the vcpu on the runqueue.
* Allow sharing of locks between cpus (sched-spin_lock-pointers.diff)
Have per-cpu pointers, initialized to per-cpu locks, which the scheduler may change during its init to reconfigure locking granularity.
There are a number of race conditions having to do with updating of
v->is_runningandv->processor, all having to do with the fact that vcpus may change cpus without an explicit migrate. Furthermore, the scheduler needs runqueues to be covered by a lock as well. The cleanest way to solve all of these is to have the scheduler lock and the runqueue lock coincide.* Add a "scheduler" trace class (trace-sched-class.diff) Uses defined on a per-scheduler basis
I've been running parallel kernel compiles on a 16-way box (2x4x2) for several hours now without deadlocks or BUG()s. As far as I'm concerned, with these changes, credit2 is now ready to be checked in, as long as it's not set to the default scheduler.
All of the above:
Signed-off-by George Dunlap <[email protected]>
Quoted 6 lines · Keir Fraser
They're all fine, even probably sched-context_switch-callback.diff, which I suppose is your new alternative to having vcpus-which-arent-yet-schedulable left on the shared runqueue? I suppose, although I reckon it could still be done another way and using the
vcpu_migratelogic, that this is a smaller and neater way to do it really.
Exactly. The migrate logic calls cpu_pick, which is also called from other contexts. Having the same function try to do both, and setting the "migrating" flag when the vcpu isn't migrating, just seems hackish and likely to be confusing to me. It does add another "Check to see if this function exists" on the hot path for the other schedulers.
I suppose we could think about changing things around, so that there's a generic "callback on context switch" flag. Then we'd only have one callback in the context switch code, and the check would only happen if the flag was set (reducing cache footprint). It would be a slightly larger patch, and make changes to the other schedulers, but those would be pretty minimal.
I'll play around with it and see how it looks.
-George
Quoted 60 lines
All this are apply-able after 4.0.
-- Keir
Quoted 50 lines · George Dunlap
Keir, any thoughts? Does this seem like a reasonable approach?
Thanks,
-GeorgeQuoted 42 lines · George Dunlap
The two attached patches change the scheduler interface to allow credit2 to have several cpus share the same runqueue. The patches should have almost no impact on the current schedulers. The patches and their reasonings are below. I've also attached the patches for the prototype credit2 scheduler, for reference.
* Add a context swich callback (sched-context_switch-callback.diff)
Add a callback to tell a scheduler that a vcpu has been completely context-switched off a cpu.
When sharing a runqueue, we can't put a scheduled-out vcpu back on the runqueue until it's been completely de-scheduled, because it may be grabbed by another processor before it's ready. This callback allows a scheduler to detect when a vcpu on its way out is completely off the processor, so that it can put the vcpu on the runqueue.
* Allow sharing of locks between cpus (sched-spin_lock-pointers.diff)
Have per-cpu pointers, initialized to per-cpu locks, which the scheduler may change during its init to reconfigure locking granularity.
There are a number of race conditions having to do with updating of
v->is_runningandv->processor, all having to do with the fact that vcpus may change cpus without an explicit migrate. Furthermore, the scheduler needs runqueues to be covered by a lock as well. The cleanest way to solve all of these is to have the scheduler lock and the runqueue lock coincide.* Add a "scheduler" trace class (trace-sched-class.diff) Uses defined on a per-scheduler basis
I've been running parallel kernel compiles on a 16-way box (2x4x2) for several hours now without deadlocks or BUG()s. As far as I'm concerned, with these changes, credit2 is now ready to be checked in, as long as it's not set to the default scheduler.
All of the above:
Signed-off-by George Dunlap <[email protected]>
Quoted 8 lines · George Dunlap
I suppose we could think about changing things around, so that there's a generic "callback on context switch" flag. Then we'd only have one callback in the context switch code, and the check would only happen if the flag was set (reducing cache footprint). It would be a slightly larger patch, and make changes to the other schedulers, but those would be pretty minimal.
I'll play around with it and see how it looks.
Nah, I think we'll just go with it as it is. It's clean and the path isn't *that* hot.
-- Keir