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: 12955122 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 18758ECAA27 for ; Thu, 25 Aug 2022 18:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240244AbiHYSM4 (ORCPT ); Thu, 25 Aug 2022 14:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235039AbiHYSMw (ORCPT ); Thu, 25 Aug 2022 14:12:52 -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 2C389BD1D2 for ; Thu, 25 Aug 2022 11:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451165; 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=Np4i0HfgmY2pkSbYaqjljpk0JKONL9AGVTW113C5hlGRvel+ZzngFg9qY9YUA1piJDkETC q5c27tvK69sanozxYkZTLHu7j5xiU7FXdCnGupWyMkqQrr6cbX82pmXF9UjEwFPoBB8Yye lq5zp25ffDqNUdYhQre0AdXntzoV/Go= 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-398-gEllmcggPJmevNTo10ISag-1; Thu, 25 Aug 2022 14:12:41 -0400 X-MC-Unique: gEllmcggPJmevNTo10ISag-1 Received: by mail-wr1-f72.google.com with SMTP id i24-20020adfaad8000000b002251cb5e812so3646677wrc.14 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=y1GIXKDRkULFEfgMkEkN4PdoHKRRwJ9tn7ivdDw32u/mK674PrLmy6G3nJJ93h1A2B Pis1cspacWnNRTGX9uoUSSaEW+IRq1tqjHtBn0I9KfKQJVd6XueaxSpJ7KC+lzjxOVuM QdAIUzl1usmHVbEiat5fm1PUtsO/uJz7gyAia+VOUwaUaENZb70DA4f7vgVfg2KmBCa7 LF5468DBwk6kv4yuz4eluaiDukjOaSg/TCtuhd+VRBu9voYZSiQbKax2ZC37X9KF5/9p TWowB4WsXdGik70D2yR3uaX4E70/xfY3WjdbfglvJlS+EBe/t2/K6n/HFtWDpJBHi9dI jo5w== X-Gm-Message-State: ACgBeo2yF8yEMADyit3UsSMHGOTbESh3tVydhFMqqhHTgC7rJJQ9VfT5 ymWXQcYOoFUWgyEOM+iCdeu50KBWYsEKVlGjWYi9BfFRlqvmFyExt38grZ548B/S60COMNl7S3z OB4amBV6BfXeLDreVvgl5gw== X-Received: by 2002:a5d:45c4:0:b0:225:4320:1401 with SMTP id b4-20020a5d45c4000000b0022543201401mr2994487wrs.474.1661451160646; 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: linux-rdma@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: 12955124 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 76B4AECAA27 for ; Thu, 25 Aug 2022 18:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243368AbiHYSNK (ORCPT ); Thu, 25 Aug 2022 14:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243250AbiHYSMx (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 A076FBD1FA 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=aa7TgxIpu/jW/iqd5xTwDqe/1bK1e/1x+Xly3SMXIUI=; b=OFyQYRjopAcYdG8hOjN1YZkgCBhK2nxGPqps+s0ePB6oUX3GUsHaYiqmPH4TzW9Hu2VBdo MefyyVT9htOF+iT+Um5L5TA9P4CyLaIjK+nlf30K8IjXcRf8jEE9FichpPC/2hNVPAfePO Q1lFhHOES+qo39S/uoK6wiIGDiYCCYM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-609-5_EHFnEhMpWQHCjvPQv7pQ-1; Thu, 25 Aug 2022 14:12:43 -0400 X-MC-Unique: 5_EHFnEhMpWQHCjvPQv7pQ-1 Received: by mail-wr1-f71.google.com with SMTP id c6-20020adfa706000000b00222c3caa23eso3618216wrd.15 for ; Thu, 25 Aug 2022 11:12:42 -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=Z0/fcBcBDejoGWPVAEXPZlzjdVK/Rza3eGqe3wmxSqtM8Ssn+cRYfx+/cKbzm21UGx vpBPB1fgj+BD5y5zFsChyxHVzoKEBmW9uvN54+uA6pFO4LNbcJmgbDoyhdkp9lpQQQuZ p9Ou34gO4rcwbsoq2bBEMP7FiJPalHSNWxqErN7DzIaZTjIlnQ0cre314F07Zy+HAkrr f7H98wdNkxZoKczQ32J+HOQljLEUM8zbJlXcaySgNNtrLpLSanL/UU9BszwuwxLmxV/A shvYvj6NHUq+krNhzlARQd8NvwDRdnTKXejbyNuLoItPDFZLlGCI4dmZfr0v+Mj6mNcq aKxg== X-Gm-Message-State: ACgBeo236V0gFVwZEA0Q0OipE3/GrZ8ncBP3GeBOgsXVzHb5KP09r3qD g48H4Q/d0kx83CgcluyqLluRn9oM4Oze3ppK64dsHmq3XwcZV5wirdJIvutbpy0gFND1U549x7x z4TICBqjNV44DbNXbeGDO1A== X-Received: by 2002:a05:6000:1f9b:b0:225:7694:3b36 with SMTP id bw27-20020a0560001f9b00b0022576943b36mr3024124wrb.310.1661451161925; Thu, 25 Aug 2022 11:12:41 -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: linux-rdma@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: 12955123 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 0DD41ECAA24 for ; Thu, 25 Aug 2022 18:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243330AbiHYSNJ (ORCPT ); Thu, 25 Aug 2022 14:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243244AbiHYSMx (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 6F70E76761 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=1661451165; 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=CbF02DFDKHKw1mk8QdaSJ/+u2pFQ5AyAaQO8hGt0DylT3cJ4o+MRbHAD3WacJjXGH+i6ki TRDvVwgPhk78Xy4coU+xqAcaUsgzZxeH9Mq5b/2e8juS1S5Btfjz6zUn+MQyXKUo97BumT bbuEMKcrc1qA7IOb+e6ECCrfGf52utE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-569--tGJvWW2P2OWUmjWsL5rOQ-1; Thu, 25 Aug 2022 14:12:44 -0400 X-MC-Unique: -tGJvWW2P2OWUmjWsL5rOQ-1 Received: by mail-wr1-f71.google.com with SMTP id n17-20020adf8b11000000b0022536079ef1so3337484wra.0 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=EniAsNlcLIzBaecQW7l44z2cg3ADgYNfNyD9f+mouKSyckCS04Tra1svBDnAUcwmy0 vxPHOYBYPVrV7kfAfhajtLer7CFwKDbK6YBie3DQ/VsyvOeaEFEJwI5C7Eauaz4kQFy8 CDena1FKzplPqBehXyq6nrYWbgB1r8IlQ366lYeD0Y9lxLW+JZ2HKFYRsh907HPlxM2j b9BIhGLwfgOQcIZjzbNYgKrDotes3VsohRU8R1Iz2YK00F0Biw2sysH6xG9tnVvyhnpl LCroCwhxuxWI65+uZ4j/Ij9nFkZcOdqUrKKno4A3u3/wEMculL7avB1KqrSMPeFUw9en zt4g== X-Gm-Message-State: ACgBeo2VuUaBxA+mQzRfe+NneJeTKRb3x+doGRDzWLznTRBEnxzVBk1Y dKqDjBy3w4F6gZX/uKaHrA01Xg7Rk5booDykZt9XR3NmlR+hjr2QXp+f4gfJlIcgclaiAWFqyQg g13F/MlVQzqWP6wzySrY4SQ== X-Received: by 2002:a5d:4012:0:b0:225:283a:8273 with SMTP id n18-20020a5d4012000000b00225283a8273mr2943768wrp.8.1661451163278; 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: linux-rdma@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: 12955125 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 07ADFECAA27 for ; Thu, 25 Aug 2022 18:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243390AbiHYSNN (ORCPT ); Thu, 25 Aug 2022 14:13:13 -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 S243271AbiHYSMx (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.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CA67BD1FF for ; Thu, 25 Aug 2022 11:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451167; 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=ISeVkgWshnkdKA5NIYfvqSUg+I10xYr89rHk0t0rhjuotbKiVPDXGdPZ1SaoC2tnukWPA9 0tudZI4OxH5LWCzjf5fDEAa0AWTrqYKv7qtOLVns3tkpsWkALy+tSEQOZm7FSvMsAxvDeS Wev26rqG4yu0tC/fOsUct4Fp3tGuBs0= 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-582-C6dFGmW3O5imV76GUTUdYw-1; Thu, 25 Aug 2022 14:12:46 -0400 X-MC-Unique: C6dFGmW3O5imV76GUTUdYw-1 Received: by mail-wr1-f70.google.com with SMTP id n17-20020adf8b11000000b0022536079ef1so3337505wra.0 for ; Thu, 25 Aug 2022 11:12:46 -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=P8odCvoNFJk0rBOcpv4vwNLEiEt1VenJ3zQCj6c2gY1WNNvxm2BFdYEZD18QPkbdWP xu1aiiDWLb7qK72w1SH069MnQppQgSBVP0IceaAR5kkdWND58Lm9tFVXjJA2CY9Qgx0T U1gbkSs7Yq2W56rmWQGjCl4meIaGV7W5xHCfQCUygLeSit1ZMd+1NF2Nev4/vL6sHKfU boaf6LwDV/wSMsO6uvY3tdQGLB99yw9cFWlV2bPsNL0KhFFiv9ax9+DT3ouU3jbGQQSu vytmGLGSTH/AmvlU5jbycxLjZOR2DDMfHXqNJgns7PZ3VyVSldk8YtBfwLSuJBR+LOWn u8XQ== X-Gm-Message-State: ACgBeo0xP7ZxaM0+vdoq03vPUwdK6+T7N7SO1tdpJWpUP77pHhBYJLmX rVQqmXu1P1oohLUOFLjxbS2gfhV9O+GkukXnbIXyvOrmkrQ28G05I0TqQqZs4wwhLv1uYdYPxHz 2CwgZTnAGv27BzQzI7Cwv+g== X-Received: by 2002:a5d:68c9:0:b0:225:330b:2d0 with SMTP id p9-20020a5d68c9000000b00225330b02d0mr2795009wrw.243.1661451165098; 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: linux-rdma@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: 12955126 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 6C99FECAA24 for ; Thu, 25 Aug 2022 18:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237844AbiHYSNO (ORCPT ); Thu, 25 Aug 2022 14:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243294AbiHYSMy (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 BE9AFBD28F for ; Thu, 25 Aug 2022 11:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661451168; 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=PRUkMFMN+pHOPJdoazbthVBUaT3To4bzQNezLuPVfvffMFenbpXxYrjUJE9wRQ8ecVNVBa hnl4MgWmbG8Bz5xNDrcMx/CC2+fEZqLjPLqG1OgADlCPBA3TmAdrXLzlYonJSKTsl5f83W 5eBOfjXkSWc3VGKpJ9QLXCIpUZPXtKM= 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-357-Wa4evslMODSrD0TlPYUK1g-1; Thu, 25 Aug 2022 14:12:47 -0400 X-MC-Unique: Wa4evslMODSrD0TlPYUK1g-1 Received: by mail-wr1-f70.google.com with SMTP id m7-20020adfa3c7000000b002251ddd0e05so3651113wrb.10 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=Hrg91cP4MO6RW1QtGltOWSikybbqfdpDWPoxadYPV5xw/X3UWUZT7xHpbwK//mbpHP ar6o8bUB7bQnfLZQyCx89oL7G8ElX+FOrMauyfx5asR1FBlhnG2q8/3vgKQCv/NcSI4U 4zjckJodBaMDz+LyM/LMbpw613Pjptk7rfMe6pg5avJIO2R+HRFthiBfRCwSKR1sfj3Y IbYDwUGDkURvDi20JKXg4L00CnV9onvPfLSwxtcQQqARK1WPWnMf6NV+nQjOL40KOmWJ nvJ66TPqbwhSu0pKcc3EIzn4niUMW/bBsb/Jr7DTTNSSM2SOH445+bB3aY80+DPW5q+K E0jg== X-Gm-Message-State: ACgBeo2d+W21PEzsCUWskGV0ZyfQHmMOSkJXMNeu7wyLkPfc4iVztB1R j5ObRr6jzebB54Yxdd71N7HZoXGxZN9K77j+Uv8Gw08KvaFWP+Yms1Ha2Si+od56vkT9E4VAJmC wzHJVas8mx7QS7ss/yL6nbw== X-Received: by 2002:a05:600c:216:b0:3a6:60e1:2726 with SMTP id 22-20020a05600c021600b003a660e12726mr2944908wmi.182.1661451166378; 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: linux-rdma@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: 12955127 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 3D8E3ECAA25 for ; Thu, 25 Aug 2022 18:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243413AbiHYSNS (ORCPT ); Thu, 25 Aug 2022 14:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243312AbiHYSMy (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 430E7BD1E4 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-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-32-4D-tUQhiN4qUqwKH4KHnZQ-1; Thu, 25 Aug 2022 14:12:48 -0400 X-MC-Unique: 4D-tUQhiN4qUqwKH4KHnZQ-1 Received: by mail-wm1-f70.google.com with SMTP id v67-20020a1cac46000000b003a615c4893dso11222023wme.3 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=q/5x2lQ/9bmixPHFDs15LBOiOf453bDvzFDsj7wCQfnVb50BBYhnz/3yyLIYqTQZ7K T0/xr58X/8ORyPkfjNgY+4ZLSLTPcangbDxdKfXjSPp8rM2+oc20hqK3i6VZvaVngK5P 9dCyglCeDMaB8ltMlE4iul60hbzMDh7sQ/7zmqhKVFjQo5nfwwEja+pxL17jGMhJAu6c vlGRFAJOIGypSqttJMiDdlmJVZ7M44E3zKOkxoSy4PcabbzSpi8cp1+u/iI34Clu04xy /XaTJrcr5xO3ov87Shn530nyscNAj1IQKLxjYO5xydSKy0LIaGp2D5UtCsev8DAftJiY eAKQ== X-Gm-Message-State: ACgBeo3MuQaUTqRldnPhQyp9o6aJwi/dlB2UWU2DsH0MN57CCIVi3pdG PVCgojfOTFTMzw9ZMoW/E4NqfU7fDoD6eVI77gPF57PoK83ruFe2G8Ax72Bm0I4T1nIKIDtmD8m ZWMaeHfmdn0qJ9m4QB70sEQ== X-Received: by 2002:a05:6000:a0d:b0:225:4bf3:95bd with SMTP id co13-20020a0560000a0d00b002254bf395bdmr3076435wrb.289.1661451167718; 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: linux-rdma@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: 12955128 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 1D86EECAA24 for ; Thu, 25 Aug 2022 18:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243466AbiHYSNh (ORCPT ); Thu, 25 Aug 2022 14:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243328AbiHYSNJ (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 43FD4BD1F9 for ; Thu, 25 Aug 2022 11:12:52 -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=qZr7gdCnQUFeKt5ugQdZLofQqTfC3GDipKWYJIctC0o=; b=gIGXxy7oQ72Y3zlWXm5CZkWWIh9/p15re4T3ok64cRYk3UdPYnkE+O2nVTFZJCFjEaFBE9 0LgbHLBvb08Tj6M8ZVmSYrv4SjP88S1LFjIcEQmUSv+7njmJcoVcIBX7ol3r9R2gC7uRs4 q6m3psxcWR29Hgxr3VcNJpzvANgyOh0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-573-7fKVF_5cOvavx56yygdIhA-1; Thu, 25 Aug 2022 14:12:50 -0400 X-MC-Unique: 7fKVF_5cOvavx56yygdIhA-1 Received: by mail-wm1-f69.google.com with SMTP id i7-20020a1c3b07000000b003a534ec2570so2767432wma.7 for ; Thu, 25 Aug 2022 11:12:49 -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=cLbHx8EJ50JrQCTWL7N9FwqYq1u68SsgT8kpmW6WSSVKjNsNrHq3WOA0IcyuOuhE2C IIThpWexfC2I5GGEtg/zH1hXlyhiC1hEZF7HUy1u68/Y7tak0XcKrph2S1f0SUDXiLuW b4HHRCiTVMdE4W6bvEMgZlt1Q2nV1e2Cef5hTnm5KjRXgg2cB1jxItDbqUwoSN3QmJsO zAVpTiFUTWiLaW9YNyYPcN2R1FvTacEoc3ms9VKlSTmrZjnCI9onEWXwa+T+fylow+/g qeRByED1JYOWrJQlcOPrOZunYPm0Ch4uj5h3qfDtbd7tnFpvpGPznOkiLF89lavN4Y+m xNSw== X-Gm-Message-State: ACgBeo2EmLSsasH1ZnjAxs5DQG6IFbB/FIE4C9G7WLIQ+uTqfRODBQTv CGW2iYCTvxVniApLwGRyUJtGC1DbNXKA9w+kUJx+GyUhC3DgFXZef428N2wVNe12Lkjl1K6J62u nyy9xeadzAIWJBYCgRmtGsQ== X-Received: by 2002:a5d:6245:0:b0:225:41ae:a930 with SMTP id m5-20020a5d6245000000b0022541aea930mr3070235wrv.342.1661451169013; 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: linux-rdma@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: 12955129 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 5A444ECAA27 for ; Thu, 25 Aug 2022 18:13:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243474AbiHYSNl (ORCPT ); Thu, 25 Aug 2022 14:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243342AbiHYSNJ (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.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33F774CD8 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=Ygl4bsiGppbXjaR+QFxwzenbyEWvTTquS8G3MYyuF5k=; b=gjZO7aIVARYnOyfIL8a9EN9KO2fTaxR3kUnPE2HeIvu546LCw4dBbTAyxdQkkNVyXCg4QR saVshhGoFmq3B5YOnXw4WPU1Qdv5aOlY/w31F/V/0voikw5khIkxgttemJBv+6ne83qlCk /EXxI75PcPUilpK0u/sgRjRpUg3Sfvg= 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-630-vIG-fyezNeyN_jW_lrZgBw-1; Thu, 25 Aug 2022 14:12:51 -0400 X-MC-Unique: vIG-fyezNeyN_jW_lrZgBw-1 Received: by mail-wr1-f70.google.com with SMTP id r23-20020adfa157000000b00225660d47b7so1748867wrr.6 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=oPVkdQCpPtYo/zpQ3JU9uuSbXzcVgtTgMfUNkAerHUbGVDBKmOOvHa2/hQ8//XzXEn WweBnvP6yJxTqyDGKgM1Nw/QJIh4+w82UjmVU6lcB0bTaqnqaR33o14oGlzDLuDsg6FQ /N+p1AuZ5bz1ik5YDT5r6Dcx7zPn2RIXiXsg2lDXCcm8jQZbhXOSUfZk1uPrT0HcVDgk wxylgq02XrJuVqJAv4YXGmWaQy2VPnpQkHWVsJTVw6y0sD5SUK2D4R673A3kLpr3E2Dw 7cMsxovSmZSHvKesDqPIm1gkeCC/HwhAngoLLKWZyxoKXJx5UpqVfJSOEnfffWH1HWHL v+Vg== X-Gm-Message-State: ACgBeo1N0F8FTtNXV2xr1y8lfAjFUoPZvUYmWOpB7oU4gNdGIyHMyULj zTwz+YgmBy1Yb7YdYSDvRhjpK95m0MhK5bm9Fe1C7BX+xzyuELbcqCUcJKcFKb/TXFRE/G6QkJg q8EA17TDj6g/LLCcEH38gLg== X-Received: by 2002:adf:e10c:0:b0:225:3168:c261 with SMTP id t12-20020adfe10c000000b002253168c261mr2960603wrz.159.1661451170433; 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: linux-rdma@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: 12955130 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 1D53DECAA24 for ; Thu, 25 Aug 2022 18:14:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243323AbiHYSOF (ORCPT ); Thu, 25 Aug 2022 14:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243374AbiHYSNL (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 DD890BD2AA 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=1661451175; 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=L9pADQwVkbb1Nadfgo3qGCrunaiUMltbPPubfw9SXCkdUw05aCzTHjKxvjZi5d6L7xa/lT AeM58nCRd6Lhw8kEKcn26u0vMbYTLn0djwKUceXYvzpaozbTz2McQH+9UWaJRcMIRQrG/S 4WYjG8/MuWM75CHv2ggN/WpCdbokGfo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-619-Lmgwz7erPMmjcl65SxRrdg-1; Thu, 25 Aug 2022 14:12:53 -0400 X-MC-Unique: Lmgwz7erPMmjcl65SxRrdg-1 Received: by mail-wr1-f71.google.com with SMTP id k20-20020adfb354000000b0022556a0b8cbso2407893wrd.5 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=Qm7atQKGAVEnhKeOid75t8heOHGQojE5ydJGHB99JXodwvjRdTu54RGMh4e3Ufusmz 5Cnk8mdDMS8eZHXHUNsXPUBv2fx3L5SEiJJs9SJsLWeZjbh4w99Kk0rzOZSUjWupUhyA 0tITFGKd+LrDnwPTTj90OilriHN3o2X1DCYxarUA5FszJiEobyY7T6GHpzJKb6bW6qmf 88C9/lZdmWRX02oUPtWjxK4S0o84NF3bUxH6VUERth1bWD/kAhcZAnqjT42LGkOl0yZl yrlvgQxzcPVLl1iD1e1KsbaYrnRAJW3l/lhf7XAaOeWzpju9FPN8QERYuOJqCJnPfNx6 kY8w== X-Gm-Message-State: ACgBeo3iOUqIWc02m9/VmnMCiJkSRPJLG4fRPpf8C1s8hnzQ5QKjzd96 0RWUsJwd+iyUg/+yZUtD0imvN3eqMFOdWDeRoRcFx+AxkFimUxTzjtnBJIXxygxnhSFq7ueDhwT Elrndp1YyeS4faUkobdCCGQ== X-Received: by 2002:a05:600c:4f04:b0:3a5:f380:69dc with SMTP id l4-20020a05600c4f0400b003a5f38069dcmr3147412wmq.103.1661451171996; Thu, 25 Aug 2022 11:12:51 -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: linux-rdma@vger.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)