[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251117024627.1128037-10-chenridong@huaweicloud.com>
Date: Mon, 17 Nov 2025 02:46:15 +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 -next 09/21] cpuset: introduce local_partition_enable()
From: Chen Ridong <chenridong@...wei.com>
The partition_enable() function introduced in the previous patch can be
reused to enable local partitions.
The local_partition_enable() function is introduced, which factors out the
local partition enablement logic from update_parent_effective_cpumask().
After passing local partition validation checks, it delegates to
partition_enable() to complete the partition setup.
This refactoring creates a clear separation between local and remote
partition operations while maintaining code reuse through the shared
partition_enable() infrastructure.
Signed-off-by: Chen Ridong <chenridong@...wei.com>
---
kernel/cgroup/cpuset.c | 86 ++++++++++++++++++++++++------------------
1 file changed, 50 insertions(+), 36 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 392b01f95e62..3c1e8431c234 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1897,6 +1897,52 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,
remote_partition_disable(cs, tmp);
}
+/**
+ * local_partition_enable - Enable local partition for a cpuset
+ * @cs: Target cpuset to become a local partition root
+ * @new_prs: New partition root state to apply
+ * @tmp: Temporary masks for CPU calculations
+ *
+ * Return: 0 on success, error code on failure
+ */
+static int local_partition_enable(struct cpuset *cs,
+ int new_prs, struct tmpmasks *tmp)
+{
+ struct cpuset *parent = parent_cs(cs);
+ enum prs_errcode err;
+
+ lockdep_assert_held(&cpuset_mutex);
+ WARN_ON_ONCE(is_remote_partition(cs)); /* For local partition only */
+
+ /*
+ * 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;
+ }
+
+ /*
+ * Need to call compute_excpus() in case
+ * exclusive_cpus not set. Sibling conflict should only happen
+ * if exclusive_cpus isn't set.
+ */
+ if (compute_excpus(cs, tmp->new_cpus))
+ WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus));
+
+ err = validate_partition(cs, new_prs, tmp->new_cpus, tmp->new_cpus, NULL);
+ if (err)
+ return err;
+
+ partition_enable(cs, parent, new_prs, tmp->new_cpus);
+
+ cpuset_update_tasks_cpumask(parent, tmp->addmask);
+ update_sibling_cpumasks(parent, cs, tmp);
+ return 0;
+}
+
/**
* update_parent_effective_cpumask - update effective_cpus mask of parent cpuset
* @cs: The cpuset that requests change in partition root state
@@ -1987,35 +2033,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
nocpu = tasks_nocpu_error(parent, cs, xcpus);
- if ((cmd == partcmd_enable) || (cmd == partcmd_enablei)) {
- /*
- * Need to call compute_excpus() in case
- * exclusive_cpus not set. Sibling conflict should only happen
- * if exclusive_cpus isn't set.
- */
- xcpus = tmp->delmask;
- if (compute_excpus(cs, xcpus))
- WARN_ON_ONCE(!cpumask_empty(cs->exclusive_cpus));
- new_prs = (cmd == partcmd_enable) ? PRS_ROOT : PRS_ISOLATED;
-
- part_error = validate_partition(cs, new_prs, xcpus, xcpus, NULL);
- if (part_error)
- return part_error;
-
- /*
- * This function will only be called when all the preliminary
- * checks have passed. At this point, the following condition
- * should hold.
- *
- * (cs->effective_xcpus & cpu_active_mask) ⊆ parent->effective_cpus
- *
- * Warn if it is not the case.
- */
- cpumask_and(tmp->new_cpus, xcpus, cpu_active_mask);
- WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus));
-
- deleting = true;
- } else if (cmd == partcmd_disable) {
+ if (cmd == partcmd_disable) {
/*
* May need to add cpus back to parent's effective_cpus
* (and maybe removed from subpartitions_cpus/isolated_cpus)
@@ -3147,14 +3165,10 @@ static int update_prstate(struct cpuset *cs, int new_prs)
* If parent is valid partition, enable local partiion.
* Otherwise, enable a remote partition.
*/
- if (is_partition_valid(parent)) {
- enum partition_cmd cmd = (new_prs == PRS_ROOT)
- ? partcmd_enable : partcmd_enablei;
-
- err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
- } else {
+ if (is_partition_valid(parent))
+ err = local_partition_enable(cs, new_prs, &tmpmask);
+ else
err = remote_partition_enable(cs, new_prs, &tmpmask);
- }
} else if (old_prs && new_prs) {
/*
* A change in load balance state only, no change in cpumasks.
--
2.34.1
Powered by blists - more mailing lists