Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4411225rdb; Mon, 11 Dec 2023 20:22:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqll8LlCsZGZRBel0CQxCUm6Cu6HuPu09XPpOpxvvsAlVlx1F6Fhy+aHn0GeZiZ6Fj55Km X-Received: by 2002:a17:902:fe82:b0:1cf:b12a:a9eb with SMTP id x2-20020a170902fe8200b001cfb12aa9ebmr4996670plm.19.1702354948671; Mon, 11 Dec 2023 20:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702354948; cv=none; d=google.com; s=arc-20160816; b=O3Eo62YXIVzT94cL8RpIYHbm1YA51cfRQmHKZHXDMTiT82bQT/AeLQ4OtpbE/oftjF VuSibqDTuB8zAXBooXt06HpDqOQjjjzENqknou1KiMg+Aur+YonOEq+/JB1yy7eh+W7T nwyRkgNFDKew7038aLO7i3eruI9wR9SOYuPhXo/zLb5Gf2ILPRlrU4e4rRbycQr6hlmK xnkj+/7N0VEYLJ3s5V0WiF8nq4YkvC0DIM6J/1VxEgU1t8yyUY6tbhpOd9gFas+DcxFk tJqozzUX0yAT981dxBb4lruou8eTYehpXdQGM49XUtXFLNkw7MT7gQlaAc3GegCvGTft o3FQ== 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=UfvFAKot0bp3HfeoPJ3dMZk7rFg3lsuy8X5EAYhpV4g=; fh=kL/RA2Gd9NuQcovU0+7My8qgZ6xDrReyLO6zCGgffAQ=; b=sSdNqTkwMMCuuZLNfKo4/Fl+9wpSE7bs5p4vBN2O5bH8Ps1GGGy41gv1+sSITwhBm2 lMvx+reoZSZybtbNgNLKy3X9Oq6it7t5ZNaTsaWHn+vo57zY6lY9RTyS1G1rNnWP9JY7 9L1pFEi+9fXJAp3LnrvCVq+mCB8hKZKN0G8ONX2trz7i3u9qeyB/euhGYrUXtmz21auP VCFJXOqR6ZJIXy0VsaR9qKPclz2zCpc8qKhsTEk9Om9nJejb49jomQfFl1OryMiZD7jm SESwyPxJd0iikTtsT37aHvWgARsnOGBJSDWa0AhyPzPyv5pSSa3glkpSRG/QzsIAJfgm 1SBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nGV5ZDxr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c22-20020a170902b69600b001d0a3ab370asi6509906pls.326.2023.12.11.20.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:22:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nGV5ZDxr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7A7CF8083B17; Mon, 11 Dec 2023 20:22:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230259AbjLLEVT (ORCPT + 99 others); Mon, 11 Dec 2023 23:21:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjLLEVK (ORCPT ); Mon, 11 Dec 2023 23:21:10 -0500 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640CBBF for ; Mon, 11 Dec 2023 20:21:17 -0800 (PST) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-59067ccb090so3240739eaf.1 for ; Mon, 11 Dec 2023 20:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354876; x=1702959676; darn=vger.kernel.org; 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=UfvFAKot0bp3HfeoPJ3dMZk7rFg3lsuy8X5EAYhpV4g=; b=nGV5ZDxr70D91ac+T6LqL8u3ojak+2fWxoTFlSoCTx3A9EXgpYNgjkIMN+wEHM30jH IkL5aDwYTG1BsCF0/VG/DWrr9JULuYCxT1R+/4IA8CxftbJrTVt5V8m0ydaJGKWcty9a TGpec6p6evfw+K801vNqDNlTLaMzFKCeigNUY5O85fW675gVFe38VV32mIFmiqzAeKoM o/buveCT4PxWa7yGqy+oNSVWj1Fu3RW1dbQMoRRDxJTBNgG7NwXQ0X2nIq2mA1VKqekc qYxFk+8X2OxG5h0VjhnbqdVvGZmfKkwY0Df5dzvicy5vggb5v6rvulsl9DOA1y+t6K+b a8sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354876; x=1702959676; 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=UfvFAKot0bp3HfeoPJ3dMZk7rFg3lsuy8X5EAYhpV4g=; b=wI+6EWXHVdVeuqL3bYdM/Qtg2BaG9EF7HLytX3T7/nm5VxQ9/93o+CrLvUSWH58KrD b9gizSb7T3O9AhnlW7AGTxKLT7a+WRL7HqTJqdhmwJcILtEUpF12k0AxXuRgPoPXoUpU m8aCT5eZrauGnFgAkMIFJu+luQlxWsLKk7sHqthyYRQRaPCjWb477X9TAddKzKqUvRq5 Qvg5WlaEvBTwKpUAlgjRFYYWkYFz0CCMHsnKnxGH4cagKDyB0M64E42EvgbLZ5sEK/Yp 2Ra5siquBDNcuyZOKPUrwh5QTM5et0ApWzWgmY+Ab+gBIHQEf6gVCjIwsVLM8806l9PO trrQ== X-Gm-Message-State: AOJu0YzQoitEZ92VwebKKkyr7KtckFyJ2+wMkGkEefDTZtG9mh1ifmeo GyvOO3LO3urg/yp7U6DrZOs= X-Received: by 2002:a05:6870:4590:b0:1fa:26b7:af18 with SMTP id y16-20020a056870459000b001fa26b7af18mr5327160oao.17.1702354876515; Mon, 11 Dec 2023 20:21:16 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id d201-20020a814fd2000000b005cc5f5aa533sm3499620ywb.43.2023.12.11.20.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:16 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 4/7] lib/group_cpus: optimize outer loop in grp_spread_init_one() Date: Mon, 11 Dec 2023 20:21:04 -0800 Message-Id: <20231212042108.682072-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 20:22:00 -0800 (PST) Similarly to the inner loop, in the outer loop we can use for_each_cpu() macro, and skip CPUs that have been copied. With this patch, the function becomes O(1), despite that it's a double-loop. Signed-off-by: Yury Norov --- lib/group_cpus.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 7ac94664230f..cded3c8ea63b 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -17,16 +17,11 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, const struct cpumask *siblmsk; int cpu, sibl; - for ( ; cpus_per_grp > 0; ) { - cpu = cpumask_first(nmsk); - - /* Should not happen, but I'm too lazy to think about it */ - if (cpu >= nr_cpu_ids) - return; - + for_each_cpu(cpu, nmsk) { __cpumask_clear_cpu(cpu, nmsk); __cpumask_set_cpu(cpu, irqmsk); - cpus_per_grp--; + if (cpus_per_grp-- == 0) + return; /* If the cpu has siblings, use them first */ siblmsk = topology_sibling_cpumask(cpu); @@ -37,6 +32,7 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, __cpumask_set_cpu(sibl, irqmsk); if (cpus_per_grp-- == 0) return; + cpu = sibl + 1; } } } -- 2.40.1