From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCH] credit: track residual from divisions done during accounting Date: Mon, 25 Feb 2013 11:12:36 +0000 Message-ID: <512B4724.5000603@citrix.com> References: <51222E8302000078000BF1F3@nat28.tlf.novell.com> <1361554003.16232.33.camel@Solace> <512B3CF702000078000C0AC6@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <512B3CF702000078000C0AC6@nat28.tlf.novell.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: Jan Beulich Cc: George Dunlap , Dario Faggioli , xen-devel List-Id: xen-devel@lists.xenproject.org On 25/02/13 09:29, Jan Beulich wrote: >>>> On 22.02.13 at 18:26, Dario Faggioli wrote: >> On Mon, 2013-02-18 at 12:37 +0000, Jan Beulich wrote: >>> --- a/xen/common/sched_credit.c >>> +++ b/xen/common/sched_credit.c >>> >>> @@ -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; >>> >>> /* Assert svc is current */ >>> @@ -250,7 +253,10 @@ static void burn_credits(struct csched_v >>> if ( (delta = now - svc->start_time) <= 0 ) >>> return; >>> >>> - credits = (delta*CSCHED_CREDITS_PER_MSEC + MILLISECS(1)/2) / MILLISECS(1); >>> + val = delta * CSCHED_CREDITS_PER_MSEC + svc->residual; >>> + svc->residual = do_div(val, MILLISECS(1)); >>> + credits = val; >>> + ASSERT(credits == val); >> >> I may be missing something, but how can the assert ever be false, given >> the assignment right before it? > > val being wider than credit, this checks that there was no truncation. ASSERT(val <= UINT_MAX); Would be clearer. David