Thomas Pfeuffer
2010-Jul-29 13:21 UTC
[Xen-devel] Question on Credit accounting in Credit Scheduler
Hello, I have looked through the source code of Credit Scheduler. In csched_acct(), the number of credits a domain gets (i.e credit_fair), is calculated as follows: credit_fair = ( ( credit_total * sdom->weight) + ( weight_total -1) ) / weigth_total But I would expect, that the Credits are calculated by credit_fair = (credit_total * sdom->weight) / weigth_total Does anybody know, what function the term (weight_total -1) has? Later, the credits a vcpu gets is calculated by credit_fair = ( credit_fair + (sdom->active_vcpu_count -1) ) / sdom->active_vcpu_count -1 Again, I would expect that the credits are calculated by credit_fair = credit_fair / sdom->active_vcpu_count I do not understand why the term (sdom->active_vcpu_count -1 ) is neccessary. Best regards, Thomas Pfeuffer _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2010-Jul-29 13:35 UTC
Re: [Xen-devel] Question on Credit accounting in Credit Scheduler
At 14:21 +0100 on 29 Jul (1280413287), Thomas Pfeuffer wrote:> Hello, > > I have looked through the source code of Credit Scheduler. > > In csched_acct(), the number of credits a domain gets (i.e credit_fair), > is calculated as follows: > > credit_fair = ( ( credit_total * sdom->weight) + ( weight_total -1) > ) / weigth_total > > But I would expect, that the Credits are calculated by > > credit_fair = (credit_total * sdom->weight) / weigth_total > > Does anybody know, what function the term (weight_total -1) has?It makes the integer division round up instead of rounding down. Tim. -- Tim Deegan <Tim.Deegan@citrix.com> Principal Software Engineer, XenServer Engineering Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Heiko Wundram
2010-Jul-29 13:40 UTC
AW: [Xen-devel] Question on Credit accounting in Credit Scheduler
> -----Ursprüngliche Nachricht----- > Von: xen-devel-bounces@lists.xensource.com [mailto:xen-devel- > bounces@lists.xensource.com] Im Auftrag von Thomas Pfeuffer > Gesendet: Donnerstag, 29. Juli 2010 15:21 > An: xen-devel@lists.xensource.com > Betreff: [Xen-devel] Question on Credit accounting in Credit Scheduler > > I have looked through the source code of Credit Scheduler. > > In csched_acct(), the number of credits a domain gets (i.e > credit_fair), > is calculated as follows: > > credit_fair = ( ( credit_total * sdom->weight) + ( weight_total - > 1) > ) / weigth_total > > But I would expect, that the Credits are calculated by > > credit_fair = (credit_total * sdom->weight) / weigth_total > > Does anybody know, what function the term (weight_total -1) has?Without knowing details of the Xen scheduling algorithm (i.e., I''m guessing that the above is integer-only math), all it does is "round up" the (fair) credits a domain gets [(x+y-1)/y means division with always rounding up, think of the "Gaußklammer", don''t know the german name, in reverse]; basically, if the above calculation is done for all domains, the respective sum of all calculated credit_fair will always be equal to or higher than credit_total, which wouldn''t be the case (because of truncation when just doing x/y) when using your function, i.e. the sum of all credit_fair might be less than credit_total. For a scheduling algorithm, you''ll want to always give away _at least_ all available credits, and this is a simple enough method to do just that without resorting to floating point calculations. --- Heiko. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
George Dunlap
2010-Jul-29 13:42 UTC
Re: [Xen-devel] Question on Credit accounting in Credit Scheduler
I''d thought of writing a div_round_up() macro that would make this a bit more clear, something like: /* Divide x by y, rounding up */ #div_round_up(x, y) (((x)+((y)-1))/(y)) -George On Thu, Jul 29, 2010 at 2:35 PM, Tim Deegan <Tim.Deegan@citrix.com> wrote:> At 14:21 +0100 on 29 Jul (1280413287), Thomas Pfeuffer wrote: >> Hello, >> >> I have looked through the source code of Credit Scheduler. >> >> In csched_acct(), the number of credits a domain gets (i.e credit_fair), >> is calculated as follows: >> >> credit_fair = ( ( credit_total * sdom->weight) + ( weight_total -1) >> ) / weigth_total >> >> But I would expect, that the Credits are calculated by >> >> credit_fair = (credit_total * sdom->weight) / weigth_total >> >> Does anybody know, what function the term (weight_total -1) has? > > It makes the integer division round up instead of rounding down. > > Tim. > > -- > Tim Deegan <Tim.Deegan@citrix.com> > Principal Software Engineer, XenServer Engineering > Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Thomas Pfeuffer
2010-Jul-30 06:25 UTC
Re: AW: [Xen-devel] Question on Credit accounting in Credit Scheduler
Hello, thanks for your answer. Best regards, Thomas Heiko Wundram wrote:>>-----Ursprüngliche Nachricht----- >>Von: xen-devel-bounces@lists.xensource.com [mailto:xen-devel- >>bounces@lists.xensource.com] Im Auftrag von Thomas Pfeuffer >>Gesendet: Donnerstag, 29. Juli 2010 15:21 >>An: xen-devel@lists.xensource.com >>Betreff: [Xen-devel] Question on Credit accounting in Credit Scheduler >> >>I have looked through the source code of Credit Scheduler. >> >>In csched_acct(), the number of credits a domain gets (i.e >>credit_fair), >>is calculated as follows: >> >> credit_fair = ( ( credit_total * sdom->weight) + ( weight_total - >>1) >> ) / weigth_total >> >>But I would expect, that the Credits are calculated by >> >> credit_fair = (credit_total * sdom->weight) / weigth_total >> >>Does anybody know, what function the term (weight_total -1) has? >> >> > >Without knowing details of the Xen scheduling algorithm (i.e., I''m guessing >that the above is integer-only math), all it does is "round up" the (fair) >credits a domain gets [(x+y-1)/y means division with always rounding up, >think of the "Gaußklammer", don''t know the german name, in reverse]; >basically, if the above calculation is done for all domains, the respective >sum of all calculated credit_fair will always be equal to or higher than >credit_total, which wouldn''t be the case (because of truncation when just >doing x/y) when using your function, i.e. the sum of all credit_fair might >be less than credit_total. > >For a scheduling algorithm, you''ll want to always give away _at least_ all >available credits, and this is a simple enough method to do just that >without resorting to floating point calculations. > >--- Heiko. > > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel