From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E61BBC4167B for ; Thu, 7 Dec 2023 21:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231589AbjLGVpi (ORCPT ); Thu, 7 Dec 2023 16:45:38 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > } > } > }