[PATCH 2/6] cpumask: Add reset_preferred_cpumask() helper

From
Yury Norov <hidden>
Date
2026-11-01 19:22:13
Also in
driver-core, linux-s390, lkml
Reply to
Yury Norov, 2026-11-01
This series adds more flexibility to control the 'preferred' status of
CPUs. As a preparation, move the steal governor's preferred-mask reset
into cpumask.h to make it globally available.

While there, rename it to shorter "reset_preferred_cpumask()".

Signed-off-by: Yury Norov <redacted>
---
 drivers/virt/steal_governor.c | 15 ++++-----------
 include/linux/cpumask.h       | 12 ++++++++++++
 2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c
index 6e31f9923dea..4cd9971fec45 100644
--- a/drivers/virt/steal_governor.c
+++ b/drivers/virt/steal_governor.c
@@ -51,15 +51,6 @@ static struct steal_governor sg_ctx = {
 	.low_threshold	=	200,	/* 2% */
 };
 
-static void restore_preferred_to_active(void)
-{
-	int cpu;
-
-	guard(cpus_read_lock)();
-	for_each_cpu(cpu, cpu_active_mask)
-		set_cpu_preferred(cpu, true);
-}
-
 static int param_set_interval_ms(const char *val, const struct kernel_param *kp)
 {
 	unsigned int interval;
@@ -247,7 +238,8 @@ static void steal_governor_loop(struct work_struct *work)
 	 * module restores to active if CPU hotplug breaks those assumptions.
 	 */
 	if (!preferred_cpus_valid()) {
-		restore_preferred_to_active();
+		scoped_guard(cpus_read_lock)
+			reset_preferred_cpumask();
 		return;
 	}
 
@@ -284,7 +276,8 @@ static int __init steal_governor_init(void)
 static void __exit steal_governor_exit(void)
 {
 	disable_delayed_work_sync(&sg_ctx.work);
-	restore_preferred_to_active();
+	scoped_guard(cpus_read_lock)
+		reset_preferred_cpumask();
 	pr_info("disabled\n");
 }
 
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index bf89bb3f30f6..c65abfc8a97f 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -1195,6 +1195,18 @@ void init_cpu_possible(const struct cpumask *src);
 #define set_cpu_preferred(cpu, preferred) do { } while (0)
 #endif
 
+/**
+ * reset_preferred_cpumask - reset preferred CPUs to the active mask.
+ *
+ * Callers must serialize against CPU hotplug and other preferred cpumask
+ * writers.
+ */
+static inline void reset_preferred_cpumask(void)
+{
+	if (IS_ENABLED(CONFIG_PREFERRED_CPU))
+		cpumask_copy(&__cpu_preferred_mask, cpu_active_mask);
+}
+
 void set_cpu_online(unsigned int cpu, bool online);
 void set_cpu_possible(unsigned int cpu, bool possible);
 
-- 
2.53.0
Thread (30 messages) 30 messages, 7 authors, last reply 6d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help