Hi, Longman,
On Tue, 18 Nov 2025 14:53:27 -0500, Longman wrote:
>On 11/16/25 8:57 PM, Sun Shaojie wrote:
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 52468d2c178a..0fd803612513 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -580,35 +580,56 @@ static inline bool cpusets_are_exclusive(struct cpuset
>> *cs1, struct cpuset *cs2)
>>
>> /**
>> * cpus_excl_conflict - Check if two cpusets have exclusive CPU conflicts
>> - * @cs1: first cpuset to check
>> - * @cs2: second cpuset to check
>> + * @cs1: current cpuset to check
>> + * @cs2: cpuset involved in the check
>> *
>> * Returns: true if CPU exclusivity conflict exists, false otherwise
>> *
>> * Conflict detection rules:
>> - * 1. If either cpuset is CPU exclusive, they must be mutually exclusive
>> + * For cgroup-v1:
>> + * see cpuset1_cpus_excl_conflict()
>> + * For cgroup-v2:
>> + * 1. If cs1 is exclusive, cs1 and cs2 must be mutually exclusive
>> * 2. exclusive_cpus masks cannot intersect between cpusets
>> - * 3. The allowed CPUs of one cpuset cannot be a subset of another's
>> exclusive CPUs
>> + * 3. If cs2 is exclusive, cs2's allowed CPUs cannot be a subset of cs1's
>> exclusive CPUs
>> + * 4. if cs1 and cs2 are not exclusive, the allowed CPUs of one cpuset
>> cannot be a subset
>> + * of another's exclusive CPUs
>> */
>> static inline bool cpus_excl_conflict(struct cpuset *cs1, struct cpuset
>> *cs2)
>
>As cs1 and cs2 is going to be handled differently, their current naming
>will make it hard to understand why they are treated differently. I will
>recommended changing the parameter name to "trial, sibling" as the
>caller call it with "cpus_excl_conflict(trial, c)" where trial is the
>new cpuset data to be tested and sibling is one of its sibling cpusets.
>It has to be clearly document what each parameter is for and the fact
>that swapping the parameters will cause it to return incorrect result.
>
>
>> {
>> - /* If either cpuset is exclusive, check if they are mutually exclusive
>> */
>> - if (is_cpu_exclusive(cs1) || is_cpu_exclusive(cs2))
>> + /* For cgroup-v1 */
>> + if (!cpuset_v2())
>> + return cpuset1_cpus_excl_conflict(cs1, cs2);
>> +
>> + /* If cs1 are exclusive, check if they are mutually exclusive */
>> + if (is_cpu_exclusive(cs1))
>> return !cpusets_are_exclusive(cs1, cs2);
>
>Code change like the following can eliminate the need to introduce a new
>cpuset1_cpus_excl_conflict() helper.
>
>diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>index ec8bebc66469..201c70fb7401 100644
>--- a/kernel/cgroup/cpuset.c
>+++ b/kernel/cgroup/cpuset.c
>@@ -599,9 +599,15 @@ static inline bool cpusets_are_exclusive(struct
>cpuset *cs1, struct cpuset *cs2)
> */
> static inline bool cpus_excl_conflict(struct cpuset *cs1, struct
>cpuset *cs2)
> {
>- /* If either cpuset is exclusive, check if they are mutually
>exclusive */
>- if (is_cpu_exclusive(cs1) || is_cpu_exclusive(cs2))
>- return !cpusets_are_exclusive(cs1, cs2);
>+ /*
>+ * If trial is exclusive or sibling is exclusive & in v1,
>+ * check if they are mutually exclusive
>+ */
>+ if (is_cpu_exclusive(trial) || (!cpuset_v2() &&
>is_cpu_exclusive(sibling)))
>+ return !cpusets_are_exclusive(trial, sibling);
>+
>+ if (!cpuset_v2())
>+ return false; /* The checking below is irrelevant to
>cpuset v1 */
>
> /* Exclusive_cpus cannot intersect */
> if (cpumask_intersects(cs1->exclusive_cpus, cs2->exclusive_cpus))
Thank you very much for your guidance and suggestions on the code.
I've updated patch v5 with some new ideas and look forward to your feedback.
patch v5 :
https://lore.kernel.org/cgroups/[email protected]/
Thanks,
Sun Shaojie