The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: "Ridong Chen" <ridong.chen@linux.dev>,
	"Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [PATCH v6 08/12] cpuset: introduce local_partition_enable()
Date: Sat, 5 Dec 2026 15:52:10 +0800	[thread overview]
Message-ID: <5c67959e-2bd4-4e3b-9ba2-9c9237655f2a@linux.dev> (raw)
In-Reply-To: <20261129024431.2485721-9-ridong.chen@linux.dev>



在 2026/11/29 10:44, Ridong Chen 写道:
> From: Ridong Chen <chenridong@xiaomi.com>
> 
> Factor the local partition enablement out of
> update_parent_effective_cpumask() into local_partition_enable(). It
> computes the effective exclusive CPUs of the cpuset, validates them
> with validate_local_partition() and then calls partition_enable() to
> set up the partition, the same way as remote_partition_enable() does
> for a remote partition.
> 
> As validate_local_partition() already rejects a root partition under an
> isolated parent, the PERR_ISOPARENT check in update_prstate() is no
> longer needed and is removed.
> 
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
> ---
>  kernel/cgroup/cpuset.c | 84 +++++++++++++++++++++++-------------------
>  1 file changed, 46 insertions(+), 38 deletions(-)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index a3b3a3fe63ff..ea5fcf583444 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -2022,10 +2022,9 @@ static bool is_user_xcpus_exclusive(struct cpuset *cs)
>   * Important: The caller must ensure that @cs's cpu mask is updated before
>   * invoking this function when exclusive CPU validation is required.
>   */
> -static enum prs_errcode __maybe_unused
> -validate_local_partition(struct cpuset *cs, int new_prs,
> -			 struct cpumask *excpus, bool excl_check,
> -			 struct tmpmasks *tmp)
> +static enum prs_errcode validate_local_partition(struct cpuset *cs, int new_prs,
> +						 struct cpumask *excpus, bool excl_check,
> +						 struct tmpmasks *tmp)
>  {
>  	struct cpuset *parent = parent_cs(cs);
>  
> @@ -2050,6 +2049,47 @@ validate_local_partition(struct cpuset *cs, int new_prs,
>  				  tmp ? tmp->delmask : NULL);
>  }
>  
> +/**
> + * 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 */
> +
> +	compute_excpus(cs, tmp->new_cpus);
> +	err = validate_local_partition(cs, new_prs, tmp->new_cpus, false, 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.
> +	 *
> +	 * (new 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
> @@ -2148,27 +2188,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)
> @@ -3108,7 +3128,6 @@ static int update_prstate(struct cpuset *cs, int new_prs)
>  	int err = PERR_NONE, old_prs = cs->partition_root_state;
>  	struct cpuset *parent = parent_cs(cs);
>  	struct tmpmasks tmpmask;
> -	int parent_prs = parent->partition_root_state;
>  	bool isolcpus_updated = false;
>  	bool disable_partition = false;
>  
> @@ -3151,18 +3170,7 @@ 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.
> -			 */
> -			if ((new_prs == PRS_ROOT) && (parent_prs == PRS_ISOLATED)) {
> -				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);
>  		}

Reviewed-by: Guopeng Zhang <zhangguopeng@kylinos.cn>

Thanks,
Guopeng

  reply	other threads:[~2026-12-05  7:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  2:44 [PATCH v6 00/12] cpuset: rework local partition logic Ridong Chen
2026-11-29  2:44 ` [PATCH v6 01/12] cpuset: introduce partition_enable() Ridong Chen
2026-12-05  4:20   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 02/12] cpuset: introduce partition_disable() Ridong Chen
2026-12-05  4:20   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 03/12] cpuset: introduce partition_update() Ridong Chen
2026-12-05  4:20   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 04/12] cpuset: use partition_enable() for remote partition enablement Ridong Chen
2026-12-05  4:21   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 05/12] cpuset: use partition_disable() for remote partition disablement Ridong Chen
2026-12-01  3:16   ` Waiman Long
2026-12-01 12:16     ` Ridong Chen
2026-11-29  2:44 ` [PATCH v6 06/12] cpuset: use partition_update() for remote partition update Ridong Chen
2026-12-05  4:50   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 07/12] cpuset: introduce validate_local_partition() Ridong Chen
2026-12-05  7:51   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 08/12] cpuset: introduce local_partition_enable() Ridong Chen
2026-12-05  7:52   ` Guopeng Zhang [this message]
2026-11-29  2:44 ` [PATCH v6 09/12] cpuset: use partition_disable() for local partition disablement Ridong Chen
2026-12-05  7:53   ` Guopeng Zhang
2026-11-29  2:44 ` [PATCH v6 10/12] cpuset: use partition_disable() to invalidate local partition Ridong Chen
2026-11-29  2:44 ` [PATCH v6 11/12] cpuset: introduce local_partition_update() Ridong Chen
2026-11-29  2:44 ` [PATCH v6 12/12] cpuset: remove update_parent_effective_cpumask Ridong Chen
2026-12-04  3:49 ` [PATCH v6 00/12] cpuset: rework local partition logic Ridong Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5c67959e-2bd4-4e3b-9ba2-9c9237655f2a@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@xiaomi.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=ridong.chen@linux.dev \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox