From nobody Wed Dec 31 13:54:11 2025 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 A5239C4332F for ; Wed, 1 Nov 2023 22:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347382AbjKAW6e (ORCPT ); Wed, 1 Nov 2023 18:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232330AbjKAW6c (ORCPT ); Wed, 1 Nov 2023 18:58:32 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C629DC1 for ; Wed, 1 Nov 2023 15:58:29 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5a82f176860so4440097b3.1 for ; Wed, 01 Nov 2023 15:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698879509; x=1699484309; 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=go9MsBs3kshTdYS1OGG6zGV5mB8GAcndMsaSv16whFQ=; b=fQxpOUk8Srjlzg4HEqBpyLixswTTIhhwCzxj5QIFaKGtvhlcwLkh5sytnhEKWLm/eB 3MRC8CjKDfqs5UeKWsj7strLuxXNGeHDFOV36zcGnsv7kkj+rgzbzFyz5tTiQseALIs5 3zxnVPC1yXdZ0Uqp4YtNiQuHUclrHz0VO+lvxkxt5alRiJ5VA0LMmvcYCRz9QGow+auA cfq43DXz/tb47WtKu/BonRARy1+W3OQiFozA/0uSztIVPFPilePaAB2KURCsLl7wewAh T2ceGlhMcqi76dHrPNFmZg3Ecy9dQPo8NpesApOGadIX1pa3vhgQ39WMmYkOjyOhDl+h i2Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698879509; x=1699484309; 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=go9MsBs3kshTdYS1OGG6zGV5mB8GAcndMsaSv16whFQ=; b=V8D+5ZbRPXV8KMwqld0skXDSNMuqIo2kKAqGQMDSfz5m7OL068bR50sIn5NF9SbDjI bojnzB8Ww21ULK4Puag456Xh7cyByP5btXtj8SzA40arEmOaNdZc7wiVIXgOCZDILzCo ydfnO9dqEb/Jrn8XnqC8M63UpRAlLY5ScbG7IMnWOkRjF6qPcF+pM+MSAUJQD2vZCfSQ D/1Un5hwkx5lf71SXD98n7hap0ykjGQrAz+jppAVJsb9XDm5bvgADkYbaispGKIp52HV oiidvqfmWLc13IEexwC15sbnQkWICEAme0s73nOEYnTY9dSHb15b1FhoEoRmhEQ8iPwV 4H8w== X-Gm-Message-State: AOJu0Yz7PsvHeED3OaJctZ5FF6zM8CPKnyXo1E8kRHHgFUfWb9uCzvyp r7WgXj6B6Qzg5IqyeCYcGm5QaNEi0iV81A== X-Google-Smtp-Source: AGHT+IGMlrmxbbg/0TDcw6lZ7xsqd4YM+pVmk+kGMG6DsE5u8YodSHB8O1sE7YpeC9+FXpv0j3RBGw== X-Received: by 2002:a81:ef0a:0:b0:5a7:aa54:42b1 with SMTP id o10-20020a81ef0a000000b005a7aa5442b1mr15615714ywm.28.1698879508881; Wed, 01 Nov 2023 15:58:28 -0700 (PDT) Received: from localhost ([50.221.102.30]) by smtp.gmail.com with ESMTPSA id u131-20020a817989000000b005a7c829dda2sm518469ywc.84.2023.11.01.15.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:58:28 -0700 (PDT) From: Yury Norov To: Thomas Gleixner , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH 1/4] cpumask: introduce for_each_cpu_and_from() Date: Wed, 1 Nov 2023 15:58:17 -0700 Message-Id: <20231101225820.51342-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231101225820.51342-1-yury.norov@gmail.com> References: <20231101225820.51342-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Similarly to for_each_cpu_and(), introduce a for_each_cpu_and_from(), which is handy when it's needed to traverse 2 cpumasks or bitmaps, starting from a given position. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 11 +++++++++++ include/linux/find.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index f10fb87d49db..fc9f9d86229a 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -332,6 +332,17 @@ unsigned int __pure cpumask_next_wrap(int n, const str= uct cpumask *mask, int sta #define for_each_cpu_and(cpu, mask1, mask2) \ for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), small_cpu= mask_bits) =20 +/** + * for_each_cpu_and_from - iterate over every cpu in both masks starting f= rom a given cpu + * @cpu: the (optionally unsigned) integer iterator + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * + * After the loop, cpu is >=3D nr_cpu_ids. + */ +#define for_each_cpu_and_from(cpu, mask1, mask2) \ + for_each_and_bit_from(cpu, cpumask_bits(mask1), cpumask_bits(mask2), smal= l_cpumask_bits) + /** * for_each_cpu_andnot - iterate over every cpu present in one mask, exclu= ding * those present in another. diff --git a/include/linux/find.h b/include/linux/find.h index 5e4f39ef2e72..dfd3d51ff590 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -563,6 +563,9 @@ unsigned long find_next_bit_le(const void *addr, unsign= ed (bit) =3D find_next_and_bit((addr1), (addr2), (size), (bit)), (bit) = < (size);\ (bit)++) =20 +#define for_each_and_bit_from(bit, addr1, addr2, size) \ + for (; (bit) =3D find_next_and_bit((addr1), (addr2), (size), (bit)), (bit= ) < (size); (bit)++) + #define for_each_andnot_bit(bit, addr1, addr2, size) \ for ((bit) =3D 0; \ (bit) =3D find_next_andnot_bit((addr1), (addr2), (size), (bit)), (bi= t) < (size);\ --=20 2.39.2 From nobody Wed Dec 31 13:54:11 2025 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 789FAC41535 for ; Wed, 1 Nov 2023 22:58:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347439AbjKAW6g (ORCPT ); Wed, 1 Nov 2023 18:58:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347154AbjKAW6d (ORCPT ); Wed, 1 Nov 2023 18:58:33 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B2EDB9 for ; Wed, 1 Nov 2023 15:58:31 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-5a82c2eb50cso4391417b3.2 for ; Wed, 01 Nov 2023 15:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698879510; x=1699484310; 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=4k0IeS2aGdp15vS08AFa8OvRrkQNOjngbPieIhmhkWY=; b=IJ+fV339yMky4n0SaOgxnEYUAvEJUPGtWNZA4D+nacF7hMV0d4NQ8a7EgRErCQa7Y5 ui5EZbEYgWAKMDweypSJvK7IPpIwX8H/3k/Kf8/KSIxdkLx/KyPPDO9ALphduoXdoDNF 9lneFyPSBxoLNmgI2vK4Gez3Pb1wmvhmfwHQN6OOg5RzXVIqPP1w6eu+7nsOkkSSoybs ci53iRCH0dhVw756+oGE3rH2hEaSVyfcESPiawFawEXI9oAZqgrIMCsegtUL7JOVzz2J UygAU1aVBI5i7zbk3q0hnTWAavqxHpVmh5pNOeKTqhg5JZUukyuozupu4P34jlYURwyH DsEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698879510; x=1699484310; 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=4k0IeS2aGdp15vS08AFa8OvRrkQNOjngbPieIhmhkWY=; b=N/BOn79s6a/k7yQgh1FHsoDIcRaDw2qlVi/WImUGH55TQty3GsDuElyjIj+ULNprxR X7ryWCbOdhv3jBGOidWrN4q7VVkdJkQ80cw32XK27W7e47YGgsFcTMEn9qaVvsszw1Kp dWO6OWN4hWmeHXeL/18k0jnuOxVi/qfjZexag53R6rCiXc+6tXxPDze9C1VZllEPtBOL afhTt8p1Nl6EeVsJPHZouIO8ZW2EmQ1TkG2P6fJdgm8IKClgd3UrXx5nxA7vQnvYU3YD hIuohw+rT9G/9mnAHw1oMUmgAAN7kFcOtDDpuLqFxuWRVE2Gep6jnOQuWEazpPT/3XV5 BC9w== X-Gm-Message-State: AOJu0YzFp8DF9tT7bMYAd0Of4x4pJJ7zcJvkpB1FRKbhtYK/qWrzNwyr sLO2sTSVHfal3CMXpxPkWTQ= X-Google-Smtp-Source: AGHT+IHoBQkkXpFMyW6Pf4ikXQPtueOnCt4+iD4agZ9Ho67+ob6SzRX7ZsSo2JjSzlwCE2DyxXFaRg== X-Received: by 2002:a81:ae63:0:b0:5a7:b8e6:6441 with SMTP id g35-20020a81ae63000000b005a7b8e66441mr14841928ywk.16.1698879510385; Wed, 01 Nov 2023 15:58:30 -0700 (PDT) Received: from localhost ([50.221.102.30]) by smtp.gmail.com with ESMTPSA id i13-20020a81910d000000b005a7bfec6c34sm529504ywg.46.2023.11.01.15.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:58:29 -0700 (PDT) From: Yury Norov To: Thomas Gleixner , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH 2/4] lib/group_cpus: relax atomicity requirement in grp_spread_init_one() Date: Wed, 1 Nov 2023 15:58:18 -0700 Message-Id: <20231101225820.51342-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231101225820.51342-1-yury.norov@gmail.com> References: <20231101225820.51342-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Because the function is called with cpus_read_lock() held, all the masks involved are stabilized, and thus any extra atomicity is not required. Signed-off-by: Yury Norov --- lib/group_cpus.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index aa3f6815bb12..b1e7d9cc9da9 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -24,8 +24,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, if (cpu >=3D nr_cpu_ids) return; =20 - cpumask_clear_cpu(cpu, nmsk); - cpumask_set_cpu(cpu, irqmsk); + __cpumask_clear_cpu(cpu, nmsk); + __cpumask_set_cpu(cpu, irqmsk); cpus_per_grp--; =20 /* If the cpu has siblings, use them first */ @@ -34,9 +34,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, sibl =3D cpumask_next(sibl, siblmsk); if (sibl >=3D nr_cpu_ids) break; - if (!cpumask_test_and_clear_cpu(sibl, nmsk)) - continue; - cpumask_set_cpu(sibl, irqmsk); + __cpumask_clear_cpu(sibl, nmsk); + __cpumask_set_cpu(sibl, irqmsk); cpus_per_grp--; } } --=20 2.39.2 From nobody Wed Dec 31 13:54:11 2025 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 956F5C4332F for ; Wed, 1 Nov 2023 22:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347519AbjKAW6l (ORCPT ); Wed, 1 Nov 2023 18:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347479AbjKAW6i (ORCPT ); Wed, 1 Nov 2023 18:58:38 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04DD7119 for ; Wed, 1 Nov 2023 15:58:33 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-5ae143e08b1so4495027b3.1 for ; Wed, 01 Nov 2023 15:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698879512; x=1699484312; 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=m79oyGTD4QwukfG6ZorJJlId+7DO0Q4m7W/CpuSor88=; b=LBOKRM9NSa9hZe7fHhoF97QCVX77EfKSDJAapY8EJ4/Khyr+wsE/XjZwmFjitutAsN P2kDEncrLKJMrCfFo+EE8crL4dSMMHPBqAZJwvvVNyHBndcdAQbz/It6OWAH5uRxlJ57 3WozknxUt8Si5Wdiy3uQRdFgfH5JFTOWUIuqSW8KurPDaJRKXAhXbCgpYKuYlMReptt/ C+aH+6i2f697PlPRPTasCqjwJT6ZRdC/RueEre/KlhR71/l5wbWeAFyAWDenqTTNhxCX J820sRULHa6sEX8/tOI87X2qiyET0GwKy1J29e1E5UoiwN311IijV2qUjfdjO0jv0zwv ccSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698879512; x=1699484312; 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=m79oyGTD4QwukfG6ZorJJlId+7DO0Q4m7W/CpuSor88=; b=vsr+7U/kZ+Ncu1FCI2xh4XgrCDziHOW24BVqppZmhdab3goNQzJfSY+EShzrqe3kPz ghR5BtTWzSx+Tb/W98OzLhoLr941I/LjY7cDT7RSjLlmzBGNJIOFhyKyyjqjFmO7aGft tv/hY4Ev0tEpeTVXD7pQQE/lHIFVe82NwF4lM7IyFBCPHuYGlGg4dQvOxo916RyJgua0 4AXTj3YPHb01bm/XrWKxnf4GRgw6mOUIq/Aon3ZFrRBRhNKfDXJsNo7UPOKshGcEGlkZ y5YG+OjXK1ySxcpp4UWrkQSpiyzSdy6PZaR4aY/38yZXc1+rkf7fMd4OH/BMYUkxsbQl xpyA== X-Gm-Message-State: AOJu0YwDJPp9z3nYyWPtnxj7xC+HIpTYbR2qhvTApiGpwAjBvxPUzNDm hhrLoJgavTZbXTe64m01Dss= X-Google-Smtp-Source: AGHT+IGCukX3KGCpiMWs7pObu7bFh/sx3d2xRTa8GoLcKd9n7mlTXpGMbXiQ9fgLiNDC0zF81k814A== X-Received: by 2002:a0d:cc44:0:b0:5a7:aaac:2bce with SMTP id o65-20020a0dcc44000000b005a7aaac2bcemr18888613ywd.35.1698879512112; Wed, 01 Nov 2023 15:58:32 -0700 (PDT) Received: from localhost ([50.221.102.30]) by smtp.gmail.com with ESMTPSA id r19-20020a81c313000000b005af81610bdbsm508017ywk.122.2023.11.01.15.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:58:31 -0700 (PDT) From: Yury Norov To: Thomas Gleixner , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH 3/4] lib/group_cpus: optimize inner loop in grp_spread_init_one() Date: Wed, 1 Nov 2023 15:58:19 -0700 Message-Id: <20231101225820.51342-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231101225820.51342-1-yury.norov@gmail.com> References: <20231101225820.51342-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 b1e7d9cc9da9..8afe0c71d204 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, =20 /* If the cpu has siblings, use them first */ siblmsk =3D topology_sibling_cpumask(cpu); - for (sibl =3D -1; cpus_per_grp > 0; ) { - sibl =3D cpumask_next(sibl, siblmsk); - if (sibl >=3D nr_cpu_ids) - break; + sibl =3D 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-- =3D=3D 0) + return; } } } --=20 2.39.2 From nobody Wed Dec 31 13:54:11 2025 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 8C225C4167D for ; Wed, 1 Nov 2023 22:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347596AbjKAW6m (ORCPT ); Wed, 1 Nov 2023 18:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347493AbjKAW6i (ORCPT ); Wed, 1 Nov 2023 18:58:38 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D378122 for ; Wed, 1 Nov 2023 15:58:34 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-5ae143e08b1so4495267b3.1 for ; Wed, 01 Nov 2023 15:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698879513; x=1699484313; 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=BD5+r2nuI4vys5xdveo4iExlvFzDpqsGUNpmHPaBBB8=; b=Zsj9tm6TsjLtzCASPgT89vKwCKbhcwQsE/0cPoZqSxGtNEa5ywDqpi/n9unpJUfDgq LbtxbgpBZ6ITARHTULfJTE+O7T3cP2KU+y849RATlvr3gXVonLmzMyCsOiKKQN/p2D3o mqQ38gAzq0JDYzDQUqHrHtpGLV49aZdNsbZ/VMZPzMzFpE25hHCKwNFydrpX+W6o3e7n h3R3HDyGqKzqwbQUiAGWyEsRygeHyu/YixCCfbes9HDunPT4i/4CVoBFszj+CPnURBAi hH5iv1ht8Aq1Roo5JPBHNnA0sXFPYDDJraE1Bs9xqndH5s/lNhiKMs0KVb9bLSzB/Zzs wBFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698879513; x=1699484313; 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=BD5+r2nuI4vys5xdveo4iExlvFzDpqsGUNpmHPaBBB8=; b=IMyUpevGNckvOliJ0XpSPciBZbXevB5MlT7HxtGvbIqoaKiDIK61CLOKmOUIg7VB+j 3A+eh0z2terK+ejK8mXOPzW+xp0vfzP9anwl2eAvZwoHM643UMtDp4JuJQoKr8v4k5SY pH6lm/sAHK39ArMCqNRL7lsEzOkuyXIoagVi74MX3tzWdP7cps5Pz7zy27fi9PuHR0/1 hOwXPxOX+792HeVgGyG0UTOSoFa1GYrcG9eN9e1rzIa5hc5sojZBRs6N/+LhtfoekeoM 1ncAmgUI9GVRHVIyAR9oNgsKxvKeW8uDkvtegtarDEcZuJMxddCmG7vcbgAVtBsENS/p 3cMA== X-Gm-Message-State: AOJu0YwXO212rLtveZgBnAJaxIzjuzaq6tGPL62VQkpeRIB6ff1r0O3s z8vj8NExJW0ujOSPCAdrIRw= X-Google-Smtp-Source: AGHT+IHL58R2DZ1AmREw1AzuvaoIhnqlkvgKhONTg8SBcToJRzagHRJ1UAtS1kAuCVlli9ejMATLiQ== X-Received: by 2002:a81:9a13:0:b0:5a7:b819:648f with SMTP id r19-20020a819a13000000b005a7b819648fmr17255751ywg.4.1698879513362; Wed, 01 Nov 2023 15:58:33 -0700 (PDT) Received: from localhost ([50.221.102.30]) by smtp.gmail.com with ESMTPSA id r2-20020a815d02000000b0059a34cfa2a8sm529378ywb.62.2023.11.01.15.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:58:33 -0700 (PDT) From: Yury Norov To: Thomas Gleixner , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH 4/4] lib/group_cpus: optimize outer loop in grp_spread_init_one() Date: Wed, 1 Nov 2023 15:58:20 -0700 Message-Id: <20231101225820.51342-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231101225820.51342-1-yury.norov@gmail.com> References: <20231101225820.51342-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Similarly to the inner loop, in the outer loop we can use for_each_cpu() macro, and skip cpus that have been copied. With this patch, the function becomes O(1), despite that it's a double-loop. Signed-off-by: Yury Norov --- lib/group_cpus.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 8afe0c71d204..2442b38cbf37 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -17,16 +17,11 @@ static void grp_spread_init_one(struct cpumask *irqmsk,= struct cpumask *nmsk, const struct cpumask *siblmsk; int cpu, sibl; =20 - for ( ; cpus_per_grp > 0; ) { - cpu =3D cpumask_first(nmsk); - - /* Should not happen, but I'm too lazy to think about it */ - if (cpu >=3D nr_cpu_ids) - return; - + for_each_cpu(cpu, nmsk) { __cpumask_clear_cpu(cpu, nmsk); __cpumask_set_cpu(cpu, irqmsk); - cpus_per_grp--; + if (cpus_per_grp-- =3D=3D 0) + return; =20 /* If the cpu has siblings, use them first */ siblmsk =3D topology_sibling_cpumask(cpu); @@ -37,6 +32,7 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, __cpumask_set_cpu(sibl, irqmsk); if (cpus_per_grp-- =3D=3D 0) return; + cpu =3D sibl + 1; } } } --=20 2.39.2