From patchwork Thu Aug 25 18:12:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955112 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F7B8ECAA25 for ; Thu, 25 Aug 2022 18:12:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243287AbiHYSMx (ORCPT ); Thu, 25 Aug 2022 14:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243213AbiHYSMv (ORCPT ); Thu, 25 Aug 2022 14:12:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF55FBD16B for ; Thu, 25 Aug 2022 11:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451163; 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=hRCkxRGTLmsrQqX09/lEo5/j9SdQgOT7KVWNp7Ie7zk=; b=FqkZw5dynESsGX9VquNDo7jVCYhnIZa9u6hWDQZwXzs563PykXPSrvCzjiXYwWJ1aileGk uG+SbCw+gC9NYxq/DKBkvklf7JuoOAUdQ40zHZKRHfeYia3Gmi7PApPWlUgxQMUQwn/axQ oTIZ70OSo7+XVaAV0uHMh5csF2ISswk= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-277-5rF5R0rqPmuZDZNxskXdOQ-1; Thu, 25 Aug 2022 14:12:42 -0400 X-MC-Unique: 5rF5R0rqPmuZDZNxskXdOQ-1 Received: by mail-wr1-f70.google.com with SMTP id d1-20020adfa341000000b0022571fbdfe2so1157966wrb.3 for ; Thu, 25 Aug 2022 11:12:41 -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; bh=hRCkxRGTLmsrQqX09/lEo5/j9SdQgOT7KVWNp7Ie7zk=; b=t/CFLq3iVtz77MWviF4G1RSlsRPFlL3YwuH+6cvscRGDCWrAGwQMMoiLeaX6I+NNOu hgIF3dpg29VtWZGyNyF1ICX+QriZs9hLD38tLgVrlFEYE8VNUikTid3/m7v+sdU8Jnk+ XoQlC95NUpeuFBmJDbUQMeevAyPk2Z/KCxJglefPN9zruWJCRkcRqZtYezewoUKJzLey sR/jyzfvrs1fy56IW31j7Oz+Ua/NDh98xWUseIUc7aJcyc8eUi+pNZK+hpARFhJnMvQI G/ZLbPI8CL4lGwctmc0d1DmAl7GY5JJ9/THHn4J+1HX25SCGITZKau9fLX/Xpi+8WkWN 0umw== X-Gm-Message-State: ACgBeo2SGC0lbrV1ltHTJyRx7Zowgo/br5KE0i4AY89TJc0hToBjv1gD lAhoOauCRRsNG4fFg4d7NMe3lW/66TUqUBLjELW/bg/iZt2rLbZOaAXMoJq05uO4cDTNai/5grR l+m2KxOKXVUYr6k3GHx7hCLW8qS2d0enujMfSxfAurO7hz5ClehxBXrKSZbjycCNYQLmT X-Received: by 2002:a5d:45c4:0:b0:225:4320:1401 with SMTP id b4-20020a5d45c4000000b0022543201401mr2994491wrs.474.1661451160693; Thu, 25 Aug 2022 11:12:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR4fjN7hsvjTudH2itqlMcc3FAuj0f548hYAGxBnKB1bc1Mv3He53yWfXNTJ/JWMyImi2TUnJQ== X-Received: by 2002:a5d:45c4:0:b0:225:4320:1401 with SMTP id b4-20020a5d45c4000000b0022543201401mr2994455wrs.474.1661451160399; Thu, 25 Aug 2022 11:12:40 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:39 -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 v3 1/9] cpumask: Make cpumask_full() check for nr_cpu_ids bits Date: Thu, 25 Aug 2022 19:12:02 +0100 Message-Id: <20220825181210.284283-2-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Consider a system with 4 CPUs and: CONFIG_NR_CPUS=64 CONFIG_CPUMASK_OFFSTACK=n In this situation, we have: nr_cpumask_bits == NR_CPUS == 64 nr_cpu_ids = 4 Per smp.c::setup_nr_cpu_ids(), nr_cpu_ids <= NR_CPUS, so we want cpumask_full() to check for nr_cpu_ids bits set. This issue is currently pointed out by the cpumask KUnit tests: [ 14.072028] # test_cpumask_weight: EXPECTATION FAILED at lib/test_cpumask.c:57 [ 14.072028] Expected cpumask_full(((const struct cpumask *)&__cpu_possible_mask)) to be true, but is false [ 14.079333] not ok 1 - test_cpumask_weight Signed-off-by: Valentin Schneider --- include/linux/cpumask.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index bd047864c7ac..1414ce8cd003 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -574,7 +574,7 @@ static inline bool cpumask_empty(const struct cpumask *srcp) */ static inline bool cpumask_full(const struct cpumask *srcp) { - return bitmap_full(cpumask_bits(srcp), nr_cpumask_bits); + return bitmap_full(cpumask_bits(srcp), nr_cpu_ids); } /** From patchwork Thu Aug 25 18:12:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35856ECAA24 for ; Thu, 25 Aug 2022 18:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243324AbiHYSMz (ORCPT ); Thu, 25 Aug 2022 14:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243229AbiHYSMv (ORCPT ); Thu, 25 Aug 2022 14:12:51 -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 C8B9F74CD8 for ; Thu, 25 Aug 2022 11:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451164; 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=aa7TgxIpu/jW/iqd5xTwDqe/1bK1e/1x+Xly3SMXIUI=; b=et1HTKQhDLL+2LCJmI26o4krfTPy3HDhyDjk5q3CUzKF7Y0y24u46ZgqqHVhAZ5or3y9SU 9iIUl/oUhHzmM5KzMkG1xK90XYdUY7W7sefQfqeTmK0zluhFmb8fu1ERjXIpns+SZQkhKu RBKJ9J7DjpsDq0W79Kt+ZgrF+5ErbSg= 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-382-6HClr6fCMJuXANS3eOpDHQ-1; Thu, 25 Aug 2022 14:12:43 -0400 X-MC-Unique: 6HClr6fCMJuXANS3eOpDHQ-1 Received: by mail-wm1-f72.google.com with SMTP id ay21-20020a05600c1e1500b003a6271a9718so10982009wmb.0 for ; Thu, 25 Aug 2022 11:12:43 -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; bh=aa7TgxIpu/jW/iqd5xTwDqe/1bK1e/1x+Xly3SMXIUI=; b=0Cy4ezCS5cd+kxuP2ojQnaoBiiYjlfGwcpuIZELsHCW3+DTinTxQ/TQEn/4orEdM+9 YPfBAIHOJAtDiSnBqkt7wBwrgYOVoFwVF6nWff1vEw/SeuvXTv8YbepPjseHOKSImshS BE73SqrHP8fX2FZqPxRT4jhJmqvKBxp7S/e0MifGa3tgViDyKt/+luhxKAcCltGV/bMb LvSEnAKBr0FUQlyaVesL0VjI2LE7fUMftWmj55NBfHXvVm8f8fkq0YREHo/fSC9GzQMT i3Mu/VccLJAKdPAnKdS7fvsQtfnbOfxSDi46K3PvHF6dgq0QR/Jd5YXYBwoX+xFqnPz3 EDlw== X-Gm-Message-State: ACgBeo26HalGHa0tQqebQTFqIeDtE9069CKiqdODtdlb742m0uHmJzSC M31C9cIsAd9d3Jz1yT13lXV55BALw+Bx9e0gdlEZvyjieuFmKghQoyOlyGS3sZ5po15EwzI29G/ 2IJhZ9pooURllw458U6/64fMrOIpEaByYLZT8t2KwKZAR2oatJ6qUWMtOLQtu4Ur61J+1 X-Received: by 2002:a05:6000:1f9b:b0:225:7694:3b36 with SMTP id bw27-20020a0560001f9b00b0022576943b36mr3024145wrb.310.1661451162052; Thu, 25 Aug 2022 11:12:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR48+XemZLeoI5/0hKjHm0hpojsmml99HpqQqzINgCYNPX/9v3T9th/wzQI0CY0AzciHT6w5pQ== X-Received: by 2002:a05:6000:1f9b:b0:225:7694:3b36 with SMTP id bw27-20020a0560001f9b00b0022576943b36mr3024110wrb.310.1661451161782; Thu, 25 Aug 2022 11:12:41 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:41 -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 v3 2/9] lib/test_cpumask: Make test_cpumask_last check for nr_cpu_ids bits Date: Thu, 25 Aug 2022 19:12:03 +0100 Message-Id: <20220825181210.284283-3-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org test_cpumask_last() currently fails on a system with CONFIG_NR_CPUS=64 CONFIG_CPUMASK_OFFSTACK=n nr_cpu_ids < NR_CPUS [ 14.088853] # test_cpumask_last: EXPECTATION FAILED at lib/test_cpumask.c:77 [ 14.088853] Expected ((unsigned int)64) - 1 == cpumask_last(((const struct cpumask *)&__cpu_possible_mask)), but [ 14.088853] ((unsigned int)64) - 1 == 63 [ 14.088853] cpumask_last(((const struct cpumask *)&__cpu_possible_mask)) == 3 [ 14.090435] not ok 3 - test_cpumask_last Per smp.c::setup_nr_cpu_ids(), nr_cpu_ids <= NR_CPUS, so we want the test to use nr_cpu_ids rather than nr_cpumask_bits. Signed-off-by: Valentin Schneider --- lib/test_cpumask.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/test_cpumask.c b/lib/test_cpumask.c index a31a1622f1f6..81b17563fcb3 100644 --- a/lib/test_cpumask.c +++ b/lib/test_cpumask.c @@ -73,8 +73,8 @@ static void test_cpumask_first(struct kunit *test) static void test_cpumask_last(struct kunit *test) { - KUNIT_EXPECT_LE(test, nr_cpumask_bits, cpumask_last(&mask_empty)); - KUNIT_EXPECT_EQ(test, nr_cpumask_bits - 1, cpumask_last(cpu_possible_mask)); + KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_last(&mask_empty)); + KUNIT_EXPECT_EQ(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask)); } static void test_cpumask_next(struct kunit *test) From patchwork Thu Aug 25 18:12:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FE41ECAA25 for ; Thu, 25 Aug 2022 18:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243251AbiHYSNL (ORCPT ); Thu, 25 Aug 2022 14:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243247AbiHYSMx (ORCPT ); Thu, 25 Aug 2022 14:12:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C919CB9FBA for ; Thu, 25 Aug 2022 11:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451166; 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=riJHOBdNMmZs8GX2vslyzCJQoAgfFKh7Rz4UoMtS+DE=; b=ZUbsfUJCyRR4dDNJNuy/3+F1OoeGSE0dje+IqYb89Ke9Cil5sAK/L7UUqmtPKTN8nFKdzW fYNBYWVm2rcXO8Fc1cL4BNtW4h6DwHFnuHoXg0aiMfuw4g0xbvpQC+Hi/ozO66RTr1Ny7E 5dmKy9gY6QzAZgg4S96WaLABX48cz6g= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-581-WMbYeYmMMt2heqnUeeBsyQ-1; Thu, 25 Aug 2022 14:12:45 -0400 X-MC-Unique: WMbYeYmMMt2heqnUeeBsyQ-1 Received: by mail-wm1-f70.google.com with SMTP id j3-20020a05600c1c0300b003a5e72421c2so2813985wms.1 for ; Thu, 25 Aug 2022 11:12:44 -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; bh=riJHOBdNMmZs8GX2vslyzCJQoAgfFKh7Rz4UoMtS+DE=; b=puRTye1gMchRGpHAX/1+IsSwAD7ftwblL4ny3PUqAVXQRdLqQVJDXhpuHjkCpNHVdu rXR8ruTBi0RTBLDVg5N7puTPJ3JwG4OIsHywEobeidyxn82cCT96cNZdtwMXhBbBE4/4 Gkt6/bAE0KVDmcPTf1RD8Njcq7YfGa8EYVFqMCB0TSYX8IIDHaspDmJKwhcjf8hokk6q J3jO6RRKHp4YuDdwB9458h49EOfbeGb35BRU9aGOj0pvXCL4KiP5AAJtjyarRoX4al+7 v+Srf0o573dsWQhCV8XqCmvD3NN5OSzaRovZLZMvtbYqtleqDn3yueF7GCVWDTPRp4wC 9BsQ== X-Gm-Message-State: ACgBeo1pAQVEBwJLwyPwGcLQh0QdAk965XBfgt3cdU7taAKXI6tE8nNt yWwmEbvP4fXnB6aCbhDx2uUpgyDRRdZRYND6oPkJbPxHtw8NMVayj8yxRh0qDqY3Fxt8P7H/HAW s9DnGPQkcya5njPYufc7ISpGjfpxLQ55Wv643v0mBlwnoTaIsOPHjcLYYC/eGX7IjOQQy X-Received: by 2002:a5d:4012:0:b0:225:283a:8273 with SMTP id n18-20020a5d4012000000b00225283a8273mr2943777wrp.8.1661451163460; Thu, 25 Aug 2022 11:12:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR6JYTLUh9FypHhvAKJFPhVhQ2keQoaiGdrhdEB1pT+zv7XCZYmsLHFf3yeX34S4q77Fazv6cQ== X-Received: by 2002:a5d:4012:0:b0:225:283a:8273 with SMTP id n18-20020a5d4012000000b00225283a8273mr2943735wrp.8.1661451163060; Thu, 25 Aug 2022 11:12:43 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:42 -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 v3 3/9] bitops: Introduce find_next_andnot_bit() Date: Thu, 25 Aug 2022 19:12:04 +0100 Message-Id: <20220825181210.284283-4-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation of introducing for_each_cpu_andnot(), add a variant of find_next_bit() that negate the bits in @addr2 when ANDing them with the bits in @addr1. Note that the _find_next_bit() @invert argument now gets split into two: @invert1 for words in @addr1, @invert2 for words in @addr2. The only current users of _find_next_bit() with @invert set are: o find_next_zero_bit() o find_next_zero_bit_le() and neither of these pass an @addr2, so the conversion is straightforward. Signed-off-by: Valentin Schneider --- include/linux/find.h | 44 ++++++++++++++++++++++++++++++++++++++------ lib/find_bit.c | 23 ++++++++++++----------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/include/linux/find.h b/include/linux/find.h index 424ef67d4a42..a195cf0a8bab 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -10,7 +10,8 @@ extern unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le); + unsigned long start, unsigned long invert1, unsigned long invert2, + unsigned long le); extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); extern unsigned long _find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size); @@ -41,7 +42,7 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, return val ? __ffs(val) : size; } - return _find_next_bit(addr, NULL, size, offset, 0UL, 0); + return _find_next_bit(addr, NULL, size, offset, 0UL, 0UL, 0); } #endif @@ -71,7 +72,38 @@ unsigned long find_next_and_bit(const unsigned long *addr1, return val ? __ffs(val) : size; } - return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0UL, 0); +} +#endif + +#ifndef find_next_andnot_bit +/** + * find_next_andnot_bit - find the next bit in *addr1 excluding all the bits + * in *addr2 + * @addr1: The first address to base the search on + * @addr2: The second address to base the search on + * @size: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns the bit number for the next set bit + * If no bits are set, returns @size. + */ +static inline +unsigned long find_next_andnot_bit(const unsigned long *addr1, + const unsigned long *addr2, unsigned long size, + unsigned long offset) +{ + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr1 & ~*addr2 & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + + return _find_next_bit(addr1, addr2, size, offset, 0UL, ~0UL, 0); } #endif @@ -99,7 +131,7 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, return val == ~0UL ? size : ffz(val); } - return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0UL, 0); } #endif @@ -247,7 +279,7 @@ unsigned long find_next_zero_bit_le(const void *addr, unsigned return val == ~0UL ? size : ffz(val); } - return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0UL, 1); } #endif @@ -266,7 +298,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned return val ? __ffs(val) : size; } - return _find_next_bit(addr, NULL, size, offset, 0UL, 1); + return _find_next_bit(addr, NULL, size, offset, 0UL, 0UL, 1); } #endif diff --git a/lib/find_bit.c b/lib/find_bit.c index 1b8e4b2a9cba..c46b66d7d2b4 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -21,27 +21,29 @@ #if !defined(find_next_bit) || !defined(find_next_zero_bit) || \ !defined(find_next_bit_le) || !defined(find_next_zero_bit_le) || \ - !defined(find_next_and_bit) + !defined(find_next_and_bit) || !defined(find_next_andnot_bit) /* * This is a common helper function for find_next_bit, find_next_zero_bit, and * find_next_and_bit. The differences are: - * - The "invert" argument, which is XORed with each fetched word before - * searching it for one bits. * - The optional "addr2", which is anded with "addr1" if present. + * - The "invert" arguments, which are XORed with each fetched word (invert1 + * for words in addr1, invert2 for those in addr2) before searching it for + * one bits. */ unsigned long _find_next_bit(const unsigned long *addr1, - const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le) + const unsigned long *addr2, + unsigned long nbits, unsigned long start, + unsigned long invert1, unsigned long invert2, + unsigned long le) { unsigned long tmp, mask; if (unlikely(start >= nbits)) return nbits; - tmp = addr1[start / BITS_PER_LONG]; + tmp = addr1[start / BITS_PER_LONG] ^ invert1; if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; - tmp ^= invert; + tmp &= addr2[start / BITS_PER_LONG] ^ invert2; /* Handle 1st word. */ mask = BITMAP_FIRST_WORD_MASK(start); @@ -57,10 +59,9 @@ unsigned long _find_next_bit(const unsigned long *addr1, if (start >= nbits) return nbits; - tmp = addr1[start / BITS_PER_LONG]; + tmp = addr1[start / BITS_PER_LONG] ^ invert1; if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; - tmp ^= invert; + tmp &= addr2[start / BITS_PER_LONG] ^ invert2; } if (le) From patchwork Thu Aug 25 18:12:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C81D2ECAA25 for ; Thu, 25 Aug 2022 18:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243322AbiHYSNg (ORCPT ); Thu, 25 Aug 2022 14:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242777AbiHYSNJ (ORCPT ); Thu, 25 Aug 2022 14:13:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 440AEBD284 for ; Thu, 25 Aug 2022 11:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451171; 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=MrW3KirCN30zCt1W75Xnts+OcNfMj70LF3woTfJkL5o=; b=YaEHJTE5zhxkklq2PBI4J5qDh4EJVaTTjPIZHhm1N+vyHas/2+Kz5BkkirDRjPIrB4+rdl 1iGIQFHPPNcZ+G8e296zEU1SpyL8gwxJ8oPNay2bDcgRiO7+Trhha2SvLvVDs1rRGpuOAH aj7mORh5IG7hya5qL6zc6xZDYSSx3WU= 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-245-u1E7guKtNGuZI_-XtfJ-4w-1; Thu, 25 Aug 2022 14:12:48 -0400 X-MC-Unique: u1E7guKtNGuZI_-XtfJ-4w-1 Received: by mail-wm1-f72.google.com with SMTP id a17-20020a05600c349100b003a545125f6eso2774455wmq.4 for ; Thu, 25 Aug 2022 11:12:47 -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; bh=MrW3KirCN30zCt1W75Xnts+OcNfMj70LF3woTfJkL5o=; b=4MDXeMKl69XdQ4UzDIZSupPrjMnia/t/lVcyn41Ey95aeyfv1xG7z24lYwu7FuwSjb ZYsiQlcPPf8rgdVz5SaWBGOWKllgkWgkNyJ+xpFRws47LOTQRLEnWnLtoKdxelCfI56q zoJGLMX4a3C/AjPIDaPE9kugpJAyVM23rm2vK782bqfmvkNZy+l++ahEiq65uzkA2Fh/ MOeutd9M2wJHXIuCZJ207GZkkIfoOvwhsVKQLuKagEf9Bd0TSlftLMKcViy4/e0+Luih 0R7ssNkXPlte5qVAFUfZ8IeUVLpWjZKbFWvGHFt5ayljE5EZQcS9j1I0ii7sH9mVyiWa gAcg== X-Gm-Message-State: ACgBeo1Qt+tKA4BATx4WV6py7tfyOibUDgOtkVkPYQjUfQjgYEtbAalt 0dp8zVf4Q2qc9WnGnCU6bPHRQwyV0+m3EoVBy/dgR/D3aRCNT25jebNCjo97OX/ueUqIT1yWbXx 4LTGEyqWBBhGtbE3nlYNmYhcN+3ITB7WdQCr9yeaZ+5/AI0AeV66JjpFrdBW74SQLBH0w X-Received: by 2002:a5d:68c9:0:b0:225:330b:2d0 with SMTP id p9-20020a5d68c9000000b00225330b02d0mr2795033wrw.243.1661451165200; Thu, 25 Aug 2022 11:12:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ao2h70S57Mc6QfTHW3PBLSxOg2mVt1GMZpIHsupvErIGsFwcjS67fyxkj1o1xP3reb4xMcw== X-Received: by 2002:a5d:68c9:0:b0:225:330b:2d0 with SMTP id p9-20020a5d68c9000000b00225330b02d0mr2794999wrw.243.1661451164866; Thu, 25 Aug 2022 11:12:44 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:44 -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 v3 4/9] cpumask: Introduce for_each_cpu_andnot() Date: Thu, 25 Aug 2022 19:12:05 +0100 Message-Id: <20220825181210.284283-5-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@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 1414ce8cd003..372a642bf9ba 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 From patchwork Thu Aug 25 18:12:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90FC4ECAA27 for ; Thu, 25 Aug 2022 18:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238113AbiHYSNP (ORCPT ); Thu, 25 Aug 2022 14:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243297AbiHYSMy (ORCPT ); Thu, 25 Aug 2022 14:12:54 -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 34864BB924 for ; Thu, 25 Aug 2022 11:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451169; 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=fi5a4KAJqfy3ci33ccYmogCkY8ciHV2wHDw8LNbyax8=; b=H8dNzrIddSnqYvhnE8FM6wxIdi82gDs4QYgLoQAAavNEgk/rYfvPZXfNEdoNXrK1zvwqmr 2iPJQucd8f1pMICkSt5pXA8xsOyugWlmNqvtGpBS6FQ15Wr5EaTLH/KLyFHQHpyzGP5y7s ItHyKc9cEEn+pAkFYA2S8NO0q6YdTlA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-614-j7j06pvjP0K5YxDzIBmiHg-1; Thu, 25 Aug 2022 14:12:47 -0400 X-MC-Unique: j7j06pvjP0K5YxDzIBmiHg-1 Received: by mail-wr1-f70.google.com with SMTP id q19-20020adfab13000000b0022588ea1182so119920wrc.20 for ; Thu, 25 Aug 2022 11:12:47 -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; bh=fi5a4KAJqfy3ci33ccYmogCkY8ciHV2wHDw8LNbyax8=; b=NGq67cesYHhvA7Y4+Rn61j/PiGr1USfiiV4yxwkI5J/N8DDW5xbLHJXQbOI0u/u5R8 fEwDI6Pafcta3GFE6DohGP05iqxPEsDhcAAXYH63KWTPrZ7l89K5qJiEMBsFLZE80jhs JVn5+RWEq9xB6I61sqSVqqi2j7Beh7yUX02lL1isto4ZQ9J0pAfV9Een9uIo8oHcc2ct 8lt42relp+lYKCx+YiD168x9oajQh2C39JIMegX1fbPBtKh5/F7Zo0x7mL3jigJgeNmz m3T7wJ8OdYlytHUsUiFe8sZytnee928rgYumzERGVn5g9ua1kGq7UNV8nty67gP7IFnh GCOg== X-Gm-Message-State: ACgBeo3mbGojPJcS1AiILWtgJk7PS0n5crICHO/Y+s8w6CuropBc9FYe TKs686GxtPXiQum6RCIwWWCCkH2Ohg3B0sHA0jdEfSOxaedUf4V+ErakgBp/AToTvoEgsCwIOa2 XgCTUenXSeOvj1Nm97FwPMoNEsfHoHUG2AqR2UT8HXW2W7cBlhbOwKYRhbCinB/6Zr1L9 X-Received: by 2002:a05:600c:216:b0:3a6:60e1:2726 with SMTP id 22-20020a05600c021600b003a660e12726mr2944921wmi.182.1661451166443; Thu, 25 Aug 2022 11:12:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR4/nJYROvYiQ2IAfhO3CgdBZ6m1FiBVpd031oI0fdbvWUxPIJUgnQVz/WpVzsga42+sehCrlg== X-Received: by 2002:a05:600c:216:b0:3a6:60e1:2726 with SMTP id 22-20020a05600c021600b003a660e12726mr2944883wmi.182.1661451166173; Thu, 25 Aug 2022 11:12:46 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:45 -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 v3 5/9] lib/test_cpumask: Add for_each_cpu_and(not) tests Date: Thu, 25 Aug 2022 19:12:06 +0100 Message-Id: <20220825181210.284283-6-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Following the recent introduction of for_each_andnot(), add some tests to ensure for_each_cpu_and(not) results in the same as iterating over the result of cpumask_and(not)(). Signed-off-by: Valentin Schneider --- lib/test_cpumask.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/test_cpumask.c b/lib/test_cpumask.c index 81b17563fcb3..62d499394d8a 100644 --- a/lib/test_cpumask.c +++ b/lib/test_cpumask.c @@ -29,6 +29,19 @@ KUNIT_EXPECT_EQ((test), nr_cpu_ids - mask_weight, iter); \ } while (0) +#define EXPECT_FOR_EACH_CPU_OP_EQ(test, op, mask1, mask2) \ + do { \ + const cpumask_t *m1 = (mask1); \ + const cpumask_t *m2 = (mask2); \ + int weight; \ + int cpu, iter = 0; \ + cpumask_##op(&mask_tmp, m1, m2); \ + weight = cpumask_weight(&mask_tmp); \ + for_each_cpu_##op(cpu, mask1, mask2) \ + iter++; \ + KUNIT_EXPECT_EQ((test), weight, iter); \ + } while (0) + #define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \ do { \ const cpumask_t *m = (mask); \ @@ -50,6 +63,7 @@ static cpumask_t mask_empty; static cpumask_t mask_all; +static cpumask_t mask_tmp; static void test_cpumask_weight(struct kunit *test) { @@ -91,10 +105,15 @@ static void test_cpumask_iterators(struct kunit *test) EXPECT_FOR_EACH_CPU_EQ(test, &mask_empty); EXPECT_FOR_EACH_CPU_NOT_EQ(test, &mask_empty); EXPECT_FOR_EACH_CPU_WRAP_EQ(test, &mask_empty); + EXPECT_FOR_EACH_CPU_OP_EQ(test, and, &mask_empty, &mask_empty); + EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, &mask_empty); + EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, &mask_empty, &mask_empty); EXPECT_FOR_EACH_CPU_EQ(test, cpu_possible_mask); EXPECT_FOR_EACH_CPU_NOT_EQ(test, cpu_possible_mask); EXPECT_FOR_EACH_CPU_WRAP_EQ(test, cpu_possible_mask); + EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, cpu_possible_mask); + EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, cpu_possible_mask, &mask_empty); } static void test_cpumask_iterators_builtin(struct kunit *test) From patchwork Thu Aug 25 18:12:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D011ECAA24 for ; Thu, 25 Aug 2022 18:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236695AbiHYSNS (ORCPT ); Thu, 25 Aug 2022 14:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243307AbiHYSMy (ORCPT ); Thu, 25 Aug 2022 14:12:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D847333E for ; Thu, 25 Aug 2022 11:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451170; 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=g9sq97waYr8mH2rClKPdli1YiqFmptQI/NPj6B1KpLs=; b=Pq0wv68CueR207FnqmJSCA5qFybyl1lakVrYFP9H36inbuq8DcfTMYr1xlQ9k5VnJGWadD v4F7bSFt0qDmfdY/q33JHLNg480kRxLIgFTadb1wy938sFGoGjFt4uVq0HB16Ox0/nQ3q6 AFP9r74wDBB2CKm/zcihKP8ovE/uOGg= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-607-VOGLwlhZMUON-7k3VhHyCw-1; Thu, 25 Aug 2022 14:12:49 -0400 X-MC-Unique: VOGLwlhZMUON-7k3VhHyCw-1 Received: by mail-wr1-f70.google.com with SMTP id q19-20020adfab13000000b0022588ea1182so119935wrc.20 for ; Thu, 25 Aug 2022 11:12:48 -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; bh=g9sq97waYr8mH2rClKPdli1YiqFmptQI/NPj6B1KpLs=; b=vBaWbCY2BavE1vfdVLd+2z/yOAZheP68qhHaXHG/kVXJtPM2J151GkNN+mLTNnSgIR +Hx85atMTp48vaMFDxBr2xhy8rLlzKpL9QBm/RzrhLlLfBL0gzRlD8CGBorcBuSefEIs lTv+JAFYIaxVlO9wlwyE7pLDlig9RLYDa36q0PO0xelKH0UtGKszcgeFSNl4Vo4bzMdD cDb8zkGIiT/ctzTFwWw8qGsNagjA9keF0kOPMSWYb/T1/YbH4FfuBMJQ06amkyOC5xTW qTV/1/tY6foHYLS+8CQW3h8+ZArfVVvKk7v9zGsyYNxt2ZDLeuBIeoHtFmkZUiiW9eZE 3LTA== X-Gm-Message-State: ACgBeo0ZTAFxZJgCNRUQfHOjQzEbE2aawAFsdH3tODtL6CLXXPl0pCJe h88jZX3HoQ/Cyu5wvduxrRNql696VgpXvs1/ta2u4zcby74V597hbZlsaksAQXnpUUX45fnH9kC FfoFOyynmhTBw3OZZp9NjNSHuAZHLVUilFaaxtu7fST/IOR8l/gjATwY2wEaxPl5VgZBI X-Received: by 2002:a05:6000:a0d:b0:225:4bf3:95bd with SMTP id co13-20020a0560000a0d00b002254bf395bdmr3076444wrb.289.1661451167801; Thu, 25 Aug 2022 11:12:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR5BpNbjLHR+235HnmP7arPWYZvpmPyiHCVfRmljczNrmIGhxXf4zF8KGcetcyQdkdacI6vzgA== X-Received: by 2002:a05:6000:a0d:b0:225:4bf3:95bd with SMTP id co13-20020a0560000a0d00b002254bf395bdmr3076409wrb.289.1661451167560; Thu, 25 Aug 2022 11:12:47 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:47 -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 v3 6/9] sched/core: Merge cpumask_andnot()+for_each_cpu() into for_each_cpu_andnot() Date: Thu, 25 Aug 2022 19:12:07 +0100 Message-Id: <20220825181210.284283-7-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This removes the second use of the sched_core_mask temporary mask. Signed-off-by: Valentin Schneider --- kernel/sched/core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ee28253c9ac0..b4c3112b0095 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -360,10 +360,7 @@ static void __sched_core_flip(bool enabled) /* * Toggle the offline CPUs. */ - cpumask_copy(&sched_core_mask, cpu_possible_mask); - cpumask_andnot(&sched_core_mask, &sched_core_mask, cpu_online_mask); - - for_each_cpu(cpu, &sched_core_mask) + for_each_cpu_andnot(cpu, cpu_possible_mask, cpu_online_mask) cpu_rq(cpu)->core_enabled = enabled; cpus_read_unlock(); From patchwork Thu Aug 25 18:12:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45AF7ECAA28 for ; Thu, 25 Aug 2022 18:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243467AbiHYSNh (ORCPT ); Thu, 25 Aug 2022 14:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243230AbiHYSNJ (ORCPT ); Thu, 25 Aug 2022 14:13:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57D30BD166 for ; Thu, 25 Aug 2022 11:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451172; 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=qZr7gdCnQUFeKt5ugQdZLofQqTfC3GDipKWYJIctC0o=; b=gpC2v0cg60h0OYbJ8mH+S1rlibXVaGDurlgdpGeizYzqMtTZ83P22NN8n48BZQVHvD89rN WUTAziQlgtyyRM1mzgcYtnWg0Y5gFZS/wi92hjejnulQAZB+Ni1lE786suaS/7eDYSe/8m yF3gLGYkaswX50G4XTKYG/vRGpFWh5M= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-365-8GETkLJ0Om2BbImCsak-8Q-1; Thu, 25 Aug 2022 14:12:50 -0400 X-MC-Unique: 8GETkLJ0Om2BbImCsak-8Q-1 Received: by mail-wr1-f69.google.com with SMTP id v19-20020adf8b53000000b00225728573e6so1130415wra.21 for ; Thu, 25 Aug 2022 11:12:50 -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; bh=qZr7gdCnQUFeKt5ugQdZLofQqTfC3GDipKWYJIctC0o=; b=a5N7xBX7XflCl6CFnXSehTzQOjMxcOB+eRrhGSMtPMZD791ni6rkDOiVRGdf0i5h0/ 2Nwe3BTHHma3ZL+ORkX9ByH0gZRK0VstL/w23LVpvEsYsY15IZerSyCYb7sp69wARC39 Y/zofdggpxHH6SHkw3NeNtPhKIkJgozvdE2i16U7QmYIcIAkM09bupErsoVluHp/DyK7 XMTb3aeSDszCGwqSgHamyV9kI8/MvCOXrk9KxiCFxTVd3ydRmo+fEzBcwdJBn2AAhGzO ++UUblbOSM/kqxIUHsMZAcDhIke5SxFz0UF+8AGOD+T7lIKghkOEgMGUG7PvOpq9IJ6S n8lw== X-Gm-Message-State: ACgBeo1zKp+BZVhMqhZ9hWJ0j9i/ETNFIulR3Cu4lYKFjVzdGYAaOI56 zDLQqM7W7OFZQ47l8+PhP6iH+smOvjFGPBYl8/QZ/vzu6mAvSR+mqSf2RUuscj/VsM9V7bpiBaA HmUXj5PJciLKucNbgPdQ79F82dHvwZ/6PH3ZX2kQCVUyqWiOOMevWN+jT4gVwXbAhs5jG X-Received: by 2002:a5d:6245:0:b0:225:41ae:a930 with SMTP id m5-20020a5d6245000000b0022541aea930mr3070265wrv.342.1661451169126; Thu, 25 Aug 2022 11:12:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7RVH5PYnY8wcHITb/gSrWocUzm2ruacYsdzIWSRq+8UMK3z//2FcJywjqklUN6v6jsYge+9A== X-Received: by 2002:a5d:6245:0:b0:225:41ae:a930 with SMTP id m5-20020a5d6245000000b0022541aea930mr3070223wrv.342.1661451168836; Thu, 25 Aug 2022 11:12:48 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:48 -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 v3 7/9] sched/topology: Introduce sched_numa_hop_mask() Date: Thu, 25 Aug 2022 19:12:08 +0100 Message-Id: <20220825181210.284283-8-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Tariq has pointed out that drivers allocating IRQ vectors would benefit from having smarter NUMA-awareness - cpumask_local_spread() only knows about the local node and everything outside is in the same bucket. sched_domains_numa_masks is pretty much what we want to hand out (a cpumask of CPUs reachable within a given distance budget), introduce sched_numa_hop_mask() to export those cpumasks. Link: http://lore.kernel.org/r/20220728191203.4055-1-tariqt@nvidia.com Signed-off-by: Valentin Schneider --- include/linux/topology.h | 9 +++++++++ kernel/sched/topology.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 4564faafd0e1..13b82b83e547 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -245,5 +245,14 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu) return cpumask_of_node(cpu_to_node(cpu)); } +#ifdef CONFIG_NUMA +extern const struct cpumask *sched_numa_hop_mask(int node, int hops); +#else +static inline const struct cpumask *sched_numa_hop_mask(int node, int hops) +{ + return ERR_PTR(-EOPNOTSUPP); +} +#endif /* CONFIG_NUMA */ + #endif /* _LINUX_TOPOLOGY_H */ diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8739c2a5a54e..f0236a0ae65c 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2067,6 +2067,34 @@ int sched_numa_find_closest(const struct cpumask *cpus, int cpu) return found; } +/** + * sched_numa_hop_mask() - Get the cpumask of CPUs at most @hops hops away. + * @node: The node to count hops from. + * @hops: Include CPUs up to that many hops away. 0 means local node. + * + * Requires rcu_lock to be held. Returned cpumask is only valid within that + * read-side section, copy it if required beyond that. + * + * Note that not all hops are equal in size; see sched_init_numa() for how + * distances and masks are handled. + * + * Also note that this is a reflection of sched_domains_numa_masks, which may change + * during the lifetime of the system (offline nodes are taken out of the masks). + */ +const struct cpumask *sched_numa_hop_mask(int node, int hops) +{ + struct cpumask ***masks = rcu_dereference(sched_domains_numa_masks); + + if (node >= nr_node_ids || hops >= sched_domains_numa_levels) + return ERR_PTR(-EINVAL); + + if (!masks) + return NULL; + + return masks[hops][node]; +} +EXPORT_SYMBOL_GPL(sched_numa_hop_mask); + #endif /* CONFIG_NUMA */ static int __sdt_alloc(const struct cpumask *cpu_map) From patchwork Thu Aug 25 18:12:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68D2BECAA25 for ; Thu, 25 Aug 2022 18:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243385AbiHYSOM (ORCPT ); Thu, 25 Aug 2022 14:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243380AbiHYSNM (ORCPT ); Thu, 25 Aug 2022 14:13:12 -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 3F79ABD2AB for ; Thu, 25 Aug 2022 11:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451176; 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=Ygl4bsiGppbXjaR+QFxwzenbyEWvTTquS8G3MYyuF5k=; b=UDU/qub69/hb84gav2crsBwR3wh0uKmMVA2L4HZ9YfYA2Khck7HgKyDeqkLJZaLWqEKkJM FPh03NHRkMXO7+H6IHel9vr0QnmqY6d8rFMWeWrggGK+XNTQBPTXBmJbARhl24mc1AcUJ5 5llIDhLLtJ6Tomku22c0xmFloS4LnCc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-36-7fl1KQ_4NxeG0HXXPdNL4Q-1; Thu, 25 Aug 2022 14:12:52 -0400 X-MC-Unique: 7fl1KQ_4NxeG0HXXPdNL4Q-1 Received: by mail-wr1-f72.google.com with SMTP id o3-20020adfa103000000b0022514e8e99bso3620708wro.19 for ; Thu, 25 Aug 2022 11:12:51 -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; bh=Ygl4bsiGppbXjaR+QFxwzenbyEWvTTquS8G3MYyuF5k=; b=olEcSpy72mumM0ef7JSZsJiCsMnFKJK1ImHlwCxK14VSmY13o/Lbyua96yxOv4SZyA wyr6LBwZk+0yvG2ipPwHym5baenbYQn0Cpwf0VKRxIkEPjb8rLOnPvjZtNheImPULzDR RuGjhFN5gd8E6tOYr1C5S8n5dnILDLphDR9x+rA5QUp2upcKGrhLaFFkh8N6nN0p2lDj MzeVRVn0ZWmBcVyUEZ7cSOoNLD6Gn6aD1L55FuJxx0W7KwGIKYU2CO1FMJvusaLNL8/H YsbHsOkb2nG/2F6i3tiOkD8/KIx7/dHBp623guGZ561eAt4kDUc8VurnBbQr60GZqQCS KgdQ== X-Gm-Message-State: ACgBeo3aUg9TlV61f7TeTbhXpmE5HMzlEmJP7inzj34gU9dYA4gPJ0f7 62xcndlV15dOuL0+ge3Um0C50WlYJLUCJ3BqvS0f4xS6eb7yl86cLOMD86oQ7grEM1b9tcb4oEW Ui41DuAEFhPAQIgj5pQ4y5Wicg/YwKXmBtCC19/DbFja3xwvy8XbqPK1XNGi4kx3Rf8K4 X-Received: by 2002:adf:e10c:0:b0:225:3168:c261 with SMTP id t12-20020adfe10c000000b002253168c261mr2960622wrz.159.1661451170511; Thu, 25 Aug 2022 11:12:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR4//RuHGtg2u96JYQmBT7E0pgZs/8dFZK5QKRpNIHW/sFCkTDIUkVmKlpjbmKJGB+DoHbT1ig== X-Received: by 2002:adf:e10c:0:b0:225:3168:c261 with SMTP id t12-20020adfe10c000000b002253168c261mr2960588wrz.159.1661451170194; Thu, 25 Aug 2022 11:12:50 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:49 -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 v3 8/9] sched/topology: Introduce for_each_numa_hop_cpu() Date: Thu, 25 Aug 2022 19:12:09 +0100 Message-Id: <20220825181210.284283-9-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The recently introduced sched_numa_hop_mask() exposes cpumasks of CPUs reachable within a given distance budget, but this means each successive cpumask is a superset of the previous one. Code wanting to allocate one item per CPU (e.g. IRQs) at increasing distances would thus need to allocate a temporary cpumask to note which CPUs have already been visited. This can be prevented by leveraging for_each_cpu_andnot() - package all that logic into one ugl^D fancy macro. Signed-off-by: Valentin Schneider --- include/linux/topology.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 13b82b83e547..6c671dc3252c 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -254,5 +254,42 @@ static inline const struct cpumask *sched_numa_hop_mask(int node, int hops) } #endif /* CONFIG_NUMA */ +/** + * for_each_numa_hop_cpu - iterate over CPUs by increasing NUMA distance, + * starting from a given node. + * @cpu: the iteration variable. + * @node: the NUMA node to start the search from. + * + * Requires rcu_lock to be held. + * Careful: this is a double loop, 'break' won't work as expected. + * + * + * Implementation notes: + * + * Providing it is valid, the mask returned by + * sched_numa_hop_mask(node, hops+1) + * is a superset of the one returned by + * sched_numa_hop_mask(node, hops) + * which may not be that useful for drivers that try to spread things out and + * want to visit a CPU not more than once. + * + * To accommodate for that, we use for_each_cpu_andnot() to iterate over the cpus + * of sched_numa_hop_mask(node, hops+1) with the CPUs of + * sched_numa_hop_mask(node, hops) removed, IOW we only iterate over CPUs + * a given distance away (rather than *up to* a given distance). + * + * hops=0 forces us to play silly games: we pass cpu_none_mask to + * for_each_cpu_andnot(), which turns it into for_each_cpu(). + */ +#define for_each_numa_hop_cpu(cpu, node) \ + for (struct { const struct cpumask *curr, *prev; int hops; } __v = \ + { sched_numa_hop_mask(node, 0), NULL, 0 }; \ + !IS_ERR_OR_NULL(__v.curr); \ + __v.hops++, \ + __v.prev = __v.curr, \ + __v.curr = sched_numa_hop_mask(node, __v.hops)) \ + for_each_cpu_andnot(cpu, \ + __v.curr, \ + __v.hops ? __v.prev : cpu_none_mask) #endif /* _LINUX_TOPOLOGY_H */ From patchwork Thu Aug 25 18:12:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12955119 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A65F5ECAA25 for ; Thu, 25 Aug 2022 18:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243364AbiHYSNp (ORCPT ); Thu, 25 Aug 2022 14:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243250AbiHYSNL (ORCPT ); Thu, 25 Aug 2022 14:13:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61FE3BD2A2 for ; Thu, 25 Aug 2022 11:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451174; 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=ywTMuS9huvM7zHWOxR6GjSmCdhb3SJi0oS2399XlZwU=; b=h1O2QNuMaG7DJWAWNFUX1AoPO6jVqGTDtuzLYS4CrSQjBm+0XAkcIKp5pU6IMpxfUZ9oGN Kx3iosbEtoI6J0qABcC3zgDqIV7b4BBxFeUSHVklQaoLIIY7UFVpkpHrzTWIPZtYtdHkpR jgI81qQeCYvtKy4tm13U0DPG4dB1U6c= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-19-p5C_TdycNzaX1yoKnc-_Aw-1; Thu, 25 Aug 2022 14:12:53 -0400 X-MC-Unique: p5C_TdycNzaX1yoKnc-_Aw-1 Received: by mail-wr1-f72.google.com with SMTP id i29-20020adfa51d000000b002251fd0ff14so3616997wrb.16 for ; Thu, 25 Aug 2022 11:12:53 -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; bh=ywTMuS9huvM7zHWOxR6GjSmCdhb3SJi0oS2399XlZwU=; b=z5xWEt1Ia08q03Ppxxgc6SXmixPZV1KZRHWkKg7CGQOUhFxgSUs+WMBcSrjzlKYr0K QqMbBS5pO35L5TiuRwjkIPFPTm9+9nOiTYAau+VrN6ci34nf/lV0TYhGdjrjuSnOlv3c 39MyZNjtGW891JZ5E8y2MuHXpvKv2N/w2ibQn6iJyxCp6bcwPpZKNyHKeqybE1vdEDv/ DB8zg7pOSdpM+HVI2U24ZGdPni4MkHgWJ5dopa69bap8z0iMfbE+GHHIovBO8M/SxzEa fvyMSIPBxI21m38GeueIpmLNFlJRXcJ8M/DuFNabFsZ2p5vv3GqY3mYUoqmj0BJwCNzg 2mrQ== X-Gm-Message-State: ACgBeo39tXZ2NukD1D2wV0XMpaZmnCc+MY+hzLw/bNjOrj88eia5egOU 7ldgEmQzs3O1RJbd+bYbVUbQsfwqXleDCFy+y6F25KeX6R+HwTevKaM7P/sBPwe+gDQV8lgl9f6 YXId8po5HNAU/wC64t18qwiv+gZ69LwvkDiWDaO+xsNzuzs7SU2YM7Ur5l6z3dJ3E9XXZ X-Received: by 2002:a05:600c:4f04:b0:3a5:f380:69dc with SMTP id l4-20020a05600c4f0400b003a5f38069dcmr3147419wmq.103.1661451172023; Thu, 25 Aug 2022 11:12:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR4fdktDFMuOCPYmE2jaQU9clFyb6AEUVJjx8ZtnEbzWQsDn4rUuPMq7JNqtJC4Fj4rAWF5AyQ== X-Received: by 2002:a05:600c:4f04:b0:3a5:f380:69dc with SMTP id l4-20020a05600c4f0400b003a5f38069dcmr3147386wmq.103.1661451171834; Thu, 25 Aug 2022 11:12:51 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id w1-20020a05600018c100b00225250f2d1bsm20371622wrq.94.2022.08.25.11.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 11:12:51 -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 v3 9/9] SHOWCASE: net/mlx5e: Leverage for_each_numa_hop_cpu() Date: Thu, 25 Aug 2022 19:12:10 +0100 Message-Id: <20220825181210.284283-10-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220825181210.284283-1-vschneid@redhat.com> References: <20220825181210.284283-1-vschneid@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Not-signed-off-by: Valentin Schneider --- drivers/net/ethernet/mellanox/mlx5/core/eq.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c index 229728c80233..0a5432903edd 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c @@ -812,6 +812,7 @@ static int comp_irqs_request(struct mlx5_core_dev *dev) int ncomp_eqs = table->num_comp_eqs; u16 *cpus; int ret; + int cpu; int i; ncomp_eqs = table->num_comp_eqs; @@ -830,8 +831,15 @@ static int comp_irqs_request(struct mlx5_core_dev *dev) ret = -ENOMEM; goto free_irqs; } - for (i = 0; i < ncomp_eqs; i++) - cpus[i] = cpumask_local_spread(i, dev->priv.numa_node); + + rcu_read_lock(); + for_each_numa_hop_cpus(cpu, dev->priv.numa_node) { + cpus[i] = cpu; + if (++i == ncomp_eqs) + goto spread_done; + } +spread_done: + rcu_read_unlock(); ret = mlx5_irqs_request_vectors(dev, cpus, ncomp_eqs, table->comp_irqs); kfree(cpus); if (ret < 0)