Lines Matching +full:cost +full:- +full:effective

7  *  Copyright (C) 2004-2007 Silicon Graphics, Inc.
11 * sysfs is Copyright (c) 2001-3 Patrick Mochel
13 * 2003-10-10 Written by Simon Derr.
14 * 2003-10-22 Updates by Stephen Hemminger.
15 * 2004 May-July Rework by Paul Jackson.
24 #include "cgroup-internal.h"
25 #include "cpuset-internal.h"
50 * node binding, add this key to provide a quick low-cost judgment
68 * Exclusive CPUs distributed out to sub-partitions of top_cpuset
89 * - update_partition_sd_lb()
90 * - remote_partition_check()
91 * - update_cpumasks_hier()
92 * - cpuset_update_flag()
93 * - cpuset_hotplug_update_tasks()
94 * - cpuset_handle_hotplug()
98 * Note that update_relax_domain_level() in cpuset-v1.c can still call
106 * 0 - member (not a partition root)
107 * 1 - partition root
108 * 2 - partition root without load balancing (isolated)
109 * -1 - invalid partition root
110 * -2 - invalid isolated partition root
112 * There are 2 types of partitions - local or remote. Local partitions are
126 #define PRS_INVALID_ROOT -1
127 #define PRS_INVALID_ISOLATED -2
147 cs->nr_deadline_tasks++; in inc_dl_tasks_cs()
154 cs->nr_deadline_tasks--; in dec_dl_tasks_cs()
159 return cs->partition_root_state > 0; in is_partition_valid()
164 return cs->partition_root_state < 0; in is_partition_invalid()
172 if (cs->partition_root_state > 0) in make_partition_invalid()
173 cs->partition_root_state = -cs->partition_root_state; in make_partition_invalid()
181 if (old_prs == cs->partition_root_state) in notify_partition_change()
183 cgroup_file_notify(&cs->partition_file); in notify_partition_change()
187 WRITE_ONCE(cs->prs_err, PERR_NONE); in notify_partition_change()
194 .relax_domain_level = -1,
199 * There are two global locks guarding cpuset structures - cpuset_mutex and
203 * paths that rely on priority inheritance (e.g. scheduler - on RT) for
220 * If a task is only holding callback_lock, then it has read-only
228 * small pieces of code, such as when reading out possibly multi-word
272 * decrease cs->attach_in_progress.
273 * wake_up cpuset_attach_wq if cs->attach_in_progress==0.
279 cs->attach_in_progress--; in dec_attach_in_progress_locked()
280 if (!cs->attach_in_progress) in dec_attach_in_progress_locked()
302 * requested and won't be changed by hotplug events. Only the effective
308 (cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE); in is_in_v2_mode()
312 * partition_is_populated - check if partition has tasks
318 * be non-NULL when this cpuset is going to become a partition itself.
326 if (cs->css.cgroup->nr_populated_csets) in partition_is_populated()
328 if (!excluded_child && !cs->nr_subparts) in partition_is_populated()
329 return cgroup_is_populated(cs->css.cgroup); in partition_is_populated()
337 if (cgroup_is_populated(child->css.cgroup)) { in partition_is_populated()
352 * One way or another, we guarantee to return some non-empty subset
369 while (!cpumask_intersects(cs->effective_cpus, pmask)) in guarantee_online_cpus()
372 cpumask_and(pmask, pmask, cs->effective_cpus); in guarantee_online_cpus()
382 * One way or another, we guarantee to return some non-empty subset
389 while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY])) in guarantee_online_mems()
391 nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]); in guarantee_online_mems()
395 * alloc_cpumasks - allocate three cpumasks for cpuset
398 * Return: 0 if successful, -ENOMEM otherwise.
400 * Only one of the two input arguments should be non-NULL.
407 pmask1 = &cs->cpus_allowed; in alloc_cpumasks()
408 pmask2 = &cs->effective_cpus; in alloc_cpumasks()
409 pmask3 = &cs->effective_xcpus; in alloc_cpumasks()
410 pmask4 = &cs->exclusive_cpus; in alloc_cpumasks()
412 pmask1 = &tmp->new_cpus; in alloc_cpumasks()
413 pmask2 = &tmp->addmask; in alloc_cpumasks()
414 pmask3 = &tmp->delmask; in alloc_cpumasks()
419 return -ENOMEM; in alloc_cpumasks()
439 return -ENOMEM; in alloc_cpumasks()
443 * free_cpumasks - free cpumasks in a tmpmasks structure
450 free_cpumask_var(cs->cpus_allowed); in free_cpumasks()
451 free_cpumask_var(cs->effective_cpus); in free_cpumasks()
452 free_cpumask_var(cs->effective_xcpus); in free_cpumasks()
453 free_cpumask_var(cs->exclusive_cpus); in free_cpumasks()
456 free_cpumask_var(tmp->new_cpus); in free_cpumasks()
457 free_cpumask_var(tmp->addmask); in free_cpumasks()
458 free_cpumask_var(tmp->delmask); in free_cpumasks()
463 * alloc_trial_cpuset - allocate a trial cpuset
479 cpumask_copy(trial->cpus_allowed, cs->cpus_allowed); in alloc_trial_cpuset()
480 cpumask_copy(trial->effective_cpus, cs->effective_cpus); in alloc_trial_cpuset()
481 cpumask_copy(trial->effective_xcpus, cs->effective_xcpus); in alloc_trial_cpuset()
482 cpumask_copy(trial->exclusive_cpus, cs->exclusive_cpus); in alloc_trial_cpuset()
487 * free_cpuset - free the cpuset
499 return cpumask_empty(cs->exclusive_cpus) ? cs->cpus_allowed in user_xcpus()
500 : cs->exclusive_cpus; in user_xcpus()
505 return cpumask_empty(cs->cpus_allowed) && in xcpus_empty()
506 cpumask_empty(cs->exclusive_cpus); in xcpus_empty()
510 * cpusets_are_exclusive() - check if two cpusets are exclusive
525 * validate_change() - Used to validate that any proposed cpuset change
533 * 'cur' is the address of an actual, in-use cpuset. Operations
541 * Return 0 if valid, -errno if not.
564 * Cpusets with tasks - existing or newly being attached - can't in validate_change()
567 ret = -ENOSPC; in validate_change()
568 if ((cgroup_is_populated(cur->css.cgroup) || cur->attach_in_progress)) { in validate_change()
569 if (!cpumask_empty(cur->cpus_allowed) && in validate_change()
570 cpumask_empty(trial->cpus_allowed)) in validate_change()
572 if (!nodes_empty(cur->mems_allowed) && in validate_change()
573 nodes_empty(trial->mems_allowed)) in validate_change()
586 * for non-isolated partition root. At this point, the target in validate_change()
594 ret = -EBUSY; in validate_change()
596 !cpuset_cpumask_can_shrink(cur->effective_cpus, user_xcpus(trial))) in validate_change()
603 ret = -EINVAL; in validate_change()
610 txset = !cpumask_empty(trial->exclusive_cpus); in validate_change()
611 cxset = !cpumask_empty(c->exclusive_cpus); in validate_change()
626 xcpus = trial->exclusive_cpus; in validate_change()
627 acpus = c->cpus_allowed; in validate_change()
629 xcpus = c->exclusive_cpus; in validate_change()
630 acpus = trial->cpus_allowed; in validate_change()
636 nodes_intersects(trial->mems_allowed, c->mems_allowed)) in validate_change()
649 * Do cpusets a, b have overlapping effective cpus_allowed masks?
653 return cpumask_intersects(a->effective_cpus, b->effective_cpus); in cpusets_overlap()
659 if (dattr->relax_domain_level < c->relax_domain_level) in update_domain_attr()
660 dattr->relax_domain_level = c->relax_domain_level; in update_domain_attr()
673 if (cpumask_empty(cp->cpus_allowed)) { in update_domain_attr_tree()
687 /* jump label reference count + the top-level cpuset */ in nr_cpusets()
695 * A 'partial partition' is a set of non-overlapping subsets whose
702 * See "What is sched_load_balance" in Documentation/admin-guide/cgroup-v1/cpusets.rst
713 * cp - cpuset pointer, used (together with pos_css) to perform a
714 * top-down scan of all cpusets. For our purposes, rebuilding
717 * csa - (for CpuSet Array) Array of pointers to all the cpusets
724 * doms - Conversion of 'csa' to an array of cpumasks, for passing to
734 * and merging them using a union-find algorithm.
744 struct cpuset *cp; /* top-down scan of cpusets */ in generate_sched_domains()
804 if (!cpumask_empty(cp->cpus_allowed) && in generate_sched_domains()
806 cpumask_intersects(cp->cpus_allowed, in generate_sched_domains()
811 !cpumask_empty(cp->effective_cpus)) in generate_sched_domains()
821 * non-empty effective_cpus will be saved into csn[]. in generate_sched_domains()
823 if ((cp->partition_root_state == PRS_ROOT) && in generate_sched_domains()
824 !cpumask_empty(cp->effective_cpus)) in generate_sched_domains()
831 if (!is_partition_valid(cp) && cpumask_empty(cp->exclusive_cpus)) in generate_sched_domains()
844 uf_node_init(&csa[i]->node); in generate_sched_domains()
855 uf_union(&csa[i]->node, &csa[j]->node); in generate_sched_domains()
862 if (uf_find(&csa[i]->node) == &csa[i]->node) in generate_sched_domains()
883 * to SD_ATTR_INIT. Also non-isolating partition root CPUs are a in generate_sched_domains()
893 cpumask_and(doms[i], csa[i]->effective_cpus, in generate_sched_domains()
896 cpumask_copy(doms[i], csa[i]->effective_cpus); in generate_sched_domains()
906 if (uf_find(&csa[j]->node) == &csa[i]->node) { in generate_sched_domains()
915 cpumask_or(dp, dp, csa[j]->effective_cpus); in generate_sched_domains()
946 if (cs->nr_deadline_tasks == 0) in dl_update_tasks_root_domain()
949 css_task_iter_start(&cs->css, 0, &it); in dl_update_tasks_root_domain()
976 if (cpumask_empty(cs->effective_cpus)) { in dl_rebuild_rd_accounting()
981 css_get(&cs->css); in dl_rebuild_rd_accounting()
988 css_put(&cs->css); in dl_rebuild_rd_accounting()
1006 * If the flag 'sched_load_balance' of any cpuset with non-empty
1008 * which has that flag enabled, or if any cpuset with a non-empty
1031 * With no CPUs in any subpartitions, top_cpuset's effective CPUs in rebuild_sched_domains_locked()
1040 * With subpartition CPUs, however, the effective CPUs of a partition in rebuild_sched_domains_locked()
1051 if (!cpumask_subset(cs->effective_cpus, in rebuild_sched_domains_locked()
1087 * cpuset_update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
1092 * effective cpuset's. As this function is called with cpuset_mutex held,
1103 css_task_iter_start(&cs->css, 0, &it); in cpuset_update_tasks_cpumask()
1115 cpumask_and(new_cpus, possible_mask, cs->effective_cpus); in cpuset_update_tasks_cpumask()
1123 * compute_effective_cpumask - Compute the effective cpumask of the cpuset
1133 cpumask_and(new_cpus, cs->cpus_allowed, parent->effective_cpus); in compute_effective_cpumask()
1178 int new_prs = cs->partition_root_state; in update_partition_sd_lb()
1194 set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); in update_partition_sd_lb()
1196 clear_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); in update_partition_sd_lb()
1204 * tasks_nocpu_error - Return true if tasks will have no effective_cpus
1212 return (cpumask_subset(parent->effective_cpus, xcpus) && in tasks_nocpu_error()
1227 cs->nr_subparts = 0; in reset_partition_data()
1228 if (cpumask_empty(cs->exclusive_cpus)) { in reset_partition_data()
1229 cpumask_clear(cs->effective_xcpus); in reset_partition_data()
1231 clear_bit(CS_CPU_EXCLUSIVE, &cs->flags); in reset_partition_data()
1233 if (!cpumask_and(cs->effective_cpus, parent->effective_cpus, cs->cpus_allowed)) in reset_partition_data()
1234 cpumask_copy(cs->effective_cpus, parent->effective_cpus); in reset_partition_data()
1238 * partition_xcpus_newstate - Exclusive CPUs state change
1253 * partition_xcpus_add - Add new exclusive CPUs to partition
1275 isolcpus_updated = (new_prs != parent->partition_root_state); in partition_xcpus_add()
1277 partition_xcpus_newstate(parent->partition_root_state, new_prs, in partition_xcpus_add()
1280 cpumask_andnot(parent->effective_cpus, parent->effective_cpus, xcpus); in partition_xcpus_add()
1285 * partition_xcpus_del - Remove exclusive CPUs from partition
1306 isolcpus_updated = (old_prs != parent->partition_root_state); in partition_xcpus_del()
1308 partition_xcpus_newstate(old_prs, parent->partition_root_state, in partition_xcpus_del()
1312 cpumask_or(parent->effective_cpus, parent->effective_cpus, xcpus); in partition_xcpus_del()
1330 * cpuset_cpu_is_isolated - Check if the given CPU is isolated
1341 * compute_effective_exclusive_cpumask - compute effective exclusive CPUs
1343 * @xcpus: effective exclusive CPUs value to be set
1355 xcpus = cs->effective_xcpus; in compute_effective_exclusive_cpumask()
1357 return cpumask_and(xcpus, user_xcpus(cs), parent->effective_xcpus); in compute_effective_exclusive_cpumask()
1362 return !list_empty(&cs->remote_sibling); in is_remote_partition()
1371 * remote_partition_enable - Enable current cpuset as a remote partition root
1399 compute_effective_exclusive_cpumask(cs, tmp->new_cpus); in remote_partition_enable()
1400 if (cpumask_empty(tmp->new_cpus) || in remote_partition_enable()
1401 cpumask_intersects(tmp->new_cpus, subpartitions_cpus) || in remote_partition_enable()
1402 cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus)) in remote_partition_enable()
1406 isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus); in remote_partition_enable()
1407 list_add(&cs->remote_sibling, &remote_children); in remote_partition_enable()
1414 cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus); in remote_partition_enable()
1420 * remote_partition_disable - Remove current cpuset from remote partition list
1432 compute_effective_exclusive_cpumask(cs, tmp->new_cpus); in remote_partition_disable()
1434 WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, subpartitions_cpus)); in remote_partition_disable()
1437 list_del_init(&cs->remote_sibling); in remote_partition_disable()
1438 isolcpus_updated = partition_xcpus_del(cs->partition_root_state, in remote_partition_disable()
1439 NULL, tmp->new_cpus); in remote_partition_disable()
1440 cs->partition_root_state = -cs->partition_root_state; in remote_partition_disable()
1441 if (!cs->prs_err) in remote_partition_disable()
1442 cs->prs_err = PERR_INVCPUS; in remote_partition_disable()
1450 cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus); in remote_partition_disable()
1455 * remote_cpus_update - cpus_exclusive change of remote partition
1467 int prs = cs->partition_root_state; in remote_cpus_update()
1473 WARN_ON_ONCE(!cpumask_subset(cs->effective_xcpus, subpartitions_cpus)); in remote_cpus_update()
1478 adding = cpumask_andnot(tmp->addmask, newmask, cs->effective_xcpus); in remote_cpus_update()
1479 deleting = cpumask_andnot(tmp->delmask, cs->effective_xcpus, newmask); in remote_cpus_update()
1487 cpumask_intersects(tmp->addmask, subpartitions_cpus) || in remote_cpus_update()
1488 cpumask_subset(top_cpuset.effective_cpus, tmp->addmask))) in remote_cpus_update()
1493 isolcpus_updated += partition_xcpus_add(prs, NULL, tmp->addmask); in remote_cpus_update()
1495 isolcpus_updated += partition_xcpus_del(prs, NULL, tmp->delmask); in remote_cpus_update()
1502 cpuset_update_tasks_cpumask(&top_cpuset, tmp->new_cpus); in remote_cpus_update()
1511 * remote_partition_check - check if a child remote partition needs update
1527 * Compute the effective exclusive CPUs that will be deleted. in remote_partition_check()
1529 if (!cpumask_andnot(delmask, cs->effective_xcpus, newmask) || in remote_partition_check()
1543 if (cpumask_intersects(child->effective_cpus, delmask)) { in remote_partition_check()
1552 * prstate_housekeeping_conflict - check for partition & housekeeping conflicts
1572 * update_parent_effective_cpumask - update effective_cpus mask of parent cpuset
1579 * For partcmd_enable*, the cpuset is being transformed from a non-partition
1586 * root back to a non-partition root. Any CPUs in effective_xcpus will be
1629 old_prs = new_prs = cs->partition_root_state; in update_parent_effective_cpumask()
1640 adding = cpumask_and(tmp->addmask, in update_parent_effective_cpumask()
1641 xcpus, parent->effective_xcpus); in update_parent_effective_cpumask()
1643 new_prs = -old_prs; in update_parent_effective_cpumask()
1644 subparts_delta--; in update_parent_effective_cpumask()
1670 !cpumask_intersects(xcpus, parent->effective_xcpus)) in update_parent_effective_cpumask()
1683 cpumask_copy(tmp->delmask, xcpus); in update_parent_effective_cpumask()
1693 cpumask_and(tmp->addmask, xcpus, parent->effective_xcpus); in update_parent_effective_cpumask()
1695 subparts_delta--; in update_parent_effective_cpumask()
1715 * & parent->effective_xcpus in update_parent_effective_cpumask()
1717 * & parent->effective_xcpus in update_parent_effective_cpumask()
1720 * delmask = newmask & parent->effective_xcpus in update_parent_effective_cpumask()
1724 deleting = cpumask_and(tmp->delmask, in update_parent_effective_cpumask()
1725 newmask, parent->effective_xcpus); in update_parent_effective_cpumask()
1727 cpumask_andnot(tmp->addmask, xcpus, newmask); in update_parent_effective_cpumask()
1728 adding = cpumask_and(tmp->addmask, tmp->addmask, in update_parent_effective_cpumask()
1729 parent->effective_xcpus); in update_parent_effective_cpumask()
1731 cpumask_andnot(tmp->delmask, newmask, xcpus); in update_parent_effective_cpumask()
1732 deleting = cpumask_and(tmp->delmask, tmp->delmask, in update_parent_effective_cpumask()
1733 parent->effective_xcpus); in update_parent_effective_cpumask()
1740 !cpumask_intersects(tmp->addmask, cpu_active_mask))) { in update_parent_effective_cpumask()
1743 adding = cpumask_and(tmp->addmask, in update_parent_effective_cpumask()
1744 xcpus, parent->effective_xcpus); in update_parent_effective_cpumask()
1750 * delmask = effective_xcpus & parent->effective_cpus in update_parent_effective_cpumask()
1760 * its effective CPUs will have to be distributed out. in update_parent_effective_cpumask()
1766 adding = cpumask_and(tmp->addmask, in update_parent_effective_cpumask()
1767 xcpus, parent->effective_xcpus); in update_parent_effective_cpumask()
1769 cpumask_subset(xcpus, parent->effective_xcpus)) { in update_parent_effective_cpumask()
1789 deleting = cpumask_and(tmp->delmask, in update_parent_effective_cpumask()
1790 xcpus, parent->effective_cpus); in update_parent_effective_cpumask()
1798 WRITE_ONCE(cs->prs_err, part_error); in update_parent_effective_cpumask()
1805 switch (cs->partition_root_state) { in update_parent_effective_cpumask()
1809 new_prs = -old_prs; in update_parent_effective_cpumask()
1810 subparts_delta--; in update_parent_effective_cpumask()
1816 new_prs = -old_prs; in update_parent_effective_cpumask()
1848 cs->partition_root_state = new_prs; in update_parent_effective_cpumask()
1850 cs->nr_subparts = 0; in update_parent_effective_cpumask()
1858 tmp->addmask); in update_parent_effective_cpumask()
1861 tmp->delmask); in update_parent_effective_cpumask()
1864 parent->nr_subparts += subparts_delta; in update_parent_effective_cpumask()
1865 WARN_ON_ONCE(parent->nr_subparts < 0); in update_parent_effective_cpumask()
1874 cpuset_update_tasks_cpumask(parent, tmp->addmask); in update_parent_effective_cpumask()
1891 * compute_partition_effective_cpumask - compute effective_cpus for partition
1929 child->prs_err = 0; in compute_partition_effective_cpumask()
1930 if (!cpumask_subset(child->effective_xcpus, in compute_partition_effective_cpumask()
1931 cs->effective_xcpus)) in compute_partition_effective_cpumask()
1932 child->prs_err = PERR_INVCPUS; in compute_partition_effective_cpumask()
1934 cpumask_subset(new_ecpus, child->effective_xcpus)) in compute_partition_effective_cpumask()
1935 child->prs_err = PERR_NOCPUS; in compute_partition_effective_cpumask()
1937 if (child->prs_err) { in compute_partition_effective_cpumask()
1938 int old_prs = child->partition_root_state; in compute_partition_effective_cpumask()
1945 cs->nr_subparts--; in compute_partition_effective_cpumask()
1946 child->nr_subparts = 0; in compute_partition_effective_cpumask()
1952 child->effective_xcpus); in compute_partition_effective_cpumask()
1958 * update_cpumasks_hier - Update effective cpumasks and tasks in the subtree
1963 * When configured cpumask is changed, the effective cpumasks of this cpuset
1997 if (!cpumask_empty(cp->exclusive_cpus) && (cp != cs)) { in update_cpumasks_hier()
2003 old_prs = new_prs = cp->partition_root_state; in update_cpumasks_hier()
2006 compute_partition_effective_cpumask(cp, tmp->new_cpus); in update_cpumasks_hier()
2008 compute_effective_cpumask(tmp->new_cpus, cp, parent); in update_cpumasks_hier()
2015 if (is_partition_valid(cp) && cpumask_empty(tmp->new_cpus)) { in update_cpumasks_hier()
2021 * If it becomes empty, inherit the effective mask of the in update_cpumasks_hier()
2026 if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus)) in update_cpumasks_hier()
2027 cpumask_copy(tmp->new_cpus, parent->effective_cpus); in update_cpumasks_hier()
2039 if (!cp->partition_root_state && !force && in update_cpumasks_hier()
2040 cpumask_equal(tmp->new_cpus, cp->effective_cpus) && in update_cpumasks_hier()
2055 switch (parent->partition_root_state) { in update_cpumasks_hier()
2068 new_prs = -cp->partition_root_state; in update_cpumasks_hier()
2069 WRITE_ONCE(cp->prs_err, in update_cpumasks_hier()
2076 if (!css_tryget_online(&cp->css)) in update_cpumasks_hier()
2086 new_prs = cp->partition_root_state; in update_cpumasks_hier()
2090 cpumask_copy(cp->effective_cpus, tmp->new_cpus); in update_cpumasks_hier()
2091 cp->partition_root_state = new_prs; in update_cpumasks_hier()
2096 if ((new_prs > 0) && cpumask_empty(cp->exclusive_cpus)) in update_cpumasks_hier()
2097 cpumask_and(cp->effective_xcpus, in update_cpumasks_hier()
2098 cp->cpus_allowed, parent->effective_xcpus); in update_cpumasks_hier()
2106 !cpumask_equal(cp->cpus_allowed, cp->effective_cpus)); in update_cpumasks_hier()
2108 cpuset_update_tasks_cpumask(cp, cp->effective_cpus); in update_cpumasks_hier()
2118 set_bit(CS_SCHED_LOAD_BALANCE, &cp->flags); in update_cpumasks_hier()
2120 clear_bit(CS_SCHED_LOAD_BALANCE, &cp->flags); in update_cpumasks_hier()
2124 * On legacy hierarchy, if the effective cpumask of any non- in update_cpumasks_hier()
2129 if (!cpumask_empty(cp->cpus_allowed) && in update_cpumasks_hier()
2135 css_put(&cp->css); in update_cpumasks_hier()
2144 * update_sibling_cpumasks - Update siblings cpumasks
2174 compute_effective_cpumask(tmp->new_cpus, sibling, in update_sibling_cpumasks()
2176 if (cpumask_equal(tmp->new_cpus, sibling->effective_cpus)) in update_sibling_cpumasks()
2179 if (!css_tryget_online(&sibling->css)) in update_sibling_cpumasks()
2185 css_put(&sibling->css); in update_sibling_cpumasks()
2191 * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
2204 int old_prs = cs->partition_root_state; in update_cpumask()
2206 /* top_cpuset.cpus_allowed tracks cpu_online_mask; it's read-only */ in update_cpumask()
2208 return -EACCES; in update_cpumask()
2217 cpumask_clear(trialcs->cpus_allowed); in update_cpumask()
2218 if (cpumask_empty(trialcs->exclusive_cpus)) in update_cpumask()
2219 cpumask_clear(trialcs->effective_xcpus); in update_cpumask()
2221 retval = cpulist_parse(buf, trialcs->cpus_allowed); in update_cpumask()
2225 if (!cpumask_subset(trialcs->cpus_allowed, in update_cpumask()
2227 return -EINVAL; in update_cpumask()
2232 * trialcs->effective_xcpus is used as a temporary cpumask in update_cpumask()
2235 if (!cpumask_empty(trialcs->exclusive_cpus) || is_partition_valid(cs)) in update_cpumask()
2240 if (cpumask_equal(cs->cpus_allowed, trialcs->cpus_allowed)) in update_cpumask()
2244 return -ENOMEM; in update_cpumask()
2248 cpumask_empty(trialcs->effective_xcpus)) { in update_cpumask()
2250 cs->prs_err = PERR_INVCPUS; in update_cpumask()
2251 } else if (prstate_housekeeping_conflict(old_prs, trialcs->effective_xcpus)) { in update_cpumask()
2253 cs->prs_err = PERR_HKEEPING; in update_cpumask()
2254 } else if (tasks_nocpu_error(parent, cs, trialcs->effective_xcpus)) { in update_cpumask()
2256 cs->prs_err = PERR_NOCPUS; in update_cpumask()
2264 force = !cpumask_equal(cs->effective_xcpus, trialcs->effective_xcpus); in update_cpumask()
2268 if ((retval == -EINVAL) && cpuset_v2()) { in update_cpumask()
2273 * The -EINVAL error code indicates that partition sibling in update_cpumask()
2285 cpumask_intersects(xcpus, cp->effective_xcpus)) { in update_cpumask()
2300 struct cpumask *xcpus = trialcs->effective_xcpus; in update_cpumask()
2303 xcpus = trialcs->cpus_allowed; in update_cpumask()
2316 } else if (!cpumask_empty(cs->exclusive_cpus)) { in update_cpumask()
2318 * Use trialcs->effective_cpus as a temp cpumask in update_cpumask()
2320 remote_partition_check(cs, trialcs->effective_xcpus, in update_cpumask()
2321 trialcs->effective_cpus, &tmp); in update_cpumask()
2325 cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed); in update_cpumask()
2326 cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus); in update_cpumask()
2335 if (cs->partition_root_state) in update_cpumask()
2343 * update_exclusive_cpumask - update the exclusive_cpus mask of a cpuset
2358 int old_prs = cs->partition_root_state; in update_exclusive_cpumask()
2361 cpumask_clear(trialcs->exclusive_cpus); in update_exclusive_cpumask()
2362 cpumask_clear(trialcs->effective_xcpus); in update_exclusive_cpumask()
2364 retval = cpulist_parse(buf, trialcs->exclusive_cpus); in update_exclusive_cpumask()
2370 if (cpumask_equal(cs->exclusive_cpus, trialcs->exclusive_cpus)) in update_exclusive_cpumask()
2380 force = !cpumask_equal(cs->effective_xcpus, trialcs->effective_xcpus); in update_exclusive_cpumask()
2387 return -ENOMEM; in update_exclusive_cpumask()
2390 if (cpumask_empty(trialcs->effective_xcpus)) { in update_exclusive_cpumask()
2392 cs->prs_err = PERR_INVCPUS; in update_exclusive_cpumask()
2393 } else if (prstate_housekeeping_conflict(old_prs, trialcs->effective_xcpus)) { in update_exclusive_cpumask()
2395 cs->prs_err = PERR_HKEEPING; in update_exclusive_cpumask()
2396 } else if (tasks_nocpu_error(parent, cs, trialcs->effective_xcpus)) { in update_exclusive_cpumask()
2398 cs->prs_err = PERR_NOCPUS; in update_exclusive_cpumask()
2405 remote_cpus_update(cs, trialcs->effective_xcpus, in update_exclusive_cpumask()
2412 trialcs->effective_xcpus, &tmp); in update_exclusive_cpumask()
2414 } else if (!cpumask_empty(trialcs->exclusive_cpus)) { in update_exclusive_cpumask()
2416 * Use trialcs->effective_cpus as a temp cpumask in update_exclusive_cpumask()
2418 remote_partition_check(cs, trialcs->effective_xcpus, in update_exclusive_cpumask()
2419 trialcs->effective_cpus, &tmp); in update_exclusive_cpumask()
2422 cpumask_copy(cs->exclusive_cpus, trialcs->exclusive_cpus); in update_exclusive_cpumask()
2423 cpumask_copy(cs->effective_xcpus, trialcs->effective_xcpus); in update_exclusive_cpumask()
2437 if (cs->partition_root_state) in update_exclusive_cpumask()
2465 do_migrate_pages(mwork->mm, &mwork->from, &mwork->to, MPOL_MF_MOVE_ALL); in cpuset_migrate_mm_workfn()
2466 mmput(mwork->mm); in cpuset_migrate_mm_workfn()
2482 mwork->mm = mm; in cpuset_migrate_mm()
2483 mwork->from = *from; in cpuset_migrate_mm()
2484 mwork->to = *to; in cpuset_migrate_mm()
2485 INIT_WORK(&mwork->work, cpuset_migrate_mm_workfn); in cpuset_migrate_mm()
2486 queue_work(cpuset_migrate_mm_wq, &mwork->work); in cpuset_migrate_mm()
2498 * cpuset_change_task_nodemask - change task's mems_allowed and mempolicy
2502 * We use the mems_allowed_seq seqlock to safely update both tsk->mems_allowed
2513 write_seqcount_begin(&tsk->mems_allowed_seq); in cpuset_change_task_nodemask()
2515 nodes_or(tsk->mems_allowed, tsk->mems_allowed, *newmems); in cpuset_change_task_nodemask()
2517 tsk->mems_allowed = *newmems; in cpuset_change_task_nodemask()
2519 write_seqcount_end(&tsk->mems_allowed_seq); in cpuset_change_task_nodemask()
2528 * cpuset_update_tasks_nodemask - Update the nodemasks of tasks in the cpuset.
2532 * effective cpuset's. As this function is called with cpuset_mutex held,
2547 * take while holding tasklist_lock. Forks can happen - the in cpuset_update_tasks_nodemask()
2555 css_task_iter_start(&cs->css, 0, &it); in cpuset_update_tasks_nodemask()
2568 mpol_rebind_mm(mm, &cs->mems_allowed); in cpuset_update_tasks_nodemask()
2570 cpuset_migrate_mm(mm, &cs->old_mems_allowed, &newmems); in cpuset_update_tasks_nodemask()
2578 * cs->old_mems_allowed. in cpuset_update_tasks_nodemask()
2580 cs->old_mems_allowed = newmems; in cpuset_update_tasks_nodemask()
2587 * update_nodemasks_hier - Update effective nodemasks and tasks in the subtree
2591 * When configured nodemask is changed, the effective nodemasks of this cpuset
2607 nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems); in update_nodemasks_hier()
2610 * If it becomes empty, inherit the effective mask of the in update_nodemasks_hier()
2614 *new_mems = parent->effective_mems; in update_nodemasks_hier()
2617 if (nodes_equal(*new_mems, cp->effective_mems)) { in update_nodemasks_hier()
2622 if (!css_tryget_online(&cp->css)) in update_nodemasks_hier()
2627 cp->effective_mems = *new_mems; in update_nodemasks_hier()
2631 !nodes_equal(cp->mems_allowed, cp->effective_mems)); in update_nodemasks_hier()
2636 css_put(&cp->css); in update_nodemasks_hier()
2651 * lock each such tasks mm->mmap_lock, scan its vma's and rebind
2661 * it's read-only in update_nodemask()
2664 retval = -EACCES; in update_nodemask()
2675 nodes_clear(trialcs->mems_allowed); in update_nodemask()
2677 retval = nodelist_parse(buf, trialcs->mems_allowed); in update_nodemask()
2681 if (!nodes_subset(trialcs->mems_allowed, in update_nodemask()
2683 retval = -EINVAL; in update_nodemask()
2688 if (nodes_equal(cs->mems_allowed, trialcs->mems_allowed)) { in update_nodemask()
2689 retval = 0; /* Too easy - nothing to do */ in update_nodemask()
2696 check_insane_mems_config(&trialcs->mems_allowed); in update_nodemask()
2699 cs->mems_allowed = trialcs->mems_allowed; in update_nodemask()
2702 /* use trialcs->mems_allowed as a temp variable */ in update_nodemask()
2703 update_nodemasks_hier(cs, &trialcs->mems_allowed); in update_nodemask()
2720 * cpuset_update_flag - read a 0 or a 1 in a file and update associated flag
2738 return -ENOMEM; in cpuset_update_flag()
2741 set_bit(bit, &trialcs->flags); in cpuset_update_flag()
2743 clear_bit(bit, &trialcs->flags); in cpuset_update_flag()
2756 cs->flags = trialcs->flags; in cpuset_update_flag()
2759 if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed) { in cpuset_update_flag()
2774 * update_prstate - update partition_root_state
2783 int err = PERR_NONE, old_prs = cs->partition_root_state; in update_prstate()
2798 return -ENOMEM; in update_prstate()
2804 if ((new_prs > 0) && cpumask_empty(cs->exclusive_cpus)) { in update_prstate()
2806 cpumask_and(cs->effective_xcpus, in update_prstate()
2807 cs->cpus_allowed, parent->effective_xcpus); in update_prstate()
2863 new_prs = -new_prs; in update_prstate()
2868 cs->partition_root_state = new_prs; in update_prstate()
2869 WRITE_ONCE(cs->prs_err, err); in update_prstate()
2873 partition_xcpus_newstate(old_prs, new_prs, cs->effective_xcpus); in update_prstate()
2900 if (cpumask_empty(cs->effective_cpus) || in cpuset_can_attach_check()
2901 (!is_in_v2_mode() && nodes_empty(cs->mems_allowed))) in cpuset_can_attach_check()
2902 return -ENOSPC; in cpuset_can_attach_check()
2908 cs->nr_migrate_dl_tasks = 0; in reset_migrate_dl_data()
2909 cs->sum_migrate_dl_bw = 0; in reset_migrate_dl_data()
2933 cpus_updated = !cpumask_equal(cs->effective_cpus, oldcs->effective_cpus); in cpuset_can_attach()
2934 mems_updated = !nodes_equal(cs->effective_mems, oldcs->effective_mems); in cpuset_can_attach()
2953 cs->nr_migrate_dl_tasks++; in cpuset_can_attach()
2954 cs->sum_migrate_dl_bw += task->dl.dl_bw; in cpuset_can_attach()
2958 if (!cs->nr_migrate_dl_tasks) in cpuset_can_attach()
2961 if (!cpumask_intersects(oldcs->effective_cpus, cs->effective_cpus)) { in cpuset_can_attach()
2962 int cpu = cpumask_any_and(cpu_active_mask, cs->effective_cpus); in cpuset_can_attach()
2966 ret = -EINVAL; in cpuset_can_attach()
2970 ret = dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); in cpuset_can_attach()
2982 cs->attach_in_progress++; in cpuset_can_attach()
2999 if (cs->nr_migrate_dl_tasks) { in cpuset_cancel_attach()
3000 int cpu = cpumask_any(cs->effective_cpus); in cpuset_cancel_attach()
3002 dl_bw_free(cpu, cs->sum_migrate_dl_bw); in cpuset_cancel_attach()
3050 cpus_updated = !cpumask_equal(cs->effective_cpus, in cpuset_attach()
3051 oldcs->effective_cpus); in cpuset_attach()
3052 mems_updated = !nodes_equal(cs->effective_mems, oldcs->effective_mems); in cpuset_attach()
3057 * in effective cpus and mems. In that case, we can optimize out in cpuset_attach()
3061 cpuset_attach_nodemask_to = cs->effective_mems; in cpuset_attach()
3076 cpuset_attach_nodemask_to = cs->effective_mems; in cpuset_attach()
3095 cpuset_migrate_mm(mm, &oldcs->old_mems_allowed, in cpuset_attach()
3103 cs->old_mems_allowed = cpuset_attach_nodemask_to; in cpuset_attach()
3105 if (cs->nr_migrate_dl_tasks) { in cpuset_attach()
3106 cs->nr_deadline_tasks += cs->nr_migrate_dl_tasks; in cpuset_attach()
3107 oldcs->nr_deadline_tasks -= cs->nr_migrate_dl_tasks; in cpuset_attach()
3124 int retval = -ENODEV; in cpuset_write_resmask()
3134 retval = -ENOMEM; in cpuset_write_resmask()
3138 switch (of_cft(of)->private) { in cpuset_write_resmask()
3149 retval = -EINVAL; in cpuset_write_resmask()
3174 cpuset_filetype_t type = seq_cft(sf)->private; in cpuset_common_seq_show()
3181 seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->cpus_allowed)); in cpuset_common_seq_show()
3184 seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->mems_allowed)); in cpuset_common_seq_show()
3187 seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->effective_cpus)); in cpuset_common_seq_show()
3190 seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems)); in cpuset_common_seq_show()
3193 seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->exclusive_cpus)); in cpuset_common_seq_show()
3196 seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->effective_xcpus)); in cpuset_common_seq_show()
3205 ret = -EINVAL; in cpuset_common_seq_show()
3217 switch (cs->partition_root_state) { in sched_partition_show()
3233 err = perr_strings[READ_ONCE(cs->prs_err)]; in sched_partition_show()
3248 int retval = -ENODEV; in sched_partition_write()
3259 return -EINVAL; in sched_partition_write()
3261 css_get(&cs->css); in sched_partition_write()
3271 css_put(&cs->css); in sched_partition_write()
3299 .name = "cpus.effective",
3305 .name = "mems.effective",
3329 .name = "cpus.exclusive.effective",
3354 * cpuset_css_alloc - Allocate a cpuset css
3357 * Return: cpuset css on success, -ENOMEM on failure.
3359 * Allocate and initialize a new cpuset css, for non-NULL @parent_css, return
3372 return ERR_PTR(-ENOMEM); in cpuset_css_alloc()
3376 return ERR_PTR(-ENOMEM); in cpuset_css_alloc()
3379 __set_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); in cpuset_css_alloc()
3380 fmeter_init(&cs->fmeter); in cpuset_css_alloc()
3381 cs->relax_domain_level = -1; in cpuset_css_alloc()
3382 INIT_LIST_HEAD(&cs->remote_sibling); in cpuset_css_alloc()
3386 __set_bit(CS_MEMORY_MIGRATE, &cs->flags); in cpuset_css_alloc()
3388 return &cs->css; in cpuset_css_alloc()
3404 set_bit(CS_ONLINE, &cs->flags); in cpuset_css_online()
3406 set_bit(CS_SPREAD_PAGE, &cs->flags); in cpuset_css_online()
3408 set_bit(CS_SPREAD_SLAB, &cs->flags); in cpuset_css_online()
3413 clear_bit(CS_SCHED_LOAD_BALANCE, &cs->flags); in cpuset_css_online()
3419 cpumask_copy(cs->effective_cpus, parent->effective_cpus); in cpuset_css_online()
3420 cs->effective_mems = parent->effective_mems; in cpuset_css_online()
3424 if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags)) in cpuset_css_online()
3430 * historical reasons - the flag may be specified during mount. in cpuset_css_online()
3433 * refuse to clone the configuration - thereby refusing the task to in cpuset_css_online()
3437 * changed to grant parent->cpus_allowed-sibling_cpus_exclusive in cpuset_css_online()
3450 cs->mems_allowed = parent->mems_allowed; in cpuset_css_online()
3451 cs->effective_mems = parent->mems_allowed; in cpuset_css_online()
3452 cpumask_copy(cs->cpus_allowed, parent->cpus_allowed); in cpuset_css_online()
3453 cpumask_copy(cs->effective_cpus, parent->cpus_allowed); in cpuset_css_online()
3486 clear_bit(CS_ONLINE, &cs->flags); in cpuset_css_offline()
3524 struct cpuset *cs = css_cs(cset->subsys[cpuset_cgrp_id]); in cpuset_can_fork()
3555 cs->attach_in_progress++; in cpuset_can_fork()
3563 struct cpuset *cs = css_cs(cset->subsys[cpuset_cgrp_id]); in cpuset_cancel_fork()
3595 set_cpus_allowed_ptr(task, current->cpus_ptr); in cpuset_fork()
3596 task->mems_allowed = current->mems_allowed; in cpuset_fork()
3631 * cpuset_init - initialize cpusets at system boot
3672 /* A partition root is allowed to have empty effective cpus */ in hotplug_update_tasks()
3674 cpumask_copy(new_cpus, parent_cs(cs)->effective_cpus); in hotplug_update_tasks()
3676 *new_mems = parent_cs(cs)->effective_mems; in hotplug_update_tasks()
3679 cpumask_copy(cs->effective_cpus, new_cpus); in hotplug_update_tasks()
3680 cs->effective_mems = *new_mems; in hotplug_update_tasks()
3695 * cpuset_hotplug_update_tasks - update tasks in a cpuset for hotunplug
3710 int partcmd = -1; in cpuset_hotplug_update_tasks()
3713 wait_event(cpuset_attach_wq, cs->attach_in_progress == 0); in cpuset_hotplug_update_tasks()
3721 if (cs->attach_in_progress) { in cpuset_hotplug_update_tasks()
3728 nodes_and(new_mems, cs->mems_allowed, parent->effective_mems); in cpuset_hotplug_update_tasks()
3730 if (!tmp || !cs->partition_root_state) in cpuset_hotplug_update_tasks()
3752 * 1) empty effective cpus but not valid empty partition. in cpuset_hotplug_update_tasks()
3775 cpus_updated = !cpumask_equal(&new_cpus, cs->effective_cpus); in cpuset_hotplug_update_tasks()
3776 mems_updated = !nodes_equal(new_mems, cs->effective_mems); in cpuset_hotplug_update_tasks()
3795 * cpuset_handle_hotplug - handle CPU/memory hot{,un}plug for a cpuset
3803 * Non-root cpusets are only affected by offlining. If any CPUs or memory
3884 if (cs == &top_cpuset || !css_tryget_online(&cs->css)) in cpuset_handle_hotplug()
3891 css_put(&cs->css); in cpuset_handle_hotplug()
3926 * cpuset_init_smp - initialize cpus_allowed
3949 * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset.
3950 * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed.
3954 * attached to the specified @tsk. Guaranteed to return some non-empty
3992 * cpuset_cpus_allowed_fallback - final fallback before complete catastrophe.
3996 * tsk->cpus_allowed, we fall back to task_cs(tsk)->cpus_allowed. In legacy
3997 * mode however, this value is the same as task_cs(tsk)->effective_cpus,
4012 cs_mask = task_cs(tsk)->cpus_allowed; in cpuset_cpus_allowed_fallback()
4020 * We own tsk->cpus_allowed, nobody can change it under us. in cpuset_cpus_allowed_fallback()
4022 * But we used cs && cs->cpus_allowed lockless and thus can in cpuset_cpus_allowed_fallback()
4024 * the wrong tsk->cpus_allowed. However, both cases imply the in cpuset_cpus_allowed_fallback()
4025 * subsequent cpuset_change_cpumask()->set_cpus_allowed_ptr() in cpuset_cpus_allowed_fallback()
4029 * changes in tsk_cs()->cpus_allowed. Otherwise we can temporary in cpuset_cpus_allowed_fallback()
4041 nodes_setall(current->mems_allowed); in cpuset_init_current_mems_allowed()
4045 * cpuset_mems_allowed - return mems_allowed mask from a tasks cpuset.
4046 * @tsk: pointer to task_struct from which to obtain cpuset->mems_allowed.
4049 * attached to the specified @tsk. Guaranteed to return some non-empty
4069 * cpuset_nodemask_valid_mems_allowed - check nodemask vs. current mems_allowed
4072 * Are any of the nodes in the nodemask allowed in current->mems_allowed?
4076 return nodes_intersects(*nodemask, current->mems_allowed); in cpuset_nodemask_valid_mems_allowed()
4080 * nearest_hardwall_ancestor() - Returns the nearest mem_exclusive or
4093 * cpuset_node_allowed - Can we allocate on a memory node?
4126 * in_interrupt - any node ok (current task context irrelevant)
4127 * GFP_ATOMIC - any node ok
4128 * tsk_is_oom_victim - any node ok
4129 * GFP_KERNEL - any node in enclosing hardwalled cpuset ok
4130 * GFP_USER - only nodes in current tasks mems allowed ok.
4140 if (node_isset(node, current->mems_allowed)) in cpuset_node_allowed()
4151 if (current->flags & PF_EXITING) /* Let dying task have memory */ in cpuset_node_allowed()
4159 allowed = node_isset(node, cs->mems_allowed); in cpuset_node_allowed()
4167 * cpuset_spread_node() - On which node to begin search for a page
4183 * only set nodes in task->mems_allowed that are online. So it
4194 return *rotor = next_node_in(*rotor, current->mems_allowed); in cpuset_spread_node()
4198 * cpuset_mem_spread_node() - On which node to begin search for a file page
4202 if (current->cpuset_mem_spread_rotor == NUMA_NO_NODE) in cpuset_mem_spread_node()
4203 current->cpuset_mem_spread_rotor = in cpuset_mem_spread_node()
4204 node_random(&current->mems_allowed); in cpuset_mem_spread_node()
4206 return cpuset_spread_node(&current->cpuset_mem_spread_rotor); in cpuset_mem_spread_node()
4210 * cpuset_mems_allowed_intersects - Does @tsk1's mems_allowed intersect @tsk2's?
4223 return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed); in cpuset_mems_allowed_intersects()
4227 * cpuset_print_current_mems_allowed - prints current's cpuset and mems_allowed
4238 cgrp = task_cs(current)->css.cgroup; in cpuset_print_current_mems_allowed()
4242 nodemask_pr_args(&current->mems_allowed)); in cpuset_print_current_mems_allowed()
4250 * - Print tasks cpuset path into seq_file.
4251 * - Used for /proc/<pid>/cpuset.
4252 * - No need to task_lock(tsk) on this tsk->cpuset reference, as it
4253 * doesn't really matter if tsk->cpuset changes after we read it,
4264 retval = -ENOMEM; in proc_cpuset_show()
4272 retval = cgroup_path_ns_locked(css->cgroup, buf, PATH_MAX, in proc_cpuset_show()
4273 current->nsproxy->cgroup_ns); in proc_cpuset_show()
4277 if (retval == -E2BIG) in proc_cpuset_show()
4278 retval = -ENAMETOOLONG; in proc_cpuset_show()
4295 nodemask_pr_args(&task->mems_allowed)); in cpuset_task_status_allowed()
4297 nodemask_pr_args(&task->mems_allowed)); in cpuset_task_status_allowed()