Received: by 2002:a05:6520:3645:b029:c0:f950:43e0 with SMTP id l5csp524118lki; Wed, 10 Mar 2021 07:06:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5cmUaKQD8MFBpXYNcImmuBqtOlGRUARy0dr0pJ0pgbVSwtwyjTXdkAOQmWf6ouLEG06Lb X-Received: by 2002:a17:906:2818:: with SMTP id r24mr4174379ejc.472.1615388783235; Wed, 10 Mar 2021 07:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615388783; cv=none; d=google.com; s=arc-20160816; b=RjFRCoyYTmRZeiNN7tOqIComuV2MmZ0Gv0grI10qgQ6VfNAV92sio4k8qUX6DTt6Ad rPIWxAW2XsI5qXQHKee3tcWnxOMqqg9vjZgW/fKA3X75/OAeZE5abIaV+esJRGOiB6Av yxO768CxIywI6CzrA4qTnV3oCYvvF+FAunmZXqfM0pILHM7If9eftvxD1ZsAzk9G2XST rdaHqCViZRG0UgQiZ7n5ilf9F77Qt+ugS3U/RjbB/P+gbDSnf0VJsvlmPrL2PQFkKagR gwl8oRb5v5khkHHeIiWBx1UPBOpXISK0bpZwRKI31LvkTnz/g+BHHNtHklYIUBQu6TJg jFyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=G++WuZlc94CXytRJI/NGHZDhvufz+ulSBA/S3u8lMyA=; b=GkXob2go3BvprXbmdJme+JOM9SdY4YI0maWYnsbGvQlcbrebx34Y3WKzZKShCRgUsM a1WnaTowO4uZCbfu9pfHzJwYIaOte1LYjfasUqjjDj8lqFKB9yC4nsVTy4L2/1y+rf2w pg59xIP9LfWAeeEpEKw6KwE93Q2FgsudagHrZmM2JqSCO5kYeXUscwXTh/khGnHL/Al4 NChPjfaPllI9zf0bSwP2gw3mNbTM0p9z/cSY2lwzm8a5Y61ncchq0PlP5kkP5L1/0FPT IRSX6W0GXrhVbtm8kPdTorsNphH1URy+pYn/OyUBY3SImYw6dwU7tZe12z6NzFGZN87f lPIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=YXBpvm0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si3664461edt.586.2021.03.10.07.05.47; Wed, 10 Mar 2021 07:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=YXBpvm0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232971AbhCJPC2 (ORCPT + 99 others); Wed, 10 Mar 2021 10:02:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbhCJPB7 (ORCPT ); Wed, 10 Mar 2021 10:01:59 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E264C061760 for ; Wed, 10 Mar 2021 07:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=G++WuZlc94CXytRJI/NGHZDhvufz+ulSBA/S3u8lMyA=; b=YXBpvm0Pznr2+boTiwEPbsf6yH gngIXUKBkgMqMQ9fCll3HeSWZFDKCP4XjxVLhNKtVtVYXB9EQkuIynsLUUVMcli6psGY60mYqDInD sPl9yFR495kxVqTRZ5EHI/eoOpDsfoXBsTmxsOycY+mfq7EGl/1Puyx5psocZTEHAJqU9oaIfisBm I+kr/7tVUi0N34jeD7L5NQvRp21igaIEfSCNwQMoRGXWZ8Y7nJ3hib8Hj1aOG/CfLhEUBgcyalfhk AXvFqYQMCXC8BAp3dpr44DNtsN79alwkOu9ugjHPx57H3JBr0yZKJaaXJqXhzL3lxTstRfWvKPfr0 QqRzoYnA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lK0LF-0074aw-Kr; Wed, 10 Mar 2021 15:01:41 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3631F3059C0; Wed, 10 Mar 2021 16:01:41 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id F2A9A287167A8; Wed, 10 Mar 2021 16:01:40 +0100 (CET) Message-ID: <20210310150109.151441252@infradead.org> User-Agent: quilt/0.66 Date: Wed, 10 Mar 2021 15:53:00 +0100 From: Peter Zijlstra To: valentin.schneider@arm.com, tglx@linutronix.de, mingo@kernel.org, bigeasy@linutronix.de, swood@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vincent.donnefort@arm.com, qais.yousef@arm.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 2/3] cpumask: Introduce DYING mask References: <20210310145258.899619710@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a cpumask that indicates (for each CPU) what direction the CPU hotplug is currently going. Notably, it tracks rollbacks. Eg. when an up fails and we do a roll-back down, it will accurately reflect the direction. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/cpumask.h | 20 ++++++++++++++++++++ kernel/cpu.c | 6 ++++++ 2 files changed, 26 insertions(+) --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -91,10 +91,12 @@ extern struct cpumask __cpu_possible_mas extern struct cpumask __cpu_online_mask; extern struct cpumask __cpu_present_mask; extern struct cpumask __cpu_active_mask; +extern struct cpumask __cpu_dying_mask; #define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask) #define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask) #define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask) #define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask) +#define cpu_dying_mask ((const struct cpumask *)&__cpu_dying_mask) extern atomic_t __num_online_cpus; @@ -826,6 +828,14 @@ set_cpu_active(unsigned int cpu, bool ac cpumask_clear_cpu(cpu, &__cpu_active_mask); } +static 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); +} /** * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask * @@ -900,6 +910,11 @@ static inline bool cpu_active(unsigned i return cpumask_test_cpu(cpu, cpu_active_mask); } +static inline bool cpu_dying(unsigned int cpu) +{ + return cpumask_test_cpu(cpu, cpu_dying_mask); +} + #else #define num_online_cpus() 1U @@ -927,6 +942,11 @@ static inline bool cpu_active(unsigned i return cpu == 0; } +static inline bool cpu_dying(unsigned int cpu) +{ + return false; +} + #endif /* NR_CPUS > 1 */ #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -160,6 +160,9 @@ static int cpuhp_invoke_callback(unsigne int (*cb)(unsigned int cpu); int ret, cnt; + if (bringup != !cpu_dying(cpu)) + set_cpu_dying(cpu, !bringup); + if (st->fail == state) { st->fail = CPUHP_INVALID; return -EAGAIN; @@ -2512,6 +2515,9 @@ EXPORT_SYMBOL(__cpu_present_mask); struct cpumask __cpu_active_mask __read_mostly; EXPORT_SYMBOL(__cpu_active_mask); +struct cpumask __cpu_dying_mask __read_mostly; +EXPORT_SYMBOL(__cpu_dying_mask); + atomic_t __num_online_cpus __read_mostly; EXPORT_SYMBOL(__num_online_cpus);