diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 9bc638c09c..67628a1f95 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -867,6 +867,17 @@ _csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc, bool_t commit) return cpu; } +static void +csched_vcpu_migrate(const struct scheduler *ops, struct vcpu *vc, + unsigned int new_cpu) +{ + BUG_ON(vc->is_running); + BUG_ON(test_bit(_VPF_migrating, &vc->pause_flags)); + BUG_ON(CSCHED_VCPU(vc) == CSCHED_VCPU(curr_on_cpu(vc->processor))); + BUG_ON(__vcpu_on_runq(CSCHED_VCPU(vc))); + vc->processor = new_cpu; +} + static int csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc) { @@ -2278,6 +2289,7 @@ static const struct scheduler sched_credit_def = { .adjust_global = csched_sys_cntl, .pick_cpu = csched_cpu_pick, + .migrate = csched_vcpu_migrate, .do_schedule = csched_schedule, .dump_cpu_state = csched_dump_pcpu, diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 343ab6306e..7be62efa33 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1554,7 +1554,29 @@ void context_saved(struct vcpu *prev) SCHED_OP(vcpu_scheduler(prev), context_saved, prev); if ( unlikely(prev->pause_flags & VPF_migrating) ) + { + /* + * If someone (e.g., vcpu_set_affinity()) has set VPF_migrating + * on prev in between when schedule() releases the scheduler + * lock and here, we need to make sure we properly mark the + * vcpu as not runnable (and all it comes with that), with + * vcpu_sleep_nosync(), before calling vcpu_migrate(). + */ + //vcpu_sleep_nosync(prev); + unsigned long flags; + spinlock_t *lock = vcpu_schedule_lock_irqsave(prev, &flags); + + BUG_ON(vcpu_runnable(prev)); + BUG_ON(!test_bit(_VPF_migrating, &prev->pause_flags)); + if ( prev->runstate.state == RUNSTATE_runnable ) + vcpu_runstate_change(prev, RUNSTATE_offline, NOW()); + BUG_ON(curr_on_cpu(prev->processor) == prev); + SCHED_OP(vcpu_scheduler(prev), sleep, prev); + + vcpu_schedule_unlock_irqrestore(lock, flags, prev); + vcpu_migrate(prev); + } } /* The scheduler timer: force a run through the scheduler */