Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1957155rdb; Thu, 7 Dec 2023 13:46:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IH80xYsVT5aUAe93K8ZdZBsMEscuzM/hdRV0rQA9GlUjt3q8rEbAZlGQbnfqo3cmy8VhEse X-Received: by 2002:a05:6a20:12cc:b0:18f:c81c:4484 with SMTP id v12-20020a056a2012cc00b0018fc81c4484mr4224679pzg.29.1701985563676; Thu, 07 Dec 2023 13:46:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701985563; cv=none; d=google.com; s=arc-20160816; b=R+a1XBYKJXqTanJOyML9nGTuuqv6Y9BvNMxg3PPVb1DMwNS/xwng1OAlFS7rdrSAFE 57IWtykjSk/MfOjE+sn/8xqOLeK0DqkwnqHGZDKdetG6G5fB6FO03hDTIegTp8JLUvfX C5uemFhuTiuh1iqeeJsiXADWZr1Y+9UQdVUr3sRcypxAkCrG68VQIwpFTP2Lo1I4ziO/ ueJQ/NSR8LASweIF+XsylPY2ffhzKdMJX7Lyk4soJOnfUlPoxW0kgef2b8uYgtIxmhio oeEW1H13lI+C7gMpCcXcVzKb2mYZDr0ffH/3xG+wyHR6tcvHR1HOeaJm1gX8UK6sskRT KArw== 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:subject:cc:to:from:date :dkim-signature; bh=DsY7f32ftoyWU2Jxp0kL0uqJ0w6vyj+hD77Ch0VIKyM=; fh=Jx5ujPV+AkkglogN9Dh3TOlpSrZkmLFElIsX7ggU1sE=; b=qwcj5S9Juzl1MNyI4YChaSL7uIVd44n+vbTJGVDgrZSbvh6R4jgCo3dzN9SOt23yYi neLlXDseL2LhlxVWrjoP1CRSikigpx9Uy2n2M5GOdc076ROLpK93O52hQZw25uMLS9lB 07Ne+u8Vs4I972N2l599kOW+Ud3MMbsfdNdpDr2chvSISzgORy+OQ0L2eMr/2o+5Dg39 G3txkMHv5Zb97LoD3JBncVAzG8RQMFa4+mfY6T7DNxijGkqjeyizyx/mvEG6xCo98Uxi UGxrNYQCFWT8ATntKHs9WBYJujD2Nu17MpWzK4Kx2uRvjMSo3YimUef9HeS6GgkBgZq4 YIvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=DQmrBGkz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id l2-20020a056a00140200b006ce500e3702si327723pfu.343.2023.12.07.13.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:46:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=DQmrBGkz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8754C80D1DE6; Thu, 7 Dec 2023 13:46:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbjLGVph (ORCPT + 99 others); Thu, 7 Dec 2023 16:45:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbjLGVpR (ORCPT ); Thu, 7 Dec 2023 16:45:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC08171C for ; Thu, 7 Dec 2023 13:45:23 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93726C433C8; Thu, 7 Dec 2023 21:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1701985522; bh=ppvsN0Qt+Uj98booU8p5G/LMRKy2P70PPnbZOdvnNYU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DQmrBGkzgUUj51ar9SYzQ6MY/lJnPuG1Yj7d1qgXr8YSv6a/ba+AdM//x/WErP82k /0QF+auhJvpNO5DVM94hy7HLKAOigUhCZroj8Xa9Hd52t6+Cp/kvqv76GQyfZauvpy /0J461uc4YRpog/5jurWKIvWNyllI49vaP2RZGLw= Date: Thu, 7 Dec 2023 13:45:21 -0800 From: Andrew Morton To: Yury Norov Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, Ming Lei , Andy Shevchenko , Rasmus Villemoes Subject: Re: [PATCH v2 3/6] lib/group_cpus: optimize inner loop in grp_spread_init_one() Message-Id: <20231207134521.c921cb0bb1ab7487d78aeb07@linux-foundation.org> In-Reply-To: <20231207203900.859776-4-yury.norov@gmail.com> References: <20231207203900.859776-1-yury.norov@gmail.com> <20231207203900.859776-4-yury.norov@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 07 Dec 2023 13:46:01 -0800 (PST) On Thu, 7 Dec 2023 12:38:57 -0800 Yury Norov wrote: > 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. > > --- a/lib/group_cpus.c > +++ b/lib/group_cpus.c > @@ -30,13 +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; I assume this test goes away because the iterator takes care of it? > + 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; > } > } > }