* [PATCH] credit: track residual from divisions done during accounting
@ 2013-02-18 12:37 Jan Beulich
2013-02-22 17:26 ` Dario Faggioli
2013-02-26 15:00 ` George Dunlap
0 siblings, 2 replies; 18+ messages in thread
From: Jan Beulich @ 2013-02-18 12:37 UTC (permalink / raw)
To: xen-devel; +Cc: George Dunlap
[-- Attachment #1: Type: text/plain, Size: 3007 bytes --]
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 <jbeulich@suse.com>
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -19,6 +19,7 @@
#include <xen/sched-if.h>
#include <xen/softirq.h>
#include <asm/atomic.h>
+#include <asm/div64.h>
#include <xen/errno.h>
#include <xen/keyhandler.h>
#include <xen/trace.h>
@@ -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;
/* 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);
atomic_sub(credits, &svc->credit);
svc->start_time += (credits * MILLISECS(1)) / CSCHED_CREDITS_PER_MSEC;
}
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -21,7 +21,7 @@
#include <xen/perfc.h>
#include <xen/sched-if.h>
#include <xen/softirq.h>
-#include <asm/atomic.h>
+#include <asm/div64.h>
#include <xen/errno.h>
#include <xen/trace.h>
#include <xen/cpu.h>
@@ -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) */
@@ -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 = time * rqd->max_weight + svc->residual;
+
+ svc->residual = do_div(val, svc->weight);
+ return 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 - svc->residual) / rqd->max_weight;
}
/*
[-- Attachment #2: sched-credit-residual.patch --]
[-- Type: text/plain, Size: 3065 bytes --]
credit: track residual from divisions done during accounting
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 <jbeulich@suse.com>
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -19,6 +19,7 @@
#include <xen/sched-if.h>
#include <xen/softirq.h>
#include <asm/atomic.h>
+#include <asm/div64.h>
#include <xen/errno.h>
#include <xen/keyhandler.h>
#include <xen/trace.h>
@@ -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;
/* 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);
atomic_sub(credits, &svc->credit);
svc->start_time += (credits * MILLISECS(1)) / CSCHED_CREDITS_PER_MSEC;
}
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -21,7 +21,7 @@
#include <xen/perfc.h>
#include <xen/sched-if.h>
#include <xen/softirq.h>
-#include <asm/atomic.h>
+#include <asm/div64.h>
#include <xen/errno.h>
#include <xen/trace.h>
#include <xen/cpu.h>
@@ -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) */
@@ -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 = time * rqd->max_weight + svc->residual;
+
+ svc->residual = do_div(val, svc->weight);
+ return 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 - svc->residual) / rqd->max_weight;
}
/*
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-18 12:37 [PATCH] credit: track residual from divisions done during accounting Jan Beulich
@ 2013-02-22 17:26 ` Dario Faggioli
2013-02-25 9:29 ` Jan Beulich
2013-02-26 15:00 ` George Dunlap
1 sibling, 1 reply; 18+ messages in thread
From: Dario Faggioli @ 2013-02-22 17:26 UTC (permalink / raw)
To: Jan Beulich; +Cc: George Dunlap, xen-devel
[-- Attachment #1.1: Type: text/plain, Size: 1166 bytes --]
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?
Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-22 17:26 ` Dario Faggioli
@ 2013-02-25 9:29 ` Jan Beulich
2013-02-25 10:45 ` Dario Faggioli
2013-02-25 11:12 ` David Vrabel
0 siblings, 2 replies; 18+ messages in thread
From: Jan Beulich @ 2013-02-25 9:29 UTC (permalink / raw)
To: Dario Faggioli; +Cc: George Dunlap, xen-devel
>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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.
Jan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-25 9:29 ` Jan Beulich
@ 2013-02-25 10:45 ` Dario Faggioli
2013-02-25 11:12 ` David Vrabel
1 sibling, 0 replies; 18+ messages in thread
From: Dario Faggioli @ 2013-02-25 10:45 UTC (permalink / raw)
To: Jan Beulich; +Cc: George Dunlap, xen-devel
[-- Attachment #1.1: Type: text/plain, Size: 1650 bytes --]
On Mon, 2013-02-25 at 09:29 +0000, Jan Beulich wrote:
> >>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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.
>
Ok. At least I was right in the "missing something" part. :-) TBH, I
figured it had to be something related to that, but was failing to spot
it... Sorry for the noise and thanks for the explanation!
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-25 9:29 ` Jan Beulich
2013-02-25 10:45 ` Dario Faggioli
@ 2013-02-25 11:12 ` David Vrabel
2013-02-25 11:30 ` Jan Beulich
1 sibling, 1 reply; 18+ messages in thread
From: David Vrabel @ 2013-02-25 11:12 UTC (permalink / raw)
To: Jan Beulich; +Cc: George Dunlap, Dario Faggioli, xen-devel
On 25/02/13 09:29, Jan Beulich wrote:
>>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-25 11:12 ` David Vrabel
@ 2013-02-25 11:30 ` Jan Beulich
2013-02-26 11:26 ` George Dunlap
0 siblings, 1 reply; 18+ messages in thread
From: Jan Beulich @ 2013-02-25 11:30 UTC (permalink / raw)
To: David Vrabel; +Cc: George Dunlap, Dario Faggioli, xen-devel
>>> On 25.02.13 at 12:12, David Vrabel <david.vrabel@citrix.com> wrote:
> On 25/02/13 09:29, Jan Beulich wrote:
>>>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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.
A matter of taste perhaps...
Jan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-25 11:30 ` Jan Beulich
@ 2013-02-26 11:26 ` George Dunlap
2013-02-26 11:46 ` Jan Beulich
0 siblings, 1 reply; 18+ messages in thread
From: George Dunlap @ 2013-02-26 11:26 UTC (permalink / raw)
To: Jan Beulich; +Cc: Dario Faggioli, David Vrabel, xen-devel
On 02/25/2013 11:30 AM, Jan Beulich wrote:
>>>> On 25.02.13 at 12:12, David Vrabel <david.vrabel@citrix.com> wrote:
>> On 25/02/13 09:29, Jan Beulich wrote:
>>>>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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.
>
> A matter of taste perhaps...
I have a taste for coders having to keep as little state in their head
as possible. :-) Comparing to UINT_MAX prompts the coder specifically
to think about the size of the variables.
-George
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 11:26 ` George Dunlap
@ 2013-02-26 11:46 ` Jan Beulich
2013-02-26 11:52 ` Tim Deegan
0 siblings, 1 reply; 18+ messages in thread
From: Jan Beulich @ 2013-02-26 11:46 UTC (permalink / raw)
To: George Dunlap; +Cc: Dario Faggioli, David Vrabel, xen-devel
>>> On 26.02.13 at 12:26, George Dunlap <george.dunlap@eu.citrix.com> wrote:
> On 02/25/2013 11:30 AM, Jan Beulich wrote:
>>>>> On 25.02.13 at 12:12, David Vrabel <david.vrabel@citrix.com> wrote:
>>> On 25/02/13 09:29, Jan Beulich wrote:
>>>>>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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.
>>
>> A matter of taste perhaps...
>
> I have a taste for coders having to keep as little state in their head
> as possible. :-) Comparing to UINT_MAX prompts the coder specifically
> to think about the size of the variables.
Okay, assuming this is the only thing you dislike, I'll change it then
and re-submit.
But for the record - using UINT_MAX here will get things out of
sync the moment the type of "credits" changes, whereas with
the way I had coded it this would be taken care of implicitly.
Jan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 11:46 ` Jan Beulich
@ 2013-02-26 11:52 ` Tim Deegan
2013-02-26 12:00 ` David Vrabel
0 siblings, 1 reply; 18+ messages in thread
From: Tim Deegan @ 2013-02-26 11:52 UTC (permalink / raw)
To: Jan Beulich; +Cc: George Dunlap, Dario Faggioli, David Vrabel, xen-devel
At 11:46 +0000 on 26 Feb (1361879193), Jan Beulich wrote:
> >>> On 26.02.13 at 12:26, George Dunlap <george.dunlap@eu.citrix.com> wrote:
> > On 02/25/2013 11:30 AM, Jan Beulich wrote:
> >>>>> On 25.02.13 at 12:12, David Vrabel <david.vrabel@citrix.com> wrote:
> >>> On 25/02/13 09:29, Jan Beulich wrote:
> >>>>>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> 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.
> >>
> >> A matter of taste perhaps...
> >
> > I have a taste for coders having to keep as little state in their head
> > as possible. :-) Comparing to UINT_MAX prompts the coder specifically
> > to think about the size of the variables.
>
> Okay, assuming this is the only thing you dislike, I'll change it then
> and re-submit.
>
> But for the record - using UINT_MAX here will get things out of
> sync the moment the type of "credits" changes, whereas with
> the way I had coded it this would be taken care of implicitly.
How about ASSERT(((typeof credits) val) == val) before the assignment?
Tim.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 11:52 ` Tim Deegan
@ 2013-02-26 12:00 ` David Vrabel
2013-02-26 12:21 ` Ian Campbell
0 siblings, 1 reply; 18+ messages in thread
From: David Vrabel @ 2013-02-26 12:00 UTC (permalink / raw)
To: Tim Deegan; +Cc: George Dunlap, Dario Faggioli, Jan Beulich, xen-devel
On 26/02/13 11:52, Tim Deegan wrote:
> At 11:46 +0000 on 26 Feb (1361879193), Jan Beulich wrote:
>>>>> On 26.02.13 at 12:26, George Dunlap <george.dunlap@eu.citrix.com> wrote:
>>> On 02/25/2013 11:30 AM, Jan Beulich wrote:
>>>>>>> On 25.02.13 at 12:12, David Vrabel <david.vrabel@citrix.com> wrote:
>>>>> On 25/02/13 09:29, Jan Beulich wrote:
>>>>>>>>> On 22.02.13 at 18:26, Dario Faggioli <dario.faggioli@citrix.com> wrote:
>>>>>>> On Mon, 2013-02-18 at 12:37 +0000, Jan Beulich wrote:
>>>>>>>> + 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.
>>>>
>>>> A matter of taste perhaps...
>>>
>>> I have a taste for coders having to keep as little state in their head
>>> as possible. :-) Comparing to UINT_MAX prompts the coder specifically
>>> to think about the size of the variables.
>>
>> Okay, assuming this is the only thing you dislike, I'll change it then
>> and re-submit.
>>
>> But for the record - using UINT_MAX here will get things out of
>> sync the moment the type of "credits" changes, whereas with
>> the way I had coded it this would be taken care of implicitly.
>
> How about ASSERT(((typeof credits) val) == val) before the assignment?
FWIW, this works for me.
David
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 12:00 ` David Vrabel
@ 2013-02-26 12:21 ` Ian Campbell
2013-02-26 12:51 ` Jan Beulich
2013-02-26 12:54 ` George Dunlap
0 siblings, 2 replies; 18+ messages in thread
From: Ian Campbell @ 2013-02-26 12:21 UTC (permalink / raw)
To: David Vrabel
Cc: George Dunlap, Dario Faggioli, Tim (Xen.org), Jan Beulich, xen-devel
On Tue, 2013-02-26 at 12:00 +0000, David Vrabel wrote:
> On 26/02/13 11:52, Tim Deegan wrote:
> > How about ASSERT(((typeof credits) val) == val) before the assignment?
Why not just
ASSERT(credits == val); /* Ensure we haven't truncated val */
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 12:21 ` Ian Campbell
@ 2013-02-26 12:51 ` Jan Beulich
2013-02-26 13:10 ` Ian Campbell
2013-02-26 12:54 ` George Dunlap
1 sibling, 1 reply; 18+ messages in thread
From: Jan Beulich @ 2013-02-26 12:51 UTC (permalink / raw)
To: David Vrabel, Ian Campbell
Cc: George Dunlap, Dario Faggioli, Tim (Xen.org), xen-devel
>>> On 26.02.13 at 13:21, Ian Campbell <ian.campbell@citrix.com> wrote:
> On Tue, 2013-02-26 at 12:00 +0000, David Vrabel wrote:
>> On 26/02/13 11:52, Tim Deegan wrote:
>> > How about ASSERT(((typeof credits) val) == val) before the assignment?
>
> Why not just
> ASSERT(credits == val); /* Ensure we haven't truncated val */
I.e. just want em to add a comment? That's certainly fine with me.
Jan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 12:21 ` Ian Campbell
2013-02-26 12:51 ` Jan Beulich
@ 2013-02-26 12:54 ` George Dunlap
2013-02-26 13:46 ` Tim Deegan
1 sibling, 1 reply; 18+ messages in thread
From: George Dunlap @ 2013-02-26 12:54 UTC (permalink / raw)
To: Ian Campbell
Cc: Dario Faggioli, Tim (Xen.org), David Vrabel, Jan Beulich, xen-devel
On 02/26/2013 12:21 PM, Ian Campbell wrote:
> On Tue, 2013-02-26 at 12:00 +0000, David Vrabel wrote:
>> On 26/02/13 11:52, Tim Deegan wrote:
>>> How about ASSERT(((typeof credits) val) == val) before the assignment?
>
> Why not just
> ASSERT(credits == val); /* Ensure we haven't truncated val */
I prefer this one to having "typeof credits" in the ASSERT. The main
thing is just to minimize the amount of effort a programmer has to
expend trying to figure out what's going on, so he can spend it on
something else. :-)
-George
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 12:51 ` Jan Beulich
@ 2013-02-26 13:10 ` Ian Campbell
0 siblings, 0 replies; 18+ messages in thread
From: Ian Campbell @ 2013-02-26 13:10 UTC (permalink / raw)
To: Jan Beulich
Cc: George Dunlap, Dario Faggioli, Tim (Xen.org), David Vrabel, xen-devel
On Tue, 2013-02-26 at 12:51 +0000, Jan Beulich wrote:
> >>> On 26.02.13 at 13:21, Ian Campbell <ian.campbell@citrix.com> wrote:
> > On Tue, 2013-02-26 at 12:00 +0000, David Vrabel wrote:
> >> On 26/02/13 11:52, Tim Deegan wrote:
> >> > How about ASSERT(((typeof credits) val) == val) before the assignment?
> >
> > Why not just
> > ASSERT(credits == val); /* Ensure we haven't truncated val */
>
> I.e. just want em to add a comment?
That's right s/val/credits/ depending on what the ASSERT is really doing
(I didn't go back and check)
Ian.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 12:54 ` George Dunlap
@ 2013-02-26 13:46 ` Tim Deegan
0 siblings, 0 replies; 18+ messages in thread
From: Tim Deegan @ 2013-02-26 13:46 UTC (permalink / raw)
To: George Dunlap
Cc: Dario Faggioli, xen-devel, Ian Campbell, Jan Beulich, David Vrabel
At 12:54 +0000 on 26 Feb (1361883253), George Dunlap wrote:
> On 02/26/2013 12:21 PM, Ian Campbell wrote:
> >On Tue, 2013-02-26 at 12:00 +0000, David Vrabel wrote:
> >>On 26/02/13 11:52, Tim Deegan wrote:
> >>>How about ASSERT(((typeof credits) val) == val) before the assignment?
> >
> >Why not just
> > ASSERT(credits == val); /* Ensure we haven't truncated val */
>
> I prefer this one to having "typeof credits" in the ASSERT. The main
> thing is just to minimize the amount of effort a programmer has to
> expend trying to figure out what's going on, so he can spend it on
> something else. :-)
Quite. It occurred to me afterwards that we could have a FITS_IN()
macro for that purpose. Or, as mentioned, a comment. :)
Tim.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-18 12:37 [PATCH] credit: track residual from divisions done during accounting Jan Beulich
2013-02-22 17:26 ` Dario Faggioli
@ 2013-02-26 15:00 ` George Dunlap
2013-02-26 15:07 ` Jan Beulich
1 sibling, 1 reply; 18+ messages in thread
From: George Dunlap @ 2013-02-26 15:00 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel
On 02/18/2013 12:37 PM, Jan Beulich wrote:
> 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 <jbeulich@suse.com>
The changes to credit1 look good, and I'm fine with a patch having those
(and a commented ASSERT) go in.
Credit2 I'm not so happy with, because the names "t2c" and "c2t" imply
(at least to me) that they are only converting, not changing anything;
particularly in the way that t2c is called. At the moment everything
will work fine, but it's just laying a trap for someone in the future. :-)
I've got a patch in my queue dealing with this section already -- why
don't you apply just the sched_credit.c part of the patch, and I'll take
the credit2 part of your patch and rework it so it satisfies me.
-George
>
> --- a/xen/common/sched_credit.c
> +++ b/xen/common/sched_credit.c
> @@ -19,6 +19,7 @@
> #include <xen/sched-if.h>
> #include <xen/softirq.h>
> #include <asm/atomic.h>
> +#include <asm/div64.h>
> #include <xen/errno.h>
> #include <xen/keyhandler.h>
> #include <xen/trace.h>
> @@ -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;
>
> /* 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);
> atomic_sub(credits, &svc->credit);
> svc->start_time += (credits * MILLISECS(1)) / CSCHED_CREDITS_PER_MSEC;
> }
> --- a/xen/common/sched_credit2.c
> +++ b/xen/common/sched_credit2.c
> @@ -21,7 +21,7 @@
> #include <xen/perfc.h>
> #include <xen/sched-if.h>
> #include <xen/softirq.h>
> -#include <asm/atomic.h>
> +#include <asm/div64.h>
> #include <xen/errno.h>
> #include <xen/trace.h>
> #include <xen/cpu.h>
> @@ -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) */
> @@ -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 = time * rqd->max_weight + svc->residual;
> +
> + svc->residual = do_div(val, svc->weight);
> + return 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 - svc->residual) / rqd->max_weight;
> }
>
> /*
>
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 15:00 ` George Dunlap
@ 2013-02-26 15:07 ` Jan Beulich
2013-02-26 15:11 ` George Dunlap
0 siblings, 1 reply; 18+ messages in thread
From: Jan Beulich @ 2013-02-26 15:07 UTC (permalink / raw)
To: George Dunlap; +Cc: xen-devel
>>> On 26.02.13 at 16:00, George Dunlap <george.dunlap@eu.citrix.com> wrote:
> On 02/18/2013 12:37 PM, Jan Beulich wrote:
>> 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 <jbeulich@suse.com>
>
> The changes to credit1 look good, and I'm fine with a patch having those
> (and a commented ASSERT) go in.
>
> Credit2 I'm not so happy with, because the names "t2c" and "c2t" imply
> (at least to me) that they are only converting, not changing anything;
> particularly in the way that t2c is called. At the moment everything
> will work fine, but it's just laying a trap for someone in the future. :-)
>
> I've got a patch in my queue dealing with this section already -- why
> don't you apply just the sched_credit.c part of the patch, and I'll take
> the credit2 part of your patch and rework it so it satisfies me.
That's fine with me of course.
May I take the above as a pre-ack to a patch modified accordingly?
Jan
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] credit: track residual from divisions done during accounting
2013-02-26 15:07 ` Jan Beulich
@ 2013-02-26 15:11 ` George Dunlap
0 siblings, 0 replies; 18+ messages in thread
From: George Dunlap @ 2013-02-26 15:11 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel
On 02/26/2013 03:07 PM, Jan Beulich wrote:
>>>> On 26.02.13 at 16:00, George Dunlap <george.dunlap@eu.citrix.com> wrote:
>> On 02/18/2013 12:37 PM, Jan Beulich wrote:
>>> 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 <jbeulich@suse.com>
>>
>> The changes to credit1 look good, and I'm fine with a patch having those
>> (and a commented ASSERT) go in.
>>
>> Credit2 I'm not so happy with, because the names "t2c" and "c2t" imply
>> (at least to me) that they are only converting, not changing anything;
>> particularly in the way that t2c is called. At the moment everything
>> will work fine, but it's just laying a trap for someone in the future. :-)
>>
>> I've got a patch in my queue dealing with this section already -- why
>> don't you apply just the sched_credit.c part of the patch, and I'll take
>> the credit2 part of your patch and rework it so it satisfies me.
>
> That's fine with me of course.
>
> May I take the above as a pre-ack to a patch modified accordingly?
Yes, I suppose that's fine. :-)
-George
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2013-02-26 15:11 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-18 12:37 [PATCH] credit: track residual from divisions done during accounting Jan Beulich
2013-02-22 17:26 ` Dario Faggioli
2013-02-25 9:29 ` Jan Beulich
2013-02-25 10:45 ` Dario Faggioli
2013-02-25 11:12 ` David Vrabel
2013-02-25 11:30 ` Jan Beulich
2013-02-26 11:26 ` George Dunlap
2013-02-26 11:46 ` Jan Beulich
2013-02-26 11:52 ` Tim Deegan
2013-02-26 12:00 ` David Vrabel
2013-02-26 12:21 ` Ian Campbell
2013-02-26 12:51 ` Jan Beulich
2013-02-26 13:10 ` Ian Campbell
2013-02-26 12:54 ` George Dunlap
2013-02-26 13:46 ` Tim Deegan
2013-02-26 15:00 ` George Dunlap
2013-02-26 15:07 ` Jan Beulich
2013-02-26 15:11 ` George Dunlap
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.