From nobody Tue Dec 16 13:35:30 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0490F1C5F39 for ; Thu, 8 May 2025 17:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746724774; cv=none; b=Wr4t1uC3qjw0Bl0bbv0hdcZXkJWhvn/IoDaIweahNBmdvMCytqIrzLX0nXe2tq9VifCQiAtcMV2wUbgrCZWLtIUla4LMGKqpi0VzMEH4khttFzh+Cx29QrTcBNVb8aQUTpV6AtGtfCUCc7Pe77eONC2cjhgokO1buy1M8v7azFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746724774; c=relaxed/simple; bh=GKn0RwtrGMP14I8u6lwMbXzRZGbgbztSeRTmMLIb1Sk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dr5iiHPQC5Xbzkm8piLs3Dhx0HmIXMJe/0nHjRBPY7cPr9L5EhF28ak0NwyhQsd2Pb+pF2XVZlkshD2Xh6aCbuVxYZkWHxKfTS+YUxXZN/IqAeKu6fDuvfSW3LF0NnTYS7xXn5n7wH3z18/TUGEfaQee9nJjqtSwY9xS1sqTNLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC9972379; Thu, 8 May 2025 10:19:20 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0504D3F58B; Thu, 8 May 2025 10:19:27 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin , Koba Ko , Shanker Donthineni , fenghuay@nvidia.com, "Yury Norov [NVIDIA]" Subject: [PATCH v10 03/30] cpumask: add cpumask_{first,next}_andnot() API Date: Thu, 8 May 2025 17:18:31 +0000 Message-Id: <20250508171858.9197-4-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250508171858.9197-1-james.morse@arm.com> References: <20250508171858.9197-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Yury Norov [NVIDIA]" With the lack of the functions, client code has to abuse less efficient cpumask_nth(). Tested-by: James Morse Reviewed-by: James Morse Reviewed-by: Reinette Chatre Signed-off-by: Yury Norov [NVIDIA] Signed-off-by: James Morse --- include/linux/cpumask.h | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index a3ee875df508..6a569c7534db 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -178,6 +178,19 @@ unsigned int cpumask_first_and(const struct cpumask *s= rcp1, const struct cpumask return find_first_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), small= _cpumask_bits); } =20 +/** + * cpumask_first_andnot - return the first cpu from *srcp1 & ~*srcp2 + * @srcp1: the first input + * @srcp2: the second input + * + * Return: >=3D nr_cpu_ids if no such cpu found. + */ +static __always_inline +unsigned int cpumask_first_andnot(const struct cpumask *srcp1, const struc= t cpumask *srcp2) +{ + return find_first_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), sm= all_cpumask_bits); +} + /** * cpumask_first_and_and - return the first cpu from *srcp1 & *srcp2 & *sr= cp3 * @srcp1: the first input @@ -284,6 +297,25 @@ unsigned int cpumask_next_and(int n, const struct cpum= ask *src1p, small_cpumask_bits, n + 1); } =20 +/** + * cpumask_next_andnot - get the next cpu in *src1p & ~*src2p + * @n: the cpu prior to the place to search (i.e. return will be > @n) + * @src1p: the first cpumask pointer + * @src2p: the second cpumask pointer + * + * Return: >=3D nr_cpu_ids if no further cpus set in both. + */ +static __always_inline +unsigned int cpumask_next_andnot(int n, const struct cpumask *src1p, + const struct cpumask *src2p) +{ + /* -1 is a legal arg here. */ + if (n !=3D -1) + cpumask_check(n); + return find_next_andnot_bit(cpumask_bits(src1p), cpumask_bits(src2p), + small_cpumask_bits, n + 1); +} + /** * cpumask_next_and_wrap - get the next cpu in *src1p & *src2p, starting f= rom * @n+1. If nothing found, wrap around and start from @@ -458,6 +490,33 @@ unsigned int cpumask_any_and_but(const struct cpumask = *mask1, return cpumask_next_and(cpu, mask1, mask2); } =20 +/** + * cpumask_any_andnot_but - pick an arbitrary cpu from *mask1 & ~*mask2, b= ut not this one. + * @mask1: the first input cpumask + * @mask2: the second input cpumask + * @cpu: the cpu to ignore + * + * If @cpu =3D=3D -1, the function returns the first matching cpu. + * Returns >=3D nr_cpu_ids if no cpus set. + */ +static __always_inline +unsigned int cpumask_any_andnot_but(const struct cpumask *mask1, + const struct cpumask *mask2, + int cpu) +{ + unsigned int i; + + /* -1 is a legal arg here. */ + if (cpu !=3D -1) + cpumask_check(cpu); + + i =3D cpumask_first_andnot(mask1, mask2); + if (i !=3D cpu) + return i; + + return cpumask_next_andnot(cpu, mask1, mask2); +} + /** * cpumask_nth - get the Nth cpu in a cpumask * @srcp: the cpumask pointer --=20 2.39.5