From: Chen Ridong 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 Signed-off-by: Ridong Chen --- kernel/cgroup/cpuset.c | 78 ++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index ef162935ba5a..847713110738 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1998,6 +1998,57 @@ 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_cpuset_lock_held(); + 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; + } + + compute_excpus(cs, tmp->new_cpus); + err = validate_partition(cs, parent, new_prs, tmp->new_cpus, NULL); + if (err) + return err; + + /* + * 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->addmask, tmp->new_cpus, cpu_active_mask); + WARN_ON_ONCE(!cpumask_subset(tmp->addmask, parent->effective_cpus)); + + 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 @@ -2096,27 +2147,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, nocpu = tasks_nocpu_error(parent, cs, tmp->delmask); } - if ((cmd == partcmd_enable) || (cmd == partcmd_enablei)) { - new_prs = (cmd == partcmd_enable) ? PRS_ROOT : PRS_ISOLATED; - - part_error = validate_partition(cs, parent, new_prs, - tmp->delmask, 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, tmp->delmask, 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) @@ -3085,9 +3116,6 @@ static int update_prstate(struct cpuset *cs, int new_prs) * Otherwise, enable a remote partition. */ if (is_partition_valid(parent)) { - enum partition_cmd cmd = (new_prs == PRS_ROOT) - ? partcmd_enable : partcmd_enablei; - /* * It is not allowed to create a root partition under * an isolated parent partition. @@ -3096,7 +3124,7 @@ static int update_prstate(struct cpuset *cs, int new_prs) err = PERR_ISOPARENT; goto out; } - err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask); + err = local_partition_enable(cs, new_prs, &tmpmask); } else { err = remote_partition_enable(cs, new_prs, &tmpmask); } -- 2.34.1