Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1621716rwb; Thu, 10 Nov 2022 20:15:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf6up3hPI2rpvWpM9yWx1KGO2H3WfaiPJfOa+TFcmZTND/MoVnnAqUPeX/GAFkhqN9Fdj+Tz X-Received: by 2002:a17:906:abd7:b0:7ad:b791:1390 with SMTP id kq23-20020a170906abd700b007adb7911390mr489990ejb.279.1668140155854; Thu, 10 Nov 2022 20:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668140155; cv=none; d=google.com; s=arc-20160816; b=rY2M97XtZJlOVUc9yeQ3UmXJa4GJAsQVQEXrw9lAKQNevfsMrtPV4TFRQ5zd80Z9Wi 71cq/I/2JJgMP/Zg28MlN4ucyh6vHCoAmKyoWEgnG5e+wFjomIzN5Z7Cdt5O7l7TkmhB +dw0EEv4FFAOC8lBbsKhcNujoosdP4HsGJzRQlDhxxeNnS2O2wj3D82sOqKpc/wP/Xf2 V6S0ViJOg1/yHnSJJVFHuHgEWfo7hKo4LP/7z4C83FvN85JXeRaSq88nWXayE3FhKlEU +uS3GomGjs5HRrTtcpUgaNciD/O5J2tQVEaMrFN5aOYlE5+V50MmV1FNlCLiWiURoO9a M5PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2kdIP1WeRYup9WYrN50JXtVx97BRTIEhufBzxLjkpYA=; b=QImbh2zEr3x6zrNqMyAhGTM8Mkn+e2WZBxmfQMT7/XaSFqrkJT/8KAN8c4IOurnVpO DopNkZn+6roGRGtoY0WSNj59QN3p1LWHhojj1oFMjh91M0eTBTfArmlU6UZkxdtf4EZ+ JuuTU3Luk92YGy29eEhSokDg+i0KGnNMbo3IR2vvuK+oF54hOQQ1GQ54sltRYA5RkaS1 /hnrwO02By+05HPM3nbSXUMyV3c6vXpKGmgWw6gjPiy+LFS7CFLktV5kHDwnXdFP497n ZScEFKgrVAfPTEPVq81jviZdWiw1rKtF0plAyXxFcrK8zpB5oQTKX57jsbn2sJgazzS1 QXCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ca+da0sU; 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 i37-20020a0564020f2500b004589ea2d983si1310108eda.287.2022.11.10.20.15.29; Thu, 10 Nov 2022 20:15:55 -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=ca+da0sU; 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 S231974AbiKKEMD (ORCPT + 99 others); Thu, 10 Nov 2022 23:12:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbiKKELk (ORCPT ); Thu, 10 Nov 2022 23:11:40 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2653222AD; Thu, 10 Nov 2022 20:11:37 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id m204so3918527oib.6; Thu, 10 Nov 2022 20:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=2kdIP1WeRYup9WYrN50JXtVx97BRTIEhufBzxLjkpYA=; b=ca+da0sURkVvT/w+o9IghO9odiWy7U2rEiwocTnlWe8gRPKeY6vA/M3PsJV+6s4GvU WfYZKSQU//3TI0w9UwCZ/DVJ1Har1ltjs8l6DnqK1nfLcti12ge1yXp0hbHK08walcTb 2TfDFld7p8zKluEDkBLpoac2orSne4kZQbn134+liUFuDZI8SVIOcAQzSASduZcqfxDr JSIdr2NxzWe9wvHvEKahSEsHFdubdsbCHf9SL16y/WELxf/ugXp1tYdJ/q2yLyUH4UrZ JQs8fb8MzBaiqfmwCv8rNYzlzupSidep31WWSr3zhIUsJ8uB4EfEChazB7e9e7zR4Axh aHww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2kdIP1WeRYup9WYrN50JXtVx97BRTIEhufBzxLjkpYA=; b=jMLWnvCntSNzazcvCBDfTmzWdqGQDC5wpqBRR7Uq5JlJ03kz3EEhPEdPG9fOC0zy/p dth4dGtaGvcXMOAwJfVpnvybAvPRn0ft5agF5aFZha8eulT7m901F7FWN+XDRTuxXc0F F1XOIGLZ76+qNg0uW3A5FIZhOoZkqd7/ckTFDjZ2JNw8ny8EK/81sszOj2nhVPFwGeoZ M2oHuYJFnp1PfEZpG54i4b42BGO851FJhYUJfJgryu2LzL915IgFIbKmjqs0jVXvVVkO lG6VdxfDW0MYQWGU8RrnikP4MG3Bt8ZFC2JjoOgDHQaNX8Ji4apfbQhQQ8mwJRBPto6e iDYg== X-Gm-Message-State: ACrzQf12wI8kuhL0GAJ1/9LrtjP9Hh0+ZCYhIdktZnz4kD43lozZw0UU 0d6owRPVKhR4Q9LVW/KwsWbkAkNKvx0= X-Received: by 2002:a05:6808:170c:b0:345:20f7:b5df with SMTP id bc12-20020a056808170c00b0034520f7b5dfmr2742007oib.46.1668139896789; Thu, 10 Nov 2022 20:11:36 -0800 (PST) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id u24-20020a056870f29800b0013c50b812a2sm746209oap.36.2022.11.10.20.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 20:11:36 -0800 (PST) Date: Thu, 10 Nov 2022 20:11:35 -0800 From: Yury Norov To: linux-kernel@vger.kernel.org, "David S. Miller" , Andy Shevchenko , Barry Song , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Ingo Molnar , Jakub Kicinski , Jason Gunthorpe , Jesse Brandeburg , Jonathan Cameron , Juri Lelli , Leon Romanovsky , Mel Gorman , Peter Zijlstra , Rasmus Villemoes , Saeed Mahameed , Steven Rostedt , Tariq Toukan , Tariq Toukan , Tony Luck , Valentin Schneider , Vincent Guittot Cc: linux-crypto@vger.kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: Re: [PATCH 3/4] sched: add sched_numa_find_nth_cpu() Message-ID: References: <20221111040027.621646-1-yury.norov@gmail.com> <20221111040027.621646-4-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221111040027.621646-4-yury.norov@gmail.com> 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 On Thu, Nov 10, 2022 at 08:00:26PM -0800, Yury Norov wrote: > The function finds Nth set CPU in a given cpumask starting from a given > node. > > Leveraging the fact that each hop in sched_domains_numa_masks includes the > same or greater number of CPUs than the previous one, we can use binary > search on hops instead of linear walk, which makes the overall complexity > of O(log n) in terms of number of cpumask_weight() calls. > > Signed-off-by: Yury Norov > --- > include/linux/topology.h | 8 ++++++++ > kernel/sched/topology.c | 42 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 50 insertions(+) > > diff --git a/include/linux/topology.h b/include/linux/topology.h > index 4564faafd0e1..63048ac3207c 100644 > --- a/include/linux/topology.h > +++ b/include/linux/topology.h > @@ -245,5 +245,13 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu) > return cpumask_of_node(cpu_to_node(cpu)); > } > > +#ifdef CONFIG_NUMA > +int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node); > +#else > +int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) Ah, this should be static of course. > +{ > + return cpumask_nth(cpu, cpus); > +} > +#endif /* CONFIG_NUMA */ > > #endif /* _LINUX_TOPOLOGY_H */ > diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c > index 8739c2a5a54e..c8f56287de46 100644 > --- a/kernel/sched/topology.c > +++ b/kernel/sched/topology.c > @@ -2067,6 +2067,48 @@ int sched_numa_find_closest(const struct cpumask *cpus, int cpu) > return found; > } > > +/* > + * sched_numa_find_nth_cpu() - given the NUMA topology, find the Nth next cpu > + * closest to @cpu from @cpumask. > + * cpumask: cpumask to find a cpu from > + * cpu: Nth cpu to find > + * > + * returns: cpu, or >= nr_cpu_ids when nothing found. > + */ > +int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) > +{ > + unsigned int first = 0, mid, last = sched_domains_numa_levels; > + struct cpumask ***masks; > + int w, ret = nr_cpu_ids; > + > + rcu_read_lock(); > + masks = rcu_dereference(sched_domains_numa_masks); > + if (!masks) > + goto out; > + > + while (last >= first) { > + mid = (last + first) / 2; > + > + if (cpumask_weight_and(cpus, masks[mid][node]) <= cpu) { > + first = mid + 1; > + continue; > + } > + > + w = (mid == 0) ? 0 : cpumask_weight_and(cpus, masks[mid - 1][node]); > + if (w <= cpu) > + break; > + > + last = mid - 1; > + } > + > + ret = (mid == 0) ? > + cpumask_nth_and(cpu - w, cpus, masks[mid][node]) : > + cpumask_nth_and_andnot(cpu - w, cpus, masks[mid][node], masks[mid - 1][node]); > +out: > + rcu_read_unlock(); > + return ret; > +} > +EXPORT_SYMBOL_GPL(sched_numa_find_nth_cpu); > #endif /* CONFIG_NUMA */ > > static int __sdt_alloc(const struct cpumask *cpu_map) > -- > 2.34.1