Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1925906rdb; Thu, 7 Dec 2023 12:39:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKlFutH/VofaqtvbawBf/XyqGyF6A+wYqNz0wP8vunRP/mC6C/UevKSYYW77p/g1Tn+EH9 X-Received: by 2002:a05:6a00:1c87:b0:6ce:8292:3a04 with SMTP id y7-20020a056a001c8700b006ce82923a04mr3748196pfw.8.1701981585683; Thu, 07 Dec 2023 12:39:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701981585; cv=none; d=google.com; s=arc-20160816; b=Lbx3gps5PMPfvc0D7v6W7e2wJK6ZP1IXbXZXY8u5aOnDoS0SWBCnSNAIKt4UVzPWxF uLpX+sKfFKwxb3vsToiE4a4WCZtAu9UJXIslmmXGITGlxhO8qwIKRcyrFc0Fn3OIKgLY jMGEqSi40xBKgJMuqWHd6IZRJqzSzbAZPxnjLibTiFtLPLKqb2QDE7QCangefyv3jLjT /79nODG9idRYqGgcZz2qNE+ROD3Pmkme4T4A+6BgJU5OnHe9AaQob4ebbNXT7lutfsE1 ikwL9MnRcEerLqRZmTX6CZY4/F4/28isftbh7IvhakHYkJH4aM/DIJei2e4S6Y3EAHz8 v+Eg== 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=U6INlgZjI/rk3Hb4b9fsbV8+DsR4OZwnMfo8QGcQs8s=; fh=1BoNDGd05aaAMfPxVJ9+hJFzTAErL73yhXGdigwpwQY=; b=uVo7UgrmZlJ0UKUTJH85ADy8SjkhMyFuCBkfyFFxbjKQIACxj6VyQx1n1laerUDKsW /Z4F4UsrTtCsRI6LXFvTu+rblfAHXKXisbAOCZZLZHcvv3OFnkIv4T7vo4ZpYITb5i9Z tzNxsnf7SFSQrPT62XZyc0IIxuREpk6DDqGDkEIFyBP/9Wn1NuopjHAKKO/EwUDaFsJw 9EAgaHdicOns202jLw/COCzvXWK0NzAAG7O8yhT97gRd925IEszMGnGlYcKQ2SeqBOyf YuOOj6dP/0OHd/2nlBIHjbyCZN8t3XBXpFni8jvvQBi11tcxX+P4g/ru3YGihyB5IH5s He3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="DWbn/axi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s10-20020a056a00194a00b006cbd3ab255bsi281902pfk.61.2023.12.07.12.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:39:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="DWbn/axi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 58F2E84EAC68; Thu, 7 Dec 2023 12:39:43 -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 S235324AbjLGUjN (ORCPT + 99 others); Thu, 7 Dec 2023 15:39:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443913AbjLGUjB (ORCPT ); Thu, 7 Dec 2023 15:39:01 -0500 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDDA41713 for ; Thu, 7 Dec 2023 12:39:07 -0800 (PST) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-5d7a47d06eeso12681877b3.1 for ; Thu, 07 Dec 2023 12:39:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701981547; x=1702586347; 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=U6INlgZjI/rk3Hb4b9fsbV8+DsR4OZwnMfo8QGcQs8s=; b=DWbn/axiW8UwkzOroASm/q4/ycZikPr7mm/pCEFCPA+2NL6KsNH8EXmNrNBptxsBOO KCVbG8AqKBYzPvkdRo6I4jWBzauwVSy9oT+BVTelVbrx0qV5uXMtS4Nm5OxqJit2jZzF BWaWW1kcf8acUPRVskKQt7CoMaVlRC0oNKklYnTLOqFlbN2EacMELWepaAHwtOvyUvYC PIEJg/82hROW7B+uVV39u6GOdXxe07IrfiShuMYYRGCiOXUEqQ1TaKW3PAw8rv/5n/kB BKtGbP8xX8owPAyv/3KtFok3su+3TEjeJcZQvf/AEfbY9B0xM6f6O2lxbHE+1Tv9mR2U ivZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701981547; x=1702586347; 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=U6INlgZjI/rk3Hb4b9fsbV8+DsR4OZwnMfo8QGcQs8s=; b=CdApIFlW/csk+l9S1xSCsd7rT59uvkrAhicByuObD00ycW7XWKuE3tE4/4N9afFrYi O1p4Ro3rnQhKU92wubNCgzmLGYd6AU31bQQEECO5XngLaG6VrLpPQW48s2qsH5kVH58B HE+pt2GwyJxFE3CLGTCIrOUKKtyJChE0RE8Dz41zJGz7YUhw2Z8hLff6cySxrxz7KNkh j+TNfPEuzLq6kk/7t5v0OhYSvK20cUBWTOqq4hvdCWwnCMkFwVPWgQsUuZjQLQ4PjaJY LQmrLPNaUl7Yd9RDjZF3LWVKjJK8K0jY96vLA+sAmRetUOodV0o4j8puQ9YaA8ggao2S 1bGQ== X-Gm-Message-State: AOJu0YxGanI8IHSdsisxhUr2pXdFsDza49mRLx/ykw4kg3k9t3KbPG9F pH6xnfTOutaf5XacWETr9pk= X-Received: by 2002:a81:bd42:0:b0:5d6:c177:4a31 with SMTP id n2-20020a81bd42000000b005d6c1774a31mr2916183ywk.50.1701981547007; Thu, 07 Dec 2023 12:39:07 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:8f7f:efcd:5388:af4f]) by smtp.gmail.com with ESMTPSA id z20-20020a81c214000000b005d900a949ccsm141308ywc.97.2023.12.07.12.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 12:39:06 -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 3/6] lib/group_cpus: optimize inner loop in grp_spread_init_one() Date: Thu, 7 Dec 2023 12:38:57 -0800 Message-Id: <20231207203900.859776-4-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 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 12:39:43 -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. Signed-off-by: Yury Norov --- lib/group_cpus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 8eb18c6bbf3b..7ac94664230f 100644 --- 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; + 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