[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251025064844.495525-15-chenridong@huaweicloud.com>
Date: Sat, 25 Oct 2025 06:48:36 +0000
From: Chen Ridong <chenridong@...weicloud.com>
To: longman@...hat.com,
tj@...nel.org,
hannes@...xchg.org,
mkoutny@...e.com
Cc: cgroups@...r.kernel.org,
linux-kernel@...r.kernel.org,
lujialin4@...wei.com,
chenridong@...wei.com
Subject: [PATCH RFC v2 14/22] cpuset: remove update_parent_effective_cpumask
From: Chen Ridong <chenridong@...wei.com>
Clean up by removing the update_parent_effective_cpumask() function.
Its logic has now been fully replaced and centralized by the new
helper functions.
Signed-off-by: Chen Ridong <chenridong@...wei.com>
---
kernel/cgroup/cpuset.c | 266 -----------------------------------------
1 file changed, 266 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 49df38237c1d..21dd9e0f16ee 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2085,272 +2085,6 @@ static int local_partition_update(struct cpuset *cs, struct tmpmasks *tmp)
return __local_partition_update(cs, NULL, tmp->new_cpus, tmp, true);
}
-/**
- * update_parent_effective_cpumask - update effective_cpus mask of parent cpuset
- * @cs: The cpuset that requests change in partition root state
- * @cmd: Partition root state change command
- * @newmask: Optional new cpumask for partcmd_update
- * @tmp: Temporary addmask and delmask
- * Return: 0 or a partition root state error code
- *
- * For partcmd_enable*, the cpuset is being transformed from a non-partition
- * root to a partition root. The effective_xcpus (cpus_allowed if
- * effective_xcpus not set) mask of the given cpuset will be taken away from
- * parent's effective_cpus. The function will return 0 if all the CPUs listed
- * in effective_xcpus can be granted or an error code will be returned.
- *
- * For partcmd_disable, the cpuset is being transformed from a partition
- * root back to a non-partition root. Any CPUs in effective_xcpus will be
- * given back to parent's effective_cpus. 0 will always be returned.
- *
- * For partcmd_update, if the optional newmask is specified, the cpu list is
- * to be changed from effective_xcpus to newmask. Otherwise, effective_xcpus is
- * assumed to remain the same. The cpuset should either be a valid or invalid
- * partition root. The partition root state may change from valid to invalid
- * or vice versa. An error code will be returned if transitioning from
- * invalid to valid violates the exclusivity rule.
- *
- * For partcmd_invalidate, the current partition will be made invalid.
- *
- * The partcmd_enable* and partcmd_disable commands are used by
- * update_prstate(). An error code may be returned and the caller will check
- * for error.
- *
- * The partcmd_update command is used by update_cpumasks_hier() with newmask
- * NULL and update_cpumask() with newmask set. The partcmd_invalidate is used
- * by update_cpumask() with NULL newmask. In both cases, the callers won't
- * check for error and so partition_root_state and prs_err will be updated
- * directly.
- */
-static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
- struct cpumask *newmask,
- struct tmpmasks *tmp)
-{
- struct cpuset *parent = parent_cs(cs);
- int adding; /* Adding cpus to parent's effective_cpus */
- int deleting; /* Deleting cpus from parent's effective_cpus */
- int old_prs, new_prs;
- int part_error = PERR_NONE; /* Partition error? */
- int isolcpus_updated = 0;
- struct cpumask *xcpus = user_xcpus(cs);
- bool nocpu;
-
- lockdep_assert_held(&cpuset_mutex);
- WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */
-
- /*
- * new_prs will only be changed for the partcmd_update and
- * partcmd_invalidate commands.
- */
- adding = deleting = false;
- old_prs = new_prs = cs->partition_root_state;
-
- /*
- * The parent must be a partition root.
- * The new cpumask, if present, or the current cpus_allowed must
- * not be empty.
- */
- if (!is_partition_valid(parent)) {
- return is_partition_invalid(parent)
- ? PERR_INVPARENT : PERR_NOTPART;
- }
- if (!newmask && xcpus_empty(cs))
- return PERR_CPUSEMPTY;
-
- nocpu = tasks_nocpu_error(parent, cs, xcpus);
-
- if (newmask) {
- /*
- * Empty cpumask is not allowed
- */
- if (cpumask_empty(newmask)) {
- part_error = PERR_CPUSEMPTY;
- goto write_error;
- }
-
- /* Check newmask again, whether cpus are available for parent/cs */
- nocpu |= tasks_nocpu_error(parent, cs, newmask);
-
- /*
- * partcmd_update with newmask:
- *
- * Compute add/delete mask to/from effective_cpus
- *
- * For valid partition:
- * addmask = exclusive_cpus & ~newmask
- * & parent->effective_xcpus
- * delmask = newmask & ~exclusive_cpus
- * & parent->effective_xcpus
- *
- * For invalid partition:
- * delmask = newmask & parent->effective_xcpus
- */
- if (is_partition_invalid(cs)) {
- adding = false;
- deleting = cpumask_and(tmp->delmask,
- newmask, parent->effective_xcpus);
- } else {
- cpumask_andnot(tmp->addmask, xcpus, newmask);
- adding = cpumask_and(tmp->addmask, tmp->addmask,
- parent->effective_xcpus);
-
- cpumask_andnot(tmp->delmask, newmask, xcpus);
- deleting = cpumask_and(tmp->delmask, tmp->delmask,
- parent->effective_xcpus);
- }
- /*
- * The new CPUs to be removed from parent's effective CPUs
- * must be present.
- */
- if (deleting) {
- cpumask_and(tmp->new_cpus, tmp->delmask, cpu_active_mask);
- WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus));
- }
-
- /*
- * Make partition invalid if parent's effective_cpus could
- * become empty and there are tasks in the parent.
- */
- if (nocpu && (!adding ||
- !cpumask_intersects(tmp->addmask, cpu_active_mask))) {
- part_error = PERR_NOCPUS;
- deleting = false;
- adding = cpumask_and(tmp->addmask,
- xcpus, parent->effective_xcpus);
- }
- } else {
- /*
- * partcmd_update w/o newmask
- *
- * delmask = effective_xcpus & parent->effective_cpus
- *
- * This can be called from:
- * 1) update_cpumasks_hier()
- * 2) cpuset_hotplug_update_tasks()
- *
- * Check to see if it can be transitioned from valid to
- * invalid partition or vice versa.
- *
- * A partition error happens when parent has tasks and all
- * its effective CPUs will have to be distributed out.
- */
- if (nocpu) {
- part_error = PERR_NOCPUS;
- if (is_partition_valid(cs))
- adding = cpumask_and(tmp->addmask,
- xcpus, parent->effective_xcpus);
- } else if (is_partition_invalid(cs) && !cpumask_empty(xcpus) &&
- cpumask_subset(xcpus, parent->effective_xcpus)) {
- struct cgroup_subsys_state *css;
- struct cpuset *child;
- bool exclusive = true;
-
- /*
- * Convert invalid partition to valid has to
- * pass the cpu exclusivity test.
- */
- rcu_read_lock();
- cpuset_for_each_child(child, css, parent) {
- if (child == cs)
- continue;
- if (!cpusets_are_exclusive(cs, child)) {
- exclusive = false;
- break;
- }
- }
- rcu_read_unlock();
- if (exclusive)
- deleting = cpumask_and(tmp->delmask,
- xcpus, parent->effective_cpus);
- else
- part_error = PERR_NOTEXCL;
- }
- }
-
-write_error:
- if (part_error)
- WRITE_ONCE(cs->prs_err, part_error);
-
- if (cmd == partcmd_update) {
- /*
- * Check for possible transition between valid and invalid
- * partition root.
- */
- switch (cs->partition_root_state) {
- case PRS_ROOT:
- case PRS_ISOLATED:
- if (part_error)
- new_prs = -old_prs;
- break;
- case PRS_INVALID_ROOT:
- case PRS_INVALID_ISOLATED:
- if (!part_error)
- new_prs = -old_prs;
- break;
- }
- }
-
- if (!adding && !deleting && (new_prs == old_prs))
- return 0;
-
- /*
- * Transitioning between invalid to valid or vice versa may require
- * changing CS_CPU_EXCLUSIVE. In the case of partcmd_update,
- * validate_change() has already been successfully called and
- * CPU lists in cs haven't been updated yet. So defer it to later.
- */
- if ((old_prs != new_prs) && (cmd != partcmd_update)) {
- int err = update_partition_exclusive_flag(cs, new_prs);
-
- if (err)
- return err;
- }
-
- /*
- * Change the parent's effective_cpus & effective_xcpus (top cpuset
- * only).
- *
- * Newly added CPUs will be removed from effective_cpus and
- * newly deleted ones will be added back to effective_cpus.
- */
- spin_lock_irq(&callback_lock);
- if (old_prs != new_prs)
- cs->partition_root_state = new_prs;
-
- /*
- * Adding to parent's effective_cpus means deletion CPUs from cs
- * and vice versa.
- */
- if (adding)
- isolcpus_updated += partition_xcpus_del(old_prs, parent,
- tmp->addmask);
- if (deleting)
- isolcpus_updated += partition_xcpus_add(new_prs, parent,
- tmp->delmask);
-
- spin_unlock_irq(&callback_lock);
- update_unbound_workqueue_cpumask(isolcpus_updated);
-
- if ((old_prs != new_prs) && (cmd == partcmd_update))
- update_partition_exclusive_flag(cs, new_prs);
-
- if (adding || deleting) {
- cpuset_update_tasks_cpumask(parent, tmp->addmask);
- update_sibling_cpumasks(parent, cs, tmp);
- }
-
- /*
- * For partcmd_update without newmask, it is being called from
- * cpuset_handle_hotplug(). Update the load balance flag and
- * scheduling domain accordingly.
- */
- if ((cmd == partcmd_update) && !newmask)
- update_partition_sd_lb(cs, old_prs);
-
- notify_partition_change(cs, old_prs);
- return 0;
-}
-
/**
* compute_partition_effective_cpumask - compute effective_cpus for partition
* @cs: partition root cpuset
--
2.34.1
Powered by blists - more mailing lists