Skip to content

Commit 8b5f1c5

Browse files
lizf-oshtejun
authored andcommitted
cpuset: use effective cpumask to build sched domains
We're going to have separate user-configured masks and effective ones. Eventually configured masks can only be changed by writing cpuset.cpus and cpuset.mems, and they won't be restricted by parent cpuset. While effective masks reflect cpu/memory hotplug and hierachical restriction, and these are the real masks that apply to the tasks in the cpuset. We calculate effective mask this way: - top cpuset's effective_mask == online_mask, otherwise - cpuset's effective_mask == configured_mask & parent effective_mask, if the result is empty, it inherits parent effective mask. Those behavior changes are for default hierarchy only. For legacy hierarchy, effective_mask and configured_mask are the same, so we won't break old interfaces. We should partition sched domains according to effective_cpus, which is the real cpulist that takes effects on tasks in the cpuset. This won't introduce behavior change. v2: - Add a comment for the call of rebuild_sched_domains(), suggested by Tejun. Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 554b0d1 commit 8b5f1c5

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎kernel/cpuset.c‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,11 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
494494
#ifdef CONFIG_SMP
495495
/*
496496
* Helper routine for generate_sched_domains().
497-
* Do cpusets a, b have overlapping cpus_allowed masks?
497+
* Do cpusets a, b have overlapping effective cpus_allowed masks?
498498
*/
499499
static int cpusets_overlap(struct cpuset *a, struct cpuset *b)
500500
{
501-
return cpumask_intersects(a->cpus_allowed, b->cpus_allowed);
501+
return cpumask_intersects(a->effective_cpus, b->effective_cpus);
502502
}
503503

504504
static void
@@ -615,7 +615,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
615615
*dattr = SD_ATTR_INIT;
616616
update_domain_attr_tree(dattr, &top_cpuset);
617617
}
618-
cpumask_copy(doms[0], top_cpuset.cpus_allowed);
618+
cpumask_copy(doms[0], top_cpuset.effective_cpus);
619619

620620
goto done;
621621
}
@@ -719,7 +719,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
719719
struct cpuset *b = csa[j];
720720

721721
if (apn == b->pn) {
722-
cpumask_or(dp, dp, b->cpus_allowed);
722+
cpumask_or(dp, dp, b->effective_cpus);
723723
if (dattr)
724724
update_domain_attr_tree(dattr + nslot, b);
725725

@@ -771,7 +771,7 @@ static void rebuild_sched_domains_locked(void)
771771
* passing doms with offlined cpu to partition_sched_domains().
772772
* Anyways, hotplug work item will rebuild sched domains.
773773
*/
774-
if (!cpumask_equal(top_cpuset.cpus_allowed, cpu_active_mask))
774+
if (!cpumask_equal(top_cpuset.effective_cpus, cpu_active_mask))
775775
goto out;
776776

777777
/* Generate domain masks and attrs */
@@ -870,6 +870,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct cpumask *new_cpus)
870870
{
871871
struct cpuset *cp;
872872
struct cgroup_subsys_state *pos_css;
873+
bool need_rebuild_sched_domains = false;
873874

874875
rcu_read_lock();
875876
cpuset_for_each_descendant_pre(cp, pos_css, cs) {
@@ -903,10 +904,21 @@ static void update_cpumasks_hier(struct cpuset *cs, struct cpumask *new_cpus)
903904

904905
update_tasks_cpumask(cp);
905906

907+
/*
908+
* If the effective cpumask of any non-empty cpuset is changed,
909+
* we need to rebuild sched domains.
910+
*/
911+
if (!cpumask_empty(cp->cpus_allowed) &&
912+
is_sched_load_balance(cp))
913+
need_rebuild_sched_domains = true;
914+
906915
rcu_read_lock();
907916
css_put(&cp->css);
908917
}
909918
rcu_read_unlock();
919+
920+
if (need_rebuild_sched_domains)
921+
rebuild_sched_domains_locked();
910922
}
911923

912924
/**
@@ -919,7 +931,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
919931
const char *buf)
920932
{
921933
int retval;
922-
int is_load_balanced;
923934

924935
/* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */
925936
if (cs == &top_cpuset)
@@ -950,17 +961,12 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
950961
if (retval < 0)
951962
return retval;
952963

953-
is_load_balanced = is_sched_load_balance(trialcs);
954-
955964
mutex_lock(&callback_mutex);
956965
cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed);
957966
mutex_unlock(&callback_mutex);
958967

959968
/* use trialcs->cpus_allowed as a temp variable */
960969
update_cpumasks_hier(cs, trialcs->cpus_allowed);
961-
962-
if (is_load_balanced)
963-
rebuild_sched_domains_locked();
964970
return 0;
965971
}
966972

0 commit comments

Comments
 (0)