Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2578967rwi; Fri, 21 Oct 2022 05:39:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rC11u0AID5udUO73E+OYXH0MpYIWe9Njd3/B0DfiIhfrz1wrtbTKo+n5TKQYsnmCMJ0d/ X-Received: by 2002:a63:1a46:0:b0:464:3966:54b9 with SMTP id a6-20020a631a46000000b00464396654b9mr16325230pgm.390.1666355989659; Fri, 21 Oct 2022 05:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666355989; cv=none; d=google.com; s=arc-20160816; b=pkvyCZA0Pir8s+xf7x2UwnVbXk5ufe4ZVLfH/zFaRXYwTKBp6/Z9Pd+VLZ6N4zaNz3 LSS7evSZvNmpF7VCceMsKqbHDg84XiiipLQ7Kq5FpZGH3rOM1HGVKfu49ggVNMUaCAJJ zmCoySnN0dUQ6KeFVnm1ZY3KSlsgwWV852xhkobCp3TarXdcSK+UOhQyInHbboc60soo /dnuyBBPljNo5zCEZMsnPm2tP+yqGXSytzmlZ/aWpcP5urZhFu/as4EyxQ0g8cv7lYrO nHziiuFZc8K0mQXV3ACD/XznBCjanlQ/Y6Q9iNueMWzSSNqQQ2Hzb29sDEklvQi7KX+/ Ifqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3rE72XJ0aceUfKerGW2NwZqel/SiYDWpKRmJbhA8td4=; b=q1DdHaPcvkRESiltJhqBx9oyBNmVcGWB/9xAOm+2rHpOFrB+2Bbaq0LOlPUY+90YUD HX2kDjNjNkOcNEn5jh+Txl5N9qral7Tr1BGXQiwYiy+sIYrb+yHrYXLvUJ0SlOhGF6Ur ghdH1LetzrDkafvkvliG3nMplc+nIXlMZneHsFWfoikwUPvIXTP77lt3lmZxkeGNzGFq in6kRe6JtyON0QUbSpEfKNCAHpP78KRYQ+ejqBcHJpEF+B6acjySR/hm476CWzwtQNxp j7VcEbjsRYGn9iEq3TUOdBQJEFcDB13TdNo1nCOvd9wsTMSGBJSTqHfrOB8k6LZi3NX7 Zf6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="e70eOLm/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a633810000000b00438ce28758csi24278567pga.136.2022.10.21.05.39.38; Fri, 21 Oct 2022 05:39:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="e70eOLm/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230027AbiJUMTw (ORCPT + 99 others); Fri, 21 Oct 2022 08:19:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiJUMTs (ORCPT ); Fri, 21 Oct 2022 08:19:48 -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 2F94C30F4B for ; Fri, 21 Oct 2022 05:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666354784; 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=3rE72XJ0aceUfKerGW2NwZqel/SiYDWpKRmJbhA8td4=; b=e70eOLm/U9zQvMRpWftedphDLBd6UXAqrhzAyEWdwrBdsf33y5wSEci4xefqJZLqwOX+4H WgoTkuNz7VC8J1kH6l2BHAlGocytE01D9nzrumMisnqO8/vE+nRjzW746ZjddnpDFu9MzJ UF/vZ33uDyk0+mJ1OQCkZIb+LoWuLxw= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-605-1q1l8tHgPWioeuaLgtiTIA-1; Fri, 21 Oct 2022 08:19:43 -0400 X-MC-Unique: 1q1l8tHgPWioeuaLgtiTIA-1 Received: by mail-qv1-f69.google.com with SMTP id cy11-20020a05621418cb00b004b17b3cf429so2212818qvb.6 for ; Fri, 21 Oct 2022 05:19: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 :subject:date:message-id:reply-to; bh=3rE72XJ0aceUfKerGW2NwZqel/SiYDWpKRmJbhA8td4=; b=QVeunZqjsaLju5U3qEa38I+OgRrLnpxNyvRtI0dEmS/wCRENVg6lnQkm3QyWsMvkkj XqDXv6l70MdrTPOM8E180WLdhVo6kp4Ai1i7DO65Uyfh+lUnkHg1vjLSU25NhNTUju5T NYFjNAQSiZvmKN+C1tjNFuVvf+FuOfkKAVxDSgsE61YPIt8o0+uuHQf/7KQFPoSLz2CO nZjvUuZQqUdFRXsH0XCxraB31pU2/bf8cXEAVaZMb3v3zsF0MGOmC3Tx4M/15tuPlrlj FZEwSWXYkvs6fB0pxyxVwY0hJgJGGyAdUPrmHkoGWkewVxz1cQ02miUSjXUt5/7cOokq FGQg== X-Gm-Message-State: ACrzQf0/MTEtYstXnuaf8h5Lx0ethZqme1x05Kt71vLwdzJjOvxCWPUF RSeWMlo7ZK6HEDLuHoKwiLKYvD3MHNpseZ4UB43jdCnAJbm9jWAhYQhXuMPLsZ9V3yQh2wMmTQS clT1w5aPcDv3Px61QjAKnlZLg X-Received: by 2002:ac8:598b:0:b0:39d:9b6:69b3 with SMTP id e11-20020ac8598b000000b0039d09b669b3mr7962671qte.39.1666354782862; Fri, 21 Oct 2022 05:19:42 -0700 (PDT) X-Received: by 2002:ac8:598b:0:b0:39d:9b6:69b3 with SMTP id e11-20020ac8598b000000b0039d09b669b3mr7962653qte.39.1666354782635; Fri, 21 Oct 2022 05:19:42 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id i9-20020ac85c09000000b0039a610a04b1sm8043410qti.37.2022.10.21.05.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 05:19: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 v5 1/3] sched/topology: Introduce sched_numa_hop_mask() Date: Fri, 21 Oct 2022 13:19:25 +0100 Message-Id: <20221021121927.2893692-2-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221021121927.2893692-1-vschneid@redhat.com> References: <20221021121927.2893692-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 12 ++++++++++++ kernel/sched/topology.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 4564faafd0e12..3e91ae6d0ad58 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) +{ + if (node == NUMA_NO_NODE && !hops) + return cpu_online_mask; + + return ERR_PTR(-EOPNOTSUPP); +} +#endif /* CONFIG_NUMA */ + #endif /* _LINUX_TOPOLOGY_H */ diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8739c2a5a54ea..e3cb8cc375204 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2067,6 +2067,37 @@ 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 from + * @node + * @node: The node to count hops from. + * @hops: Include CPUs up to that many hops away. 0 means local node. + * + * Return: On success, a pointer to a cpumask of CPUs at most @hops away from + * @node, an error value otherwise. + * + * 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 distance; 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(unsigned int node, unsigned 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 ERR_PTR(-EBUSY); + + return masks[hops][node]; +} +EXPORT_SYMBOL_GPL(sched_numa_hop_mask); + #endif /* CONFIG_NUMA */ static int __sdt_alloc(const struct cpumask *cpu_map) -- 2.31.1