Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4778631rdb; Tue, 12 Dec 2023 09:04:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwuGpGlVcMHfkWNjm8ypQsZrsFDvKzb853P+X+sS5wmRDB/3vF/EVvhZbM+T15Z74WEveU X-Received: by 2002:a17:902:6502:b0:1d3:45b7:bc24 with SMTP id b2-20020a170902650200b001d345b7bc24mr512667plk.49.1702400685388; Tue, 12 Dec 2023 09:04:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702400685; cv=none; d=google.com; s=arc-20160816; b=BF4XbGYK7CY6em/t/NjPk5VkjO5Ec1VxWf8mSxCIUhC/Y24YVNWLXQ27QN6SHTL09s T77JwrzoFe3+DNkQfIN5MyxyWolWaQlj3594pDCj3L3eZPn805l0PI6rZbqqIjNjGIYR BkdS5MdesOpR28yx80E6Zgl9DvNK6o8tagtYbzg/8c1zOEDv5m5rFKuFry3duQh/ov9h Ymt8D4j0iiWTAJdPSZNMN4d6JMaKFU4UCO2+UtM5z9XfI6DyoxTZ44VUvaSHdpKP823Q pFs7gSMAVhyUj9kUs2S1trjd4r/anMdFLCFU6QbXfVsskNbbj9EV2adxkzEL+zzphQvL S1BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kldGEgyoOibSxMWFBb5z8YejTwIf3uVcbk6Oh/hN9Oo=; fh=P8WKVbhiWBy10Q9giupoRy5TLybsQirmOwtBEYAPRCY=; b=glNmwAunVe8PrXw8Me+hM8cNfT/nKxcNhGgasTQNicU1IykxkgO0825olZFmp24UGN lW3KBlvcMAiPHo1M0QrUKkhRrGEgrhi7wJkla7HLGstkoJqlnnlg8lsOjE0eV0FMhamf XrNm264Mdp6WOAVDC4rWt+VfJhZzidFWiaqGVRauiNzJEjvzpjU/+sLzSs5ZhKQIyD52 yknDOcd7iCo3dfANjkVrW+Iws9BovIolOqwOq/NSIuqkJaws1aCj7r/qNamnYX+Fbn+o 7BBYIdU3trnxZMrZFV9BvOTS1GQL4ODFAAVZqzxGhAgbpZ6+LpDf6wgham7Q8dbfu1FL 4+nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BYbIlyGi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id jb13-20020a170903258d00b001d33a1454adsi1175178plb.363.2023.12.12.09.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:04:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BYbIlyGi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id AC7258092CAD; Tue, 12 Dec 2023 09:04:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232746AbjLLREQ (ORCPT + 99 others); Tue, 12 Dec 2023 12:04:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232728AbjLLREP (ORCPT ); Tue, 12 Dec 2023 12:04:15 -0500 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7494F99 for ; Tue, 12 Dec 2023 09:04:21 -0800 (PST) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-5d8a772157fso51640937b3.3 for ; Tue, 12 Dec 2023 09:04:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702400660; x=1703005460; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kldGEgyoOibSxMWFBb5z8YejTwIf3uVcbk6Oh/hN9Oo=; b=BYbIlyGimLCfnnMBCstZyG1WCR0veNsYLjAQNHF/GhHy7TtnDvPxCuLMtVe/uoEOiW YWJLf7IRp8+1bPLiiWV2exdg9bOPf4tYgOBKE6TdQ3Ei6newKN8llltCm1IRMY829zH2 w2KiVuTCt+QxARSX2L5FMNrh/8xaBHSHAF1IcxDMaIddm4LcHdVisKDD1HtCYWD7BChU baHSsiwNdRchdNSUqS7KPC66/0J09S/tIKQom44HGiBo+znAtH4Zzj44Sc+rcadt22C8 dtIOeO2nBwF+Je4FI7JXb1I60i813ztg17tuFzbAmhruOP/qjK+Itec5K22knhdSuFQ4 WIBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702400660; x=1703005460; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kldGEgyoOibSxMWFBb5z8YejTwIf3uVcbk6Oh/hN9Oo=; b=oNGL8uxT7US2Vqxyj4UE/2Usiz5nUGd4Rjm9MCN0H09qlsgUocvoPurkoqvysGfJ7q APVZvOxuuy1sNyH5ap1C+/1ngVoXBVg4zBmtNVoWxcW2gKRYEGD3sGOFkaqGS3oYqewx c1tejnjSK6qHZ6NUL7gy6Scs7pZabjeXvNCJjsL2Ju9LpdHhb5GJ1/lTMbdareBB8FS7 /QTYSN5RxofjsL//uQQpKA8xzSC9J9x08huOP4sUs5G9i8UIXdyJ4WpYHiOL6dFzb0TG 3tTYoNtlFWgejfzz/gnoLYVT6uqWFjasbiQQ3AKRSFetxW8V5ZRSc32GHUPPykkQNwKv umLw== X-Gm-Message-State: AOJu0YzBQIO7j+Vn937cQWwRDBMU5vviGw+Own0dBeJ1m0GHUQQ9FKwh l3Q734BiN4YQEcZyxMMfPLk= X-Received: by 2002:a81:5c82:0:b0:5d7:1941:aab with SMTP id q124-20020a815c82000000b005d719410aabmr5721824ywb.70.1702400660301; Tue, 12 Dec 2023 09:04:20 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id w204-20020a8149d5000000b005d35a952324sm336901ywa.56.2023.12.12.09.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:04:19 -0800 (PST) Date: Tue, 12 Dec 2023 09:04:19 -0800 From: Yury Norov To: Ming Lei Cc: Andrew Morton , Thomas Gleixner , linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Subject: Re: [PATCH v3 2/7] lib/group_cpus: optimize inner loop in grp_spread_init_one() Message-ID: References: <20231212042108.682072-1-yury.norov@gmail.com> <20231212042108.682072-3-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 12 Dec 2023 09:04:42 -0800 (PST) On Tue, Dec 12, 2023 at 05:46:53PM +0800, Ming Lei wrote: > On Mon, Dec 11, 2023 at 08:21:02PM -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, > > 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; > > It doesn't have to 'cpu + 1', see below comment. > > > + > > + 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) > > if (--cpus_per_grp == 0) That's right, I'll send a new version this weekend. > > + return; > > I think for_each_cpu_and() should work just fine, cause cpu has been cleared > from nmsk, so the change can be something like, then patch 1 isn't > necessary. It works just fine except that it's O(N^2), where O(N) is easily achievable. Again, it's not about performance, it's about coding habits. > for_each_cpu_and(sibl, siblmsk, nmsk) { > cpumask_clear_cpu(sibl, nmsk); > cpumask_set_cpu(sibl, irqmsk); > if (--cpus_per_grp == 0) > return; > } > > > Thanks, > Ming