[PATCH -next RFC 07/11] cpuset: refactor out invalidate_cs_partition

Chen Ridong posted 11 patches 1 month ago
There is a newer version of this series
[PATCH -next RFC 07/11] cpuset: refactor out invalidate_cs_partition
Posted by Chen Ridong 1 month ago
From: Chen Ridong <chenridong@huawei.com>

Refactor the invalidate_cs_partition function to handle cpuset partition
invalidation when modifying cpuset.cpus. This refactoring also makes the
function reusable for handling cpuset.cpus.exclusive updates in subsequent
patches.

Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cpuset.c | 49 +++++++++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 5cfc53fe717c..71190f142700 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2376,6 +2376,40 @@ static int parse_cpulist(const char *buf, struct cpumask *out_mask)
 	return 0;
 }
 
+/**
+ * invalidate_cs_partition - Validate and mark the validity of a cpuset partition configuration
+ * @cs: The cpuset to validate
+ * This function checks multiple constraints for a cpuset partition configuration.
+ * If any check fails, it sets the appropriate error code in the cpuset and returns true.
+ * Mainly used to ensure correctness and consistency of partition configurations.
+ * Return: true if the configuration is invalid, false if valid.
+ */
+static bool invalidate_cs_partition(struct cpuset *cs)
+{
+	struct cpuset *parent = parent_cs(cs);
+
+	if (cs_is_member(cs))
+		return false;
+
+	if (cpumask_empty(cs->effective_xcpus)) {
+		cs->prs_err = PERR_INVCPUS;
+		return true;
+	}
+
+	if (prstate_housekeeping_conflict(cs->partition_root_state,
+					  cs->effective_xcpus)) {
+		cs->prs_err = PERR_HKEEPING;
+		return true;
+	}
+
+	if (tasks_nocpu_error(parent, cs, cs->effective_xcpus)) {
+		cs->prs_err = PERR_NOCPUS;
+		return true;
+	}
+
+	return false;
+}
+
 /**
  * update_cpumask - update the cpus_allowed mask of a cpuset and all tasks in it
  * @cs: the cpuset to consider
@@ -2405,19 +2439,8 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
 
 	compute_trialcs_excpus(trialcs, cs);
 
-	if (old_prs) {
-		if (is_partition_valid(cs) &&
-		    cpumask_empty(trialcs->effective_xcpus)) {
-			invalidate = true;
-			cs->prs_err = PERR_INVCPUS;
-		} else if (prstate_housekeeping_conflict(old_prs, trialcs->effective_xcpus)) {
-			invalidate = true;
-			cs->prs_err = PERR_HKEEPING;
-		} else if (tasks_nocpu_error(parent, cs, trialcs->effective_xcpus)) {
-			invalidate = true;
-			cs->prs_err = PERR_NOCPUS;
-		}
-	}
+	invalidate = invalidate_cs_partition(trialcs);
+	cs->prs_err = trialcs->prs_err;
 
 	/*
 	 * Check all the descendants in update_cpumasks_hier() if
-- 
2.34.1
Re: [PATCH -next RFC 07/11] cpuset: refactor out invalidate_cs_partition
Posted by Waiman Long 1 month ago
On 8/28/25 8:56 AM, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> Refactor the invalidate_cs_partition function to handle cpuset partition
> invalidation when modifying cpuset.cpus. This refactoring also makes the
> function reusable for handling cpuset.cpus.exclusive updates in subsequent
> patches.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
>   kernel/cgroup/cpuset.c | 49 +++++++++++++++++++++++++++++++-----------
>   1 file changed, 36 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 5cfc53fe717c..71190f142700 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -2376,6 +2376,40 @@ static int parse_cpulist(const char *buf, struct cpumask *out_mask)
>   	return 0;
>   }
>   
> +/**
> + * invalidate_cs_partition - Validate and mark the validity of a cpuset partition configuration

The function name has "invalidate", but the description uses validate. 
It is confusing.

My suggestion

   validate_partition - Check the validity of a cpuset partition 
configuration

   Return 0 if valid, a non-zero prs_errcode otherwise

Cheers,
Longman

Re: [PATCH -next RFC 07/11] cpuset: refactor out invalidate_cs_partition
Posted by Chen Ridong 1 month ago

On 2025/8/30 3:56, Waiman Long wrote:
> 
> On 8/28/25 8:56 AM, Chen Ridong wrote:
>> From: Chen Ridong <chenridong@huawei.com>
>>
>> Refactor the invalidate_cs_partition function to handle cpuset partition
>> invalidation when modifying cpuset.cpus. This refactoring also makes the
>> function reusable for handling cpuset.cpus.exclusive updates in subsequent
>> patches.
>>
>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>> ---
>>   kernel/cgroup/cpuset.c | 49 +++++++++++++++++++++++++++++++-----------
>>   1 file changed, 36 insertions(+), 13 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 5cfc53fe717c..71190f142700 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -2376,6 +2376,40 @@ static int parse_cpulist(const char *buf, struct cpumask *out_mask)
>>       return 0;
>>   }
>>   +/**
>> + * invalidate_cs_partition - Validate and mark the validity of a cpuset partition configuration
> 
> The function name has "invalidate", but the description uses validate. It is confusing.
> 
> My suggestion
> 
>   validate_partition - Check the validity of a cpuset partition configuration
> 
>   Return 0 if valid, a non-zero prs_errcode otherwise
> 
> Cheers,
> Longman

Thank you Longman,

I originally used that name for a local value 'invalidated' within update_cpumask. However, since
subsequent patches have removed the invalidated, validate_partition would be a much more appropriate
name. I will update it accordingly.

-- 
Best regards,
Ridong