From patchwork Tue Nov 22 20:39:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 24569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2429322wrr; Tue, 22 Nov 2022 12:42:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf62aIhL2vk9VHfXruGpWe927vvK+ATRE7k4agQl+hj3yZN24bt60DLiacb9KE5hvunGHlh8 X-Received: by 2002:a17:903:2ce:b0:186:e852:b271 with SMTP id s14-20020a17090302ce00b00186e852b271mr5974778plk.117.1669149770408; Tue, 22 Nov 2022 12:42:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669149770; cv=none; d=google.com; s=arc-20160816; b=Q9Jb9C004FTXOQpy1RyQweAj9QkTO9Ba2l2XfRGJ83H7z87xb300MocYUVS029V0co zQSj/jyJniX0o4lW/9MHoZjkwAx2szJFaPaJ8t57QNjb5YVqHbFYFRfw4pRa29mRf5kd QB1ZMNtL7JVclMnXPbn9wteOR7mbNcfauvvZUacSvvsUaNwNUcc7PbKEOVk7EbsFSUHn n2hYzxhD94mqAz+cy2a9Fr2SEKl+zNi6QiP9C42vs/3vGhrvhzRN3/gfs8IPEa/7Blbh GwboTOvnRbz5UX4qTm7sHCpe2JPG3BZZFv85TRLS291TaJfDOH0b3W5scU3HT8ZK3B6Z B/NQ== 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=cFSjMHcTwF7l0DhaN0DevHsG91NXuGHG1NwvOYmk39Kc+Bs3+JJFMvDvZ/AkRkEJqU bJdU60U7oqIElJcinweIKnjOqLENUg2YLxwpRjmGsQBkDGXPMyXomaz4zDiQ/7xGApb4 VIgVXmgQmfSJTy1TfJYe858Gno6wKMWhXOg278HKALRJmVydtKMi57IHAEn5un8jTc2X mwe9JjZo+7Z9DQkYn+w9PXyPGtjiNEkSCqiL3Ys4mKdyz3+IfCvUoUP48BCBjG/d45O7 tFU82FkKbSqk2JiaRKTvzeulIltj1FRW6FEyS7cXWwXOC5h7N3mL3qgmnG6HiwVeYP7L hJNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=bnGoELNa; 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 u6-20020a631406000000b004701d95bcf8si15178926pgl.564.2022.11.22.12.42.28; Tue, 22 Nov 2022 12:42:50 -0800 (PST) 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=bnGoELNa; 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 S235107AbiKVUlv (ORCPT + 99 others); Tue, 22 Nov 2022 15:41:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234918AbiKVUkM (ORCPT ); Tue, 22 Nov 2022 15:40:12 -0500 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3023577203; Tue, 22 Nov 2022 12:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1669149594; bh=x9R+wwQH5rqLJeAi6RdxV1lJR8FdIA7e9hgUlPRECwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bnGoELNan/vc9SvhKpw1Z2W9cReETv3HGMpfsFA5aAp8J5FyLHvjo5sSHjqsbjrqx TMZvZcr0iuRK4//JAiMJoaVVmOfcfinRJlewZhxgC57UYPeRntGI1BWuAGgkH0/sBm N9/Z/LQkfmZx47N4xR8Fo1mHO6WdSnRxRsJowv5uiDO4s6EhFmc6DHVs3Y9jrCIvD6 rl2QxeP0Lx1MbSGLMEDuYESaUX1oKCJtyQZuHz9aNnRP+6UoalW0vs3xUWYQyw7nwE IjwMjtjV7AOxEZh1ylVy+Elatn2F+jR206j1coPcYEu7FRQzAjwIbFDsANCRxhHuXb OBuYG9HM/UlBg== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4NGx2d70T8zWgq; Tue, 22 Nov 2022 15:39:53 -0500 (EST) 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 23/30] cpumask: Implement cpumask_{first,next}_{not,}andnot Date: Tue, 22 Nov 2022 15:39:25 -0500 Message-Id: <20221122203932.231377-24-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122203932.231377-1-mathieu.desnoyers@efficios.com> References: <20221122203932.231377-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?1750230389545758081?= X-GMAIL-MSGID: =?utf-8?q?1750230389545758081?= 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)