Skip to content

Commit be4c9dd

Browse files
lizf-oshtejun
authored andcommitted
cpuset: enable onlined cpu/node in effective masks
Firstly offline cpu1: # echo 0-1 > cpuset.cpus # echo 0 > /sys/devices/system/cpu/cpu1/online # cat cpuset.cpus 0-1 # cat cpuset.effective_cpus 0 Then online it: # echo 1 > /sys/devices/system/cpu/cpu1/online # cat cpuset.cpus 0-1 # cat cpuset.effective_cpus 0-1 And cpuset will bring it back to the effective mask. The implementation is quite straightforward. Instead of calculating the offlined cpus/mems and do updates, we just set the new effective_mask to online_mask & congifured_mask. This is a behavior change for default hierarchy, so legacy hierarchy won't be affected. v2: - make refactoring of cpuset_hotplug_update_tasks() as seperate patch, suggested by Tejun. - make hotplug_update_tasks_insane() use @new_cpus and @new_mems as hotplug_update_tasks_sane() does. Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 390a36a commit be4c9dd

1 file changed

Lines changed: 36 additions & 29 deletions

File tree

‎kernel/cpuset.c‎

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,26 +2080,27 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs)
20802080
}
20812081
}
20822082

2083-
static void hotplug_update_tasks_legacy(struct cpuset *cs,
2084-
struct cpumask *off_cpus,
2085-
nodemask_t *off_mems)
2083+
static void
2084+
hotplug_update_tasks_legacy(struct cpuset *cs,
2085+
struct cpumask *new_cpus, nodemask_t *new_mems,
2086+
bool cpus_updated, bool mems_updated)
20862087
{
20872088
bool is_empty;
20882089

20892090
mutex_lock(&callback_mutex);
2090-
cpumask_andnot(cs->cpus_allowed, cs->cpus_allowed, off_cpus);
2091-
cpumask_andnot(cs->effective_cpus, cs->effective_cpus, off_cpus);
2092-
nodes_andnot(cs->mems_allowed, cs->mems_allowed, *off_mems);
2093-
nodes_andnot(cs->effective_mems, cs->effective_mems, *off_mems);
2091+
cpumask_copy(cs->cpus_allowed, new_cpus);
2092+
cpumask_copy(cs->effective_cpus, new_cpus);
2093+
cs->mems_allowed = *new_mems;
2094+
cs->effective_mems = *new_mems;
20942095
mutex_unlock(&callback_mutex);
20952096

20962097
/*
20972098
* Don't call update_tasks_cpumask() if the cpuset becomes empty,
20982099
* as the tasks will be migratecd to an ancestor.
20992100
*/
2100-
if (!cpumask_empty(off_cpus) && !cpumask_empty(cs->cpus_allowed))
2101+
if (cpus_updated && !cpumask_empty(cs->cpus_allowed))
21012102
update_tasks_cpumask(cs);
2102-
if (!nodes_empty(*off_mems) && !nodes_empty(cs->mems_allowed))
2103+
if (mems_updated && !nodes_empty(cs->mems_allowed))
21032104
update_tasks_nodemask(cs);
21042105

21052106
is_empty = cpumask_empty(cs->cpus_allowed) ||
@@ -2118,24 +2119,24 @@ static void hotplug_update_tasks_legacy(struct cpuset *cs,
21182119
mutex_lock(&cpuset_mutex);
21192120
}
21202121

2121-
static void hotplug_update_tasks(struct cpuset *cs,
2122-
struct cpumask *off_cpus,
2123-
nodemask_t *off_mems)
2122+
static void
2123+
hotplug_update_tasks(struct cpuset *cs,
2124+
struct cpumask *new_cpus, nodemask_t *new_mems,
2125+
bool cpus_updated, bool mems_updated)
21242126
{
2127+
if (cpumask_empty(new_cpus))
2128+
cpumask_copy(new_cpus, parent_cs(cs)->effective_cpus);
2129+
if (nodes_empty(*new_mems))
2130+
*new_mems = parent_cs(cs)->effective_mems;
2131+
21252132
mutex_lock(&callback_mutex);
2126-
cpumask_andnot(cs->effective_cpus, cs->effective_cpus, off_cpus);
2127-
if (cpumask_empty(cs->effective_cpus))
2128-
cpumask_copy(cs->effective_cpus,
2129-
parent_cs(cs)->effective_cpus);
2130-
2131-
nodes_andnot(cs->effective_mems, cs->effective_mems, *off_mems);
2132-
if (nodes_empty(cs->effective_mems))
2133-
cs->effective_mems = parent_cs(cs)->effective_mems;
2133+
cpumask_copy(cs->effective_cpus, new_cpus);
2134+
cs->effective_mems = *new_mems;
21342135
mutex_unlock(&callback_mutex);
21352136

2136-
if (!cpumask_empty(off_cpus))
2137+
if (cpus_updated)
21372138
update_tasks_cpumask(cs);
2138-
if (!nodes_empty(*off_mems))
2139+
if (mems_updated)
21392140
update_tasks_nodemask(cs);
21402141
}
21412142

@@ -2149,8 +2150,10 @@ static void hotplug_update_tasks(struct cpuset *cs,
21492150
*/
21502151
static void cpuset_hotplug_update_tasks(struct cpuset *cs)
21512152
{
2152-
static cpumask_t off_cpus;
2153-
static nodemask_t off_mems;
2153+
static cpumask_t new_cpus;
2154+
static nodemask_t new_mems;
2155+
bool cpus_updated;
2156+
bool mems_updated;
21542157
retry:
21552158
wait_event(cpuset_attach_wq, cs->attach_in_progress == 0);
21562159

@@ -2165,14 +2168,18 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
21652168
goto retry;
21662169
}
21672170

2168-
cpumask_andnot(&off_cpus, cs->effective_cpus,
2169-
top_cpuset.effective_cpus);
2170-
nodes_andnot(off_mems, cs->effective_mems, top_cpuset.effective_mems);
2171+
cpumask_and(&new_cpus, cs->cpus_allowed, parent_cs(cs)->effective_cpus);
2172+
nodes_and(new_mems, cs->mems_allowed, parent_cs(cs)->effective_mems);
2173+
2174+
cpus_updated = !cpumask_equal(&new_cpus, cs->effective_cpus);
2175+
mems_updated = !nodes_equal(new_mems, cs->effective_mems);
21712176

21722177
if (cgroup_on_dfl(cs->css.cgroup))
2173-
hotplug_update_tasks(cs, &off_cpus, &off_mems);
2178+
hotplug_update_tasks(cs, &new_cpus, &new_mems,
2179+
cpus_updated, mems_updated);
21742180
else
2175-
hotplug_update_tasks_legacy(cs, &off_cpus, &off_mems);
2181+
hotplug_update_tasks_legacy(cs, &new_cpus, &new_mems,
2182+
cpus_updated, mems_updated);
21762183

21772184
mutex_unlock(&cpuset_mutex);
21782185
}

0 commit comments

Comments
 (0)