Skip to content

Commit 772b653

Browse files
deggemanPeter Zijlstra
authored andcommitted
sched/deadline: Merge dl_task_can_attach() and dl_cpu_busy()
Both functions are doing almost the same, that is checking if admission control is still respected. With exclusive cpusets, dl_task_can_attach() checks if the destination cpuset (i.e. its root domain) has enough CPU capacity to accommodate the task. dl_cpu_busy() checks if there is enough CPU capacity in the cpuset in case the CPU is hot-plugged out. dl_task_can_attach() is used to check if a task can be admitted while dl_cpu_busy() is used to check if a CPU can be hotplugged out. Make dl_cpu_busy() able to deal with a task and use it instead of dl_task_can_attach() in task_can_attach(). Signed-off-by: Dietmar Eggemann <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Juri Lelli <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f1304ec commit 772b653

File tree

3 files changed

+24
-44
lines changed

3 files changed

+24
-44
lines changed

kernel/sched/core.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8805,8 +8805,11 @@ int task_can_attach(struct task_struct *p,
88058805
}
88068806

88078807
if (dl_task(p) && !cpumask_intersects(task_rq(p)->rd->span,
8808-
cs_cpus_allowed))
8809-
ret = dl_task_can_attach(p, cs_cpus_allowed);
8808+
cs_cpus_allowed)) {
8809+
int cpu = cpumask_any_and(cpu_active_mask, cs_cpus_allowed);
8810+
8811+
ret = dl_cpu_busy(cpu, p);
8812+
}
88108813

88118814
out:
88128815
return ret;
@@ -9090,8 +9093,10 @@ static void cpuset_cpu_active(void)
90909093
static int cpuset_cpu_inactive(unsigned int cpu)
90919094
{
90929095
if (!cpuhp_tasks_frozen) {
9093-
if (dl_cpu_busy(cpu))
9094-
return -EBUSY;
9096+
int ret = dl_cpu_busy(cpu, NULL);
9097+
9098+
if (ret)
9099+
return ret;
90959100
cpuset_update_active_cpus();
90969101
} else {
90979102
num_cpus_frozen++;

kernel/sched/deadline.c

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,41 +2992,6 @@ bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr)
29922992
}
29932993

29942994
#ifdef CONFIG_SMP
2995-
int dl_task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_allowed)
2996-
{
2997-
unsigned long flags, cap;
2998-
unsigned int dest_cpu;
2999-
struct dl_bw *dl_b;
3000-
bool overflow;
3001-
int ret;
3002-
3003-
dest_cpu = cpumask_any_and(cpu_active_mask, cs_cpus_allowed);
3004-
3005-
rcu_read_lock_sched();
3006-
dl_b = dl_bw_of(dest_cpu);
3007-
raw_spin_lock_irqsave(&dl_b->lock, flags);
3008-
cap = dl_bw_capacity(dest_cpu);
3009-
overflow = __dl_overflow(dl_b, cap, 0, p->dl.dl_bw);
3010-
if (overflow) {
3011-
ret = -EBUSY;
3012-
} else {
3013-
/*
3014-
* We reserve space for this task in the destination
3015-
* root_domain, as we can't fail after this point.
3016-
* We will free resources in the source root_domain
3017-
* later on (see set_cpus_allowed_dl()).
3018-
*/
3019-
int cpus = dl_bw_cpus(dest_cpu);
3020-
3021-
__dl_add(dl_b, p->dl.dl_bw, cpus);
3022-
ret = 0;
3023-
}
3024-
raw_spin_unlock_irqrestore(&dl_b->lock, flags);
3025-
rcu_read_unlock_sched();
3026-
3027-
return ret;
3028-
}
3029-
30302995
int dl_cpuset_cpumask_can_shrink(const struct cpumask *cur,
30312996
const struct cpumask *trial)
30322997
{
@@ -3048,7 +3013,7 @@ int dl_cpuset_cpumask_can_shrink(const struct cpumask *cur,
30483013
return ret;
30493014
}
30503015

3051-
bool dl_cpu_busy(unsigned int cpu)
3016+
int dl_cpu_busy(int cpu, struct task_struct *p)
30523017
{
30533018
unsigned long flags, cap;
30543019
struct dl_bw *dl_b;
@@ -3058,11 +3023,22 @@ bool dl_cpu_busy(unsigned int cpu)
30583023
dl_b = dl_bw_of(cpu);
30593024
raw_spin_lock_irqsave(&dl_b->lock, flags);
30603025
cap = dl_bw_capacity(cpu);
3061-
overflow = __dl_overflow(dl_b, cap, 0, 0);
3026+
overflow = __dl_overflow(dl_b, cap, 0, p ? p->dl.dl_bw : 0);
3027+
3028+
if (!overflow && p) {
3029+
/*
3030+
* We reserve space for this task in the destination
3031+
* root_domain, as we can't fail after this point.
3032+
* We will free resources in the source root_domain
3033+
* later on (see set_cpus_allowed_dl()).
3034+
*/
3035+
__dl_add(dl_b, p->dl.dl_bw, dl_bw_cpus(cpu));
3036+
}
3037+
30623038
raw_spin_unlock_irqrestore(&dl_b->lock, flags);
30633039
rcu_read_unlock_sched();
30643040

3065-
return overflow;
3041+
return overflow ? -EBUSY : 0;
30663042
}
30673043
#endif
30683044

kernel/sched/sched.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ extern void __setparam_dl(struct task_struct *p, const struct sched_attr *attr);
324324
extern void __getparam_dl(struct task_struct *p, struct sched_attr *attr);
325325
extern bool __checkparam_dl(const struct sched_attr *attr);
326326
extern bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr);
327-
extern int dl_task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_allowed);
328327
extern int dl_cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
329-
extern bool dl_cpu_busy(unsigned int cpu);
328+
extern int dl_cpu_busy(int cpu, struct task_struct *p);
330329

331330
#ifdef CONFIG_CGROUP_SCHED
332331

0 commit comments

Comments
 (0)