From patchwork Wed Aug 10 10:51:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12940433 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 7D9EFC00140 for ; Wed, 10 Aug 2022 10:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231583AbiHJKvn (ORCPT ); Wed, 10 Aug 2022 06:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbiHJKvl (ORCPT ); Wed, 10 Aug 2022 06:51:41 -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 ESMTP id 70EFCDF38 for ; Wed, 10 Aug 2022 03:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660128699; 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=MQv4si4iinlbQRu6xS6GknH+Qg1JB3I9EHkZZqgX3n4=; b=ZyOQhKkG2E5Uu4Pm719O90t0F8rbmw6v4yZwaqt/ZsK1XPIRT/jJg2DVogIxZvRQ16hEGS Sv4UHEc+xKkrRLLDBarlA6tb/UKJ+5fXwSJ1PkLn7wgrsaHysJoojTaLIlqd/Xkz4TKj+6 GYuZAQmIO2ljjc2BwUPw/XvqeHX/5G4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-7k_O8BUAP6uXR60siDFXqA-1; Wed, 10 Aug 2022 06:51:38 -0400 X-MC-Unique: 7k_O8BUAP6uXR60siDFXqA-1 Received: by mail-wm1-f71.google.com with SMTP id v11-20020a1cf70b000000b003a318238826so459704wmh.2 for ; Wed, 10 Aug 2022 03:51:38 -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=MQv4si4iinlbQRu6xS6GknH+Qg1JB3I9EHkZZqgX3n4=; b=GwDMGb36LjV731T60CFHkK6qKVmwVwmUe5CdClGKjYEzJskKRDvux71wkb2ElyjyIo UHo+6LjwIPBhnZU8rpOQncBXXYwqzerOHbjS0A4Dh9QvUD2iWTpxwONVOGsEisnWejZl Istk6MjUqh4dKU3qI4Ab/cP6G3cu9xOEMWHu8/tQiF6DETDMdSe2gDwDHA4nVgapdab5 ykgwjAWjSgilk9Z94w73b+kDCib2+j25Afaxn0aR5XVMtPY+ZwVFM54/hfOUj63CFj4e mLljwGPXkmYwDmEdNMittQ4jIPB0J+tXczcmkb11azXaGPOQ+GDM3Xi9GY4khhVS5hhM SyVA== X-Gm-Message-State: ACgBeo2vvqwIE1Bau15ssjEfMUTvkoCzDIzcMVY8p8sM4AQZUAd2VEx8 IzvMt3dj0ZrpVRsWGyScVLDZcurCcQUtCu3DWKAzD9yLUDWdnzNp0GEFOpMkBFt94u0Yk/waPav q5/wzF5WkaFgzS0766d5YSreFxtgcBMsisPZDp0Ny/zTW72okI2GJOsFZ7auvqEAMdkaB X-Received: by 2002:a5d:5a10:0:b0:221:7c17:abee with SMTP id bq16-20020a5d5a10000000b002217c17abeemr13504090wrb.698.1660128697155; Wed, 10 Aug 2022 03:51:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR6aliMmCChoxMsmZYTSaLR+bJli/MBSTjuZvyXHArHGycG0JudiAhqIQ8qazm4dpTtVYs/4QA== X-Received: by 2002:a5d:5a10:0:b0:221:7c17:abee with SMTP id bq16-20020a5d5a10000000b002217c17abeemr13504058wrb.698.1660128696856; Wed, 10 Aug 2022 03:51:36 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id g6-20020a5d5406000000b0021e491fd250sm16138637wrv.89.2022.08.10.03.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 03:51:36 -0700 (PDT) From: Valentin Schneider To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tariq Toukan , Tariq Toukan , "David S. Miller" , Saeed Mahameed , Jakub Kicinski , Ingo Molnar , Peter Zijlstra , Juri Lelli , Eric Dumazet , Paolo Abeni , Gal Pressman , Vincent Guittot Subject: [PATCH 1/2] sched/topology: Introduce sched_numa_hop_mask() Date: Wed, 10 Aug 2022 11:51:18 +0100 Message-Id: <20220810105119.2684079-1-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: 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. Add in an iteration helper to iterate over CPUs at an incremental distance from a given node. Link: http://lore.kernel.org/r/20220728191203.4055-1-tariqt@nvidia.com Signed-off-by: Valentin Schneider --- include/linux/topology.h | 12 ++++++++++++ kernel/sched/topology.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 4564faafd0e1..d66e3cf40823 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -245,5 +245,17 @@ 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 -ENOTSUPP; +} +#endif /* CONFIG_NUMA */ + +#define for_each_numa_hop_mask(node, hops, mask) \ + for (mask = sched_numa_hop_mask(node, hops); !IS_ERR_OR_NULL(mask); \ + mask = sched_numa_hop_mask(node, ++hops)) #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 Wed Aug 10 10:51:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12940434 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 B4616C25B08 for ; Wed, 10 Aug 2022 10:51:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbiHJKvp (ORCPT ); Wed, 10 Aug 2022 06:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231573AbiHJKvn (ORCPT ); Wed, 10 Aug 2022 06:51:43 -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 ESMTP id 3D225E089 for ; Wed, 10 Aug 2022 03:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660128701; 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=+QKswYb/p0TG7A62JGLMqklr1fmwHxQqVazk8yHSBgY=; b=Uhr2TQZ53Up2F3qnTgWFd6yJ2s5x5SSFjTCmjK9sDuleIFRX6rWspuIqZMvVzv0DqidRUL dE0lHpVUTopdCYOyu0dSmOqG8u9OTSpEbMt+xHtl4FSsXohEjmktFGBjg4zFzjnHOxlwSh Krks5Hhp91wlAvclJ1dUKx33P4EelKw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-245-1PZwv9H6Nt-K4z6NRCTJig-1; Wed, 10 Aug 2022 06:51:40 -0400 X-MC-Unique: 1PZwv9H6Nt-K4z6NRCTJig-1 Received: by mail-wm1-f71.google.com with SMTP id n1-20020a7bcbc1000000b003a4e8c818f5so458039wmi.6 for ; Wed, 10 Aug 2022 03:51:40 -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=+QKswYb/p0TG7A62JGLMqklr1fmwHxQqVazk8yHSBgY=; b=y3kKOG6UMlkFUMxQWckeZwFeqqzH4XRRI52X7KJlSAFCpTjgTKQevPREd7MRX6QZQJ BAahX1Dh9BTdEs/1fysm9HDiiBQGfP/QxzSuP+AjegaKXVqYKPJgQB6SEhsC8XXbJ1sC XwANfI/qQPaiiiGBcHiOEgHx6PyCeiU2CRbpDGc39CchkLw2W0Mi80rXDTwkUA6GVmlV ZOYBFnw6WrGOOl0AAoVJOAW50ru+tQC5dyYuqthT7xVC/8+ae2CIoHq7nKZNpEz1G9Re 8hRAE0gvG7C1y/9Zw4nUv1N6RDqNUC8Goafk7uITgNa7P9gjBxYysNvCLfC5AgUDfnHJ 8qdw== X-Gm-Message-State: ACgBeo2GZYXNw2oscusnBXoNm0O3X6gKVHeXTTvbcgY/v4q67eUjCWxH Ac02XCjgwwvs0eX9P3Zm0myQkYMmR9nJmzs/uazaNPeuANia7TkJOIjqvTp9zzTJaUMlqcnsIaF SYU49NZWWnz0DEbUdcdmrlWEXGOShCDo7axknl7aDbX0qm+JzCtUANQ7U3MFS/wa8+g0L X-Received: by 2002:a05:6000:1a88:b0:222:ca4d:f0d2 with SMTP id f8-20020a0560001a8800b00222ca4df0d2mr9771179wry.610.1660128698827; Wed, 10 Aug 2022 03:51:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR6s8knuL4j1oq3Fzd8so/k3D+RKPKqXDCFBb2MFvV+e9VEEggyzQfUdfbVef77LJNUZXnar9w== X-Received: by 2002:a05:6000:1a88:b0:222:ca4d:f0d2 with SMTP id f8-20020a0560001a8800b00222ca4df0d2mr9771155wry.610.1660128698644; Wed, 10 Aug 2022 03:51:38 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id g6-20020a5d5406000000b0021e491fd250sm16138637wrv.89.2022.08.10.03.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 03:51:38 -0700 (PDT) From: Valentin Schneider To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tariq Toukan , Tariq Toukan , "David S. Miller" , Saeed Mahameed , Jakub Kicinski , Ingo Molnar , Peter Zijlstra , Juri Lelli , Eric Dumazet , Paolo Abeni , Gal Pressman , Vincent Guittot Subject: [PATCH 2/2] net/mlx5e: Leverage sched_numa_hop_mask() Date: Wed, 10 Aug 2022 11:51:19 +0100 Message-Id: <20220810105119.2684079-2-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220810105119.2684079-1-vschneid@redhat.com> References: <20220810105119.2684079-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 Signed-off-by: Valentin Schneider --- drivers/net/ethernet/mellanox/mlx5/core/eq.c | 16 ++++++++++++++-- 1 file changed, 14 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..2eb4ffd96a95 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c @@ -809,9 +809,12 @@ static void comp_irqs_release(struct mlx5_core_dev *dev) static int comp_irqs_request(struct mlx5_core_dev *dev) { struct mlx5_eq_table *table = dev->priv.eq_table; + const struct cpumask *mask; int ncomp_eqs = table->num_comp_eqs; + int hops = 0; u16 *cpus; int ret; + int cpu; int i; ncomp_eqs = table->num_comp_eqs; @@ -830,8 +833,17 @@ 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_mask(dev->priv.numa_node, hops, mask) { + for_each_cpu(cpu, mask) { + 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)