From: "Jan Beulich" Subject: [PATCH v2] credit1: track residual from divisions done during accounting Date: Tue, 26 Feb 2013 15:44:24 +0000 Message-ID: <512CE66802000078000C1237@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part85B5F548.0__=" 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 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. --=__Part85B5F548.0__= 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 Acked-by: George Dunlap --- v2: Comment ASSERT() and drop credit2 portion upon George's request. --- 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); /* make sure we haven't truncated val */ atomic_sub(credits, &svc->credit); svc->start_time +=3D (credits * MILLISECS(1)) / CSCHED_CREDITS_PER_MSE= C; } --=__Part85B5F548.0__= Content-Type: text/plain; name="sched-credit1-residual.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sched-credit1-residual.patch" credit1: 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 =0AAcked-by: George Dunlap = =0A---=0Av2: Comment ASSERT() and drop = credit2 portion upon George's request.=0A=0A--- a/xen/common/sched_credit.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); /* make sure we haven't truncated val */=0A = atomic_sub(credits, &svc->credit);=0A svc->start_time +=3D (credits * = MILLISECS(1)) / CSCHED_CREDITS_PER_MSEC;=0A }=0A --=__Part85B5F548.0__= 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 --=__Part85B5F548.0__=--