From: George Dunlap Subject: [PATCH 2/2] credit2: track residual from divisions done during accounting Date: Tue, 26 Feb 2013 17:08:17 +0000 Message-ID: <1361898497-5719-2-git-send-email-george.dunlap@eu.citrix.com> References: <1361898497-5719-1-git-send-email-george.dunlap@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1361898497-5719-1-git-send-email-george.dunlap@eu.citrix.com> 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@lists.xen.org Cc: George Dunlap List-Id: xen-devel@lists.xenproject.org This should help with under-accounting of vCPU-s running for extremly short periods of time, but becoming runnable again at a high frequency. Original-patch-by: Jan Beulich Signed-off-by: George Dunlap --- xen/common/sched_credit2.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 804049e..189b56a 100644 --- 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 { 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; 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; - int weight; + unsigned int weight; + unsigned int residual; int credit; s_time_t start_time; /* When we were scheduled (used for credit) */ @@ -271,16 +272,24 @@ struct csched_dom { /* * Time-to-credit, credit-to-time. + * + * We keep track of the "residual" time to make sure that frequent short + * schedules still get accounted for in the end. + * * FIXME: Do pre-calculated division? */ -static s_time_t t2c(struct csched_runqueue_data *rqd, s_time_t time, struct csched_vcpu *svc) +static void t2c_update(struct csched_runqueue_data *rqd, s_time_t time, + struct csched_vcpu *svc) { - return time * rqd->max_weight / svc->weight; + uint64_t val = time * rqd->max_weight + svc->residual; + + svc->residual = do_div(val, svc->weight); + svc->credit -= val; } 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) / rqd->max_weight; } /* @@ -636,8 +645,7 @@ void burn_credits(struct csched_runqueue_data *rqd, struct csched_vcpu *svc, s_t delta = now - svc->start_time; if ( delta > 0 ) { - /* This will round down; should we consider rounding up...? */ - svc->credit -= t2c(rqd, delta, svc); + t2c_update(rqd, delta, svc); svc->start_time = now; d2printk("b d%dv%d c%d\n", -- 1.7.9.5