Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp463341imn; Fri, 29 Jul 2022 12:24:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sDX0YdCNCkk+3n/8+cgsw0+xCmpeiTTRdLLeaWxMtCCv5rc21O0bxY/5mbY9nzKPg6QlQH X-Received: by 2002:a50:fb13:0:b0:43c:ef2b:d29 with SMTP id d19-20020a50fb13000000b0043cef2b0d29mr5035628edq.378.1659122680907; Fri, 29 Jul 2022 12:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659122680; cv=none; d=google.com; s=arc-20160816; b=QQHktZqx8vmhm2bLJt8pEmiR8WZqlpZUS0Tu0BKPB5l2dDC7IMAFcmq0n4IGRYt5fI XhaYeXaP0Z0e2yuvdslTx/6HTEZ79fKz3RBbfT9rJ+P2K4xUCQ5mlFfnzNBKDdD4cf68 cZ0rwAJi533OG4TTV+9tubk1kciU0i18X8ZVnvBsE4cVdHRR0Mho3kQ5DSxxQyJv9tAo jqo82FtZmFe/6OIn9rsKWdw1iFU1YjlajG+4+Hvx06N2q3tCyXRVrbMmdNyHKzt+mRcc qC59kF91hEfeBBmYE4BMZwD/QOeZPcTtCkNJBLQjoScTcatMg693RPOHTPciPG7hy7q0 genw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=wX+6cXKANeTzmsi6b1Rv2x8YVliOIgrKgheBkN7FLYs=; b=Q6Yn5u5WWkyg03Br2kIdBTkVxlwKG45LRHVgTRg38u+2V+2BBS4FQKh/o0YGlWxoSE KI9yk9/n+orIPx9xm3HC2kEImf8jfWSEZJxgZ/ELv3+EVPGSU4XNyIuJxJp6BCYgw5Jo vzMEkWIWWYQPXpdQYJ4WaKPSfsGEWhLansgkoaq8rid6w3O3Z17weZzPufCr9ODK6QGO l9tgYMCjUZWeTRPoNI8ETZhhkSaJNyqxtlDXfBx2DLgz64Ueh8lAAceeUsuMNsvcTsEJ R33jKKnZ5zNPzTcKF7cLlAne6wEW8jVZRphOaHvCK9sPDWYxumkaRUm93sGZNuYj+iAU Genw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=kRucnBt9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020a50ef14000000b0043aa5c04926si1601322eds.150.2022.07.29.12.24.15; Fri, 29 Jul 2022 12:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=kRucnBt9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238671AbiG2TDH (ORCPT + 99 others); Fri, 29 Jul 2022 15:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238588AbiG2TCy (ORCPT ); Fri, 29 Jul 2022 15:02:54 -0400 Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC9488E24; Fri, 29 Jul 2022 12:02:49 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 9DB8F318B5E; Fri, 29 Jul 2022 15:02:48 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id y4PqTlgBnJHS; Fri, 29 Jul 2022 15:02:48 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C4461319089; Fri, 29 Jul 2022 15:02:44 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com C4461319089 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1659121364; bh=wX+6cXKANeTzmsi6b1Rv2x8YVliOIgrKgheBkN7FLYs=; h=From:To:Date:Message-Id; b=kRucnBt9zeu06kROqMnvMcC1bVK0f06QFXBmnLTF4HaUNlwLqMqNHFr7p9CLVzN0j OelIf3hawqxn0HNh9pXY6Hn/a5wbG6FHZXD/mCqS8g1w9Zi62PhaR6C4N8RA+sAEV7 p160MWsNY9sYuWUqu9XFSytU95Cq6oyPkktedVbElcqPcrXTBsvvZ8D+DLv2YlCWBZ IO9GeM8FixRvrXTM1Y3wJdkVP5Fon6PKTxB3dIf+hrlHSGf/PYDaZhiXrDT4Oj6TM2 0INjMlcLUWM20IVNBV9CBHsuh7YfNtxrHLIDGHmJbKUrytQ3rLJzqVGGHHE0h9dv4P QDu6wJBLzQg0Q== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9IxLtaW2HgUY; Fri, 29 Jul 2022 15:02:44 -0400 (EDT) Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id 2906C318A6B; Fri, 29 Jul 2022 15:02:43 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , Florian Weimer , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Mathieu Desnoyers Subject: [PATCH v3 08/23] cpumask: implement cpumask_{first,next}_{zero,one}_and_zero Date: Fri, 29 Jul 2022 15:02:10 -0400 Message-Id: <20220729190225.12726-9-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220729190225.12726-1-mathieu.desnoyers@efficios.com> References: <20220729190225.12726-1-mathieu.desnoyers@efficios.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow finding the first or next bit within two input cpumasks which is either: - both zero and zero, - respectively one and zero. Signed-off-by: Mathieu Desnoyers --- include/linux/cpumask.h | 86 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index fe29ac7cc469..0f5c3e47423f 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -134,6 +134,18 @@ static inline unsigned int cpumask_first_and(const struct cpumask *srcp1, return 0; } +static inline unsigned int cpumask_first_one_and_zero(const struct cpumask *srcp1, + const struct cpumask *srcp2) +{ + return 0; +} + +static inline unsigned int cpumask_first_zero_and_zero(const struct cpumask *srcp1, + const struct cpumask *srcp2) +{ + return 0; +} + static inline unsigned int cpumask_last(const struct cpumask *srcp) { return 0; @@ -157,6 +169,20 @@ static inline unsigned int cpumask_next_and(int n, return n+1; } +static inline unsigned int cpumask_next_one_and_zero(int n, + const struct cpumask *srcp1, + const struct cpumask *srcp2) +{ + return n+1; +} + +static inline unsigned int cpumask_next_zero_and_zero(int n, + const struct cpumask *srcp1, + const struct cpumask *srcp2) +{ + return n+1; +} + static inline unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap) { @@ -230,6 +256,32 @@ unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask return find_first_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); } +/** + * cpumask_first_one_and_zero - return the first cpu from *srcp1 & ~*srcp2 + * @src1p: the first input + * @src2p: the second input + * + * Returns >= nr_cpu_ids if no cpus match in both. + */ +static inline +unsigned int cpumask_first_one_and_zero(const struct cpumask *srcp1, const struct cpumask *srcp2) +{ + return find_first_one_and_zero_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); +} + +/** + * cpumask_first_zero_and_zero - return the first cpu from ~*srcp1 & ~*srcp2 + * @src1p: the first input + * @src2p: the second input + * + * Returns >= nr_cpu_ids if no cpus match in both. + */ +static inline +unsigned int cpumask_first_zero_and_zero(const struct cpumask *srcp1, const struct cpumask *srcp2) +{ + return find_first_zero_and_zero_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); +} + /** * cpumask_last - get the last CPU in a cpumask * @srcp: - the cpumask pointer @@ -258,6 +310,40 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1); } +/** + * cpumask_next_one_and_zero - return the next cpu from *srcp1 & ~*srcp2 + * @n: the cpu prior to the place to search (ie. return will be > @n) + * @src1p: the first input + * @src2p: the second input + * + * Returns >= nr_cpu_ids if no cpus match in both. + */ +static inline +unsigned int cpumask_next_one_and_zero(int n, const struct cpumask *srcp1, const struct cpumask *srcp2) +{ + /* -1 is a legal arg here. */ + if (n != -1) + cpumask_check(n); + return find_next_one_and_zero_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits, n+1); +} + +/** + * cpumask_next_zero_and_zero - return the next cpu from ~*srcp1 & ~*srcp2 + * @n: the cpu prior to the place to search (ie. return will be > @n) + * @src1p: the first input + * @src2p: the second input + * + * Returns >= nr_cpu_ids if no cpus match in both. + */ +static inline +unsigned int cpumask_next_zero_and_zero(int n, const struct cpumask *srcp1, const struct cpumask *srcp2) +{ + /* -1 is a legal arg here. */ + if (n != -1) + cpumask_check(n); + return find_next_zero_and_zero_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits, n+1); +} + int __pure cpumask_next_and(int n, const struct cpumask *, const struct cpumask *); int __pure cpumask_any_but(const struct cpumask *mask, unsigned int cpu); unsigned int cpumask_local_spread(unsigned int i, int node); -- 2.17.1