Skip to content

Commit 431c69f

Browse files
willdeaconPeter Zijlstra
authored andcommitted
cpuset: Honour task_cpu_possible_mask() in guarantee_online_cpus()
Asymmetric systems may not offer the same level of userspace ISA support across all CPUs, meaning that some applications cannot be executed by some CPUs. As a concrete example, upcoming arm64 big.LITTLE designs do not feature support for 32-bit applications on both clusters. Modify guarantee_online_cpus() to take task_cpu_possible_mask() into account when trying to find a suitable set of online CPUs for a given task. This will avoid passing an invalid mask to set_cpus_allowed_ptr() during ->attach() and will subsequently allow the cpuset hierarchy to be taken into account when forcefully overriding the affinity mask for a task which requires migration to a compatible CPU. Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d4b96fb commit 431c69f

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

include/linux/cpuset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static inline void cpuset_read_unlock(void) { }
185185
static inline void cpuset_cpus_allowed(struct task_struct *p,
186186
struct cpumask *mask)
187187
{
188-
cpumask_copy(mask, cpu_possible_mask);
188+
cpumask_copy(mask, task_cpu_possible_mask(p));
189189
}
190190

191191
static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)

kernel/cgroup/cpuset.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,29 @@ static inline bool is_in_v2_mode(void)
372372
}
373373

374374
/*
375-
* Return in pmask the portion of a cpusets's cpus_allowed that
376-
* are online. If none are online, walk up the cpuset hierarchy
377-
* until we find one that does have some online cpus.
375+
* Return in pmask the portion of a task's cpusets's cpus_allowed that
376+
* are online and are capable of running the task. If none are found,
377+
* walk up the cpuset hierarchy until we find one that does have some
378+
* appropriate cpus.
378379
*
379380
* One way or another, we guarantee to return some non-empty subset
380381
* of cpu_online_mask.
381382
*
382383
* Call with callback_lock or cpuset_mutex held.
383384
*/
384-
static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)
385+
static void guarantee_online_cpus(struct task_struct *tsk,
386+
struct cpumask *pmask)
385387
{
386-
while (!cpumask_intersects(cs->effective_cpus, cpu_online_mask)) {
388+
const struct cpumask *possible_mask = task_cpu_possible_mask(tsk);
389+
struct cpuset *cs;
390+
391+
if (WARN_ON(!cpumask_and(pmask, possible_mask, cpu_online_mask)))
392+
cpumask_copy(pmask, cpu_online_mask);
393+
394+
rcu_read_lock();
395+
cs = task_cs(tsk);
396+
397+
while (!cpumask_intersects(cs->effective_cpus, pmask)) {
387398
cs = parent_cs(cs);
388399
if (unlikely(!cs)) {
389400
/*
@@ -393,11 +404,13 @@ static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)
393404
* cpuset's effective_cpus is on its way to be
394405
* identical to cpu_online_mask.
395406
*/
396-
cpumask_copy(pmask, cpu_online_mask);
397-
return;
407+
goto out_unlock;
398408
}
399409
}
400-
cpumask_and(pmask, cs->effective_cpus, cpu_online_mask);
410+
cpumask_and(pmask, pmask, cs->effective_cpus);
411+
412+
out_unlock:
413+
rcu_read_unlock();
401414
}
402415

403416
/*
@@ -2199,15 +2212,13 @@ static void cpuset_attach(struct cgroup_taskset *tset)
21992212

22002213
percpu_down_write(&cpuset_rwsem);
22012214

2202-
/* prepare for attach */
2203-
if (cs == &top_cpuset)
2204-
cpumask_copy(cpus_attach, cpu_possible_mask);
2205-
else
2206-
guarantee_online_cpus(cs, cpus_attach);
2207-
22082215
guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
22092216

22102217
cgroup_taskset_for_each(task, css, tset) {
2218+
if (cs != &top_cpuset)
2219+
guarantee_online_cpus(task, cpus_attach);
2220+
else
2221+
cpumask_copy(cpus_attach, task_cpu_possible_mask(task));
22112222
/*
22122223
* can_attach beforehand should guarantee that this doesn't
22132224
* fail. TODO: have a better way to handle failure here
@@ -3302,9 +3313,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
33023313
unsigned long flags;
33033314

33043315
spin_lock_irqsave(&callback_lock, flags);
3305-
rcu_read_lock();
3306-
guarantee_online_cpus(task_cs(tsk), pmask);
3307-
rcu_read_unlock();
3316+
guarantee_online_cpus(tsk, pmask);
33083317
spin_unlock_irqrestore(&callback_lock, flags);
33093318
}
33103319

0 commit comments

Comments
 (0)