From patchwork Thu Nov 3 20:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 15160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp742370wru; Thu, 3 Nov 2022 13:06:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/ucBUxi4AB1WXTgtrcbsRVPLpcVqT4FrCPAJt2b85dx5DiREzhXmKRTeC06SgdDpxstop X-Received: by 2002:a05:6a00:1250:b0:56e:13c8:ee1f with SMTP id u16-20020a056a00125000b0056e13c8ee1fmr10030331pfi.82.1667505990412; Thu, 03 Nov 2022 13:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667505990; cv=none; d=google.com; s=arc-20160816; b=xLZ+dheCUKzOqcmzg1yTbp4029FcpCCABohb+oKS4nukPNhkj80qJFcsAoEb/627zx GqSP6peD2xrvU//++qKcZWh+Ee5BS1H/Ljvrh67pn5t+EYy4x1d3VFWXn0XR8nJhd+RT ZntqGGOG4xkRPDkZtLvL0muM8Gz4SBa2PY4BrMBDWDNKFyjsOdWwPFCUVmFHD/iyu1Qy RgvDVa4mA6Cyf7OS7lKxt0u+q7h4cNsGbpXPTeoR82OzFpAX6+OAEqJ+i5vjKu0L+KN9 SN8IW8TH75v7O2dRwk2vNfpNkChiUQRpdI+vx4pHbBSrgtgnUdSkclzRrQK/lN32hOsk 87wA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a63f44a000000b0046b08e9060fsi2291016pgk.485.2022.11.03.13.06.16; Thu, 03 Nov 2022 13:06:30 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748506761540356910?= X-GMAIL-MSGID: =?utf-8?q?1748506761540356910?= 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)