xen: rtds: only tickle non-already tickled CPUs
PATCH v2 1/1 xen: rtds: only tickle non-already tickled CPUs
From: naroahlee <[email protected]>
Bug Analysis:
When more than one idle VCPUs that have the same PCPU as their previous running core invoke runq_tickle(), they will tickle the same PCPU. The tickled PCPU will only pick at most one VCPU, i.e., the highest-priority one, to execute. The other VCPUs will not be scheduled for a period, even when there is an idle core, making these VCPUs unnecessarily starve for one period.
Therefore, always make sure that we only tickle PCPUs that have not been tickled already.
--- xen/common/sched_rt.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
xen/common/sched_rt.c +12 -14
@@ -1144,9 +1144,10 @@ rt_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc)* Called by wake() and context_saved() * We have a running candidate here, the kick logic is: * Among all the cpus that are within the cpu affinity -* 1) if the new->cpu is idle, kick it. This could benefit cache hit -* 2) if there are any idle vcpu, kick it. -* 3) now all pcpus are busy; +* 1) if there are any idle vcpu, kick it. +* For cache benefit, we first search new->cpu. +* +* 2) now all pcpus are busy; * among all the running vcpus, pick lowest priority one * if snext has higher priority, kick it. *
@@ -1174,17 +1175,11 @@ runq_tickle(const struct scheduler *ops, struct rt_vcpu *new)cpumask_and (¬_tickled, online, new->vcpu->cpu_hard_affinity);cpumask_andnot (¬_tickled, ¬_tickled, &prv->tickled); -/* 1) if new's previous cpu is idle, kick it for cache benefit */ -if (is_idle_vcpu (curr_on_cpu (new->vcpu->processor)) ) - { -SCHED_STAT_CRANK (tickled_idle_cpu); - cpu_to_tickle = new->vcpu->processor; - goto out; - } - -/* 2) if there are any idle pcpu, kick it */ +/* 1) if there are any idle pcpu, kick it */ /* The same loop also find the one with lowest priority */ -for_each_cpu (cpu, ¬_tickled) +/* For cache benefit, we search new->cpu first */ + cpu =cpumask_test_or_cycle (new->vcpu->processor, ¬_tickled); +while ( cpu != nr_cpu_ids ) { iter_vc =curr_on_cpu (cpu);if (is_idle_vcpu (iter_vc) )
@@ -1197,9 +1192,12 @@ runq_tickle(const struct scheduler *ops, struct rt_vcpu *new)if ( latest_deadline_vcpu ==NULL || iter_svc->cur_deadline > latest_deadline_vcpu->cur_deadline ) latest_deadline_vcpu = iter_svc; + +cpumask_clear_cpu (cpu, ¬_tickled); + cpu =cpumask_cycle (cpu, ¬_tickled); } -/* 3) candicate has higher priority, kick out lowest priority vcpu */ +/* 2) candicate has higher priority, kick out lowest priority vcpu */ if ( latest_deadline_vcpu !=NULL && new->cur_deadline < latest_deadline_vcpu->cur_deadline ) {
Signature · 10 lines
1.9.1 --- CC: <[email protected]> CC: <[email protected]> _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 20 lines · Haoran Li
From: naroahlee <[email protected]>
Bug Analysis:
When more than one idle VCPUs that have the same PCPU as their previous running core invokerunq_tickle(), they will tickle the same PCPU. The tickled PCPU will only pick at most one VCPU, i.e., the highest-priority one, to execute. The other VCPUs will not be scheduled for a period, even when there is an idle core, making these VCPUs unnecessarily starve for one period.
Therefore, always make sure that we only tickle PCPUs that have not been tickled already.--- xen/common/sched_rt.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)xen/common/sched_rt.c +0
-0
xen/common/sched_rt.c rt_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) · line 1149
Quoted 9 lines
xen/common/sched_rt.c +3
-3@@ -1144,9 +1144,10 @@ rt_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc)* Called by wake() and context_saved() * We have a running candidate here, the kick logic is: * Among all the cpus that are within the cpu affinity -* 1) if the new->cpu is idle, kick it. This could benefit cache hit -* 2) if there are any idle vcpu, kick it. -* 3) now all pcpus are busy; +* 1) if there are any idle vcpu, kick it. +* For cache benefit, we first search new->cpu. +*
Please ditch this empty line.
Quoted 43 lines
xen/common/sched_rt.c +9
-12+* 2) now all pcpus are busy; * among all the running vcpus, pick lowest priority one * if snext has higher priority, kick it. * @@ -1174,17 +1175,11 @@ runq_tickle(const struct scheduler *ops, struct rt_vcpu *new)cpumask_and (¬_tickled, online, new->vcpu->cpu_hard_affinity);cpumask_andnot (¬_tickled, ¬_tickled, &prv->tickled); -/* 1) if new's previous cpu is idle, kick it for cache benefit */ -if (is_idle_vcpu (curr_on_cpu (new->vcpu->processor)) ) - { -SCHED_STAT_CRANK (tickled_idle_cpu); - cpu_to_tickle = new->vcpu->processor; - goto out; - } - -/* 2) if there are any idle pcpu, kick it */ +/* 1) if there are any idle pcpu, kick it */ /* The same loop also find the one with lowest priority */ -for_each_cpu (cpu, ¬_tickled) +/* For cache benefit, we search new->cpu first */ + cpu =cpumask_test_or_cycle (new->vcpu->processor, ¬_tickled); +while ( cpu != nr_cpu_ids ) { iter_vc =curr_on_cpu (cpu);if (is_idle_vcpu (iter_vc) )@@ -1197,9 +1192,12 @@ runq_tickle(const struct scheduler *ops, struct rt_vcpu *new)if ( latest_deadline_vcpu ==NULL || iter_svc->cur_deadline > latest_deadline_vcpu->cur_deadline ) latest_deadline_vcpu = iter_svc; + +cpumask_clear_cpu (cpu, ¬_tickled); + cpu =cpumask_cycle (cpu, ¬_tickled); } -/* 3) candicate has higher priority, kick out lowest priority vcpu */ +/* 2) candicate has higher priority, kick out lowest priority vcpu */ if ( latest_deadline_vcpu !=NULL && new->cur_deadline < latest_deadline_vcpu->cur_deadline ) { --1.9.1
Quoted 3 lines
---
CC: <[email protected]>
CC: <[email protected]>
The code looks good to me.
The empty line in the comment may not be a bit deal.
Thanks,
Meng
-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 4 lines · Haoran Li
From: naroahlee <[email protected]>
Bug Analysis:
Just kill this line above.
Quoted 9 lines
When more than one idle VCPUs that have the same PCPU as their previous running core invoke
runq_tickle(), they will tickle the same PCPU. The tickled PCPU will only pick at most one VCPU, i.e., the highest-priority one, to execute. The other VCPUs will not be scheduled for a period, even when there is an idle core, making these VCPUs unnecessarily starve for one period.
Therefore, always make sure that we only tickle PCPUs that have not been tickled already.
And I'd say to wrap around the lines at a shorter threshold. `git log', for instance, indents the changelogs, and the idea would be for them to look good on 80 characters terminal.
Quoted 5 lines
xen/common/sched_rt.c +0
-0@@ -1144,9 +1144,10 @@ rt_vcpu_sleep(const struct scheduler *ops, struct vcpu *vc) * Called by wake() and context_saved()
xen/common/sched_rt.c rt_vcpu_sleep(const struct scheduler *ops, · line 1152
Quoted 10 lines
xen/common/sched_rt.c +4
-3* We have a running candidate here, the kick logic is: * Among all the cpus that are within the cpu affinity - * 1) if the new->cpu is idle, kick it. This could benefit cache hit - * 2) if there are any idle vcpu, kick it. - * 3) now all pcpus are busy; + * 1) if there are any idle vcpu, kick it. + * For cache benefit, we first search new->cpu. + * + * 2) now all pcpus are busy;
As Meng said, no blank line here.
Quoted 11 lines
xen/common/sched_rt.c +0
-0* among all the running vcpus, pick lowest priority one* if snext has higher priority, kick it.
*xen/common/sched_rt.c +0
-0@@ -1174,17 +1175,11 @@ runq_tickle(const struct scheduler *ops, struct rt_vcpu *new) cpumask_and(¬_tickled, online, new->vcpu->cpu_hard_affinity); cpumask_andnot(¬_tickled, ¬_tickled, &prv->tickled);
- /* 1) if new's previous cpu is idle, kick it for cache benefit */
- if ( is_idle_vcpu(curr_on_cpu(new->vcpu->processor)) )
Quoted 9 lines
- {
- SCHED_STAT_CRANK(tickled_idle_cpu);
- cpu_to_tickle =new->vcpu->processor;
- goto out;
- }
-
- /* 2) if there are any idle pcpu, kick it */
+ /* 1) if there are any idle pcpu, kick it */
While there, do you mind adding a full stop at the end of the sentence?
xen/common/sched_rt.c runq_tickle(const struct scheduler *ops, struct rt_vcpu *new) · line 1180
Quoted 4 lines
/* The same loop also find the one with lowest priority */ - for_each_cpu(cpu,
¬_tickled)xen/common/sched_rt.c +1
-0+/* For cache benefit, we search new->cpu first */
And this looks to me to be misindented.
If you fix these things and resend, you can add (together to Meng's one):
And I'm Cc-ing George, so he can also adivse if he wants, as hee is also a scheduler maintainer... not to mention that he will most likely be the one that will commit the change, so please do Cc him yourself as well when you resend the patch (I should have asked to do that before, but did not notice he was not there).
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]
https://lists.xen.org/xen-devel