From: George Dunlap Subject: Re: [PATCH] credit2: add a callback to migrate to a new cpu Date: Thu, 28 Apr 2011 11:08:40 +0100 Message-ID: References: <83859d845ef5d35309b7.1303837548@elijah> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <83859d845ef5d35309b7.1303837548@elijah> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: george.dunlap@eu.citrix.com, Keir Fraser List-Id: xen-devel@lists.xenproject.org This bug is present in 4.1 as well; this patch will apply and build cleanly if c/s 22982:591c459ee00a is included as well. -George On Tue, Apr 26, 2011 at 6:05 PM, George Dunlap wrote: > In credit2, there needs to be a strong correlation between > v->processor and the runqueue to which a vcpu is assigned; > much of the code relies on this invariant. =A0Allow credit2 > to manage the actual migration itself. > > This fixes the most recent credit2 bug reported on the list > (Xen BUG at sched_credit2.c:1606) in Xen 4.1, as well as > the bug at sched_credit2.c:811 in -unstable (which catches the > same condition earlier). > > Signed-off-by: George Dunlap > > diff -r 80401982465d -r 83859d845ef5 xen/common/sched_credit2.c > --- a/xen/common/sched_credit2.c =A0 =A0 =A0 =A0Mon Apr 25 13:17:05 2011 = +0100 > +++ b/xen/common/sched_credit2.c =A0 =A0 =A0 =A0Tue Apr 26 18:03:32 2011 = +0100 > @@ -1352,32 +1352,28 @@ > =A0static int > =A0csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc) > =A0{ > - =A0 =A0struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); > =A0 =A0 int new_cpu; > > - =A0 =A0/* The scheduler interface doesn't have an explicit mechanism to > - =A0 =A0 * involve the choosable scheduler in the migrate process, so we > - =A0 =A0 * infer that a change may happen by the call to cpu_pick, and > - =A0 =A0 * remove it from the old runqueue while the lock for the old > - =A0 =A0 * runqueue is held. =A0It can't be actively waiting to run. =A0= It > - =A0 =A0 * will be added to the new runqueue when it next wakes. > - =A0 =A0 * > - =A0 =A0 * If we want to be able to call pick() separately, we need to a= dd > - =A0 =A0 * a mechansim to remove a vcpu from an old processor / runqueue > - =A0 =A0 * before releasing the lock. */ > - =A0 =A0BUG_ON(__vcpu_on_runq(svc)); > - > =A0 =A0 new_cpu =3D choose_cpu(ops, vc); > - =A0 =A0/* If we're suggesting moving to a different runqueue, remove it > - =A0 =A0 * from the old runqueue while we have the lock. =A0It will be a= dded > - =A0 =A0 * to the new one when it wakes. */ > - =A0 =A0if ( svc->rqd !=3D NULL > - =A0 =A0 =A0 =A0 && RQD(ops, new_cpu) !=3D svc->rqd ) > - =A0 =A0 =A0 =A0runq_deassign(ops, vc); > > =A0 =A0 return new_cpu; > =A0} > > +static void > +csched_vcpu_migrate(const struct scheduler *ops, struct vcpu *vc, int ne= w_cpu) > +{ > + =A0 =A0struct csched_vcpu * const svc =3D CSCHED_VCPU(vc); > + =A0 =A0struct csched_runqueue_data *trqd; > + > + =A0 =A0/* Check if new_cpu is valid */ > + =A0 =A0BUG_ON(!cpu_isset(new_cpu, CSCHED_PRIV(ops)->initialized)); > + > + =A0 =A0trqd =3D RQD(ops, new_cpu); > + > + =A0 =A0if ( trqd !=3D svc->rqd ) > + =A0 =A0 =A0 =A0migrate(ops, svc, trqd, NOW()); > +} > + > =A0static int > =A0csched_dom_cntl( > =A0 =A0 const struct scheduler *ops, > @@ -2121,6 +2117,7 @@ > =A0 =A0 .adjust =A0 =A0 =A0 =A0 =3D csched_dom_cntl, > > =A0 =A0 .pick_cpu =A0 =A0 =A0 =3D csched_cpu_pick, > + =A0 =A0.migrate =A0 =A0 =A0 =A0=3D csched_vcpu_migrate, > =A0 =A0 .do_schedule =A0 =A0=3D csched_schedule, > =A0 =A0 .context_saved =A0=3D csched_context_saved, > > diff -r 80401982465d -r 83859d845ef5 xen/common/schedule.c > --- a/xen/common/schedule.c =A0 =A0 Mon Apr 25 13:17:05 2011 +0100 > +++ b/xen/common/schedule.c =A0 =A0 Tue Apr 26 18:03:32 2011 +0100 > @@ -489,7 +489,11 @@ > =A0 =A0 =A0* Switch to new CPU, then unlock new and old CPU. =A0This is s= afe because > =A0 =A0 =A0* the lock pointer cant' change while the current lock is held= . > =A0 =A0 =A0*/ > - =A0 =A0v->processor =3D new_cpu; > + =A0 =A0if ( VCPU2OP(v)->migrate ) > + =A0 =A0 =A0 =A0SCHED_OP(VCPU2OP(v), migrate, v, new_cpu); > + =A0 =A0else > + =A0 =A0 =A0 =A0v->processor =3D new_cpu; > + > > =A0 =A0 if ( old_lock !=3D new_lock ) > =A0 =A0 =A0 =A0 spin_unlock(new_lock); > diff -r 80401982465d -r 83859d845ef5 xen/include/xen/sched-if.h > --- a/xen/include/xen/sched-if.h =A0 =A0 =A0 =A0Mon Apr 25 13:17:05 2011 = +0100 > +++ b/xen/include/xen/sched-if.h =A0 =A0 =A0 =A0Tue Apr 26 18:03:32 2011 = +0100 > @@ -170,6 +170,7 @@ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 bool_t tasklet_work_scheduled); > > =A0 =A0 int =A0 =A0 =A0 =A0 =A0(*pick_cpu) =A0 =A0 =A0 (const struct sche= duler *, struct vcpu *); > + =A0 =A0void =A0 =A0 =A0 =A0 (*migrate) =A0 =A0 =A0 =A0(const struct sch= eduler *, struct vcpu *, int); > =A0 =A0 int =A0 =A0 =A0 =A0 =A0(*adjust) =A0 =A0 =A0 =A0 (const struct sc= heduler *, struct domain *, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s= truct xen_domctl_scheduler_op *); > =A0 =A0 int =A0 =A0 =A0 =A0 =A0(*adjust_global) =A0(const struct schedule= r *, > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >