Skip to contentSkip to conversation

Revert "sched/deadline: Remove cpu_active_mask from cpudl_find()"

PATCH In review Sai Harshini Nimmala 2 participants 2 messages Jun 25, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "sched/deadline: Remove cpu_active_mask from cpudl_find()"

The original commit 9659e1ee removes checking the cpu_active_mask while finding the best cpu to place a deadline task, citing the reason that this mask rarely changes and removing the check will give performance gains.
However, on hotplugging, the cpu dying path has a brief duration between the CPUHP_TEARDOWN_CPU and CPUHP_AP_SCHED_STARTING hotplug states where the DL task can be scheduled on this cpu because the corresponding cpu bit in cpu->free_cpus has not been cleared yet. Without the cpu_active_mask check we could end up putting a DL task on such cpus leading to a BUG.
The cpu_active_mask will be updated promptly before either of these states and will provide a more accurate check for the use case above.

---
 kernel/sched/cpudeadline.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/cpudeadline.c +3 -1
index 5cc4012..0346837 100644
@@ -120,7 +120,8 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	const struct sched_dl_entity *dl_se = &p->dl;
 
 	if (later_mask &&
-	    cpumask_and(later_mask, cp->free_cpus, p->cpus_ptr)) {
+	    cpumask_and(later_mask, cp->free_cpus, p->cpus_ptr) &&
+	    cpumask_and(later_mask, later_mask, cpu_active_mask)) {
 		return 1;
 	} else {
 		int best_cpu = cpudl_maximum(cp);
@@ -128,6 +129,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 		WARN_ON(best_cpu != -1 && !cpu_present(best_cpu));
 
 		if (cpumask_test_cpu(best_cpu, p->cpus_ptr) &&
+		    cpumask_test_cpu(best_cpu, cpu_active_mask) &&
 		    dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
 			if (later_mask)
 				cpumask_set_cpu(best_cpu, later_mask);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#1 lore raw

Hi,

Quoted 24 lines · Sai Harshini Nimmala

The original commit 9659e1ee removes checking the cpu_active_mask while finding the best cpu to place a deadline task, citing the reason that this mask rarely changes and removing the check will give performance gains.
However, on hotplugging, the cpu dying path has a brief duration between the CPUHP_TEARDOWN_CPU and CPUHP_AP_SCHED_STARTING hotplug states where the DL task can be scheduled on this cpu because the corresponding cpu bit in cpu->free_cpus has not been cleared yet. Without the cpu_active_mask check we could end up putting a DL task on such cpus leading to a BUG.
The cpu_active_mask will be updated promptly before either of these states and will provide a more accurate check for the use case above.

---
 kernel/sched/cpudeadline.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/cpudeadline.c +0 -0
index 5cc4012..0346837 100644

kernel/sched/cpudeadline.c int cpudl_find(struct cpudl *cp, struct task_struct *p, · line 127

Quoted 9 lines
kernel/sched/cpudeadline.c +2 -1
@@ -120,7 +120,8 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	const struct sched_dl_entity *dl_se = &p->dl;
 
 	if (later_mask &&
-	    cpumask_and(later_mask, cp->free_cpus, p->cpus_ptr)) {
+	    cpumask_and(later_mask, cp->free_cpus, p->cpus_ptr) &&
+	    cpumask_and(later_mask, later_mask, cpu_active_mask)) {
 		return 1;
 	} else {
 		int best_cpu = cpudl_maximum(cp);

So, I believe the patch you want to revert only removed the condition above.

kernel/sched/cpudeadline.c int cpudl_find(struct cpudl *cp, struct task_struct *p, · line 135

Quoted 8 lines
kernel/sched/cpudeadline.c +1 -0
@@ -128,6 +129,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 		WARN_ON(best_cpu != -1 && !cpu_present(best_cpu));
 
 		if (cpumask_test_cpu(best_cpu, p->cpus_ptr) &&
+		    cpumask_test_cpu(best_cpu, cpu_active_mask) &&
 		    dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
 			if (later_mask)
 				cpumask_set_cpu(best_cpu, later_mask);

Did you actually experience issues with this second part as well? I'm thinking the WARN_ON should have fired in that case, no?

Thanks,

Juri