Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp666156rwb; Thu, 18 Aug 2022 10:02:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR7IaD4iW1UrvLRxV6Yen7G0uwr6bFReMNQuSFCal0ulXDyXIKHM7OjlGk0vruX0US4SF1Fq X-Received: by 2002:a17:90b:3142:b0:1f7:338a:1d38 with SMTP id ip2-20020a17090b314200b001f7338a1d38mr9143729pjb.223.1660842147836; Thu, 18 Aug 2022 10:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660842147; cv=none; d=google.com; s=arc-20160816; b=lciW9wo+a3/r7VZQMEUnuVDichmvDKkyaTDr2ThqX0MaTHt8oGRhyob2ATUnOP8pB1 FNBDPY8JxYAYpfToV15AEurY8Ucc/3caGj4mkJfciHg0F+BfXVyotbmS2z3Qplx+gDKK 1dXjGzgXlLsWbGS5xvSzVk8wPDk3AF+cNPbNsyj1S0jX043Wbp9GrNua8h5K1HzOAg2l 7NhYq4KfxM6oXyOs9huDjaLeRxZHALc3haK9tTZsHp9JtesYVXlwvashJkMb+ZGu5gPo Ju9RAV+k0HlCBxdZSWSrdKfV16UoqeamlYdavbKlI/cBSw6x+f2MKUaUe474x6BX8Yvx FJPg== 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=arlslM0zqM3hjrB6NkCnIv83KEx3JCpo+lVC73SmhFUm7UDtmYm4OyDT4kvEze5gc7 a2rTPqwPX2zw7pP2I+acISwNgX4QZfze+C4R8Uk5hP8+dayBT7IZpwtcHLpIHjSy53qa bgdKg8bU6opRllO8QzJj02ko6uW0z31OG/s5JVtgPfGca86Kf6sBnL4qOIWwpxpQl1h6 GzUNV29hKNoc/WgAvgWEeHdc2Yh8k2u8phjrqgrLuVcq18VcmSSH/rbg1urJVF3kHonN nRb2Ud/SiJb3FnykTEJWHFPN9WEeCnviG8iiev6U4mltuiV6d9pmKjMWNQSqfoqfo30e 87IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bC3Ak9Wt; 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 t18-20020a17090aba9200b001efd3b69df0si1710700pjr.117.2022.08.18.10.02.09; Thu, 18 Aug 2022 10:02:27 -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=bC3Ak9Wt; 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 S1345005AbiHRQp6 (ORCPT + 99 others); Thu, 18 Aug 2022 12:45:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344950AbiHRQpg (ORCPT ); Thu, 18 Aug 2022 12:45:36 -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 D5AA7B99F2 for ; Thu, 18 Aug 2022 09:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660841134; 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=bC3Ak9Wth7r0KqCXyA6QdLS0cdsUN66l2i2359vuRcM3SsT3EkKBqXxyQaTsP9JPYsPX82 b12a7PCWs9tfvpK53PJqDhW327PyMD21m1jdn8m68Tg03KudcjTu138b7WPSgoP0P0O8mY 5or1Vhh1P3riWAKilDtexhfDXwFLiuY= 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-131-4DDVoVx0ONmcIPY1pebQxw-1; Thu, 18 Aug 2022 12:45:33 -0400 X-MC-Unique: 4DDVoVx0ONmcIPY1pebQxw-1 Received: by mail-wm1-f69.google.com with SMTP id v24-20020a7bcb58000000b003a37681b861so811288wmj.9 for ; Thu, 18 Aug 2022 09:45:33 -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=e7Bgw73nRXYT7HiDQler/U58TQsLk27XD2WK6pjknPEA6xdFuhiYzu3p9uouasWqZV RUEYzwb1S4c6aZM6c0lMLfLep0lt+LhoMDS7biqACz9KKtjq1te6AkY1PoUHC+E7blpO 6ra7dA90uVUsFiYxh2v1/rwe+RaIAe+KHSTxXDK6IYrhFZSF39hiDUXKUn2RTfZYvE0G Xe/0hydfAH0Fvai9I0Fs69H0IBM5khT9VZ3qRj5ofzFX91OSDm6GFALptwhOZX77R37D VkBqWFrPsLqFPw0gTYsuVGVfFBaqibkGfcF/dWq4AXQaJhr6RdQcemVpy5NiX9Vh5b5x m+dA== X-Gm-Message-State: ACgBeo2C6MHHNZJm84Yf+a9aro0lHz54r4LtQPDDh+lzn5nKCMu7pxyt LUDpGGA6lPcjWdJ29ZN5IVYos4MwJXS6lEcl8TxPz23rqrG0nmxoMe+Po48XWwD+8Bx0Gi4J1HN 3RbIWXkVOC5cxRIKRVjlZIHCf X-Received: by 2002:a5d:5408:0:b0:220:63d5:d9f3 with SMTP id g8-20020a5d5408000000b0022063d5d9f3mr2077545wrv.249.1660841132685; Thu, 18 Aug 2022 09:45:32 -0700 (PDT) X-Received: by 2002:a5d:5408:0:b0:220:63d5:d9f3 with SMTP id g8-20020a5d5408000000b0022063d5d9f3mr2077533wrv.249.1660841132508; Thu, 18 Aug 2022 09:45:32 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id d7-20020a05600c3ac700b003a5ad7f6de2sm2465458wms.15.2022.08.18.09.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 09:45:32 -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 , Barry Song , Heiko Carstens , Tony Luck , Jonathan Cameron , Gal Pressman , Tariq Toukan Subject: [PATCH v2 3/5] sched/topology: Introduce sched_numa_hop_mask() Date: Thu, 18 Aug 2022 17:45:20 +0100 Message-Id: <20220818164522.1087673-1-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220817175812.671843-1-vschneid@redhat.com> References: <20220817175812.671843-1-vschneid@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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