From patchwork Thu Apr 6 01:56:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 80022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp711840vqo; Wed, 5 Apr 2023 18:59:10 -0700 (PDT) X-Google-Smtp-Source: AKy350bvHyppI/okMbIvHY8FOr7FkjbwCqiFyLccuJSoZVpcno7wrVEYXpDKdduzbvvs9LOfC0a0 X-Received: by 2002:a17:906:f8c9:b0:947:eaed:1f87 with SMTP id lh9-20020a170906f8c900b00947eaed1f87mr4097231ejb.19.1680746350000; Wed, 05 Apr 2023 18:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680746349; cv=none; d=google.com; s=arc-20160816; b=etmjgjAtsy9JbYOzFn71Ch3IGhbReadMZBKn8B42kfpKRxO+KZrmQ15ql0Gv4Y3JQH 2f+axIwnJ4oG7LQ7l1Guu/+0X3rP6Hzb6kvE77DcZE0Z+K0HJhUoEPv7+KVdiI7ouy8X tJh+VjoxjFuKhXPe4ueA1POwWAHyrczGaC7knAppdVCGKVL6rSQb/G6Oi23Hq/RYKxyq pQjeRk5Hvkzhly833SCfnnpy0vf9Ep+gDye2kr2RCrdvxUtHisKYNHAsOaaUTgRuuq9O pyXkoNYfyePgYSMs666iNC/ncZ0rf/nJd4kQKI1QKUGiio+Ju02kbFQVjnLUzewwRNts h1bA== 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; bh=GN+sUs27ysqTC3ebxS5dgKiSF9/pny2Yx3svyi9Q5KY=; b=JmHY7cO/zR9PXTTh7v2yoLz86sfrmL/HK1gBZMUOY93vHhMp28LGoGSYmRQty1+GWL jpGLU/W7XzHfB/jtYjo81dnZQt63XY8X3AioakbvnJ0skWOc0WcSDts7ZJ+Uiu1fTgmc qcrCBaZHd2KA80O8rmkhd99DHbf3LyunjEHq82ofhdCQSVYU1aPPTn+r1Le9Noh76Nzu P0CgY/yySEwodvzHxx8T+q4DndT+xmYNgjlYyAIu9uiWKnWwZW3FKKEGePSQ5nfMoUy3 PQB0qxmeqJOD2GXbiQF8NJoOKPE5rib3nCBDrs5VWYEc4MIczBo0YeyilqRC0o+nRyjR jnrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca9-20020a170906a3c900b009334d676751si198208ejb.609.2023.04.05.18.58.45; Wed, 05 Apr 2023 18:59:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234636AbjDFB5J (ORCPT + 99 others); Wed, 5 Apr 2023 21:57:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231889AbjDFB5D (ORCPT ); Wed, 5 Apr 2023 21:57:03 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D68ABA9 for ; Wed, 5 Apr 2023 18:57:01 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4PsPkd3XFqz4f3nqJ for ; Thu, 6 Apr 2023 09:56:57 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgCnUyHoJi5kX936GA--.31319S5; Thu, 06 Apr 2023 09:56:59 +0800 (CST) From: Ye Bin To: dennis@kernel.org, tj@kernel.org, cl@linux.com, linux-mm@kvack.org, yury.norov@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk Cc: linux-kernel@vger.kernel.org, dchinner@redhat.com, yebin10@huawei.com, yebin@huaweicloud.com Subject: [PATCH v2 1/2] cpu/hotplug: introduce 'num_dying_cpus' to get dying CPUs count Date: Thu, 6 Apr 2023 09:56:28 +0800 Message-Id: <20230406015629.1804722-2-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230406015629.1804722-1-yebin@huaweicloud.com> References: <20230406015629.1804722-1-yebin@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgCnUyHoJi5kX936GA--.31319S5 X-Coremail-Antispam: 1UD129KBjvJXoW7WFy8ZFykGrW5KFWDCFy5CFg_yoW5JF4rpr 4UGFW5trWUAFyIga9Yyws8Xr1F9wn5Crn5Gay29F13JFy3Ja4vq3WkuFy5Jr15WrZ3ur1a vrZ0qr409a15Xa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU2_M3UUUUU = X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=2.1 required=5.0 tests=KHOP_HELO_FCRDNS,MAY_BE_FORGED, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762390284677936440?= X-GMAIL-MSGID: =?utf-8?q?1762390284677936440?= From: Ye Bin Introduce '__num_dying_cpus' variable to cache the number of dying CPUs in the core and just return the cached variable. Signed-off-by: Ye Bin --- include/linux/cpumask.h | 20 ++++++++++++++++---- kernel/cpu.c | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 2a61ddcf8321..8127fd598f51 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -135,6 +135,8 @@ extern struct cpumask __cpu_dying_mask; extern atomic_t __num_online_cpus; +extern atomic_t __num_dying_cpus; + extern cpumask_t cpus_booted_once_mask; static __always_inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits) @@ -1018,10 +1020,14 @@ set_cpu_active(unsigned int cpu, bool active) static __always_inline void set_cpu_dying(unsigned int cpu, bool dying) { - if (dying) - cpumask_set_cpu(cpu, &__cpu_dying_mask); - else - cpumask_clear_cpu(cpu, &__cpu_dying_mask); + if (dying) { + if (!cpumask_test_and_set_cpu(cpu, &__cpu_dying_mask)) + atomic_inc(&__num_dying_cpus); + } + else { + if (cpumask_test_and_clear_cpu(cpu, &__cpu_dying_mask)) + atomic_dec(&__num_dying_cpus); + } } /** @@ -1073,6 +1079,11 @@ static __always_inline unsigned int num_online_cpus(void) { return arch_atomic_read(&__num_online_cpus); } + +static __always_inline unsigned int num_dying_cpus(void) +{ + return arch_atomic_read(&__num_dying_cpus); +} #define num_possible_cpus() cpumask_weight(cpu_possible_mask) #define num_present_cpus() cpumask_weight(cpu_present_mask) #define num_active_cpus() cpumask_weight(cpu_active_mask) @@ -1108,6 +1119,7 @@ static __always_inline bool cpu_dying(unsigned int cpu) #define num_possible_cpus() 1U #define num_present_cpus() 1U #define num_active_cpus() 1U +#define num_dying_cpus() 0U static __always_inline bool cpu_online(unsigned int cpu) { diff --git a/kernel/cpu.c b/kernel/cpu.c index f4a2c5845bcb..1c96c04cb259 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2662,6 +2662,8 @@ EXPORT_SYMBOL(__cpu_dying_mask); atomic_t __num_online_cpus __read_mostly; EXPORT_SYMBOL(__num_online_cpus); +atomic_t __num_dying_cpus __read_mostly; + void init_cpu_present(const struct cpumask *src) { cpumask_copy(&__cpu_present_mask, src);