Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3631407rwb; Fri, 20 Jan 2023 20:27:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXsBT8Tp1UzbxwC+iVXy5vptjfO+ONhsCqPstCeJfeDOIchx/j25XxrnI1FOgqysk58RQMiO X-Received: by 2002:a05:6402:60b:b0:470:25cf:99d1 with SMTP id n11-20020a056402060b00b0047025cf99d1mr18320436edv.31.1674275239632; Fri, 20 Jan 2023 20:27:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674275239; cv=none; d=google.com; s=arc-20160816; b=PdCmIWNEFbZGSqA9I0Jp6zrnpUdzOTdk/FVKsfR0nLM/qMzVJiiB8AQn5/7Ej39jAi cA2wPLkpGFaMl/gs3tJUiujnodZpLxPGQVjvqszA2UU8D4T5WemLQIfdlw9ujRFlrs7g zHdFV5z0Iye6/ocb3NO7o+NDKdsxgyTk2gklcD4UM5Ner6Ho5kDBSJPfviNWz4R3KWws 4eBExaomusp65ErZlhMnljrEpGnydZcY2YDQjEhIfjODS15G627jpSIKrjeCNA67RxyY J2m8iZ3BK6LrueW51ypBBcgVonTbsfp2+C7UnyTM0ZAOAG/rbBAlademaHGxvy24dT5W YEDg== 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=HV7BA/e9O5RDYHc0GpSLhXnbGhSUVych30GpzNnayWI=; b=UAZYji2NGI3nOcq3nMQa8vwwuWjf8Q2lSdR8dut0hErBDlH9sOxxhF18A+DkudSGcv NW9OyEwP/bepmljxesLYCCnl7R0o+nLQYOFKyGq/odDlr4kJ2RAajntj9Yyvo67t1eTU sEgjwS5wqMyKCfBJ6Aegb2eC0JjJXtaFlZNfON9GGU9Mk/EHF8QryECz514y161Emtqy gujH6xLrtHjp7f1PLFMepP9FIHcoUipLln7FIrGa/394JhOrvdlcs0KSGD6+zCsgmj2/ HpBW8wJgchavUhHwKkquKm2TcdkJ8m3p4HXvx9yXZj6TNKqIprNObltKJ2KxzSJBUQKt 0xOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p1ffXzls; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a0564020e0600b00498a501d3a0si43851145edh.448.2023.01.20.20.26.56; Fri, 20 Jan 2023 20:27:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@gmail.com header.s=20210112 header.b=p1ffXzls; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229487AbjAUEZX (ORCPT + 99 others); Fri, 20 Jan 2023 23:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjAUEZJ (ORCPT ); Fri, 20 Jan 2023 23:25:09 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E6B5518DD; Fri, 20 Jan 2023 20:24:48 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id g16so3765754qtu.2; Fri, 20 Jan 2023 20:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HV7BA/e9O5RDYHc0GpSLhXnbGhSUVych30GpzNnayWI=; b=p1ffXzlsXkgwWfnkIN5dHKAoPB+qji3zKzAGLiA4NxXTWvd6Z5peqTNBzwpVXCjgWv X2KKCxq2paGC1/zLxjdoEhzEWNI2LNxkGahKE2Db+Ym896BEyDDW5Qm0XZfSf31bZzo4 72HnXJPhg8EvFePscmT7w3TWAXiYUav9sZfCYD6u5hdSpAGdi3hYJea4S9WrfmxTusgK kdX2DgvAeI25XaoojL/FWH5uJ4NwJym5E8VvzXANuNP9chp+0WWyAetY4hDJTl2nNaGr p6j0dB11+ap2OQmYo4f/7ESulz4ABsI0p+JBqEOIMBbq+7qP0BIHpb5lbQ2neX3XRYo1 Y0Lw== 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=HV7BA/e9O5RDYHc0GpSLhXnbGhSUVych30GpzNnayWI=; b=iYYJ8KwaY1vyyDOsQxu6nBdhTL3vINiPF7HMfmrvYhEa08fpfgn+nHpM7jMvTlnEy2 Kh/zIuIYc6MUhKd9wN56BlXwHNOnGOGfPLj+cSj7vq6Vz5hOzFiASHFUl3iyOBBnsySO qTWOUhDuBZexF+TiK9yJEjV21AHeOaRy84VSk+tc9K0re4UJhCRE6JbTqxFWZk3njQW9 Qp2JOLklHEg+zzQ8nhlVjt+EpAyn6E3s/5ISYkEcmxKmyDO93Oc5FHMj0GgzYAbanGk9 B/1PSpE1+0/opHANMnCf51KcpeoMd1/nMlB63z0k7rbnTByzCjVQ54jvaQ0zGcY+kbFZ PF3Q== X-Gm-Message-State: AFqh2kqNXMHZ7WUYJ1I11q0OQXYAk4AwPmv5aAiyo8UnGMIDd0TDxcn1 SnaC3xsiWewDrEUlpJYCn2OLJAqt0M0= X-Received: by 2002:ac8:760b:0:b0:3ac:7f6b:ed11 with SMTP id t11-20020ac8760b000000b003ac7f6bed11mr23372537qtq.15.1674275087742; Fri, 20 Jan 2023 20:24:47 -0800 (PST) Received: from localhost (50-242-44-45-static.hfc.comcastbusiness.net. [50.242.44.45]) by smtp.gmail.com with ESMTPSA id e13-20020ac84b4d000000b003b62cd6e60esm9329010qts.43.2023.01.20.20.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 20:24:47 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, "David S. Miller" , Andy Shevchenko , Barry Song , Ben Segall , Dietmar Eggemann , Gal Pressman , Greg Kroah-Hartman , Haniel Bristot de Oliveira , Heiko Carstens , Ingo Molnar , Jacob Keller , Jakub Kicinski , Jason Gunthorpe , Jesse Brandeburg , Jonathan Cameron , Juri Lelli , Leon Romanovsky , Linus Torvalds , Mel Gorman , Peter Lafreniere , Peter Zijlstra , Rasmus Villemoes , Saeed Mahameed , Steven Rostedt , Tariq Toukan , Tariq Toukan , Tony Luck , Valentin Schneider , Vincent Guittot Cc: Yury Norov , linux-crypto@vger.kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH 6/9] sched/topology: Introduce sched_numa_hop_mask() Date: Fri, 20 Jan 2023 20:24:33 -0800 Message-Id: <20230121042436.2661843-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230121042436.2661843-1-yury.norov@gmail.com> References: <20230121042436.2661843-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-crypto@vger.kernel.org From: Valentin Schneider 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 Reviewed-by: Yury Norov Signed-off-by: Yury Norov --- include/linux/topology.h | 7 +++++++ kernel/sched/topology.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 72f264575698..344c2362755a 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -247,11 +247,18 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu) #ifdef CONFIG_NUMA int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node); +extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops); #else static __always_inline int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) { return cpumask_nth(cpu, cpus); } + +static inline const struct cpumask * +sched_numa_hop_mask(unsigned int node, unsigned 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 2bf89186a10f..1233affc106c 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2124,6 +2124,39 @@ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) return ret; } EXPORT_SYMBOL_GPL(sched_numa_find_nth_cpu); + +/** + * 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; + + if (node >= nr_node_ids || hops >= sched_domains_numa_levels) + return ERR_PTR(-EINVAL); + + masks = rcu_dereference(sched_domains_numa_masks); + 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.34.1