From patchwork Fri Oct 28 16:49:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 12461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp937833wru; Fri, 28 Oct 2022 09:57:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53G09U4DSZbdbu0eiuiP/Sut1MKOZMq0Th7+4qelSc3OcLDdWYlfabIPZ9/1LvNBZh872h X-Received: by 2002:a05:6402:4006:b0:461:f4e2:82e0 with SMTP id d6-20020a056402400600b00461f4e282e0mr399336eda.68.1666976237836; Fri, 28 Oct 2022 09:57:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666976237; cv=none; d=google.com; s=arc-20160816; b=HqiWruO1i94NFiE/xll8Wq+mhX6uVLKVKsWwsQaacAJl63ExFvXojKMX2FcvKqhv1G SNlju1S0O1I0XLFGhTw28wZkxvTrbNxDTtIa7zYBvjryaFspU4fMFxgSU7KCrW8ZCbup C6lmlaOAteSG7n6r8rRkWAxfF+hHZLB5zcWiMAcFDzLLgakz6x01cmq+H2yWpFpEpBK0 IfoyKq4H0ysKZODM+3pOtAZKoYzF8GbOXUSdBNUfjmkdefE1fy9kbgwFSaYivwi59YbY xExBRihnubMjaZL7zmS6wPd28b5lMNLbu4VAWGrXWi/kdEjfVfrAcIZtUjpSV+fpOO7c ggLQ== 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=VvsEtK8QyUxcxneO/iuaAhunkW+JQwkOSt7vFL/EoPg=; b=pY1ULvlz2/BnffBHETyq+VU8um6YxJ8c2Fg53DQIH4HvV1xbRutMfW5wJwhFYuHdfJ /KK75QQneNvLqAoQK/lOuzw2eEicIHJ/9WTQXiKZdao/R9finEdan4fvxHoGCK3FtOP+ 8p+Ek+b9BxqascPH8SvHgSjRYO+NJ5VGf249LuKdrsP3EOuufPnCr4JVlU3vz2V6xgXB GMCGfjxlX+LqpIuXhZ76hvoDLmiy8ALAuDpBrnh+59LhqvFRXzwY7NUQHu0MPOHW0ud1 0AAs9JXseNZvLl03aWpS77pj+QmzdNG4dhpWiNV3+4alb3Ud0jxUbbtj28Ivtz/aXjWv U53Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BA7jwZm4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l3-20020a170907914300b007806c7c3fc1si3527247ejs.975.2022.10.28.09.56.53; Fri, 28 Oct 2022 09:57:17 -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=BA7jwZm4; 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 S230077AbiJ1Qvq (ORCPT + 99 others); Fri, 28 Oct 2022 12:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbiJ1Qvh (ORCPT ); Fri, 28 Oct 2022 12:51:37 -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 DE4727A507 for ; Fri, 28 Oct 2022 09:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666975836; 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=VvsEtK8QyUxcxneO/iuaAhunkW+JQwkOSt7vFL/EoPg=; b=BA7jwZm4L2EUUnGJjmclXxwcitCximX7YZFQlxcmXDVTJ3vqYt7A/5rUneAJxRwPVIJBxJ IJs726Tlej8GEkZMyhp++90kcQaHuQA1vm+4rKA5FSnf4rqm3NtVzkXzD15JL0FyxskYWa 4+o81ml9r57vhiuamqsQG71qw3vdB84= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-376-QvosMIWnPjS7kfFBNzxPig-1; Fri, 28 Oct 2022 12:50:34 -0400 X-MC-Unique: QvosMIWnPjS7kfFBNzxPig-1 Received: by mail-wr1-f70.google.com with SMTP id m24-20020adfa3d8000000b00236774fd74aso1322309wrb.8 for ; Fri, 28 Oct 2022 09:50:34 -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=VvsEtK8QyUxcxneO/iuaAhunkW+JQwkOSt7vFL/EoPg=; b=pr+hhcov0nFItsTi0TyqEmGcHh/+fu/a6Y1ndrPELRXx+UkiPmHv910MbS6G139oVM IPpeF5pqECkB9ssOp/nDlazH4S38ifUDnN4Cquzed2U2hsi79uO7GlicObQiJlP2pMjH zemjJgB/e1UNkTBHO2+EnMMM7ljFy2gdL2WGvO5XFEnjCvEdl4MOvIlwkBrkIgCnt8ww NYAVfK10Xqls1y616TtrXpjas2jgUBa+Yae/C32jq7iekpcq9khpJoUiVHMLmKcIWEwe 6IpZwG8Ty+UuSdBMN7MkP0mmJ+FJGpOygnZJIy17p+ovuTeZwCVwDkhG6F9fp4olyG8K 7B8Q== X-Gm-Message-State: ACrzQf0+eoIORO4uL9D4I19prpOhqdbTalAUQ/E/XVf3U2mYLCt1xe8m bHuhZc2dTbFf9XEXbMuMUgdv/x29UAI0rzpJkE0OkdtSDuRBWCymKMlAu909EBtgHdDp2sF/uGR EjfIDLW81zeo7wqjpxDAVndZo X-Received: by 2002:a05:600c:46ce:b0:3c6:f274:33b2 with SMTP id q14-20020a05600c46ce00b003c6f27433b2mr100190wmo.27.1666975833547; Fri, 28 Oct 2022 09:50:33 -0700 (PDT) X-Received: by 2002:a05:600c:46ce:b0:3c6:f274:33b2 with SMTP id q14-20020a05600c46ce00b003c6f27433b2mr100162wmo.27.1666975833298; Fri, 28 Oct 2022 09:50:33 -0700 (PDT) Received: from vschneid.remote.csb ([149.71.65.94]) by smtp.gmail.com with ESMTPSA id ay31-20020a05600c1e1f00b003cf537ec2efsm5065923wmb.36.2022.10.28.09.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 09:50:32 -0700 (PDT) From: Valentin Schneider To: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 v6 1/3] sched/topology: Introduce sched_numa_hop_mask() Date: Fri, 28 Oct 2022 17:49:57 +0100 Message-Id: <20221028164959.1367250-2-vschneid@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028164959.1367250-1-vschneid@redhat.com> References: <20221028164959.1367250-1-vschneid@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747951275664813684?= X-GMAIL-MSGID: =?utf-8?q?1747951275664813684?= 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 --- include/linux/topology.h | 10 ++++++++++ kernel/sched/topology.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 4564faafd0e12..64199545d7cf6 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -245,5 +245,15 @@ 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(unsigned int node, unsigned int hops); +#else +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 8739c2a5a54ea..3bce567241fc4 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2067,6 +2067,38 @@ 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; + + 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)