Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4410943rdb; Mon, 11 Dec 2023 20:21:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTAOhA22DG9S1ScAyLafZdY2QVZWmaLALNdL8PyWOaDmmwNX+STp8mXO/zdTelULAUbW8s X-Received: by 2002:a05:6870:55d1:b0:1fb:75a:de77 with SMTP id qk17-20020a05687055d100b001fb075ade77mr7067158oac.101.1702354892212; Mon, 11 Dec 2023 20:21:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702354892; cv=none; d=google.com; s=arc-20160816; b=Ifdco2HI5tqYc0zDebkJVHuxe6FOhIUjQpJe3G0k3AY2BqvjPHo0uGSM02i6xhOiji EET8ZgNrAG/mDEmEzNdgRcTBeokqV9LTyLKuyqejFABkbtvoEDssTJhF9om9Yb+V/aUY 9XrASy4Crgv/06Yikf0rvsKTcu0i/HSgptPSSBZH49YhmthGpXffGHP98iNSbH3b05kj QjSNnECYs1qbDVu+9B1NIp53/6Qyv5cm72nTc0fHt+5s4cyZ5HWyEdZ6Ddxr8pm1a/Ol UTUtTjyb+kgHpW2+Yme6IO0oWQDIB4LC5R3sxjvHPfwxCBamcefzCuZrhHHPU5nVggSa Hvpg== 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=WnIA3EnzQnW3AuT6MleWaZcP0AeUqS6iyw6BtYD4kcc=; fh=kL/RA2Gd9NuQcovU0+7My8qgZ6xDrReyLO6zCGgffAQ=; b=HJ3ZdK1gTKNk4j3MAmmp2U1d0VYwDsHNeQ5LsycMs3Vtz+0aw+30FO9gp/SL51/JCZ 6BgzjYaFR/t94UzWxVfZcO461WaNiIN4uSc4O5/pH753BInGXSpmt6eTtHHMg92Qo89i ZQil4IfgbSNHvGk+Qw9rLXAAZaoMjSlQjCCD2NPqe9Hqjl3ZjOO5l9lV68wzNE49+G/V 3+lSJysgYVvFSKxTOtpTOywRjwfzu4/SyFCpeRd5et8RH1pwVq42VSlWGvYJnmhPfaML Zd7LkUP0lBy6Ey0tN0zYwwJQAvajZo9YLVbYr+QagSeKY3mt7M7jEZPRQU/aUIyqa+Ox YpAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OHfysT+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id s1-20020a6550c1000000b005c688ef7549si7049209pgp.98.2023.12.11.20.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OHfysT+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id C25E9802208F; Mon, 11 Dec 2023 20:21:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbjLLEVM (ORCPT + 99 others); Mon, 11 Dec 2023 23:21:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjLLEVH (ORCPT ); Mon, 11 Dec 2023 23:21:07 -0500 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78130BE for ; Mon, 11 Dec 2023 20:21:14 -0800 (PST) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-db632fef2dcso5149597276.1 for ; Mon, 11 Dec 2023 20:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354873; x=1702959673; 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=WnIA3EnzQnW3AuT6MleWaZcP0AeUqS6iyw6BtYD4kcc=; b=OHfysT+epVFcBYHsdrSPc3m18F9K4ChXioYHGhxstZd27LcdgBb7Hbm6g5h/w+Q+uQ ENvPeOOKw6NBUCkoHDMYTuABJN/wanYTdYlhK/ORa/oNpw+pszDXyF+UF/HN1l/zNu/P svRJ+5qrFw7vyMQnnhkGTzp75HlqYJm6iaYQgL1zPoc3tI38euqUN54sk8PH7qan9mDM wQm55jXXDXWHFpFheSd8bqHgMrTuNqNwtHJ/QnNadAarEEen0xHXz4cazo3EgqNAFqRs bifPuMuPKoFcGVwg796itBtyZTfQNHoZ6jD6EveO8mmTnokCXIsw08DOBXDhgtmMUth3 Z9dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354873; x=1702959673; 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=WnIA3EnzQnW3AuT6MleWaZcP0AeUqS6iyw6BtYD4kcc=; b=LjjmgiBg28RByHIMxn7cvi9/GcY91uztuAax6pYRtArkx5orSR+r7nlgdnAg8yc8t0 GGuBYSmABPBCR8fZEV3xQz5TXXSswiyh1H6asVZqI3kP90qy25CzIiLofgiBWO7u2b2L iYNedYc4pvSTMONQe50Yf82jhPrL//Fv08xmzJJpFjVA1Qg285Ewxd26JWlYCJ8aV1uZ 39TpPrmuoeF9NRj/3nEt00Pg+OyXIE510Z1nsa9b1yajbew688F7JcjKYfF1vPSsG+Wy Dbi9hAGMqqt8QnZIpmtmflcI2lxyLyZq1YCSE+Ia9xBOsuvyjki8uIp4rcUzloalJRKz JbJg== X-Gm-Message-State: AOJu0Yx+uofILTXqfUnhh2Gce2USubWODk/DCiVnahWcERnJoRkALGY+ pZIEEuuXalsdnmwa2xp12e0= X-Received: by 2002:a25:db51:0:b0:dbc:b394:6ab5 with SMTP id g78-20020a25db51000000b00dbcb3946ab5mr1084932ybf.95.1702354873535; Mon, 11 Dec 2023 20:21:13 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id k15-20020a056902024f00b00d89679f6d22sm2917283ybs.64.2023.12.11.20.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:12 -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 2/7] lib/group_cpus: optimize inner loop in grp_spread_init_one() Date: Mon, 11 Dec 2023 20:21:02 -0800 Message-Id: <20231212042108.682072-3-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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 11 Dec 2023 20:21:30 -0800 (PST) The loop starts from the beginning every time we switch to the next sibling mask. This is the Schlemiel the Painter's style of coding because we know for sure that nmsk is clear up to current CPU, and we can just continue from the next CPU. Also, we can do it nicer if leverage the dedicated for_each() iterator, and simplify the logic of clearing a bit in nmsk. Signed-off-by: Yury Norov --- lib/group_cpus.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index ee272c4cefcc..10dead3ab0e0 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -30,14 +30,13 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, /* If the cpu has siblings, use them first */ siblmsk = topology_sibling_cpumask(cpu); - for (sibl = -1; cpus_per_grp > 0; ) { - sibl = cpumask_next(sibl, siblmsk); - if (sibl >= nr_cpu_ids) - break; - if (!cpumask_test_and_clear_cpu(sibl, nmsk)) - continue; + sibl = cpu + 1; + + for_each_cpu_and_from(sibl, siblmsk, nmsk) { + cpumask_clear_cpu(sibl, nmsk); cpumask_set_cpu(sibl, irqmsk); - cpus_per_grp--; + if (cpus_per_grp-- == 0) + return; } } } -- 2.40.1