Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp926626rwe; Thu, 25 Aug 2022 11:41:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4usw2ysGRrLvyju2Ppuu9dDPF1MwmmdQa4222PuFUBKXEaBMIUaubowjERbO9P9a9RECbc X-Received: by 2002:a05:6402:28cb:b0:43b:c6d7:ef92 with SMTP id ef11-20020a05640228cb00b0043bc6d7ef92mr4231559edb.333.1661452868324; Thu, 25 Aug 2022 11:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661452868; cv=none; d=google.com; s=arc-20160816; b=g2v+hCS1q6VYTpalgT19TdOJqekNo95Dq0d15Ox19HwYr/XhBQJ2yAP8b9k2b/vL5/ 98ayi8IzpJs16fCxQNlUCHt1qIuIZ2/o4IkH4LuxZVB+Q4AhjQo1nb7DEdVhTNa7wp60 8oKarIuu5vudHf+nNgS7YF4TlEW1adYcBLJxuKa0LoDGzungonocSZDm/+tyjnZqjYfs DhuvfXSLsSoanHw/AKDXncFiTW5dkorJLFqvioC9T0BZ7dXm7Ma2yOUBL9+T/azS+R8W 1a7B7KMLooQxt2EACEjcgoHVyXslWwGr2j0k6spOuX0g7FPVRmDgP2YaSPDcIX6Flvkc c52g== 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=qZr7gdCnQUFeKt5ugQdZLofQqTfC3GDipKWYJIctC0o=; b=Ll5gnRk/56Ehs8rvFxnWXdmPap5NR70OYieby6Rg2f0gTIz0EnvhWKTtHyOhrBuE4a 2IpU+5HKt99NsgIqd4YQtbZ2m9oZuGY2D8t0ln8vZ2PjUVGtEg+ataMs8t8QDRzow5SP ALfxvISgq12WLEHNP6baP+2upsEpc/4uamWxYMrthEOOo4emwI0UK+CFfvc2ygclbRRC d/3+9KDJcIEtmHBS0WyWgwRWaXxBcjyRFNRcv4BiGJmzPDpvk4y1z6xWauJI8xPSnIgt FWkt4B0CrJnOt28L+9ZF6jz1n4SBT120+QcDLyYdBuMke6s6MYv2dylsPy7znCjHUeoj t55w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gIGXxy7o; 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 x5-20020a05640226c500b0043aa4fc7b9fsi157011edd.17.2022.08.25.11.40.41; Thu, 25 Aug 2022 11:41:08 -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=gIGXxy7o; 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 S243182AbiHYSNi (ORCPT + 99 others); Thu, 25 Aug 2022 14:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242880AbiHYSNJ (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 207C5BD12B 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-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-616-brBdKSnePTGhGg9lJLVpww-1; Thu, 25 Aug 2022 14:12:50 -0400 X-MC-Unique: brBdKSnePTGhGg9lJLVpww-1 Received: by mail-wr1-f72.google.com with SMTP id n17-20020adf8b11000000b0022536079ef1so3337552wra.0 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=Gs0cA4skfwo6q2PVObCIBGEcDNzxCblfB3aaRCl0GJ8jfnXYjssG+jPBR6Y8xTBjyR 7pIHj6njuS5HWQiBxA1LdWO+bPI++zw/VNmmaAnnXmhuWYgDa+NCjXgSnlYBWJaZBbcx VglcgfBBzVd5lrB/VsKMdWIPxHfzu+e030//nX5+O3sN89O8tjw1gu/MsiZBmTagbSa5 HA7HdbtkBqkWocj0wD5BjL0/LKjTqxq00z8eyMf5aBkMTPrYUD6tDFaQ5+tU7aQGYMvw DB31HUnaxx5AI9iZp5lO4LN9eLmOpLjBb+uUhmlXGn+FNCM4lBhQZTtwJ7Lbrw50UsEL 0iDg== X-Gm-Message-State: ACgBeo0/i2k2Q4z2T6BXXzPZGMXj5AVduf3k4sPvs85W/otRTaxVBVfN Gl9BySJcml8JsstCd0688zH59a5oXb5pGNg98m6lEmnE/C8NDnRgjctGJvq/E1zD/sFvSq4tKxi mnAcrV3S0N1wI9QEITbIcDGy+ X-Received: by 2002:a5d:6245:0:b0:225:41ae:a930 with SMTP id m5-20020a5d6245000000b0022541aea930mr3070243wrv.342.1661451169014; Thu, 25 Aug 2022 11:12:49 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 | 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) -- 2.31.1