Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1223999rwb; Fri, 23 Sep 2022 09:39:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM471or2pWJwwT5exy0Lt7FGYPAqZHsMurIVJGmtlQ2QeFw6gANP7Zl/ej+L1LgseQSB0747 X-Received: by 2002:a17:907:74e:b0:74f:83d4:cf58 with SMTP id xc14-20020a170907074e00b0074f83d4cf58mr7989635ejb.178.1663951181363; Fri, 23 Sep 2022 09:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663951181; cv=none; d=google.com; s=arc-20160816; b=QWuxc88yjlFCUHpXNfql/rP/gpyz+ZROjrhxJcrbVkOY6M7M2Q6IJaRU7j4S6seCW6 fgxnbrA2Vg2KfNGYvVp7Ws2wMjeplla01qgJCdRzPcMvUpuzJnk6a1R8b35cK06bZh08 pjO4PZK3SPKJiTYytZoa//YdmqU4KVpSi6sAfyzsM4u3/awa6odAAwZql8E2hTcIr2tt pMb3ubFoQkU2MlGiyEN0oujxCtnaRecrIXR5vzpIYDGu2rktdjnOqYVkZgtYRlDIbyuD NntIbC5j+FNT8ej9PXelOrREuW8u4QdHBUu0pi9GgsLpjXxya+4brUDa2Tm4ME7HgLe3 vmJQ== 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=f1rD50vdBgPCmvLBNPOPtby9Vrss+ZY8l15m1i9q/gc=; b=enQKBckUmw7er6FLgtwelucemklnmWDkEwC6cQeATVQis3IkrsJl6Z0zGZzSleAkPw R72P1o7RiRfJ/qDQtJfjy7NNTvvUZT+AGocIkBEeMUq4jzYqIg/IeWOrqaqbilwmdLGC DAzb6Ms7lSu6rUFkGU60avSHYPbIdRlJQduwR5t2Rvt2jYDJ/rUg4/IZFv1sO2odlV8/ xmgFYXHeZ0bbBEKMDmW6BjzqpZCpCUcJijhW4I+x553qjdEc3cUV23FyglZWbAPLolp5 dFOUePoTHfSl5fnu3ihV7TUiYCe1KfvQ7Gd4tfKE4tT8IwU7IlxCga+/NHVetxk+xBXQ bIRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NpSRSG7b; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs39-20020a1709072d2700b0078261e73261si5029172ejc.567.2022.09.23.09.39.14; Fri, 23 Sep 2022 09:39:41 -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=@redhat.com header.s=mimecast20190719 header.b=NpSRSG7b; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232828AbiIWP4s (ORCPT + 99 others); Fri, 23 Sep 2022 11:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbiIWP43 (ORCPT ); Fri, 23 Sep 2022 11:56:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F09CB1476A3 for ; Fri, 23 Sep 2022 08:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663948571; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f1rD50vdBgPCmvLBNPOPtby9Vrss+ZY8l15m1i9q/gc=; b=NpSRSG7b69eNngqmg/OoaA+brpTPxZSOlvAtp50NFcHG9qimsx4S+zdhZwTFZ+HWEhCOoV gGmHujo4PkmxoN5goxgUFXnlyN9SRt4IBRTn6jZWfV/6u8QK1iw5TuiyAfHSYQgjibcm8s oE6Vg/INYJEdQGpBrgYxr3JaHjOBIQw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-144-TB7ErMFhODKJPQwkRZKVdg-1; Fri, 23 Sep 2022 11:56:01 -0400 X-MC-Unique: TB7ErMFhODKJPQwkRZKVdg-1 Received: by mail-wm1-f72.google.com with SMTP id d5-20020a05600c34c500b003b4fb42ccdeso2899998wmq.8 for ; Fri, 23 Sep 2022 08:56:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=f1rD50vdBgPCmvLBNPOPtby9Vrss+ZY8l15m1i9q/gc=; b=YIJ3VLG+Hp6uLycCL1ZubOsKcHXISnegf2vpgIC0vNb2iq/w87kA2A46btoIq3SRjo Y5wf5xSEzazJ2n+dCJr+JJ/Cx6B8g15Z9cKh3MdO40N0Y9UzTzcWwBGdxGe5dkRcgQ+r yZE5FaqdleHuFIj5iPFyajgg7c41oIjhWVshOl8CeG6QQFLjBfCZGe7EM/0mzRqZj70L U7fg836E/C4Pd43j4PblViDtgHidQ95nF3UUcCv2DUd8YwgFn18T0qJTSV3pP/jMceux fTczfLAM+40v7OmC+q7fx6FrQ1jzpp1LtqW0Em6jpcyEX5+6Ru00ml1cYI8ziHqczBhx lRYw== X-Gm-Message-State: ACrzQf3h4DQAjyE2Kl2jFKH9cStRzc8o7Rb4Uosji53I0npjZ+jPQu1v b+pbvtFAlDkCkQu2o4TIM2HIoYidKKqdvfGSpYyo+xK3BJ0oQrObf6ZpgQ6g+xlpWv0vwjkg6Yw O0JFc36bFAYN8aCKUGs0UWzb2 X-Received: by 2002:a5d:610a:0:b0:22a:2a9d:880 with SMTP id v10-20020a5d610a000000b0022a2a9d0880mr5436949wrt.22.1663948558613; Fri, 23 Sep 2022 08:55:58 -0700 (PDT) X-Received: by 2002:a5d:610a:0:b0:22a:2a9d:880 with SMTP id v10-20020a5d610a000000b0022a2a9d0880mr5436937wrt.22.1663948558409; Fri, 23 Sep 2022 08:55:58 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id i7-20020a5d5587000000b0021badf3cb26sm9055429wrv.63.2022.09.23.08.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 08:55:57 -0700 (PDT) From: Valentin Schneider To: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Mel Gorman , Greg Kroah-Hartman , Heiko Carstens , Tony Luck , Jonathan Cameron , Gal Pressman , Tariq Toukan , Jesse Brandeburg Subject: [PATCH v4 2/7] cpumask: Introduce for_each_cpu_andnot() Date: Fri, 23 Sep 2022 16:55:37 +0100 Message-Id: <20220923155542.1212814-1-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220923132527.1001870-1-vschneid@redhat.com> References: <20220923132527.1001870-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 for_each_cpu_and() is very convenient as it saves having to allocate a temporary cpumask to store the result of cpumask_and(). The same issue applies to cpumask_andnot() which doesn't actually need temporary storage for iteration purposes. Following what has been done for for_each_cpu_and(), introduce for_each_cpu_andnot(). Signed-off-by: Valentin Schneider --- include/linux/cpumask.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 1b442fb2001f..4c69e338bb8c 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -238,6 +238,25 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p, nr_cpumask_bits, n + 1); } +/** + * cpumask_next_andnot - get the next cpu in *src1p & ~*src2p + * @n: the cpu prior to the place to search (ie. return will be > @n) + * @src1p: the first cpumask pointer + * @src2p: the second cpumask pointer + * + * Returns >= nr_cpu_ids if no further cpus set in *src1p & ~*src2p + */ +static inline +unsigned int cpumask_next_andnot(int n, const struct cpumask *src1p, + const struct cpumask *src2p) +{ + /* -1 is a legal arg here. */ + if (n != -1) + cpumask_check(n); + return find_next_andnot_bit(cpumask_bits(src1p), cpumask_bits(src2p), + nr_cpumask_bits, n + 1); +} + /** * for_each_cpu - iterate over every cpu in a mask * @cpu: the (optionally unsigned) integer iterator @@ -317,6 +336,26 @@ unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int sta (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \ (cpu) < nr_cpu_ids;) +/** + * for_each_cpu_andnot - iterate over every cpu present in one mask, excluding + * those present in another. + * @cpu: the (optionally unsigned) integer iterator + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * + * This saves a temporary CPU mask in many places. It is equivalent to: + * struct cpumask tmp; + * cpumask_andnot(&tmp, &mask1, &mask2); + * for_each_cpu(cpu, &tmp) + * ... + * + * After the loop, cpu is >= nr_cpu_ids. + */ +#define for_each_cpu_andnot(cpu, mask1, mask2) \ + for ((cpu) = -1; \ + (cpu) = cpumask_next_andnot((cpu), (mask1), (mask2)), \ + (cpu) < nr_cpu_ids;) + /** * cpumask_any_but - return a "random" in a cpumask, but not this one. * @mask: the cpumask to search -- 2.31.1