Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2161168rwi; Thu, 3 Nov 2022 13:29:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GPi8jMB3cFT3oisi8S3tZvK0cKCBnlI9Sn66OikNvSLJhfYwWH+vPr9oFcN4Mqi9BNbys X-Received: by 2002:a63:2544:0:b0:46f:ed91:33ca with SMTP id l65-20020a632544000000b0046fed9133camr12797274pgl.383.1667507340039; Thu, 03 Nov 2022 13:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667507340; cv=none; d=google.com; s=arc-20160816; b=0CJ2eCH+EgeurckPwZwHcGnsx5Zjy43IL/cduZnk+hO9BODcSclgbk54rHnCGu9XBq eG75OOKVg3/y+wUVKHtQVgP/bG/Ve+YWL1YPjHg8n+2NA8wRvjV+tu8k5iyIN61mfgCc uad6tFLqdTv38GWUY9ITL0Y4GTs160bkRRBkjG4kBr5qgnyck9bap1LVm8WlEBwr6I5Y D1uCMd+84PNHcfplSwfn+zTf8PNXnRCF3Ek26qqTKXQRwz4niUVoOSrgrOWZOU0sHK7o 92JIAAsD9R7FOSeqSacVwgom7XGHsEBejKjfZjt3lLnpgIF8EMzoyPFVEoBH1hcg4bbn ivRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ecf8zEyhfc2MfDNc0mBnFVuwqhldjRijSkgRAjw68iw=; b=Ks1wmrbWCnG9lK0AeKQvPTUE4gYdCZq4P1hLtF4OP/Cfq5rJZaSiMc71BoXVCnRsHE lq/Inf74lsETqYT+msUEbTa9X1GOdO+rA4JbGYv5BuQaEQUu8WHRaXw2G2aG8TtfGUVe D4z5cxKI5+1CouWxAFz3+cn0BKJvdsZQGj2YTBoH3G5muh3trRXOWZnfnOUUzo+Y5bq0 tRZZr73fbpzSfcLnABJGmvzVzU5aLfZ02ul+eqU/uNjbOeYvT0ROi3baNZzFcZdzOiUF /j2JLgtKA5TRR/ex8dG3c+HTHUu9CdCZ63V78aCNk9iSAsA91Rjedq9g7lJoJaDdOZzm DxMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=bsjZAgee; 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 j2-20020a056a00174200b0056c6f255a7csi2209056pfc.170.2022.11.03.13.28.27; Thu, 03 Nov 2022 13:29:00 -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=smtpout1 header.b=bsjZAgee; 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 S231540AbiKCUF2 (ORCPT + 97 others); Thu, 3 Nov 2022 16:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbiKCUFA (ORCPT ); Thu, 3 Nov 2022 16:05:00 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E7392035B; Thu, 3 Nov 2022 13:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1667505897; bh=x9R+wwQH5rqLJeAi6RdxV1lJR8FdIA7e9hgUlPRECwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bsjZAgeeRailyAxjOa/qBj/1jx1wRPknx6JOoX13RvhJ17qi9q6twiYwgrWy5I3im AF49CqwbD6q/0XNkubDRjmnLs/CZGRIFhJYOo+u74H0v6Qk3tC2VFTP6Jpm6PrhAY2 7+fftDWGtWW8QToirejz3Du1M0fqOcFAj/ZHa1bROmDrpaVqiMpBYb22Xt+MxrZ4b+ q6dv5QB8fxvVJSiE0lTdALJva5SFASJfigHlTMMZtGN1ibH/9POo+gmS3ueScJc5pc lo4yREGzYyTDNLDpeboSv78t2w6zHUOq3J3x73s/ifPvK7UqJhMm/xiwdGZ2l1/kdx qfCGTJ8322OSA== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4N3F953Yl4zfjT; Thu, 3 Nov 2022 16:04:57 -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 , Alexander Mikhalitsyn , Chris Kennelly , Mathieu Desnoyers Subject: [PATCH v5 07/24] cpumask: Implement cpumask_{first,next}_{not,}andnot Date: Thu, 3 Nov 2022 16:03:42 -0400 Message-Id: <20221103200359.328736-8-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221103200359.328736-1-mathieu.desnoyers@efficios.com> References: <20221103200359.328736-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index c2aa0aa26b45..271bccc0a6d7 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -153,6 +153,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_andnot - 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_andnot(const struct cpumask *srcp1, const struct cpumask *srcp2) +{ + return find_first_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); +} + +/** + * cpumask_first_notandnot - 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_notandnot(const struct cpumask *srcp1, const struct cpumask *srcp2) +{ + return find_first_notandnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); +} + /** * cpumask_last - get the last CPU in a cpumask * @srcp: - the cpumask pointer @@ -195,6 +221,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_andnot - 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_andnot(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_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits, n+1); +} + +/** + * cpumask_next_notandnot - 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_notandnot(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_notandnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits, n+1); +} + #if NR_CPUS == 1 /* Uniprocessor: there is only one valid CPU */ static inline unsigned int cpumask_local_spread(unsigned int i, int node) -- 2.25.1