Skip to content

Commit

Permalink
cpuset: convert cpuset->cpus_allowed to cpumask_var_t
Browse files Browse the repository at this point in the history
Impact: use new cpumask API

This patch mainly does the following things:
- change cs->cpus_allowed from cpumask_t to cpumask_var_t
- call alloc_bootmem_cpumask_var() for top_cpuset in cpuset_init_early()
- call alloc_cpumask_var() for other cpusets
- replace cpus_xxx() to cpumask_xxx()

Signed-off-by: Li Zefan <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Rusty Russell <[email protected]>
Acked-by: Mike Travis <[email protected]>
Cc: Paul Menage <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Li Zefan authored and torvalds committed Jan 8, 2009
1 parent 645fcc9 commit 300ed6c
Showing 1 changed file with 60 additions and 40 deletions.
100 changes: 60 additions & 40 deletions kernel/cpuset.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct cpuset {
struct cgroup_subsys_state css;

unsigned long flags; /* "unsigned long" so bitops work */
cpumask_t cpus_allowed; /* CPUs allowed to tasks in cpuset */
cpumask_var_t cpus_allowed; /* CPUs allowed to tasks in cpuset */
nodemask_t mems_allowed; /* Memory Nodes allowed to tasks */

struct cpuset *parent; /* my parent */
Expand Down Expand Up @@ -195,8 +195,6 @@ static int cpuset_mems_generation;

static struct cpuset top_cpuset = {
.flags = ((1 << CS_CPU_EXCLUSIVE) | (1 << CS_MEM_EXCLUSIVE)),
.cpus_allowed = CPU_MASK_ALL,
.mems_allowed = NODE_MASK_ALL,
};

/*
Expand Down Expand Up @@ -278,7 +276,7 @@ static struct file_system_type cpuset_fs_type = {
};

/*
* Return in *pmask the portion of a cpusets's cpus_allowed that
* Return in pmask the portion of a cpusets's cpus_allowed that
* are online. If none are online, walk up the cpuset hierarchy
* until we find one that does have some online cpus. If we get
* all the way to the top and still haven't found any online cpus,
Expand All @@ -293,13 +291,13 @@ static struct file_system_type cpuset_fs_type = {

static void guarantee_online_cpus(const struct cpuset *cs, cpumask_t *pmask)
{
while (cs && !cpus_intersects(cs->cpus_allowed, cpu_online_map))
while (cs && !cpumask_intersects(cs->cpus_allowed, cpu_online_mask))
cs = cs->parent;
if (cs)
cpus_and(*pmask, cs->cpus_allowed, cpu_online_map);
cpumask_and(pmask, cs->cpus_allowed, cpu_online_mask);
else
*pmask = cpu_online_map;
BUG_ON(!cpus_intersects(*pmask, cpu_online_map));
cpumask_copy(pmask, cpu_online_mask);
BUG_ON(!cpumask_intersects(pmask, cpu_online_mask));
}

/*
Expand Down Expand Up @@ -409,7 +407,7 @@ void cpuset_update_task_memory_state(void)

static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
{
return cpus_subset(p->cpus_allowed, q->cpus_allowed) &&
return cpumask_subset(p->cpus_allowed, q->cpus_allowed) &&
nodes_subset(p->mems_allowed, q->mems_allowed) &&
is_cpu_exclusive(p) <= is_cpu_exclusive(q) &&
is_mem_exclusive(p) <= is_mem_exclusive(q);
Expand All @@ -421,7 +419,19 @@ static int is_cpuset_subset(const struct cpuset *p, const struct cpuset *q)
*/
static struct cpuset *alloc_trial_cpuset(const struct cpuset *cs)
{
return kmemdup(cs, sizeof(*cs), GFP_KERNEL);
struct cpuset *trial;

trial = kmemdup(cs, sizeof(*cs), GFP_KERNEL);
if (!trial)
return NULL;

if (!alloc_cpumask_var(&trial->cpus_allowed, GFP_KERNEL)) {
kfree(trial);
return NULL;
}
cpumask_copy(trial->cpus_allowed, cs->cpus_allowed);

return trial;
}

/**
Expand All @@ -430,6 +440,7 @@ static struct cpuset *alloc_trial_cpuset(const struct cpuset *cs)
*/
static void free_trial_cpuset(struct cpuset *trial)
{
free_cpumask_var(trial->cpus_allowed);
kfree(trial);
}

Expand Down Expand Up @@ -482,7 +493,7 @@ static int validate_change(const struct cpuset *cur, const struct cpuset *trial)
c = cgroup_cs(cont);
if ((is_cpu_exclusive(trial) || is_cpu_exclusive(c)) &&
c != cur &&
cpus_intersects(trial->cpus_allowed, c->cpus_allowed))
cpumask_intersects(trial->cpus_allowed, c->cpus_allowed))
return -EINVAL;
if ((is_mem_exclusive(trial) || is_mem_exclusive(c)) &&
c != cur &&
Expand All @@ -492,7 +503,7 @@ static int validate_change(const struct cpuset *cur, const struct cpuset *trial)

/* Cpusets with tasks can't have empty cpus_allowed or mems_allowed */
if (cgroup_task_count(cur->css.cgroup)) {
if (cpus_empty(trial->cpus_allowed) ||
if (cpumask_empty(trial->cpus_allowed) ||
nodes_empty(trial->mems_allowed)) {
return -ENOSPC;
}
Expand All @@ -507,7 +518,7 @@ static int validate_change(const struct cpuset *cur, const struct cpuset *trial)
*/
static int cpusets_overlap(struct cpuset *a, struct cpuset *b)
{
return cpus_intersects(a->cpus_allowed, b->cpus_allowed);
return cpumask_intersects(a->cpus_allowed, b->cpus_allowed);
}

static void
Expand All @@ -532,7 +543,7 @@ update_domain_attr_tree(struct sched_domain_attr *dattr, struct cpuset *c)
cp = list_first_entry(&q, struct cpuset, stack_list);
list_del(q.next);

if (cpus_empty(cp->cpus_allowed))
if (cpumask_empty(cp->cpus_allowed))
continue;

if (is_sched_load_balance(cp))
Expand Down Expand Up @@ -627,7 +638,7 @@ static int generate_sched_domains(cpumask_t **domains,
*dattr = SD_ATTR_INIT;
update_domain_attr_tree(dattr, &top_cpuset);
}
*doms = top_cpuset.cpus_allowed;
cpumask_copy(doms, top_cpuset.cpus_allowed);

ndoms = 1;
goto done;
Expand All @@ -646,7 +657,7 @@ static int generate_sched_domains(cpumask_t **domains,
cp = list_first_entry(&q, struct cpuset, stack_list);
list_del(q.next);

if (cpus_empty(cp->cpus_allowed))
if (cpumask_empty(cp->cpus_allowed))
continue;

/*
Expand Down Expand Up @@ -739,7 +750,7 @@ static int generate_sched_domains(cpumask_t **domains,
struct cpuset *b = csa[j];

if (apn == b->pn) {
cpus_or(*dp, *dp, b->cpus_allowed);
cpumask_or(dp, dp, b->cpus_allowed);
if (dattr)
update_domain_attr_tree(dattr + nslot, b);

Expand Down Expand Up @@ -848,7 +859,7 @@ void rebuild_sched_domains(void)
static int cpuset_test_cpumask(struct task_struct *tsk,
struct cgroup_scanner *scan)
{
return !cpus_equal(tsk->cpus_allowed,
return !cpumask_equal(&tsk->cpus_allowed,
(cgroup_cs(scan->cg))->cpus_allowed);
}

Expand All @@ -866,7 +877,7 @@ static int cpuset_test_cpumask(struct task_struct *tsk,
static void cpuset_change_cpumask(struct task_struct *tsk,
struct cgroup_scanner *scan)
{
set_cpus_allowed_ptr(tsk, &((cgroup_cs(scan->cg))->cpus_allowed));
set_cpus_allowed_ptr(tsk, ((cgroup_cs(scan->cg))->cpus_allowed));
}

/**
Expand Down Expand Up @@ -916,21 +927,21 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
* with tasks have cpus.
*/
if (!*buf) {
cpus_clear(trialcs->cpus_allowed);
cpumask_clear(trialcs->cpus_allowed);
} else {
retval = cpulist_parse(buf, &trialcs->cpus_allowed);
retval = cpulist_parse(buf, trialcs->cpus_allowed);
if (retval < 0)
return retval;

if (!cpus_subset(trialcs->cpus_allowed, cpu_online_map))
if (!cpumask_subset(trialcs->cpus_allowed, cpu_online_mask))
return -EINVAL;
}
retval = validate_change(cs, trialcs);
if (retval < 0)
return retval;

/* Nothing to do if the cpus didn't change */
if (cpus_equal(cs->cpus_allowed, trialcs->cpus_allowed))
if (cpumask_equal(cs->cpus_allowed, trialcs->cpus_allowed))
return 0;

retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
Expand All @@ -940,7 +951,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
is_load_balanced = is_sched_load_balance(trialcs);

mutex_lock(&callback_mutex);
cs->cpus_allowed = trialcs->cpus_allowed;
cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed);
mutex_unlock(&callback_mutex);

/*
Expand Down Expand Up @@ -1028,7 +1039,7 @@ static int update_tasks_nodemask(struct cpuset *cs, const nodemask_t *oldmem)
cpuset_being_rebound = cs; /* causes mpol_dup() rebind */

fudge = 10; /* spare mmarray[] slots */
fudge += cpus_weight(cs->cpus_allowed); /* imagine one fork-bomb/cpu */
fudge += cpumask_weight(cs->cpus_allowed);/* imagine 1 fork-bomb/cpu */
retval = -ENOMEM;

/*
Expand Down Expand Up @@ -1176,7 +1187,8 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val)

if (val != cs->relax_domain_level) {
cs->relax_domain_level = val;
if (!cpus_empty(cs->cpus_allowed) && is_sched_load_balance(cs))
if (!cpumask_empty(cs->cpus_allowed) &&
is_sched_load_balance(cs))
async_rebuild_sched_domains();
}

Expand Down Expand Up @@ -1219,7 +1231,7 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
cs->flags = trialcs->flags;
mutex_unlock(&callback_mutex);

if (!cpus_empty(trialcs->cpus_allowed) && balance_flag_changed)
if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed)
async_rebuild_sched_domains();

out:
Expand Down Expand Up @@ -1335,12 +1347,12 @@ static int cpuset_can_attach(struct cgroup_subsys *ss,
struct cpuset *cs = cgroup_cs(cont);
int ret = 0;

if (cpus_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
return -ENOSPC;

if (tsk->flags & PF_THREAD_BOUND) {
mutex_lock(&callback_mutex);
if (!cpus_equal(tsk->cpus_allowed, cs->cpus_allowed))
if (!cpumask_equal(&tsk->cpus_allowed, cs->cpus_allowed))
ret = -EINVAL;
mutex_unlock(&callback_mutex);
}
Expand Down Expand Up @@ -1516,7 +1528,7 @@ static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
int ret;

mutex_lock(&callback_mutex);
ret = cpulist_scnprintf(page, PAGE_SIZE, &cs->cpus_allowed);
ret = cpulist_scnprintf(page, PAGE_SIZE, cs->cpus_allowed);
mutex_unlock(&callback_mutex);

return ret;
Expand Down Expand Up @@ -1755,7 +1767,7 @@ static void cpuset_post_clone(struct cgroup_subsys *ss,
parent_cs = cgroup_cs(parent);

cs->mems_allowed = parent_cs->mems_allowed;
cs->cpus_allowed = parent_cs->cpus_allowed;
cpumask_copy(cs->cpus_allowed, parent_cs->cpus_allowed);
return;
}

Expand All @@ -1781,6 +1793,10 @@ static struct cgroup_subsys_state *cpuset_create(
cs = kmalloc(sizeof(*cs), GFP_KERNEL);
if (!cs)
return ERR_PTR(-ENOMEM);
if (!alloc_cpumask_var(&cs->cpus_allowed, GFP_KERNEL)) {
kfree(cs);
return ERR_PTR(-ENOMEM);
}

cpuset_update_task_memory_state();
cs->flags = 0;
Expand All @@ -1789,7 +1805,7 @@ static struct cgroup_subsys_state *cpuset_create(
if (is_spread_slab(parent))
set_bit(CS_SPREAD_SLAB, &cs->flags);
set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
cpus_clear(cs->cpus_allowed);
cpumask_clear(cs->cpus_allowed);
nodes_clear(cs->mems_allowed);
cs->mems_generation = cpuset_mems_generation++;
fmeter_init(&cs->fmeter);
Expand All @@ -1816,6 +1832,7 @@ static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont)
update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);

number_of_cpusets--;
free_cpumask_var(cs->cpus_allowed);
kfree(cs);
}

Expand All @@ -1839,6 +1856,8 @@ struct cgroup_subsys cpuset_subsys = {

int __init cpuset_init_early(void)
{
alloc_bootmem_cpumask_var(&top_cpuset.cpus_allowed);

top_cpuset.mems_generation = cpuset_mems_generation++;
return 0;
}
Expand All @@ -1854,7 +1873,7 @@ int __init cpuset_init(void)
{
int err = 0;

cpus_setall(top_cpuset.cpus_allowed);
cpumask_setall(top_cpuset.cpus_allowed);
nodes_setall(top_cpuset.mems_allowed);

fmeter_init(&top_cpuset.fmeter);
Expand Down Expand Up @@ -1943,7 +1962,7 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs)
* has online cpus, so can't be empty).
*/
parent = cs->parent;
while (cpus_empty(parent->cpus_allowed) ||
while (cpumask_empty(parent->cpus_allowed) ||
nodes_empty(parent->mems_allowed))
parent = parent->parent;

Expand Down Expand Up @@ -1984,21 +2003,22 @@ static void scan_for_empty_cpusets(struct cpuset *root)
}

/* Continue past cpusets with all cpus, mems online */
if (cpus_subset(cp->cpus_allowed, cpu_online_map) &&
if (cpumask_subset(cp->cpus_allowed, cpu_online_mask) &&
nodes_subset(cp->mems_allowed, node_states[N_HIGH_MEMORY]))
continue;

oldmems = cp->mems_allowed;

/* Remove offline cpus and mems from this cpuset. */
mutex_lock(&callback_mutex);
cpus_and(cp->cpus_allowed, cp->cpus_allowed, cpu_online_map);
cpumask_and(cp->cpus_allowed, cp->cpus_allowed,
cpu_online_mask);
nodes_and(cp->mems_allowed, cp->mems_allowed,
node_states[N_HIGH_MEMORY]);
mutex_unlock(&callback_mutex);

/* Move tasks from the empty cpuset to a parent */
if (cpus_empty(cp->cpus_allowed) ||
if (cpumask_empty(cp->cpus_allowed) ||
nodes_empty(cp->mems_allowed))
remove_tasks_in_empty_cpuset(cp);
else {
Expand Down Expand Up @@ -2039,7 +2059,7 @@ static int cpuset_track_online_cpus(struct notifier_block *unused_nb,
}

cgroup_lock();
top_cpuset.cpus_allowed = cpu_online_map;
cpumask_copy(top_cpuset.cpus_allowed, cpu_online_mask);
scan_for_empty_cpusets(&top_cpuset);
ndoms = generate_sched_domains(&doms, &attr);
cgroup_unlock();
Expand Down Expand Up @@ -2084,7 +2104,7 @@ static int cpuset_track_online_nodes(struct notifier_block *self,

void __init cpuset_init_smp(void)
{
top_cpuset.cpus_allowed = cpu_online_map;
cpumask_copy(top_cpuset.cpus_allowed, cpu_online_mask);
top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY];

hotcpu_notifier(cpuset_track_online_cpus, 0);
Expand All @@ -2096,7 +2116,7 @@ void __init cpuset_init_smp(void)
* @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed.
* @pmask: pointer to cpumask_t variable to receive cpus_allowed set.
*
* Description: Returns the cpumask_t cpus_allowed of the cpuset
* Description: Returns the cpumask_var_t cpus_allowed of the cpuset
* attached to the specified @tsk. Guaranteed to return some non-empty
* subset of cpu_online_map, even if this means going outside the
* tasks cpuset.
Expand Down

0 comments on commit 300ed6c

Please sign in to comment.