Re: [PATCH v4 04/20] cpumask: Introduce cpu_preferred_mask

From: Shrikanth Hegde

Date: Thu Jun 18 2026 - 04:28:34 EST




On 6/18/26 9:23 AM, Shrikanth Hegde wrote:
Hi Yury.

+void set_cpu_preferred(unsigned int cpu, bool preferred)
+{
+    if (!IS_ENABLED(CONFIG_PREFERRED_CPU))
+        return;
+
+    assign_cpu((cpu), &__cpu_preferred_mask, (preferred));
+}

set_cpu_xxx() is a macro on purpose - it improves code generation
quite a lot. See 5c563ee90a22d. Can you keep set_cpu_preferred aligned
with the other set_cpu(), i.e. make it a macro?


Ok. only reason was to avoid ifdeffery there.

you mean below?

#ifdef CONFIG_PREFERRED_CPU
#else
#endif

Ok. I misread your comment. I believe you meant to do like below.
preferred mask is always defined, either same as active or allocated.


diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 30ea64cc1656..5a643d608ea6 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -1169,10 +1169,10 @@ 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_preferred(cpu, preferred) assign_cpu((cpu), &__cpu_preferred_mask, (preferred))
void set_cpu_online(unsigned int cpu, bool online);
void set_cpu_possible(unsigned int cpu, bool possible);
-void set_cpu_preferred(unsigned int cpu, bool preferred);
/**
* to_cpumask - convert a NR_CPUS bitmap to a struct cpumask *
diff --git a/kernel/cpu.c b/kernel/cpu.c
index c196ba5d8b2a..d623a9c5554a 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -3159,14 +3159,6 @@ void set_cpu_possible(unsigned int cpu, bool possible)
}
}
-void set_cpu_preferred(unsigned int cpu, bool preferred)
-{
- if (!IS_ENABLED(CONFIG_PREFERRED_CPU))
- return;
-
- assign_cpu((cpu), &__cpu_preferred_mask, (preferred));
-}
-
/*
* Activate the first processor.
*/