Skip to contentSkip to conversation

xen: recalculate per-cpupool credits when updating timeslice

PATCH In review Juergen Gross 4 participants 7 messages Jan 29, 2016 – Feb 2, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: recalculate per-cpupool credits when updating timeslice

When modifying the timeslice of the credit scheduler in a cpupool the cpupool global credit value (n_cpus * credits_per_tslice) isn't recalculated. This will lead to wrong scheduling decisions later.

Do the recalculation when updating the timeslice.

---
 xen/common/sched_credit.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/common/sched_credit.c +7 -0
index 03fb2c2..912511e 100644
@@ -1086,12 +1086,19 @@ csched_dom_cntl(
 static inline void
 __csched_set_tslice(struct csched_private *prv, unsigned timeslice)
 {
+    unsigned long flags;
+
+    spin_lock_irqsave(&prv->lock, flags);
+
     prv->tslice_ms = timeslice;
     prv->ticks_per_tslice = CSCHED_TICKS_PER_TSLICE;
     if ( prv->tslice_ms < prv->ticks_per_tslice )
         prv->ticks_per_tslice = 1;
     prv->tick_period_us = prv->tslice_ms * 1000 / prv->ticks_per_tslice;
     prv->credits_per_tslice = CSCHED_CREDITS_PER_MSEC * prv->tslice_ms;
+    prv->credit = prv->credits_per_tslice * prv->ncpus;
+
+    spin_unlock_irqrestore(&prv->lock, flags);
 }
 
 static int
Signature · 1 line
2.6.2
#1 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 29.01.16 at 11:21, <[email protected]> wrote:
xen/common/sched_credit.c +4 -0
@@ -1086,12 +1086,19 @@ csched_dom_cntl(
 static inline void
 __csched_set_tslice(struct csched_private *prv, unsigned timeslice)
 {
+    unsigned long flags;
+
+    spin_lock_irqsave(&prv->lock, flags);
+

xen/common/sched_credit.c csched_dom_cntl( · line 1102

Quoted 10 lines
xen/common/sched_credit.c +3 -0
     prv->tslice_ms = timeslice;
     prv->ticks_per_tslice = CSCHED_TICKS_PER_TSLICE;
     if ( prv->tslice_ms < prv->ticks_per_tslice )
         prv->ticks_per_tslice = 1;
     prv->tick_period_us = prv->tslice_ms * 1000 / prv->ticks_per_tslice;
     prv->credits_per_tslice = CSCHED_CREDITS_PER_MSEC * prv->tslice_ms;
+    prv->credit = prv->credits_per_tslice * prv->ncpus;
+
+    spin_unlock_irqrestore(&prv->lock, flags);
 }

The added locking, which has no reason give for in the description at all, puzzles me: I can see it being needed (and having been missing) when called from csched_sys_cntl(), but it's not clear to me why it would be needed when called from csched_init(). Yet csched_sys_cntl() subsequently als updates prv->ratelimit_us, and hence the lock would perhaps better be taken there?

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 29.01.16 at 11:21, <[email protected]> wrote:
xen/common/sched_credit.c +7 -0
@@ -1086,12 +1086,19 @@ csched_dom_cntl(
 static inline void
 __csched_set_tslice(struct csched_private *prv, unsigned timeslice)
 {
+    unsigned long flags;
+
+    spin_lock_irqsave(&prv->lock, flags);
+
     prv->tslice_ms = timeslice;
     prv->ticks_per_tslice = CSCHED_TICKS_PER_TSLICE;
     if ( prv->tslice_ms < prv->ticks_per_tslice )
         prv->ticks_per_tslice = 1;
     prv->tick_period_us = prv->tslice_ms * 1000 / prv->ticks_per_tslice;
     prv->credits_per_tslice = CSCHED_CREDITS_PER_MSEC * prv->tslice_ms;
+    prv->credit = prv->credits_per_tslice * prv->ncpus;
+
+    spin_unlock_irqrestore(&prv->lock, flags);
Quoted 8 lines

xen/common/sched_credit.c csched_dom_cntl( · line 1102

Quoted 1 line
xen/common/sched_credit.c +0 -0
 }

The added locking, which has no reason give for in the description at all, puzzles me: I can see it being needed (and having been missing) when called from csched_sys_cntl(), but it's not clear to me why it would be needed when called from csched_init(). Yet csched_sys_cntl() subsequently als updates prv->ratelimit_us, and hence the lock would perhaps better be taken there?

The locking is needed to protect against csched_alloc_pdata() and csched_free_pdata(). prv->credit could be permananently wrong without the lock, while prv->ratelimit_us can't be modified concurrently in a wrong way (it could be modified by two concurrent calls of csched_sys_cntl(), but even with locking one of both calls would be the winner, same applies to the case with no lock).

OTOH I don't mind moving the lock to csched_sys_cntl(). Dario, George, any preferences?

Juergen

#4 lore raw
Quoted 40 lines · Juergen Gross
Quoted 25 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 29.01.16 at 11:21, <[email protected]> wrote:
xen/common/sched_credit.c +0 -0
@@ -1086,12 +1086,19 @@ csched_dom_cntl(

 static inline void
 __csched_set_tslice(struct csched_private *prv, unsigned timeslice)
 {
+    unsigned long flags;

xen/common/sched_credit.c +3 -0
+
+    spin_lock_irqsave(&prv->lock, flags);
+

     prv->tslice_ms = timeslice; prv->ticks_per_tslice = CSCHED_TICKS_PER_TSLICE; if ( prv->tslice_ms < prv->ticks_per_tslice ) prv->ticks_per_tslice = 1; prv->tick_period_us = prv->tslice_ms * 1000 / prv-

Quoted 7 lines
Quoted 1 line

ticks_per_tslice;

     prv->credits_per_tslice = CSCHED_CREDITS_PER_MSEC * prv-

Quoted 1 line

tslice_ms;

+    prv->credit = prv->credits_per_tslice * prv->ncpus; +
+    spin_unlock_irqrestore(&prv->lock, flags); }

Quoted 6 lines

The added locking, which has no reason give for in the description at all, puzzles me: I can see it being needed (and having been missing) when called from csched_sys_cntl(), but it's not clear to me why it would be needed when called from csched_init(). Yet csched_sys_cntl() subsequently als updates prv->ratelimit_us, and hence the lock would perhaps better be taken there?

The locking is needed to protect against csched_alloc_pdata() and csched_free_pdata(). prv->credit could be permananently wrong without the lock, while prv->ratelimit_us can't be modified concurrently in a wrong way (it could be modified by two concurrent calls of csched_sys_cntl(), but even with locking one of both calls would be the winner, same applies to the case with no lock).

Quoted 3 lines

OTOH I don't mind moving the lock to csched_sys_cntl(). Dario, George, any preferences?

Yes, I think having the lock in csched_sys_cntl() would be preferable.

In any case, since the lack of locking and lack of recalculation look like two pretty independent existing bugs to me, can we have either:
 a. two patches;
 b. one patch but with both the issues described in the changelog.

My preference going to a.

Thanks and Regards,
Dario

Signature · 4 lines
<<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)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 44 lines · Dario Faggioli
Quoted 40 lines · Juergen Gross
Quoted 25 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 29.01.16 at 11:21, <[email protected]> wrote:
xen/common/sched_credit.c +7 -0
@@ -1086,12 +1086,19 @@ csched_dom_cntl(
 static inline void
 __csched_set_tslice(struct csched_private *prv, unsigned
 timeslice)
 {
+    unsigned long flags;
+
+    spin_lock_irqsave(&prv->lock, flags);
+
     prv->tslice_ms = timeslice;
     prv->ticks_per_tslice = CSCHED_TICKS_PER_TSLICE;
     if ( prv->tslice_ms < prv->ticks_per_tslice )
         prv->ticks_per_tslice = 1;
     prv->tick_period_us = prv->tslice_ms * 1000 / prv-
 > ticks_per_tslice;
     prv->credits_per_tslice = CSCHED_CREDITS_PER_MSEC * prv-
 > tslice_ms;
+    prv->credit = prv->credits_per_tslice * prv->ncpus;
+
+    spin_unlock_irqrestore(&prv->lock, flags);
Quoted 1 line

}

Quoted 6 lines

The added locking, which has no reason give for in the description at all, puzzles me: I can see it being needed (and having been missing) when called from csched_sys_cntl(), but it's not clear to me why it would be needed when called from csched_init(). Yet csched_sys_cntl() subsequently als updates prv->ratelimit_us, and hence the lock would perhaps better be taken there?

The locking is needed to protect against csched_alloc_pdata() and csched_free_pdata(). prv->credit could be permananently wrong without the lock, while prv->ratelimit_us can't be modified concurrently in a wrong way (it could be modified by two concurrent calls of csched_sys_cntl(), but even with locking one of both calls would be the winner, same applies to the case with no lock).

Quoted 3 lines

OTOH I don't mind moving the lock to csched_sys_cntl(). Dario, George, any preferences?

Quoted 8 lines

Yes, I think having the lock in csched_sys_cntl() would be preferable.

In any case, since the lack of locking and lack of recalculation look like two pretty independent existing bugs to me, can we have either:
a. two patches;
b. one patch but with both the issues described in the changelog.

My preference going to a.

Without setting prv->credit the lock isn't necessary. In case of a race domain weights wouldn't be honored correctly for just one timeslice and I doubt this would be noticeable at all.

OTOH I don't mind splitting the patch into two, I have to respin anyway.

Juergen

#6 lore raw
Quoted 9 lines · Juergen Gross
Quoted 8 lines · Dario Faggioli


In any case, since the lack of locking and lack of recalculation look
like two pretty independent existing bugs to me, can we have either:
 a. two patches;
 b. one patch but with both the issues described in the changelog.

Quoted 6 lines
Quoted 1 line

My preference going to a.

Without setting prv->credit the lock isn't necessary. In case of a race domain weights wouldn't be honored correctly for just one timeslice and I doubt this would be noticeable at all.

Ah, yes, I see what you mean now!!

Quoted 3 lines

OTOH I don't mind splitting the patch into two, I have to respin anyway.

Well, no, given you explanation above, to which I agree (sory for not seeing this before), keeping it being just one patch would actually be better IMO...

But then, please, explain in the changelog that the recalculation would introduce a race, and hence you also need to lock.

Thanks and regards,
Dario

Signature · 4 lines
<<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)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Tested-by on v1 1/1
#7 lore raw
In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

When modifying the timeslice of the credit scheduler in a cpupool the cpupool global credit value (n_cpus * credits_per_tslice) isn't recalculated. This will lead to wrong scheduling decisions later.

Do the recalculation when updating the timeslice.

We had notice that the quota's were not working after the timeslice was changed in a mono-cpupool running two guests doing 'for loops'. Applied Juergen's patch to a SuSE xen-4.4.3_02-26.2 rpm, the patch was offset by 6 lines. The guests now observe the quotas when the timeslice is changed.

Signature · 2 lines
Sent from my Fujitsu Primergy RXI300 IA64
Firmenangaben: Fujitsu Technology Solutions GmbH / ts.fujitsu.com/imprint