[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250625191108.1646208-3-sshegde@linux.ibm.com>
Date: Thu, 26 Jun 2025 00:41:01 +0530
From: Shrikanth Hegde <sshegde@...ux.ibm.com>
To: mingo@...hat.com, peterz@...radead.org, juri.lelli@...hat.com,
vincent.guittot@...aro.org, tglx@...utronix.de, yury.norov@...il.com,
maddy@...ux.ibm.com
Cc: sshegde@...ux.ibm.com, vschneid@...hat.com, dietmar.eggemann@....com,
rostedt@...dmis.org, kprateek.nayak@....com, huschle@...ux.ibm.com,
srikar@...ux.ibm.com, linux-kernel@...r.kernel.org,
christophe.leroy@...roup.eu, linuxppc-dev@...ts.ozlabs.org,
gregkh@...uxfoundation.org
Subject: [RFC v2 2/9] cpumask: Introduce cpu_avoid_mask
Introduce cpu_avoid_mask and get/set routines for it.
By having the mask, it is easier for other kernel subsystem to consume
it as well. One could quickly know which CPUs are currently marked as
avoid.
Signed-off-by: Shrikanth Hegde <sshegde@...ux.ibm.com>
---
There is a sysfs patch later in the series which prints this mask. If it
should be sqashed into this patch, let me know.
include/linux/cpumask.h | 17 +++++++++++++++++
kernel/cpu.c | 3 +++
2 files changed, 20 insertions(+)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 7ae80a7ca81e..6394c67a4fb3 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -84,6 +84,7 @@ static __always_inline void set_nr_cpu_ids(unsigned int nr)
* cpu_enabled_mask - has bit 'cpu' set iff cpu can be brought online
* cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
* cpu_active_mask - has bit 'cpu' set iff cpu available to migration
+ * cpu_avoid_mask - has bit 'cpu' set iff cpu is to be avoided now
*
* If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
*
@@ -101,6 +102,10 @@ static __always_inline void set_nr_cpu_ids(unsigned int nr)
* (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
* hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
*
+ * A CPU is said to be avoided when there is contention for underlying
+ * physical CPU resource in paravirtulized environment. It is recommneded
+ * not run anything on that CPU though it is online.
+ *
* Subtleties:
* 1) UP ARCHes (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
* assumption that their single CPU is online. The UP
@@ -118,12 +123,14 @@ extern struct cpumask __cpu_enabled_mask;
extern struct cpumask __cpu_present_mask;
extern struct cpumask __cpu_active_mask;
extern struct cpumask __cpu_dying_mask;
+extern struct cpumask __cpu_avoid_mask;
#define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
#define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask)
#define cpu_enabled_mask ((const struct cpumask *)&__cpu_enabled_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)
+#define cpu_avoid_mask ((const struct cpumask *)&__cpu_avoid_mask)
extern atomic_t __num_online_cpus;
@@ -1133,6 +1140,7 @@ void init_cpu_possible(const struct cpumask *src);
#define set_cpu_present(cpu, present) assign_cpu((cpu), &__cpu_present_mask, (present))
#define set_cpu_active(cpu, active) assign_cpu((cpu), &__cpu_active_mask, (active))
#define set_cpu_dying(cpu, dying) assign_cpu((cpu), &__cpu_dying_mask, (dying))
+#define set_cpu_avoid(cpu, avoid) assign_cpu((cpu), &__cpu_avoid_mask, (avoid))
void set_cpu_online(unsigned int cpu, bool online);
@@ -1222,6 +1230,11 @@ static __always_inline bool cpu_dying(unsigned int cpu)
return cpumask_test_cpu(cpu, cpu_dying_mask);
}
+static __always_inline bool cpu_avoid(unsigned int cpu)
+{
+ return cpumask_test_cpu(cpu, cpu_avoid_mask);
+}
+
#else
#define num_online_cpus() 1U
@@ -1260,6 +1273,10 @@ static __always_inline bool cpu_dying(unsigned int cpu)
return false;
}
+static __always_inline bool cpu_avoid(unsigned int cpu)
+{
+ return false;
+}
#endif /* NR_CPUS > 1 */
#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
diff --git a/kernel/cpu.c b/kernel/cpu.c
index a59e009e0be4..44e8c66d2839 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -3107,6 +3107,9 @@ EXPORT_SYMBOL(__cpu_active_mask);
struct cpumask __cpu_dying_mask __read_mostly;
EXPORT_SYMBOL(__cpu_dying_mask);
+struct cpumask __cpu_avoid_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_avoid_mask);
+
atomic_t __num_online_cpus __read_mostly;
EXPORT_SYMBOL(__num_online_cpus);
--
2.43.0
Powered by blists - more mailing lists