From: "Jan Beulich" Subject: [PATCH] credit: track residual from divisions done during accounting Date: Mon, 18 Feb 2013 12:37:07 +0000 Message-ID: <51222E8302000078000BF1F3@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part58682663.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: George Dunlap List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part58682663.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This should help with under-accounting of vCPU-s running for extremly short periods of time, but becoming runnable again at a high frequency. Signed-off-by: Jan Beulich --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -136,6 +137,7 @@ struct csched_vcpu { struct csched_dom *sdom; struct vcpu *vcpu; atomic_t credit; + unsigned int residual; s_time_t start_time; /* When we were scheduled (used for credit) */ uint16_t flags; int16_t pri; @@ -242,6 +244,7 @@ __runq_remove(struct csched_vcpu *svc) static void burn_credits(struct csched_vcpu *svc, s_time_t now) { s_time_t delta; + uint64_t val; unsigned int credits; =20 /* Assert svc is current */ @@ -250,7 +253,10 @@ static void burn_credits(struct csched_v if ( (delta =3D now - svc->start_time) <=3D 0 ) return; =20 - credits =3D (delta*CSCHED_CREDITS_PER_MSEC + MILLISECS(1)/2) / = MILLISECS(1); + val =3D delta * CSCHED_CREDITS_PER_MSEC + svc->residual; + svc->residual =3D do_div(val, MILLISECS(1)); + credits =3D val; + ASSERT(credits =3D=3D val); atomic_sub(credits, &svc->credit); svc->start_time +=3D (credits * MILLISECS(1)) / CSCHED_CREDITS_PER_MSE= C; } --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -205,7 +205,7 @@ struct csched_runqueue_data { =20 struct list_head runq; /* Ordered list of runnable vms */ struct list_head svc; /* List of all vcpus assigned to this runqueue = */ - int max_weight; + unsigned int max_weight; =20 cpumask_t idle, /* Currently idle */ tickled; /* Another cpu in the queue is already = targeted for this one */ @@ -244,7 +244,8 @@ struct csched_vcpu { struct csched_dom *sdom; struct vcpu *vcpu; =20 - int weight; + unsigned int weight; + unsigned int residual; =20 int credit; s_time_t start_time; /* When we were scheduled (used for credit) */ @@ -275,12 +276,15 @@ struct csched_dom { */ static s_time_t t2c(struct csched_runqueue_data *rqd, s_time_t time, = struct csched_vcpu *svc) { - return time * rqd->max_weight / svc->weight; + uint64_t val =3D time * rqd->max_weight + svc->residual; + + svc->residual =3D do_div(val, svc->weight); + return val; } =20 static s_time_t c2t(struct csched_runqueue_data *rqd, s_time_t credit, = struct csched_vcpu *svc) { - return credit * svc->weight / rqd->max_weight; + return (credit * svc->weight - svc->residual) / rqd->max_weight; } =20 /* --=__Part58682663.1__= Content-Type: text/plain; name="sched-credit-residual.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sched-credit-residual.patch" credit: track residual from divisions done during accounting=0A=0AThis = should help with under-accounting of vCPU-s running for extremly=0Ashort = periods of time, but becoming runnable again at a high frequency.=0A=0ASign= ed-off-by: Jan Beulich =0A=0A--- a/xen/common/sched_cred= it.c=0A+++ b/xen/common/sched_credit.c=0A@@ -19,6 +19,7 @@=0A #include = =0A #include =0A #include =0A+= #include =0A #include =0A #include =0A #include =0A@@ -136,6 +137,7 @@ struct csched_vcpu = {=0A struct csched_dom *sdom;=0A struct vcpu *vcpu;=0A = atomic_t credit;=0A+ unsigned int residual;=0A s_time_t start_time; = /* When we were scheduled (used for credit) */=0A uint16_t flags;=0A = int16_t pri;=0A@@ -242,6 +244,7 @@ __runq_remove(struct csched_vcpu = *svc)=0A static void burn_credits(struct csched_vcpu *svc, s_time_t = now)=0A {=0A s_time_t delta;=0A+ uint64_t val;=0A unsigned int = credits;=0A =0A /* Assert svc is current */=0A@@ -250,7 +253,10 @@ = static void burn_credits(struct csched_v=0A if ( (delta =3D now - = svc->start_time) <=3D 0 )=0A return;=0A =0A- credits =3D = (delta*CSCHED_CREDITS_PER_MSEC + MILLISECS(1)/2) / MILLISECS(1);=0A+ = val =3D delta * CSCHED_CREDITS_PER_MSEC + svc->residual;=0A+ svc->residu= al =3D do_div(val, MILLISECS(1));=0A+ credits =3D val;=0A+ ASSERT(cre= dits =3D=3D val);=0A atomic_sub(credits, &svc->credit);=0A = svc->start_time +=3D (credits * MILLISECS(1)) / CSCHED_CREDITS_PER_MSEC;=0A= }=0A--- a/xen/common/sched_credit2.c=0A+++ b/xen/common/sched_credit2.c=0A= @@ -21,7 +21,7 @@=0A #include =0A #include =0A= #include =0A-#include =0A+#include =0A #include =0A #include =0A #include = =0A@@ -205,7 +205,7 @@ struct csched_runqueue_data {=0A =0A = struct list_head runq; /* Ordered list of runnable vms */=0A struct = list_head svc; /* List of all vcpus assigned to this runqueue */=0A- = int max_weight;=0A+ unsigned int max_weight;=0A =0A cpumask_t idle, = /* Currently idle */=0A tickled; /* Another cpu = in the queue is already targeted for this one */=0A@@ -244,7 +244,8 @@ = struct csched_vcpu {=0A struct csched_dom *sdom;=0A struct vcpu = *vcpu;=0A =0A- int weight;=0A+ unsigned int weight;=0A+ unsigned = int residual;=0A =0A int credit;=0A s_time_t start_time; /* When = we were scheduled (used for credit) */=0A@@ -275,12 +276,15 @@ struct = csched_dom {=0A */=0A static s_time_t t2c(struct csched_runqueue_data = *rqd, s_time_t time, struct csched_vcpu *svc)=0A {=0A- return time * = rqd->max_weight / svc->weight;=0A+ uint64_t val =3D time * rqd->max_weig= ht + svc->residual;=0A+=0A+ svc->residual =3D do_div(val, svc->weight);= =0A+ return val;=0A }=0A =0A static s_time_t c2t(struct csched_runqueue_= data *rqd, s_time_t credit, struct csched_vcpu *svc)=0A {=0A- return = credit * svc->weight / rqd->max_weight;=0A+ return (credit * svc->weight= - svc->residual) / rqd->max_weight;=0A }=0A =0A /*=0A --=__Part58682663.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part58682663.1__=--