Skip to content

Commit 53916d5

Browse files
jlelliPeter Zijlstra
authored andcommitted
sched/deadline: Check bandwidth overflow earlier for hotplug
Currently we check for bandwidth overflow potentially due to hotplug operations at the end of sched_cpu_deactivate(), after the cpu going offline has already been removed from scheduling, active_mask, etc. This can create issues for DEADLINE tasks, as there is a substantial race window between the start of sched_cpu_deactivate() and the moment we possibly decide to roll-back the operation if dl_bw_deactivate() returns failure in cpuset_cpu_inactive(). An example is a throttled task that sees its replenishment timer firing while the cpu it was previously running on is considered offline, but before dl_bw_deactivate() had a chance to say no and roll-back happened. Fix this by directly calling dl_bw_deactivate() first thing in sched_cpu_deactivate() and do the required calculation in the former function considering the cpu passed as an argument as offline already. By doing so we also simplify sched_cpu_deactivate(), as there is no need anymore for any kind of roll-back if we fail early. Signed-off-by: Juri Lelli <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Phil Auld <[email protected]> Tested-by: Waiman Long <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d4742f6 commit 53916d5

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

kernel/sched/core.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8182,19 +8182,14 @@ static void cpuset_cpu_active(void)
81828182
cpuset_update_active_cpus();
81838183
}
81848184

8185-
static int cpuset_cpu_inactive(unsigned int cpu)
8185+
static void cpuset_cpu_inactive(unsigned int cpu)
81868186
{
81878187
if (!cpuhp_tasks_frozen) {
8188-
int ret = dl_bw_deactivate(cpu);
8189-
8190-
if (ret)
8191-
return ret;
81928188
cpuset_update_active_cpus();
81938189
} else {
81948190
num_cpus_frozen++;
81958191
partition_sched_domains(1, NULL, NULL);
81968192
}
8197-
return 0;
81988193
}
81998194

82008195
static inline void sched_smt_present_inc(int cpu)
@@ -8256,6 +8251,11 @@ int sched_cpu_deactivate(unsigned int cpu)
82568251
struct rq *rq = cpu_rq(cpu);
82578252
int ret;
82588253

8254+
ret = dl_bw_deactivate(cpu);
8255+
8256+
if (ret)
8257+
return ret;
8258+
82598259
/*
82608260
* Remove CPU from nohz.idle_cpus_mask to prevent participating in
82618261
* load balancing when not active
@@ -8301,15 +8301,7 @@ int sched_cpu_deactivate(unsigned int cpu)
83018301
return 0;
83028302

83038303
sched_update_numa(cpu, false);
8304-
ret = cpuset_cpu_inactive(cpu);
8305-
if (ret) {
8306-
sched_smt_present_inc(cpu);
8307-
sched_set_rq_online(rq, cpu);
8308-
balance_push_set(cpu, false);
8309-
set_cpu_active(cpu, true);
8310-
sched_update_numa(cpu, true);
8311-
return ret;
8312-
}
8304+
cpuset_cpu_inactive(cpu);
83138305
sched_domains_numa_masks_clear(cpu);
83148306
return 0;
83158307
}

kernel/sched/deadline.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,6 +3495,13 @@ static int dl_bw_manage(enum dl_bw_request req, int cpu, u64 dl_bw)
34953495
}
34963496
break;
34973497
case dl_bw_req_deactivate:
3498+
/*
3499+
* cpu is not off yet, but we need to do the math by
3500+
* considering it off already (i.e., what would happen if we
3501+
* turn cpu off?).
3502+
*/
3503+
cap -= arch_scale_cpu_capacity(cpu);
3504+
34983505
/*
34993506
* cpu is going offline and NORMAL tasks will be moved away
35003507
* from it. We can thus discount dl_server bandwidth
@@ -3512,9 +3519,10 @@ static int dl_bw_manage(enum dl_bw_request req, int cpu, u64 dl_bw)
35123519
if (dl_b->total_bw - fair_server_bw > 0) {
35133520
/*
35143521
* Leaving at least one CPU for DEADLINE tasks seems a
3515-
* wise thing to do.
3522+
* wise thing to do. As said above, cpu is not offline
3523+
* yet, so account for that.
35163524
*/
3517-
if (dl_bw_cpus(cpu))
3525+
if (dl_bw_cpus(cpu) - 1)
35183526
overflow = __dl_overflow(dl_b, cap, fair_server_bw, 0);
35193527
else
35203528
overflow = 1;

0 commit comments

Comments
 (0)