Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1925835rdb; Thu, 7 Dec 2023 12:39:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjmh0/pq+e7SinsE0qfFQY68dBJoEf3UyDwvxn9o54ZQasRjSbadChJmjqONfVn6BBbA5L X-Received: by 2002:a17:90b:2b4d:b0:286:6cc0:b91e with SMTP id rr13-20020a17090b2b4d00b002866cc0b91emr2234366pjb.85.1701981577660; Thu, 07 Dec 2023 12:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701981577; cv=none; d=google.com; s=arc-20160816; b=fTMuGzjwtRYI7v0uicGuIkbgghuOgOH4KC7ftG1jLtmV+1KoFV+BfcMTIw/uID80Ys NvouUZMrAVawU0rCSI60RbMEla5StfyaI7+fHBIKUIxHisxCBVMx7NdqZfn4omujx4Ms uANNRmd5Edpru9gPRMCipD4RM4yin2y4cyWLgKN7iGJ2EMRAjMQdgWmXAlb06/D3+qvv MfNYyk9tM4yiR6oEsrM6YQfuT43+iAQRLoYmLNl3iEOmtfV395vHDXDPd94zDJ+YAfPa PMknbALXmvUBY2tLsbkbG1P5kvQnZDffyyupFuw3KfG16JXks4fR77kKsrYJagMmKu+0 idHQ== 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=1BoNDGd05aaAMfPxVJ9+hJFzTAErL73yhXGdigwpwQY=; b=KQIwahocHitMYP+9ChxvyrWzt6rQN1pMf8AsAuBxBZYcan9/6IFbRTBSheAbIDrGYM ViyXWmXlMKUQPjF6ein/TrYjlljJyo7HJtSeKiJuw6Ctje25e1H+h4wMJloFvfi8VeEL tUm1q2CEsgJ+tpKzJvGxR7ohV8Chc3Dm63mZs0BT1DtbWAmZELLDdYVhjI8NQypHOB3O mXkGBR46OCpn9iV9OqmfmPxZmDBL5p5lUc+WFVGvWWUeOqPQGRwlGW696OHayPKXHRlt XBP0UOvRQpTuhVn0qhM42xMKPp/o7bR9aa8sWfNc/mBS5gnILiNu2J+5XhU0tM+bc8cP YsOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MIScm2Vv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id fu23-20020a17090ad19700b00288704afe21si1659395pjb.84.2023.12.07.12.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:39:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MIScm2Vv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 7A011814970A; Thu, 7 Dec 2023 12:39:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443941AbjLGUjQ (ORCPT + 99 others); Thu, 7 Dec 2023 15:39:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443919AbjLGUjC (ORCPT ); Thu, 7 Dec 2023 15:39:02 -0500 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196B51716 for ; Thu, 7 Dec 2023 12:39:09 -0800 (PST) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5d74186170fso11258817b3.3 for ; Thu, 07 Dec 2023 12:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701981548; x=1702586348; 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=MIScm2VvEVU4s1sy5ocmZstsmGKOmkh/6AYKwCPbDHLecICfLkOth+fXDtpsmimxc3 GB0dSRmWxMlNtoAiDh/v8cMEnCI5bVfF/OF1NWWaDKMoa3Kej2VZi6eSZX/U9u9D+SJf KIvcwuJwPbHBJVQG2/2mx8ouxmv7NQ+v9lkgm+wlLnauwIBy1TLUbtzn1QIFu22L5luD qwFREiw3asBYiOG695ZWNxPPnkW5r4yN3eS4UM4L49HfjzJ0ad5UFbEELIB2HXbCYQkA JOiNb3nrnfl6Md7TIeJch+GFpcZTcBOLI3ssVx2EXsTMbt8uD3V6vO0nRVoGEotW0zdL k6kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701981548; x=1702586348; 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=Mm2pfLlFOGT0+6Sr/G+laWXve1YCehSkup6yaCIUv6Xg2F6/Pj1DeS7grch+yIcCG3 YStk6z/wsjvUvKuT1yrQ+QUmlnhZQYRLHGBRmMvCGsL3KO7+aQHYvCJhNcLJcCResYCx 22qsW3jZ6ngHEdrFxO7Z18eaIB1hUJl7KZOyZ5DGNS7UIPHsJdfxVDxJg2GcHiBgr6Wg RccAJTad38oWFpcyY8jht78xfsej8wxl3fsJS7hreJSRRk1JaYqLmT4uAQraAfWMZv61 c+k05nO6Vd2/5h9L/yin1ohxOXwaQBOBkoDM2gPlqaxL7LfkO3fGqht5jnZdGhXnOQRZ tnjQ== X-Gm-Message-State: AOJu0Yy/ie5n6pixmUBJlg+c03IX3x2X4sOuR2hc6iSnv71kgDzh71N7 1JkyROd6sgzck7wx/o0L12g= X-Received: by 2002:a0d:d455:0:b0:5d8:21f9:4efc with SMTP id w82-20020a0dd455000000b005d821f94efcmr2883577ywd.14.1701981548260; Thu, 07 Dec 2023 12:39:08 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:8f7f:efcd:5388:af4f]) by smtp.gmail.com with ESMTPSA id i9-20020a81d509000000b005d774946228sm141804ywj.68.2023.12.07.12.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:39:07 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , linux-kernel@vger.kernel.org Cc: Yury Norov , Ming Lei , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v2 4/6] lib/group_cpus: optimize outer loop in grp_spread_init_one() Date: Thu, 7 Dec 2023 12:38:58 -0800 Message-Id: <20231207203900.859776-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231207203900.859776-1-yury.norov@gmail.com> References: <20231207203900.859776-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 07 Dec 2023 12:39:33 -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