From nobody Thu Apr 9 12:50:36 2026 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 05291ECAAA1 for ; Mon, 5 Sep 2022 23:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232100AbiIEXIy (ORCPT ); Mon, 5 Sep 2022 19:08:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbiIEXIh (ORCPT ); Mon, 5 Sep 2022 19:08:37 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED3C9696FD for ; Mon, 5 Sep 2022 16:08:24 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id c20so6895355qtw.8 for ; Mon, 05 Sep 2022 16:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Hk/srkBtxVkS+zUVkai21MOd0Ml2smnzuFrvLhiDgCY=; b=IEfScbVqtsTPgpyexhCh2rcgdcvGqGXJm4/pS4rm+XxbUBiy6QXx8PMESOdBrCMG6V WSRjzyNudWEjWQZbObdPjHo6oUVbEUNM9nJ9gC6lVvirLHMi6Qd9EvJvZepVa5DNTRME 9lIxHLN+Z/XE9pKuKKwRdUEwH6ge0ieNiwPkvWhOzCeX6JG3Hmb5XNzR2fsmxTdAnvyO p+dcUc2NRxW6J3OO17Zlb0J99JfHswcEdFFtinWuPsXUSX6ZCQOuqYbowmgas0V0Y5Gr iOWgWXSa6hvShxI+VZgv/n4z3NVTJ8PqvakqH71AxwYYL1gMbqsMGV396Mitad/2xD1F 7NaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=Hk/srkBtxVkS+zUVkai21MOd0Ml2smnzuFrvLhiDgCY=; b=1uZmIuRsD8NFR93x5KAaeXYxSl8uk9bAmoucWVn4u8ZKf5CJ12jsF/8rDxPP0RqXtc MSA5VbQbErkWYsQdezqY21KggCoqll+aawgQclIx2lf8xs+lVVgJpmPz5sTb7FkVuoQ8 HzxBRApVuNs+D5z4QI4dd6UNGms0KHiy4/4O972Z3sVSqb8X8a45uih6Cr+pY/+BGEbV TVEU3xEUvhMjULKQUuvaBZkTtSy0FLdGNMyffL9qr9aJQOD2Es+Eliim00exSYhw/kiF JGgSKQpSXlPlyLnlz8dixNYfHX0BjkZaWJVLt4a7SBkCchjp40oIhJjST0gBmTmTbZDJ QBYQ== X-Gm-Message-State: ACgBeo0kK7plAmarE+52WJWWBAgdrnlF0Irs8T4EMqAkcFjxyPko1jd/ yaKa/V1RwV2jpYqMTBecHg2O6JQuT+E= X-Google-Smtp-Source: AA6agR6HM9+H1spruQ9WCbZ6vf7t8Yub5iwBItNOFc0oOxdMD6wVF7v4LKmGEEYHZmOXkqPuGS8lkQ== X-Received: by 2002:a05:622a:58e:b0:343:79d8:2e76 with SMTP id c14-20020a05622a058e00b0034379d82e76mr41753624qtb.404.1662419303767; Mon, 05 Sep 2022 16:08:23 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:dde1:6b3e:62e9:1461]) by smtp.gmail.com with ESMTPSA id t12-20020ac8760c000000b003434d1a7a14sm7763916qtq.62.2022.09.05.16.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 16:08:23 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Stephen Rothwell , Peter Zijlstra , Thomas Gleixner , "Paul E . McKenney" , Vlastimil Babka , Dmitry Vyukov , Valentin Schneider , Sander Vanheule , Alexey Klimov , Eric Biggers Subject: [PATCH v2 1/5] smp: don't declare nr_cpu_ids if NR_CPUS == 1 Date: Mon, 5 Sep 2022 16:08:16 -0700 Message-Id: <20220905230820.3295223-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905230820.3295223-1-yury.norov@gmail.com> References: <20220905230820.3295223-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" SMP and NR_CPUS are independent options, hence nr_cpu_ids may be declared even if NR_CPUS =3D=3D 1, which is useless. Signed-off-by: Yury Norov --- kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/smp.c b/kernel/smp.c index 650810a6f29b..e971c9626a1b 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -1088,9 +1088,11 @@ static int __init maxcpus(char *str) =20 early_param("maxcpus", maxcpus); =20 +#if (NR_CPUS > 1) /* Setup number of possible processor ids */ unsigned int nr_cpu_ids __read_mostly =3D NR_CPUS; EXPORT_SYMBOL(nr_cpu_ids); +#endif =20 /* An arch may set nr_cpu_ids earlier if needed, so this would be redundan= t */ void __init setup_nr_cpu_ids(void) --=20 2.34.1 From nobody Thu Apr 9 12:50:36 2026 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 87DDAECAAD3 for ; Mon, 5 Sep 2022 23:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231942AbiIEXIu (ORCPT ); Mon, 5 Sep 2022 19:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbiIEXIi (ORCPT ); Mon, 5 Sep 2022 19:08:38 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E038169F4C for ; Mon, 5 Sep 2022 16:08:25 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id w4so3159613qvp.2 for ; Mon, 05 Sep 2022 16:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=WHXMwpMSBlWycN6d/vhs25RqbJ8DeUhQOZSip6Rd89Q=; b=UN3+8xu9H0+JeCy05eXfJIGoKXTGUl6QMvOPpJyfPBAkQuQrgIzn6kY1dVop8tSVIF ToHjyfc/q9bCilDsW8Bv7v5QTT64fG7jPnRboICcpTmd3fQTsBw4Z5nyF+Em12GUxXH9 bDnNIWh772WfCN6z/gAkS0yINk0DyIBGbFevqdBDae9nX/4xVbffhAdezGpVVSikl2mc 4veipSnCWXdYPsNEbDSgZtVG7EwCm+5Xk9QbVN4DAUGR3UtOb0mx29DwnJlOL6u2ZVx/ QTd+qsNPhOF/+SI8zAbBiYQEFvARf9EiktESqTfSaKfouBFY1NnUBXEMe9G9alfSqwbo XINA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=WHXMwpMSBlWycN6d/vhs25RqbJ8DeUhQOZSip6Rd89Q=; b=cYbeIAPVTpAMxhuiuPPvWoSEBSwwHgYeGE40U3D8ZNIkGwZ1nl/hYBpUhJ9e9sZgGk 3MMne4OjJcOn7Ibn7SAhPnHciTTfUTTTwrF9WA4+gvp9YYssVw33G7NFKdLJCNsi7Ne3 bzQUiXaRHdq+dANhNI4Wk6wIqT6KpIeRqrnE3JAlzUL7NW4WnBbmzjP1gMi51Z2hOVyx FqQa7qnWacHX1OyaIY86a7pVscEAlGOdZyi2XBykRdAmVAlQCqsJXj8r1hKunOmaXSp9 WNM/VUs6ya5FwTLgg/EkG7DnBkZsT81FWveRmghRi6mcF8SFIaXri7wabw7uJiIswnV1 9OrQ== X-Gm-Message-State: ACgBeo3wy/cOIwmEejxFFcjJSLORY8UwVqtMOUMVhZvRrYLZnQcoOlU6 LOlBHw/oT+TgI+JJtO+Hh4mNJ5dDT0I= X-Google-Smtp-Source: AA6agR4R5334toZfMm5VhkdPkNnIK+OTRsIlblI87A0MwX0R0LWen3GYa5a4aoBGFsqF75HbYkS3Aw== X-Received: by 2002:a05:6214:242a:b0:4aa:9c94:5d9a with SMTP id gy10-20020a056214242a00b004aa9c945d9amr1761590qvb.64.1662419304878; Mon, 05 Sep 2022 16:08:24 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:dde1:6b3e:62e9:1461]) by smtp.gmail.com with ESMTPSA id d3-20020a05620a166300b006b5c061844fsm8916160qko.49.2022.09.05.16.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 16:08:24 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Stephen Rothwell , Peter Zijlstra , Thomas Gleixner , "Paul E . McKenney" , Vlastimil Babka , Dmitry Vyukov , Valentin Schneider , Sander Vanheule , Alexey Klimov , Eric Biggers Subject: [PATCH v2 2/5] smp: add set_nr_cpu_ids() Date: Mon, 5 Sep 2022 16:08:17 -0700 Message-Id: <20220905230820.3295223-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905230820.3295223-1-yury.norov@gmail.com> References: <20220905230820.3295223-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" In preparation to support compile-time nr_cpu_ids, add a setter for the variable. This is a no-op for all arches. Signed-off-by: Yury Norov --- arch/loongarch/kernel/setup.c | 2 +- arch/mips/kernel/setup.c | 2 +- arch/x86/kernel/smpboot.c | 4 ++-- arch/x86/xen/smp_pv.c | 2 +- include/linux/cpumask.h | 5 +++++ kernel/smp.c | 4 ++-- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 8f5c2f9a1a83..18a81edd3ac5 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -346,7 +346,7 @@ static void __init prefill_possible_map(void) for (; i < NR_CPUS; i++) set_cpu_possible(i, false); =20 - nr_cpu_ids =3D possible; + set_nr_cpu_ids(possible); } #endif =20 diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 2ca156a5b231..e8a0759cb4d0 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -750,7 +750,7 @@ static void __init prefill_possible_map(void) for (; i < NR_CPUS; i++) set_cpu_possible(i, false); =20 - nr_cpu_ids =3D possible; + set_nr_cpu_ids(possible); } #else static inline void prefill_possible_map(void) {} diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index f24227bc3220..3f3ea0287f69 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1316,7 +1316,7 @@ static void __init smp_sanity_check(void) nr++; } =20 - nr_cpu_ids =3D 8; + set_nr_cpu_ids(8); } #endif =20 @@ -1569,7 +1569,7 @@ __init void prefill_possible_map(void) possible =3D i; } =20 - nr_cpu_ids =3D possible; + set_nr_cpu_ids(possible); =20 pr_info("Allowing %d CPUs, %d hotplug CPUs\n", possible, max_t(int, possible - num_processors, 0)); diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index ba7af2eca755..480be82e9b7b 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -179,7 +179,7 @@ static void __init _get_smp_config(unsigned int early) * hypercall to expand the max number of VCPUs an already * running guest has. So cap it up to X. */ if (subtract) - nr_cpu_ids =3D nr_cpu_ids - subtract; + set_nr_cpu_ids(nr_cpu_ids - subtract); #endif =20 } diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index bd047864c7ac..0588bfe350d4 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -39,6 +39,11 @@ typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); = } cpumask_t; #define nr_cpu_ids 1U #else extern unsigned int nr_cpu_ids; + +static inline void set_nr_cpu_ids(unsigned int nr) +{ + nr_cpu_ids =3D nr; +} #endif =20 #ifdef CONFIG_CPUMASK_OFFSTACK diff --git a/kernel/smp.c b/kernel/smp.c index e971c9626a1b..150310a0947a 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -1070,7 +1070,7 @@ static int __init nrcpus(char *str) int nr_cpus; =20 if (get_option(&str, &nr_cpus) && nr_cpus > 0 && nr_cpus < nr_cpu_ids) - nr_cpu_ids =3D nr_cpus; + set_nr_cpu_ids(nr_cpus); =20 return 0; } @@ -1097,7 +1097,7 @@ EXPORT_SYMBOL(nr_cpu_ids); /* An arch may set nr_cpu_ids earlier if needed, so this would be redundan= t */ void __init setup_nr_cpu_ids(void) { - nr_cpu_ids =3D find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1; + set_nr_cpu_ids(find_last_bit(cpumask_bits(cpu_possible_mask), NR_CPUS) + = 1); } =20 /* Called by boot processor to activate the rest. */ --=20 2.34.1 From nobody Thu Apr 9 12:50:36 2026 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 36F06ECAAD3 for ; Mon, 5 Sep 2022 23:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232442AbiIEXI6 (ORCPT ); Mon, 5 Sep 2022 19:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231377AbiIEXIi (ORCPT ); Mon, 5 Sep 2022 19:08:38 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16DBA647C6 for ; Mon, 5 Sep 2022 16:08:27 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id s22so7095813qkj.3 for ; Mon, 05 Sep 2022 16:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=WEHKHp4kn4V6UYQyjoIY/dqbYCfhgoChOkAi2IzYwg8=; b=X4PKt6fFt/RIqUVAvPGMJDPAeR2/o/H695HAeDwsdTrhicxzgeZYQcPlcFO5PDUeEe DTmQ2hu8/MIomiJIt3FXja+/yeIoB98wi8wtgUwhJ0pg16zFXZ9cjudcQYJpmTT/5BnG NICGE1AnIjW7xyggdGWQ4GHW1pch1wTBJ+Zo5sI76gPKTDQbY2eJEqNG13DgSbOcM/aG B1LZ9TLd6ZPFvVTpBOJUxJAu3CN81C/rKPKg4Vb5DpLiLOfVDQFOVqbLK8sJPJ3F1/l0 uR74mtEH2NxS3qDr0E4cP5YHABriyev21n0VlsTzhFxrzKBVlTFchwWVazt80nWWBVFH CJnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=WEHKHp4kn4V6UYQyjoIY/dqbYCfhgoChOkAi2IzYwg8=; b=faJjbcpXC5hnh8B7Pi+ttdn9x1eZLiWq3I0zwUzO8bNi/RKck9imixAIwaE2nx/BS4 epfDzI7JwgYO3WFNFUVVLcFR4yy9cHKS5qFqkUxqSycvZtNhvICrhqYXuB6ZZNo68wMN ZgHhGVKUGVGcCJ3pMBLRHEsxkGyp/McMuSNT+zb114qj0E56ceTbxmoolU8SQUup2Y9q B+VQaRFcj8ie8KD4dvUFmxKwFNKzXPJsEC/9neFGC/f2t8+BxUfwN7LHEy62gi74SlzX NGCzCWTsOEZCpr6jK4alTLo+1UEbRFz7o8kI/bLcDb24hmEwRNzKpmGNLBPc6fIuWF/5 UTzQ== X-Gm-Message-State: ACgBeo1p0UWio51Z3Ed/dIywjOp0zg02yS+lY34AwQfI+cH4qTDqyNcz Y4sEEUbkNwtSmCpWAMgJAnIvLXx1Cg8= X-Google-Smtp-Source: AA6agR58DCLIIGF0c9auUdxzbOvavzjfTdGwnTCZNfXNbqDh9liVIgHjykLWpSCIAoCu4nzGLcz3Mg== X-Received: by 2002:a05:620a:2989:b0:6bc:5cdc:88e9 with SMTP id r9-20020a05620a298900b006bc5cdc88e9mr34410118qkp.141.1662419305859; Mon, 05 Sep 2022 16:08:25 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:dde1:6b3e:62e9:1461]) by smtp.gmail.com with ESMTPSA id g16-20020a05620a40d000b006b93b61bc74sm9789783qko.9.2022.09.05.16.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 16:08:25 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Stephen Rothwell , Peter Zijlstra , Thomas Gleixner , "Paul E . McKenney" , Vlastimil Babka , Dmitry Vyukov , Valentin Schneider , Sander Vanheule , Alexey Klimov , Eric Biggers Subject: [PATCH v2 3/5] lib/cpumask: delete misleading comment Date: Mon, 5 Sep 2022 16:08:18 -0700 Message-Id: <20220905230820.3295223-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905230820.3295223-1-yury.norov@gmail.com> References: <20220905230820.3295223-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 comment says that HOTPLUG config option enables all cpus in cpu_possible_mask up to NR_CPUs. This is wrong. Even if HOTPLUG is enabled, the mask is populated on boot with respect to ACPI/DT records. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 0588bfe350d4..8bac1dee8448 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -72,10 +72,6 @@ static inline void set_nr_cpu_ids(unsigned int nr) * cpu_online_mask is the dynamic subset of cpu_present_mask, * indicating those CPUs available for scheduling. * - * If HOTPLUG is enabled, then cpu_possible_mask is forced to have - * all NR_CPUS bits set, otherwise it is just the set of CPUs that - * ACPI reports present at boot. - * * If HOTPLUG is enabled, then cpu_present_mask varies dynamically, * depending on what ACPI reports as currently plugged in, otherwise * cpu_present_mask is just a copy of cpu_possible_mask. --=20 2.34.1 From nobody Thu Apr 9 12:50:36 2026 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 73EECECAAA1 for ; Mon, 5 Sep 2022 23:09:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbiIEXJi (ORCPT ); Mon, 5 Sep 2022 19:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231607AbiIEXIi (ORCPT ); Mon, 5 Sep 2022 19:08:38 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2079269F69 for ; Mon, 5 Sep 2022 16:08:28 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id m5so7100065qkk.1 for ; Mon, 05 Sep 2022 16:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=5nia01YVD1nOxZpuw1Ju3+MSuIMcZP6UORERwrWolic=; b=Hcj7b7/mvchl/778193I7X2cHOU66rPsy7p0dNS9j8Gi3qP9idutbicIcbR+6j0op0 nF1C02g+0KMG/tbH/e1NnKiJvUPilOaJbLGJw8/XM3ttHJSpRCC5QdIPiMYmAb6ZAAjI qk06hGPXUQnasmdjdkKSqpgBCqnrSabABX2FOaOaRBgYFc2hygQBy8tDmps797rdfX2m QSf5ckbUXWlIKWyykf0dQo7K2nbRR6KB2+O4ZVDQD3G8xeSy0ryTFffmjfUyja8/EYcY AgqhmEszZgWYj4V6z6HKlnfeP255UZw4k+x73+bpGnuS1kSDl3oDVG2Wpj8mFsMmJHUb htxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=5nia01YVD1nOxZpuw1Ju3+MSuIMcZP6UORERwrWolic=; b=En8JA61nokFpZ4Tl3bT3yWzErm6zBQA/bybdWi/+KVwPV1yUUzRcYOf2xXAgftLVCZ hJZvSRdBW9dlaFnvyOocUHn5ecJoEpB0N6t2HOB5fJJfij9x5Dg7e5OKHOMQN7FRTp+X Fak8e8WReGu6qclhedqo8RMhjxmIBoR217D6khRD+ex3rTjHAMlL6JfqCDt83bxLR9rh 14otGCSG8fTmzS2vj5lLnaTwH4SskbefSJJb84Z1PaR4TeuMIXPS+15TQ+NlUuVrmc9W /F0fG+fD+r14APsS7thZD320rGYUkqfB8jhegZqjESLaVplzHZfmMs8WXMKBjfNOTjEg ddsA== X-Gm-Message-State: ACgBeo0pfS7+Q7/hHtFA9Qrt84smvcnfF/y/xKYRk5yE2czJf1Wq/nHu Dc9iFuBE1JEJpLSg/sEOrOPyVF2MfBs= X-Google-Smtp-Source: AA6agR6TyDOcWsBx7ANttUfOkGRDfVaPJJ6/zKxgOsfByiGkVBlSfVsUnp/Z3X+WlI2U5osgYW+6vA== X-Received: by 2002:a05:620a:69c:b0:6bb:ebec:39c1 with SMTP id f28-20020a05620a069c00b006bbebec39c1mr33966927qkh.600.1662419307078; Mon, 05 Sep 2022 16:08:27 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:dde1:6b3e:62e9:1461]) by smtp.gmail.com with ESMTPSA id o11-20020ac872cb000000b003422c7ccbc5sm7954128qtp.59.2022.09.05.16.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 16:08:26 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Stephen Rothwell , Peter Zijlstra , Thomas Gleixner , "Paul E . McKenney" , Vlastimil Babka , Dmitry Vyukov , Valentin Schneider , Sander Vanheule , Alexey Klimov , Eric Biggers Subject: [PATCH v2 4/5] lib/cpumask: deprecate nr_cpumask_bits Date: Mon, 5 Sep 2022 16:08:19 -0700 Message-Id: <20220905230820.3295223-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905230820.3295223-1-yury.norov@gmail.com> References: <20220905230820.3295223-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" Cpumask code is written in assumption that when CONFIG_CPUMASK_OFFSTACK is enabled, all cpumasks have boot-time defined size, otherwise the size is always NR_CPUS. The latter is wrong because the number of possible cpus is always calculated on boot, and it may be less than NR_CPUS. On my 4-cpu arm64 VM the nr_cpu_ids is 4, as expected, and nr_cpumask_bits is 256, which corresponds to NR_CPUS. This not only leads to useless traversing of cpumask bits greater than 4, this also makes some cpumask routines fail. For example, cpumask_full(0b1111000..000) would erroneously return false in the example above because tail bits in the mask are all unset. This patch deprecates nr_cpumask_bits and wires it to nr_cpu_ids unconditionally, so that cpumask routines will not waste time traversing unused part of cpu masks. It also fixes cpumask_full() and similar routines. As a side effect, because now a length of cpumasks is defined at run-time even if CPUMASK_OFFSTACK is disabled, compiler can't optimize corresponding functions. It increases kernel size by ~2.5KB if OFFSTACK is off. This is addressed in the following patch. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 8bac1dee8448..e01fba8ecc27 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -46,13 +46,8 @@ static inline void set_nr_cpu_ids(unsigned int nr) } #endif =20 -#ifdef CONFIG_CPUMASK_OFFSTACK -/* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also, - * not all bits may be allocated. */ +/* Deprecated. Always use nr_cpu_ids. */ #define nr_cpumask_bits nr_cpu_ids -#else -#define nr_cpumask_bits ((unsigned int)NR_CPUS) -#endif =20 /* * The following particular system cpumasks and operations manage --=20 2.34.1 From nobody Thu Apr 9 12:50:36 2026 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 B613DECAAA1 for ; Mon, 5 Sep 2022 23:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232560AbiIEXJC (ORCPT ); Mon, 5 Sep 2022 19:09:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230005AbiIEXIk (ORCPT ); Mon, 5 Sep 2022 19:08:40 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B78B6A488 for ; Mon, 5 Sep 2022 16:08:29 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id m9so4564841qvv.7 for ; Mon, 05 Sep 2022 16:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=O4yRGqEn6L/4OFD6cxa3VXtqQyIbnJ79Kwqapqi4kFI=; b=JJwG3wZl+3v7TyUrdNN78c67d0VjSAHn0E2H2AEfKVcLs07nDDFnz0mp35a1sklXlp MOkYRV4lGznqDAwiJh7cvoRUpLohHpYJm/CCFvsICkN3+Uvn6Nt8OWffVyjNpAePuuJH +YuPNoYWEr+UN224P5VnXRpl3kEIpcgip5j1YQIFOmEYmPK15ThPo/pnMTl3QX/+/G0l 4iKyTUZI5CQ1CRtCoQfogIP3bVTKl441e2wymERu/Cz5SvDvVpFJe+Hy+0CcRqMMvgIU JeOzcAhNzPyEpFIaxZLbU6oohO9b3Fy7P4piH815ZO2N6BlazgxJIVkrVf0hVXKsP6ot QNiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=O4yRGqEn6L/4OFD6cxa3VXtqQyIbnJ79Kwqapqi4kFI=; b=teV3EjSYigrq8/e66Gexs5K1gpq9DgUKp3P1R9Sm3a4rJ8RX+DQxfLMBDgQeIoq/e+ kWIh6b1YWlu8w2oDFyn0Kbw+YRJBpEe84q2IrwH3FuD21hAZfNgZDJ59CQAaCW4rAObE jYa0kXg/6bqYE0q3XRPWdJkHePNffOKniQ6Smw2rksHv4UYoOe60nQ1EWm8MQBDq00QT 50H83K3ZOk3X36HuAQ9ZpBB4VO8937fC3amZbM5WSWz33cj6E+dK6YAfO3WkgKsA842a gP/8gSdY9/qRHuiWy8QKibqZeCmGbkOd+G1TOFwI6zDcCjgMVxsIsk3DP2biRa9pfx+X zHKw== X-Gm-Message-State: ACgBeo2G6kW64+W1y7AvA4mfBjeQniCYdzMi/ycSBwdnaGWkozjDguxW d/fTWg77S1afM09Y8yDXGMRnxlZIA0o= X-Google-Smtp-Source: AA6agR6dh4igMPx1JjrupJhhmgnLE84HKJdEzxqcVsLZquVcZL+yCpw3prOLIvk5CN3f5ECJecMaSw== X-Received: by 2002:a05:6214:20a8:b0:477:1882:3e7 with SMTP id 8-20020a05621420a800b00477188203e7mr42914082qvd.44.1662419308057; Mon, 05 Sep 2022 16:08:28 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:dde1:6b3e:62e9:1461]) by smtp.gmail.com with ESMTPSA id d3-20020a05620a166300b006b5c061844fsm8916289qko.49.2022.09.05.16.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 16:08:27 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Stephen Rothwell , Peter Zijlstra , Thomas Gleixner , "Paul E . McKenney" , Vlastimil Babka , Dmitry Vyukov , Valentin Schneider , Sander Vanheule , Alexey Klimov , Eric Biggers Subject: [PATCH v2 5/5] lib/cpumask: add FORCE_NR_CPUS config option Date: Mon, 5 Sep 2022 16:08:20 -0700 Message-Id: <20220905230820.3295223-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905230820.3295223-1-yury.norov@gmail.com> References: <20220905230820.3295223-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 size of cpumasks is hard-limited by compile-time parameter NR_CPUS, but defined at boot-time when kernel parses ACPI/DT tables, and stored in nr_cpu_ids. In many practical cases, number of CPUs for a target is known at compile time, and can be provided with NR_CPUS. In that case, compiler may be instructed to rely on NR_CPUS as on actual number of CPUs, not an upper limit. It allows to optimize many cpumask routines and significantly shrink size of the kernel image. This patch adds FORCE_NR_CPUS option to teach the compiler to rely on NR_CPUS and enable corresponding optimizations. If FORCE_NR_CPUS=3Dy, kernel will not set nr_cpu_ids at boot, but only check that the actual number of possible CPUs is equal to NR_CPUS, and WARN if that doesn't hold. The new option is especially useful in embedded applications because kernel configurations are unique for each SoC, the number of CPUs is constant and known well, and memory limitations are typically harder. For my 4-CPU ARM64 build with NR_CPUS=3D4, FORCE_NR_CPUS=3Dy saves 46KB: add/remove: 3/4 grow/shrink: 46/729 up/down: 652/-46952 (-46300) Signed-off-by: Yury Norov --- include/linux/cpumask.h | 10 +++++++--- kernel/smp.c | 2 +- lib/Kconfig | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index e01fba8ecc27..0753202819e5 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -35,16 +35,20 @@ typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS);= } cpumask_t; */ #define cpumask_pr_args(maskp) nr_cpu_ids, cpumask_bits(maskp) =20 -#if NR_CPUS =3D=3D 1 -#define nr_cpu_ids 1U +#if (NR_CPUS =3D=3D 1) || defined(CONFIG_FORCE_NR_CPUS) +#define nr_cpu_ids ((unsigned int)NR_CPUS) #else extern unsigned int nr_cpu_ids; +#endif =20 static inline void set_nr_cpu_ids(unsigned int nr) { +#if (NR_CPUS =3D=3D 1) || defined(CONFIG_FORCE_NR_CPUS) + WARN_ON(nr !=3D nr_cpu_ids); +#else nr_cpu_ids =3D nr; -} #endif +} =20 /* Deprecated. Always use nr_cpu_ids. */ #define nr_cpumask_bits nr_cpu_ids diff --git a/kernel/smp.c b/kernel/smp.c index 150310a0947a..661d09ae5d6a 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -1088,7 +1088,7 @@ static int __init maxcpus(char *str) =20 early_param("maxcpus", maxcpus); =20 -#if (NR_CPUS > 1) +#if (NR_CPUS > 1) && !defined(CONFIG_FORCE_NR_CPUS) /* Setup number of possible processor ids */ unsigned int nr_cpu_ids __read_mostly =3D NR_CPUS; EXPORT_SYMBOL(nr_cpu_ids); diff --git a/lib/Kconfig b/lib/Kconfig index dc1ab2ed1dc6..77ead982c8b9 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -527,6 +527,15 @@ config CPUMASK_OFFSTACK them on the stack. This is a bit more expensive, but avoids stack overflow. =20 +config FORCE_NR_CPUS + bool "NR_CPUS is set to an actual number of CPUs" + depends on SMP + help + Say Yes if you have NR_CPUS set to an actual number of possible + CPUs in your system, not to a default value. This forces the core + code to rely on compile-time value and optimize kernel routines + better. + config CPU_RMAP bool depends on SMP --=20 2.34.1