From patchwork Fri Oct 21 12:19:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Schneider X-Patchwork-Id: 6672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp668534wrr; Fri, 21 Oct 2022 05:27:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RmZyLYuk24MK4PbFW8q2hh684yZVgOGGZCyS+yobHxitO3BKbDQ3U0NBCGzi6uwwfCckh X-Received: by 2002:a17:906:fd85:b0:77b:b538:6472 with SMTP id xa5-20020a170906fd8500b0077bb5386472mr15184248ejb.48.1666355217220; Fri, 21 Oct 2022 05:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666355217; cv=none; d=google.com; s=arc-20160816; b=nfScsh5/cZDc2P8j3UzdKzDjybzqk9C/iX96fCKTtgO8RQuh3nGbJcvNyhL9qO/1C9 mXXo5voWmlPM4kfxNl04O/GdA2b9ybQlnqdnZVZWnecGMtOUXsvKB0Ij7lYzK6iNnS5Y zueR98yEaNXwOuKo47SlyRhJetskUhv0bGMp5AHG8IvDyGifW23PLMjsBp8rqXgtGjND djDoh1A3UTkt8nUdl6GAvvJA09zzMby3N1OpKOT7irlnVtj98oCK/K/v72PZvQffsbLo Tan18RmE8Mgs0ApBMT52B95qZ7XGplyz3dd+h4Qb+zprFjk/9HSUvL6bgumdFNRWPBhw kauw== 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=M7y76rMK0l0e5eWAROAZYTUlkl1SI1ptrjBCD2DTCug=; b=cpxwadISywKH/LDjf+DpTawcNMguAUzN6/cslErvuBHJ0/GH3137J0SwKb92C4Rk7H kt6PBtpaN6X8B27OwymPOw1TgLfR2SFSGZ8Y5QoORBVcIPDCnLBjh9gaUsFUT4Lp2nrp G7083jWs6wkIObdATF8bvQfsKtZHAz2pzXpyF0jvT5RDj/ClHLyyz8rTh+NnQUjCgV+B wdIhBhQTh7zSmfv6vsDabLfLxuuDGCVY0lvkzSqoonvr91Ag8wZo+WxBEqkgiEi8VbfD wnL5QFUBVgWJKaJb1/+F9bIsdYqTPNSeVAqO0xl5CdBwFyjIBaMniA1Mv13HDqtuY7KY ZqTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iaFWoxx9; 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 hh14-20020a170906a94e00b0077ef3eece57si18787217ejb.144.2022.10.21.05.26.31; Fri, 21 Oct 2022 05:26:57 -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=iaFWoxx9; 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 S230146AbiJUMUF (ORCPT + 99 others); Fri, 21 Oct 2022 08:20:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbiJUMTv (ORCPT ); Fri, 21 Oct 2022 08:19:51 -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 C64B536416 for ; Fri, 21 Oct 2022 05:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666354787; 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=M7y76rMK0l0e5eWAROAZYTUlkl1SI1ptrjBCD2DTCug=; b=iaFWoxx9m8gLFiAiPyW4PAYLz31ZogwxI6T5E7RlBPVAB9c/PFgt+4ZmdesDoZGU3Jt0WI T1jRD0+QKzC1z2RgxvjQgaEWdYBmPxeGxtYiIjpv8OGiYdaeCXPr9lH+qOw3FNiGKpCahm 71NXp3uQTYuZetAxghOI3E3VD+XvEUw= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-148--ZrLuHGgPLOf4VPKpPlUXg-1; Fri, 21 Oct 2022 08:19:46 -0400 X-MC-Unique: -ZrLuHGgPLOf4VPKpPlUXg-1 Received: by mail-qk1-f199.google.com with SMTP id n13-20020a05620a294d00b006cf933c40feso3383312qkp.20 for ; Fri, 21 Oct 2022 05:19:46 -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=M7y76rMK0l0e5eWAROAZYTUlkl1SI1ptrjBCD2DTCug=; b=C2RXKMYhXbgOet4AuZx3BEXPzeYlTMCFAW1xip+4KG0scArk+My3g39NcrGmI9lZuP YTm33eHdxTmXol5yzPOumvmmUIlZZk4BP1Z1H/ojJ1+kCBYos6XNSLyb8PdOdYvjxUY+ 7ranTj+PBtxcj8/8+b+J0j5t21bUw3wKGR2EbWugmpG8/ux8ASEurQ9niEXG+HOYyc+i 4lmV2Cgsln7TZ20xjEDXowc59+HM44eBKAnplVOLdpQMKFMrL2X8hOSHRMQY07LPIjiP SxdIaLjodnjJ30Iv7ks0BbDTA13CWR3u0pjk4jsnCDBjanUiiWePyXBeo4uiHHPOCCzH OoJQ== X-Gm-Message-State: ACrzQf1739Tho6KZjstEOrPVHO/Nj8IkI+aV6RHEhhaXztSxQ74WjIdx qv6aSb01Nze+KmU/QSjO4guVEcjkIRPtTB2KRj847eGjanCE4iME/OGupht7Mpbw5UVZd1fV3v5 Y1RDvVLkMFR6gS5+5xW3O3uDM X-Received: by 2002:a05:620a:2a02:b0:6ee:7de4:9690 with SMTP id o2-20020a05620a2a0200b006ee7de49690mr13676786qkp.172.1666354786338; Fri, 21 Oct 2022 05:19:46 -0700 (PDT) X-Received: by 2002:a05:620a:2a02:b0:6ee:7de4:9690 with SMTP id o2-20020a05620a2a0200b006ee7de49690mr13676761qkp.172.1666354786116; Fri, 21 Oct 2022 05:19:46 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 05:19:45 -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 2/3] sched/topology: Introduce for_each_numa_hop_mask() Date: Fri, 21 Oct 2022 13:19:26 +0100 Message-Id: <20221021121927.2893692-3-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 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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747300088103996752?= X-GMAIL-MSGID: =?utf-8?q?1747300088103996752?= The recently introduced sched_numa_hop_mask() exposes cpumasks of CPUs reachable within a given distance budget, wrap the logic for iterating over all (distance, mask) values inside an iterator macro. Signed-off-by: Valentin Schneider --- include/linux/topology.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/include/linux/topology.h b/include/linux/topology.h index 3e91ae6d0ad58..8185e12ec1ccc 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -246,16 +246,36 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu) } #ifdef CONFIG_NUMA -extern const struct cpumask *sched_numa_hop_mask(int node, int hops); +extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops); #else -static inline const struct cpumask *sched_numa_hop_mask(int node, int hops) +static inline const struct cpumask * +sched_numa_hop_mask(unsigned int node, unsigned int hops) { - if (node == NUMA_NO_NODE && !hops) - return cpu_online_mask; - return ERR_PTR(-EOPNOTSUPP); } #endif /* CONFIG_NUMA */ +/** + * for_each_numa_hop_mask - iterate over cpumasks of increasing NUMA distance + * from a given node. + * @mask: the iteration variable. + * @node: the NUMA node to start the search from. + * + * Requires rcu_lock to be held. + * + * Yields cpu_online_mask for @node == NUMA_NO_NODE. + */ +#define for_each_numa_hop_mask(mask, node) \ + for (unsigned int __hops = 0; \ + /* \ + * Unsightly trickery required as we can't both initialize \ + * @mask and declare __hops in for()'s first clause \ + */ \ + mask = __hops > 0 ? mask : \ + node == NUMA_NO_NODE ? \ + cpu_online_mask : sched_numa_hop_mask(node, 0), \ + !IS_ERR_OR_NULL(mask); \ + __hops++, \ + mask = sched_numa_hop_mask(node, __hops)) #endif /* _LINUX_TOPOLOGY_H */