From nobody Wed Dec 17 06:44:19 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 179D0C4332F for ; Tue, 12 Dec 2023 04:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229553AbjLLEVL (ORCPT ); Mon, 11 Dec 2023 23:21:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjLLEVG (ORCPT ); Mon, 11 Dec 2023 23:21:06 -0500 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 E8100BC for ; Mon, 11 Dec 2023 20:21:12 -0800 (PST) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5d34f8f211fso51824747b3.0 for ; Mon, 11 Dec 2023 20:21:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354872; x=1702959672; 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=t+ncE/Ke8W/9eSicUFGfjAMk7XfHt6TzmaC+XB67O8c=; b=KFhC6+sG0Yct0kbrjF8kru2+7eFqJ+jyWXZ8zx09j3ICTxS4R5J7BJwET1Pa/46csG hnRMJDSXiv7080WkfDc6oD1A/X11udEChsOy6yKF8zHOxxwLDWJ+4PXU1uYFbe0boYiu JrAgU1NLoRSBqsFr6LnH/vSq8GS/UgT8T6oP4Bd1Xd2VuDJ8Mw5j5KYJYjoI4vaN4bRA pAG80H6VUw012GJ0to3+X1f1CZp/Su8wdVIpOO9oOZVvIeFnSkH68VggVP0zVO3KAaKW 2PTEZeMM5HZKdOpRt3hiwwCALimP6npekktcCWXVqav/Yx2IcJbGGoTTyoZ9EpgzsKIX Lbsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354872; x=1702959672; 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=t+ncE/Ke8W/9eSicUFGfjAMk7XfHt6TzmaC+XB67O8c=; b=AGRkyAt5vj/8FP1pyssl/6GJS6vkRAaJqWQc/XxSRTnZdo/Ln/0iJDb0Eaf4l1YN6U UD4CMh3uXDnOIboXFjPE+WYPcKrJOdd1rkcJKqTvtoKwPZOcemUdF7nSMUBkln4lV0Ii RVuO5evz5i8UUo/GgKddX//hxvXyeoPadFEa+BupVTzilm6ypXUUjlkSCO3ZRpA82lmR 7Ync0gjXAWqJf3G7dMqell+nUe42YngggrjvpaEW0Oeo7f20ajEWJjk8oMEcQB3KYEnF 8WHQx38JHqBgwXThn8tpAlFdaEo6vqpPDP1qLY9u+d/a1RqJvtMEw6ozwfpjQwcoYdIs NH7Q== X-Gm-Message-State: AOJu0YyzjVBQVdwvw1kHZfC98Mle2ZoVyGkIt/LShYc/NyvJq/S01Tbo bejMCJOAoIu8v25QX3BbaGk= X-Google-Smtp-Source: AGHT+IEeX2Fjxhk9K32Om1pj9o6qab9oTQx/j4eXkeWOy5mqJJ0M7g6qMU7pyCHEVme7gUTFxZKbhw== X-Received: by 2002:a81:8357:0:b0:5de:99bb:e94 with SMTP id t84-20020a818357000000b005de99bb0e94mr4783843ywf.5.1702354871979; Mon, 11 Dec 2023 20:21:11 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id eo18-20020a05690c2c1200b005e1764a7a33sm612703ywb.52.2023.12.11.20.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:11 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 1/7] cpumask: introduce for_each_cpu_and_from() Date: Mon, 11 Dec 2023 20:21:01 -0800 Message-Id: <20231212042108.682072-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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 cfb545841a2c..73ff2e0ef090 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.40.1 From nobody Wed Dec 17 06:44:19 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 3DB36C4167D for ; Tue, 12 Dec 2023 04:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229590AbjLLEVN (ORCPT ); Mon, 11 Dec 2023 23:21:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjLLEVH (ORCPT ); Mon, 11 Dec 2023 23:21:07 -0500 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78130BE for ; Mon, 11 Dec 2023 20:21:14 -0800 (PST) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-db632fef2dcso5149597276.1 for ; Mon, 11 Dec 2023 20:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354873; x=1702959673; 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=WnIA3EnzQnW3AuT6MleWaZcP0AeUqS6iyw6BtYD4kcc=; b=OHfysT+epVFcBYHsdrSPc3m18F9K4ChXioYHGhxstZd27LcdgBb7Hbm6g5h/w+Q+uQ ENvPeOOKw6NBUCkoHDMYTuABJN/wanYTdYlhK/ORa/oNpw+pszDXyF+UF/HN1l/zNu/P svRJ+5qrFw7vyMQnnhkGTzp75HlqYJm6iaYQgL1zPoc3tI38euqUN54sk8PH7qan9mDM wQm55jXXDXWHFpFheSd8bqHgMrTuNqNwtHJ/QnNadAarEEen0xHXz4cazo3EgqNAFqRs bifPuMuPKoFcGVwg796itBtyZTfQNHoZ6jD6EveO8mmTnokCXIsw08DOBXDhgtmMUth3 Z9dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354873; x=1702959673; 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=WnIA3EnzQnW3AuT6MleWaZcP0AeUqS6iyw6BtYD4kcc=; b=LjjmgiBg28RByHIMxn7cvi9/GcY91uztuAax6pYRtArkx5orSR+r7nlgdnAg8yc8t0 GGuBYSmABPBCR8fZEV3xQz5TXXSswiyh1H6asVZqI3kP90qy25CzIiLofgiBWO7u2b2L iYNedYc4pvSTMONQe50Yf82jhPrL//Fv08xmzJJpFjVA1Qg285Ewxd26JWlYCJ8aV1uZ 39TpPrmuoeF9NRj/3nEt00Pg+OyXIE510Z1nsa9b1yajbew688F7JcjKYfF1vPSsG+Wy Dbi9hAGMqqt8QnZIpmtmflcI2lxyLyZq1YCSE+Ia9xBOsuvyjki8uIp4rcUzloalJRKz JbJg== X-Gm-Message-State: AOJu0Yx+uofILTXqfUnhh2Gce2USubWODk/DCiVnahWcERnJoRkALGY+ pZIEEuuXalsdnmwa2xp12e0= X-Google-Smtp-Source: AGHT+IH/dyVXmwJ7xvXoArsQoaPu4V0yLoTqqVrUMw4RHWw7ImGRHaaKsDJfxZLshP4EAOXWO7kwCg== X-Received: by 2002:a25:db51:0:b0:dbc:b394:6ab5 with SMTP id g78-20020a25db51000000b00dbcb3946ab5mr1084932ybf.95.1702354873535; Mon, 11 Dec 2023 20:21:13 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id k15-20020a056902024f00b00d89679f6d22sm2917283ybs.64.2023.12.11.20.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:12 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 2/7] lib/group_cpus: optimize inner loop in grp_spread_init_one() Date: Mon, 11 Dec 2023 20:21:02 -0800 Message-Id: <20231212042108.682072-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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, 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, =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; - if (!cpumask_test_and_clear_cpu(sibl, nmsk)) - continue; + 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.40.1 From nobody Wed Dec 17 06:44:19 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 E66F1C4332F for ; Tue, 12 Dec 2023 04:21:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229669AbjLLEVQ (ORCPT ); Mon, 11 Dec 2023 23:21:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbjLLEVJ (ORCPT ); Mon, 11 Dec 2023 23:21:09 -0500 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3656EBC for ; Mon, 11 Dec 2023 20:21:16 -0800 (PST) Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-da077db5145so4288155276.0 for ; Mon, 11 Dec 2023 20:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354875; x=1702959675; 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=pcK8BvqeLnlnGvCjlzdUPO//8WS/BTL6dVTgbP4I0qA=; b=JN28sTpkGz87XAw+tUM9cVcgd2bhlaa4enrddq2IMAE07lKigzYXHEYGMDemtNEemd +TQlEoTK4LlmCI04xOAiSdnLWfPzSMkCy60Zss/dQQHuLuE8EYZkpR+hSzPnbNXHAg/A tmcpl8PxdVGaCnwddloNM+WsbqUETlXKsyRbZR2n/JR9ltIOLuYywepi1P9NeZibeZol oBqhYGH0QVZR9U1LfC6za8Sw3BSLWeKeF44aqUf+g7jXHvyymzlNF8GpyseQEIU1KwGM PXtqcEDaHPY86IxW1j5p9kx8NbhiLFyj+OKgLTOa2weJsh3FBPwXQU2/qJ2LVuJgM5WY RAAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354875; x=1702959675; 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=pcK8BvqeLnlnGvCjlzdUPO//8WS/BTL6dVTgbP4I0qA=; b=fN7xgkb8cKOnKRIlmNgwaMNm/t43z32ZQaWZAs1HIu2FnX534vaQYi6ZYZfsy3WNUU /H5b+b3obobNv4m9YuVOVK2633ZC5Cq7sKoG8+fS3bCnmkh9wMGgvBNXTbzDzmYmlq8r whRGUZUpWHmuvWZnRP9CVlIvG1l0FmZLqs5z1BiQPuWq2sMg7DlKpXPS7RPIzE5tcnk0 PwyjoRV49j/oiha5bTgjxj5LGaUcul+hRILt762Qps86IX2MsySb/V+tJ+GTdXjY4Yo/ g7ltYOY3zXhS2sTOCViuBwyGNlBcHqfqmwOQ1EbZC3UKfbTX1zsyanPf5cyjzjZJ6oC4 3N0Q== X-Gm-Message-State: AOJu0YxPOBxXGrTydHgQVgAH0FY9U5zO/P7RHiUDJNP+rA+ql3cd0hgw QqQqlKhyjWUjDuuh0/vPKF8= X-Google-Smtp-Source: AGHT+IFRyIqy04++PSjU5C+NX9E24AEHWQZ6EgG62T/pPRCR9jQf9bIwn33Th5+YNGG7Sb8f9bMGTQ== X-Received: by 2002:a5b:309:0:b0:db7:dad0:76c8 with SMTP id j9-20020a5b0309000000b00db7dad076c8mr3671333ybp.100.1702354875225; Mon, 11 Dec 2023 20:21:15 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id 13-20020a25040d000000b00d7f06aa25c5sm3008349ybe.58.2023.12.11.20.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:14 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 3/7] lib/group_cpus: relax atomicity requirement in grp_spread_init_one() Date: Mon, 11 Dec 2023 20:21:03 -0800 Message-Id: <20231212042108.682072-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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 nmsk and irqmsk are stable, extra atomicity is not required. Signed-off-by: Yury Norov --- lib/group_cpus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 10dead3ab0e0..7ac94664230f 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 */ @@ -33,8 +33,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, sibl =3D cpu + 1; =20 for_each_cpu_and_from(sibl, siblmsk, nmsk) { - cpumask_clear_cpu(sibl, nmsk); - cpumask_set_cpu(sibl, irqmsk); + __cpumask_clear_cpu(sibl, nmsk); + __cpumask_set_cpu(sibl, irqmsk); if (cpus_per_grp-- =3D=3D 0) return; } --=20 2.40.1 From nobody Wed Dec 17 06:44:19 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 041E2C4332F for ; Tue, 12 Dec 2023 04:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbjLLEVV (ORCPT ); Mon, 11 Dec 2023 23:21:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjLLEVK (ORCPT ); Mon, 11 Dec 2023 23:21:10 -0500 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640CBBF for ; Mon, 11 Dec 2023 20:21:17 -0800 (PST) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-59067ccb090so3240739eaf.1 for ; Mon, 11 Dec 2023 20:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354876; x=1702959676; 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=UfvFAKot0bp3HfeoPJ3dMZk7rFg3lsuy8X5EAYhpV4g=; b=nGV5ZDxr70D91ac+T6LqL8u3ojak+2fWxoTFlSoCTx3A9EXgpYNgjkIMN+wEHM30jH IkL5aDwYTG1BsCF0/VG/DWrr9JULuYCxT1R+/4IA8CxftbJrTVt5V8m0ydaJGKWcty9a TGpec6p6evfw+K801vNqDNlTLaMzFKCeigNUY5O85fW675gVFe38VV32mIFmiqzAeKoM o/buveCT4PxWa7yGqy+oNSVWj1Fu3RW1dbQMoRRDxJTBNgG7NwXQ0X2nIq2mA1VKqekc qYxFk+8X2OxG5h0VjhnbqdVvGZmfKkwY0Df5dzvicy5vggb5v6rvulsl9DOA1y+t6K+b a8sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354876; x=1702959676; 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=UfvFAKot0bp3HfeoPJ3dMZk7rFg3lsuy8X5EAYhpV4g=; b=wI+6EWXHVdVeuqL3bYdM/Qtg2BaG9EF7HLytX3T7/nm5VxQ9/93o+CrLvUSWH58KrD b9gizSb7T3O9AhnlW7AGTxKLT7a+WRL7HqTJqdhmwJcILtEUpF12k0AxXuRgPoPXoUpU m8aCT5eZrauGnFgAkMIFJu+luQlxWsLKk7sHqthyYRQRaPCjWb477X9TAddKzKqUvRq5 Qvg5WlaEvBTwKpUAlgjRFYYWkYFz0CCMHsnKnxGH4cagKDyB0M64E42EvgbLZ5sEK/Yp 2Ra5siquBDNcuyZOKPUrwh5QTM5et0ApWzWgmY+Ab+gBIHQEf6gVCjIwsVLM8806l9PO trrQ== X-Gm-Message-State: AOJu0YzQoitEZ92VwebKKkyr7KtckFyJ2+wMkGkEefDTZtG9mh1ifmeo GyvOO3LO3urg/yp7U6DrZOs= X-Google-Smtp-Source: AGHT+IHtPBBe0oc/SwS4zRYwzLNnU7oeIKh41ypn77HlaZZ4UfICRn76rQMWuKxSuSM02lrwwpsltA== X-Received: by 2002:a05:6870:4590:b0:1fa:26b7:af18 with SMTP id y16-20020a056870459000b001fa26b7af18mr5327160oao.17.1702354876515; Mon, 11 Dec 2023 20:21:16 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id d201-20020a814fd2000000b005cc5f5aa533sm3499620ywb.43.2023.12.11.20.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:16 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 4/7] lib/group_cpus: optimize outer loop in grp_spread_init_one() Date: Mon, 11 Dec 2023 20:21:04 -0800 Message-Id: <20231212042108.682072-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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 7ac94664230f..cded3c8ea63b 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.40.1 From nobody Wed Dec 17 06:44:19 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 9C220C4332F for ; Tue, 12 Dec 2023 04:21:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231416AbjLLEV0 (ORCPT ); Mon, 11 Dec 2023 23:21:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbjLLEVM (ORCPT ); Mon, 11 Dec 2023 23:21:12 -0500 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D09BE for ; Mon, 11 Dec 2023 20:21:19 -0800 (PST) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5e1e656d019so2479317b3.1 for ; Mon, 11 Dec 2023 20:21:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354878; x=1702959678; 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=pqzdM1JWQlsu7k/N7xBtV+SLaOrDoqGHT+SByeHgWqU=; b=UC6d6PO3w2NZb5d9tH0UdWas3rs/ZjAl8v6ylZ9E3ARFTOUXyTe0/WRsugYKxN1PUC yGXhWx7auSab/uE99Hw5eOfSCWAVKKzvcV0/95TYjOreSlSip1IZgfQmDbkFy90dl+DR wVdWg/xq26ELYqUJ4WGF0K7DY75R+WzgUO9oUM2Pf3K+zfNbTwnRSvgMP0VloIoy720t 27drinVXkFUosKN4/8P7IpS9hqEQgbml8ginjsHnVL3MREfq3i3AYRie8UJ6gpypaUrQ A4ALxWCt3MQYm6P7A+MzDEPpx3r1loiwRaH8G34hs7Ylghw5GdXrlRoH4z4aXMxj0qY3 MVig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354878; x=1702959678; 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=pqzdM1JWQlsu7k/N7xBtV+SLaOrDoqGHT+SByeHgWqU=; b=r9fYSdaN/bzt1lYXPDRBvo9yzD5/3ZC92Vkb6RCoikEKyUpQI/d0xl19HaW6z0ep1m K9eGhRkJVdHMM+qHs7AEVrCAmelUYbQ1Vpz81s8fv7RtvhwVAuwUlqxUAP8kLO8epAXH 3rZj7R+5JNV2OEgoAWZ+c544KbZj58D/uw9Kb2UyCEWlV2+GRayDwvVuBmCyRFggGGkH FDXQqacw+cT4NebawJureaKvKFoARG24nV/LiQpGqX2zYhUKwgO/YJ8sbXrEdx+Bzyq1 vafXlqgxqdnEHdlsiHNLAS7FgQzISUzunfcBgRwuPL/9pGM43N/M9dEoYEF6uRvOh+Oy PXSQ== X-Gm-Message-State: AOJu0YzcV/tKw98sNaV3IUes5c85siBq4K1K7DI7BRqNqhOMolHy91jC BRKEnljsLW7D21lHH+02VIY= X-Google-Smtp-Source: AGHT+IEpOxgjKzCRWRfaNbZ9gq8uVyIb3GxyH8tmiruZoPiABPHG5lIqbyLddNf9/MgHO/C8v1nIlg== X-Received: by 2002:a81:7188:0:b0:5d7:1941:2c23 with SMTP id m130-20020a817188000000b005d719412c23mr4611909ywc.80.1702354878116; Mon, 11 Dec 2023 20:21:18 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id en9-20020a05690c2b8900b005de84505114sm3311734ywb.58.2023.12.11.20.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:17 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 5/7] lib/cgroup_cpus: don't zero cpumasks in group_cpus_evenly() on allocation Date: Mon, 11 Dec 2023 20:21:05 -0800 Message-Id: <20231212042108.682072-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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" nmsk and npresmsk are both allocated with zalloc_cpumask_var(), but they are initialized by copying later in the code, and so may be allocated uninitialized. Signed-off-by: Yury Norov --- lib/group_cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index cded3c8ea63b..c7fcd04c87bf 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -347,10 +347,10 @@ struct cpumask *group_cpus_evenly(unsigned int numgrp= s) int ret =3D -ENOMEM; struct cpumask *masks =3D NULL; =20 - if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) + if (!alloc_cpumask_var(&nmsk, GFP_KERNEL)) return NULL; =20 - if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL)) + if (!alloc_cpumask_var(&npresmsk, GFP_KERNEL)) goto fail_nmsk; =20 node_to_cpumask =3D alloc_node_to_cpumask(); --=20 2.40.1 From nobody Wed Dec 17 06:44:19 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 90B3DC4332F for ; Tue, 12 Dec 2023 04:21:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229533AbjLLEVb (ORCPT ); Mon, 11 Dec 2023 23:21:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232156AbjLLEVW (ORCPT ); Mon, 11 Dec 2023 23:21:22 -0500 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96ED2ED for ; Mon, 11 Dec 2023 20:21:20 -0800 (PST) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5e180547bdeso8182947b3.1 for ; Mon, 11 Dec 2023 20:21:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354879; x=1702959679; 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=AdhzPeT3AA9HptxSHcMzOSBTny61/xtguzzqnxzNv6M=; b=Ff6LXL2mmXdHFhM2dDVobDBS+ra3e849llVqg/aOU3YDKtqmNwIS0Ckip0d6bvJ8qE WYCJdzU0ISBzUdtvmwpZu6g32YBg3rLE8yhCY/+k8ToBsBby+x1k3L+e9gAwmbbKBt1X PU9QuWxy9gfqpeccvTV9zAnUpEIpEQZ4X4IhL3RjsKT8hyXgaFweDo2V2v7ZgGoD/P4k 5jUUS4RWiyu0JHbmbM8D3KsFHtu4ejuw/2cYX9J1VQvSWYQ+y8H7zPdaT699mFLvW4Rn 7PVz2LtsMfKeVec9JjkOil89LRxOn2FYK0G+4s4ttYYys2SqWHrdDWCfN+Sx1mt6w5jx oyAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354879; x=1702959679; 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=AdhzPeT3AA9HptxSHcMzOSBTny61/xtguzzqnxzNv6M=; b=wkSTsAvtSaypiKucJdrTgLspVOTS53dVSklSlquclHKtNv14DMFU2hKjj3osadffC/ 1BeV8IC2mdmwlecJ3jvrFxkCrz0SftqehREhiFNiX09UaOFuhK+pbnf5wQM1dRU8Mgvq uoRUcmCKZ8Pbj0J1Ux8+8cpDg66VvKp21C0cJz0/WMJCoVkwB0ANOt92vKSsZ93JuqTK 5sN8uZHlUhylZxOP0tySYsGAegzQLapHdYaLGOqyUikIPUIzcC/Q7cSlCbd6YzogZwWU Jk2GZN1OCfwZKy4vEOAhhGgw51zy0W9+KMjLf1U2AparI5JJf7E4echFhhHC6cejjV9R yPCQ== X-Gm-Message-State: AOJu0YxZM6d0Ib7jLsDXyX2ieYSD+6XmPid8DSzGsq/fnCtgZHS397sF QZWeRkk/gTcFriHr5Hokmo4= X-Google-Smtp-Source: AGHT+IExfnPyAJ5PLQqQOEJpb87ZUtep7+F+6LrM5ia0x5oyyOAvC78bzvYcK2XUjAd6dQq4r+fB7w== X-Received: by 2002:a05:690c:2c01:b0:5df:5d59:5539 with SMTP id eo1-20020a05690c2c0100b005df5d595539mr2477617ywb.44.1702354879588; Mon, 11 Dec 2023 20:21:19 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id f68-20020a0ddc47000000b005d16b6edfffsm3495210ywe.120.2023.12.11.20.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:19 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 6/7] lib/group_cpus: drop unneeded cpumask_empty() call in __group_cpus_evenly() Date: Mon, 11 Dec 2023 20:21:06 -0800 Message-Id: <20231212042108.682072-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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 function is called twice. First time it's called with cpumask_present as a parameter, which can't be empty. Second time it's called with a mask created with cpumask_andnot(), which returns false if the result is an empty mask. We can safely drop redundand cpumask_empty() call from the __group_cpus_evenly() and save few cycles. Signed-off-by: Yury Norov Reviewed-by: Ming Lei --- lib/group_cpus.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index c7fcd04c87bf..664a56171a1b 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -252,9 +252,6 @@ static int __group_cpus_evenly(unsigned int startgrp, u= nsigned int numgrps, nodemask_t nodemsk =3D NODE_MASK_NONE; struct node_groups *node_groups; =20 - if (cpumask_empty(cpu_mask)) - return 0; - nodes =3D get_nodes_in_cpumask(node_to_cpumask, cpu_mask, &nodemsk); =20 /* @@ -394,9 +391,14 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps) curgrp =3D 0; else curgrp =3D nr_present; - cpumask_andnot(npresmsk, cpu_possible_mask, npresmsk); - ret =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, - npresmsk, nmsk, masks); + + if (cpumask_andnot(npresmsk, cpu_possible_mask, npresmsk)) + /* If npresmsk is not empty */ + ret =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, + npresmsk, nmsk, masks); + else + ret =3D 0; + if (ret >=3D 0) nr_others =3D ret; =20 --=20 2.40.1 From nobody Wed Dec 17 06:44:19 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 488BCC4332F for ; Tue, 12 Dec 2023 04:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345810AbjLLEVf (ORCPT ); Mon, 11 Dec 2023 23:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232308AbjLLEVW (ORCPT ); Mon, 11 Dec 2023 23:21:22 -0500 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15628FD for ; Mon, 11 Dec 2023 20:21:22 -0800 (PST) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5e180547bdeso8183077b3.1 for ; Mon, 11 Dec 2023 20:21:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702354881; x=1702959681; 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=Mhqx4gBGm5WucjtLuvVJR4mQPOrDNcNzK+o09f7n6v4=; b=aa0ltg7q1na+bhl2xIMKgJhC7szOWXRyrN85rbIhd5JJpSgcOeDPN9ZP4bukpK1U78 4ha0vP0X+Gho+XHEcgzMz0wty/AXdtbYPo09Mjo4Hy+JzcCosKJ6RZlIP4W/iv15chkR rhibmo7DLcPCGuktvV7zOu+CkpIN0Hyh80bDe+TfytxJrAiNToy81YyJmd4cch9mQTRc 0W6+AeYkfM3cLcpobGe5nL4uuQ7Dbl1H7we/LuNR9ROCLz+GcFfdXP+eEMP/MAARUFmM rRTboHyVE3LU9Uwpej2MuNjRRDBULHZ9a8W4TDObNn8/RXlGlRG7/egXVHcKmq1gZlyn GHSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702354881; x=1702959681; 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=Mhqx4gBGm5WucjtLuvVJR4mQPOrDNcNzK+o09f7n6v4=; b=TEh+bry36o/VGIiWfaOUc8mEHYF9cUwuHgBaNDv1Z/Lv7N2bIPA43Qi9l1eaUbLlB2 77MAyq+yMaCDu6VXbJ/DZwhupZSkAiia7dcvpSDGmW55JfGcbdXWsgV0lAbEfAJHeH+/ IEiP+ib3ZmYV+ReOS2xkiEamBL6NYxwiyqqi7CS6KJG5ZPErZ4GwPRG1IUqlcGYGSEnq 70ecAuW4HZVDZuQhaLHEuV2ebJTivWxKL+vzGgyW1LJ0pNhyR0P/VDzJEGygSwHruY/l oYmYzRUdjRrLK9yOkSxJCox/D+28gBrPEQJ5Bl24u0qifQaZMfRNOzEfgmXq1QkpQo2w gopg== X-Gm-Message-State: AOJu0YwfPsdljeGNmxT3YLnG8eSYnMDSh1tnNQHk23oqMjGXHH54m/1U FD7Jz5zsXXTcg003fNRj2a8= X-Google-Smtp-Source: AGHT+IG5N2bPse685zyTRp1xN8khGwhlFoSDKrPeXSZF5CtDHpERvj72vHNfpPizip/QTwc1lMEJqA== X-Received: by 2002:a81:784c:0:b0:5e1:8bd7:c66c with SMTP id t73-20020a81784c000000b005e18bd7c66cmr1002488ywc.7.1702354881171; Mon, 11 Dec 2023 20:21:21 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id c189-20020a0ddac6000000b005d1b2153b7bsm3526835ywe.18.2023.12.11.20.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 20:21:20 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v3 7/7] lib/group_cpus: simplify grp_spread_init_one() for more Date: Mon, 11 Dec 2023 20:21:07 -0800 Message-Id: <20231212042108.682072-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212042108.682072-1-yury.norov@gmail.com> References: <20231212042108.682072-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 outer and inner loops of grp_spread_init_one() do the same thing - move a bit from nmsk to irqmsk. The inner loop iterates the sibling group, which includes the CPU picked by outer loop. And it means that we can drop the part that moves the bit in the outer loop. Signed-off-by: Yury Norov --- lib/group_cpus.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 664a56171a1b..7aa7a6289355 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -18,14 +18,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, = struct cpumask *nmsk, int cpu, sibl; =20 for_each_cpu(cpu, nmsk) { - __cpumask_clear_cpu(cpu, nmsk); - __cpumask_set_cpu(cpu, irqmsk); - if (cpus_per_grp-- =3D=3D 0) - return; - - /* If the cpu has siblings, use them first */ siblmsk =3D topology_sibling_cpumask(cpu); - sibl =3D cpu + 1; + sibl =3D cpu; =20 for_each_cpu_and_from(sibl, siblmsk, nmsk) { __cpumask_clear_cpu(sibl, nmsk); --=20 2.40.1