Skip to contentSkip to conversation

cpumask: avoid cast-away-const for deprecated cpu_*_map.

PATCH In review Rusty Russell 1 participant 1 message Feb 7, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 cpumask: avoid cast-away-const for deprecated cpu_*_map.

James Bottomley encountered a Voyager bug where gcc was discarding changes to cpu_possible_map, which is now #defined to cpu_possible_mask with the const cast away.

The modern way is to use init_cpu_possible or set_cpu_possible, but not everyone is converted yet. I'm concerned that other archs might have similar problems, so let's expose the underlying bits for the moment (and prepend those names with __).

(This also makes accessing cpu_*_mask slightly more efficient, rather than going via a pointer).

---
 include/linux/cpumask.h |   28 +++++++++++++++++++---------
 kernel/cpu.c            |   44 ++++++++++++++++++++------------------------
 2 files changed, 39 insertions(+), 33 deletions(-)
include/linux/cpumask.h +19 -9
@@ -482,16 +482,26 @@ int __next_cpu_nr(int n, const cpumask_t
  *    only one CPU.
  */
 
-extern const struct cpumask *const cpu_possible_mask;
-extern const struct cpumask *const cpu_online_mask;
-extern const struct cpumask *const cpu_present_mask;
-extern const struct cpumask *const cpu_active_mask;
+#define cpu_possible_mask \
+	((const struct cpumask *)to_cpumask(__cpu_possible_bits))
+#define cpu_online_mask \
+	((const struct cpumask *)to_cpumask(__cpu_online_bits))
+#define cpu_present_mask \
+	((const struct cpumask *)to_cpumask(__cpu_present_bits))
+#define cpu_active_mask \
+	((const struct cpumask *)to_cpumask(__cpu_active_bits))
 
-/* These strip const, as traditionally they weren't const. */
-#define cpu_possible_map	(*(cpumask_t *)cpu_possible_mask)
-#define cpu_online_map		(*(cpumask_t *)cpu_online_mask)
-#define cpu_present_map		(*(cpumask_t *)cpu_present_mask)
-#define cpu_active_map		(*(cpumask_t *)cpu_active_mask)
+/* Deprecated non-const versions. */
+#define cpu_possible_map	(*to_cpumask(__cpu_possible_bits))
+#define cpu_online_map		(*to_cpumask(__cpu_online_bits))
+#define cpu_present_map		(*to_cpumask(__cpu_present_bits))
+#define cpu_active_map		(*to_cpumask(__cpu_active_bits))
+
+/* Don't use these directly: use cpu_*_mask, set_cpu_* or init_cpu_*. */
+extern unsigned long __cpu_possible_bits[];
+extern unsigned long __cpu_online_bits[];
+extern unsigned long __cpu_present_bits[];
+extern unsigned long __cpu_active_bits[];
 
 #if NR_CPUS > 1
 #define num_online_cpus()	cpumask_weight(cpu_online_mask)
kernel/cpu.c +20 -24

89 lines not on this page · raw message