xen: sched: Credit2: during scheduling, update the idle mask before using it
PATCH 1/1 xen: sched: Credit2: during scheduling, update the idle mask before using it
Load balancing, when happening, at the end of a "scheduler epoch", can trigger vcpu migration, which in its turn may call runq_tickle(). If the cpu where this happens was idle, but we're now going to schedule a vcpu on it, let's update the runq's idle cpus mask accordingly _before_ doing load balancing.
Not doing that, in fact, may cause runq_tickle() to think that the cpu is still idle, and tickle it to go pick up a vcpu from the runqueue, which might be wrong/unideal.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
---
Backporting: this does not fix a system crash. However, it fixes the behavior of the scheduler --which I'd call wrong more than just suboptimal.
Therefore, I'd be inclined to ask for this to be backported. It should be fairly straightforward, but as usual, I'm up for helping with that.
Thanks and Regards,
Dario
--- xen/common/sched_credit2.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/common/sched_credit2.c +7 -7
@@ -3554,6 +3554,13 @@ csched2_schedule(__set_bit (__CSFLAG_scheduled, &snext->flags); } +/* Clear the idle mask if necessary */ +if (cpumask_test_cpu (cpu, &rqd->idle) ) + { +__cpumask_clear_cpu (cpu, &rqd->idle); +smt_idle_mask_clear (cpu, &rqd->smt_idle); + } +/* * The reset condition is "has a scheduler epoch come to an end?". * The way this is enforced is checking whether the vcpu at the top
@@ -3574,13 +3581,6 @@ csched2_schedule(balance_load (ops, cpu, now); } -/* Clear the idle mask if necessary */ -if (cpumask_test_cpu (cpu, &rqd->idle) ) - { -__cpumask_clear_cpu (cpu, &rqd->idle); -smt_idle_mask_clear (cpu, &rqd->smt_idle); - } - snext->start_time = now; snext->tickled_cpu =-1 ;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 11.10.18 at 15:44, <[email protected]> wrote:
Load balancing, when happening, at the end of a "scheduler epoch", can trigger vcpu migration, which in its turn may call
runq_tickle(). If the cpu where this happens was idle, but we're now going to schedule a vcpu on it, let's update the runq's idle cpus mask accordingly _before_ doing load balancing.Not doing that, in fact, may cause
runq_tickle()to think that the cpu is still idle, and tickle it to go pick up a vcpu from the runqueue, which might be wrong/unideal.
Makes sense to me; I seem to vaguely recall that something along these lines was done years ago for credit1 as well.
Quoted 5 lines
Backporting: this does not fix a system crash. However, it fixes the behavior of the scheduler --which I'd call wrong more than just suboptimal.
Therefore, I'd be inclined to ask for this to be backported. It should be fairly straightforward, but as usual, I'm up for helping with that.
I'll try to remember to pick it up when I've seen it go in.
xen/common/sched_credit2.c csched2_schedule( · line 3562
Quoted 12 lines
xen/common/sched_credit2.c +6
-0@@ -3554,6 +3554,13 @@ csched2_schedule(__set_bit (__CSFLAG_scheduled, &snext->flags); } +/* Clear the idle mask if necessary */ +if (cpumask_test_cpu (cpu, &rqd->idle) ) + { +__cpumask_clear_cpu (cpu, &rqd->idle); +smt_idle_mask_clear (cpu, &rqd->smt_idle); + }
I realize you're merely moving code, but is there a reason to do the test-and-clear in two steps rather than one. It being the non-atomic variant, it can't be shared memory, and hence the cache line ping-pong consideration applicable in other cases is irrelevant here afaict.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.10.18 at 15:44, <[email protected]> wrote:
Not doing that, in fact, may cause
runq_tickle()to think that the cpu
is still idle, and tickle it to go pick up a vcpu from the runqueue,
which might be wrong/unideal.Makes sense to me; I seem to vaguely recall that something along these lines was done years ago for credit1 as well.
Mmm... yes, there have been a few, not identical, but vaguely similar (or, at least, related to making sure that we actually tickle idle cpus, etc).
Quoted 5 lines
Quoted 5 lines
Backporting: this does not fix a system crash. However, it fixes the
behavior of the scheduler --which I'd call wrong more than just suboptimal.
Quoted 7 lines
Quoted 4 lines
Therefore, I'd be inclined to ask for this to be backported. It should
be fairly straightforward, but as usual, I'm up for helping with that.I'll try to remember to pick it up when I've seen it go in.
Thanks. I'll try myself keeping an eye on the staging trees at relevant times.
Quoted 6 lines
Quoted 6 lines
xen/common/sched_credit2.c +0
-0@@ -3554,6 +3554,13 @@ csched2_schedule(__set_bit (__CSFLAG_scheduled, &snext->flags); }
Quoted 13 lines
xen/common/sched_credit2.c csched2_schedule( · line 3562
Quoted 6 lines
xen/common/sched_credit2.c +6
-0+/* Clear the idle mask if necessary */ +if (cpumask_test_cpu (cpu, &rqd->idle) ) + { +__cpumask_clear_cpu (cpu, &rqd->idle); +smt_idle_mask_clear (cpu, &rqd->smt_idle); + }I realize you're merely moving code, but is there a reason to do the test-and-clear in two steps rather than one. It being the non-atomic variant, it can't be shared memory, and hence the cache line ping-pong consideration applicable in other cases is irrelevant here afaict.
Indeed it's not that, IMO. In fact, access to this mask is serialized via a spinlock, so there can't be two CPUs trying to read/update it concurrently.
I don't know, I guess the original structure of the code is inherited from Credit1 (where things are _not_ serialized, so trying to avoid ping-pong makes sense).
Then, when I did 222234f2ad1 "xen: credit2: use non-atomic cpumask and bit operations", I didn't go as far as I should have. It's weird because ISTR having thought about it, but I may be confusing this with something else.
In any event, I think we very well can turn these in __test_and_clear/set(). But I'd do that in a separate patch.
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 Software Engineer @ SUSE https://www.suse.com/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Dario Faggioli
Load balancing, when happening, at the end of a "scheduler epoch", can
trigger vcpu migration, which in its turn may callrunq_tickle(). If the
cpu where this happens was idle, but we're now going to schedule a vcpu
on it, let's update the runq's idle cpus mask accordingly _before_ doing
load balancing.
Quoted 9 lines
Not doing that, in fact, may cause
runq_tickle()to think that the cpu
is still idle, and tickle it to go pick up a vcpu from the runqueue, which might be wrong/unideal.Signed-off-by Dario Faggioli <[email protected]>---
Cc: George Dunlap <[email protected]>
Ping?
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 Software Engineer @ SUSE https://www.suse.com/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Dario Faggioli
Load balancing, when happening, at the end of a "scheduler epoch", can trigger vcpu migration, which in its turn may call
runq_tickle(). If the cpu where this happens was idle, but we're now going to schedule a vcpu on it, let's update the runq's idle cpus mask accordingly _before_ doing load balancing.Not doing that, in fact, may cause
runq_tickle()to think that the cpu is still idle, and tickle it to go pick up a vcpu from the runqueue, which might be wrong/unideal.Signed-off-by Dario Faggioli <[email protected]>
Patch looks good:
One comment: The title seems to have excessive tags. You only need enough for people scrolling through to figure out the domain; "xen/credit2:", or even just "credit2:" is enough. More than that makes the line too long and can obscure important information if the lines end up being clipped.
Do you mind if I change that on check-in?
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · George Dunlap
Quoted 1 line · Dario Faggioli
Reviewed-by George Dunlap <[email protected]>
Quoted 8 lines
One comment: The title seems to have excessive tags. You only need enough for people scrolling through to figure out the domain; "xen/credit2:", or even just "credit2:" is enough. More than that makes
the line too long and can obscure important information if the lines end
up being clipped.
Makes sense.
Quoted 2 lines
Do you mind if I change that on check-in?
Go ahead, no problem at all.
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 Software Engineer @ SUSE https://www.suse.com/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel