Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2007467rwb; Fri, 11 Nov 2022 03:50:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ztrb9kYfQyADow9ePhtnKpxROI2PnLvEFhsvEQPocN9eUld4XcEIlCJf9pQoGmEWgKrNk X-Received: by 2002:a17:907:20db:b0:78a:16ad:8250 with SMTP id qq27-20020a17090720db00b0078a16ad8250mr1493796ejb.747.1668167451387; Fri, 11 Nov 2022 03:50:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668167451; cv=none; d=google.com; s=arc-20160816; b=mKjYbFScVGcEfvj9fv3SqGmXLP/8bL7T+Oo6YhO6Dvf7mCrVqwMJu2Vat3/nCdBtOn LofoaRIHcYx+fWmCgLQhfbbALy6aGND5PaCCqhDMJaOmctmESyMoCda71NycixQyJYrc 1EjyQ+/tBNx/33ZYgpqsmQX8rc7XZL4TGyIPjexhsKw4UcQ87yX9v3rvQrMVPmoxJpXM kxJUWtb4i2pqBN9PADf33H3E8bW+zhhOBkJJpwscwSNvbkmP/yN5PDlRwlBw/PQHP8Vv wbK20CJS8gslKOYGx90jfWC1UudmVZm0/DWrle5mv67VNtYYEiNTW5ocVdSRrSpn11D3 r4sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=gplkFq8HCTLLxeth8RJQwKnNBqRj2UC+LOJTQROti6s=; b=JGRCNBEGeV7zx1fLoGuiwBzMvl+KxAd0QmmxwFIxzBQs01KExyHW/f7wTSzV98DdY4 36S2Cq0R+5CVxP1yFDkG2zfty0cf4hjUfq0XsZ1lKn/taFX+ZiYnDeYZ0JloKE3MVdfx K6JyfK/FAhEnacacKeHh8Vn1zGFMg91FExNeBrOKX71tXvouxq6RdXgi0irjwdjXwWA3 WViNodpdlrCn/bTTRwXyYMJukYgEdueDuRUdsRmlxinScIAflSa/bX+p5wrbUOsRIVwQ V4DWPurfoB7w4IDB2KJHO1YTfqmrQ9nvitgMBvk9EroLuMWN9wxPes9Nt8cqty98I4MZ 6n2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aagjEUbP; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e12-20020a17090658cc00b0078d3ba4d567si1628437ejs.422.2022.11.11.03.50.18; Fri, 11 Nov 2022 03:50:51 -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=@intel.com header.s=Intel header.b=aagjEUbP; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232963AbiKKLml (ORCPT + 99 others); Fri, 11 Nov 2022 06:42:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbiKKLml (ORCPT ); Fri, 11 Nov 2022 06:42:41 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EA8F293; Fri, 11 Nov 2022 03:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668166960; x=1699702960; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=124+lIYjUM+GMbJrh07c3Hmq7RwI2uO23bDDOBcYH8A=; b=aagjEUbPjNTEda7sEzNZguqxSmdc2FzoirdaF4wJSHFDsdr2Yi/Z2JyE T9kBr5XiPpp60Rs09+oZWbaUi47bvpqkZ18KjdvcvOe2BkYgHD9xmH1Cw IjvdiEg4jydldh2LiNQYY543zZGHgoZtypumHHat046zVpq226vLzqaxE E7CFBW4bktE76oRNOTlgj0aLVulS3gxIYhZH2iR1mhmAfCaELYplN40qi Lm/FstDY1erKKXo9c8TPDejoZA/O91z7jiIApDxFBrXkLCbetYk7i+A6w tvPsrT7VHDlCrn/9q9l5Fu8GPb4JFEjmpVEXSRqCeJ5+1Ke4SOrWrPUXv g==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="294940955" X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="294940955" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2022 03:42:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="882740444" X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="882740444" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga006.fm.intel.com with ESMTP; 11 Nov 2022 03:42:33 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1otSQX-00Afyh-3D; Fri, 11 Nov 2022 13:42:30 +0200 Date: Fri, 11 Nov 2022 13:42:29 +0200 From: Andy Shevchenko To: Yury Norov Cc: linux-kernel@vger.kernel.org, "David S. Miller" , 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 , 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> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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-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. ... > +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; *** ? Hmm... Do we really need such deep indirection? > + 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]); See below. > + if (w <= cpu) > + break; > + > + last = mid - 1; > + } We have lib/bsearch.h. I haven't really looked deeply into the above, but my gut feelings that that might be useful here. Can you check that? > + 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]); You can also shorten this by inversing the conditional: ret = mid ? ...not 0... : ...for 0...; > +out: out_unlock: ? > + rcu_read_unlock(); > + return ret; > +} -- With Best Regards, Andy Shevchenko