[RFC 05/13] cpumask: add get_cpumask_var debug operations

From: Mike Travis
Date: Sat Sep 06 2008 - 19:52:09 EST


* Adds debugging to the get_cpumask_var operations. It uses a primitive
per_cpu lock variable and will only discover nested get_cpumask_var
operations on the same variable.

Applies to linux-2.6.tip/master.

Signed-off-by: Mike Travis <travis@xxxxxxx>
---
arch/x86/Kconfig.debug | 12 ++++++++++++
include/linux/cpumask_ptr.h | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)

--- linux-2.6.tip.orig/arch/x86/Kconfig.debug
+++ linux-2.6.tip/arch/x86/Kconfig.debug
@@ -92,6 +92,18 @@ config DEBUG_PER_CPU_MAPS

Say N if unsure.

+config DEBUG_PER_CPUMASK_VAR
+ bool "Debug per_cpumask variables"
+ depends on DEBUG_KERNEL
+ depends on X86_SMP
+ default n
+ help
+ Say Y to verify that the per_cpumask variables being accessed
+ are available. Adds a fair amount of code to kernel memory
+ and decreases performance.
+
+ Say N if unsure.
+
config X86_PTDUMP
bool "Export kernel pagetable layout to userspace via debugfs"
depends on DEBUG_KERNEL
--- linux-2.6.tip.orig/include/linux/cpumask_ptr.h
+++ linux-2.6.tip/include/linux/cpumask_ptr.h
@@ -53,11 +53,45 @@ static inline void free_cpumask_ptr(cpum
{
kfree(*p);
}
+
+#ifndef CONFIG_DEBUG_CPUMASK_VAR
#define DEFINE_PER_CPUMASK(v) DEFINE_PER_CPU(cpumask_t, v)
#define DECLARE_PER_CPUMASK(v) DECLARE_PER_CPU(cpumask_t, v)
#define get_cpumask_var(p, v) _get_cpumask_ptr(&(p), &get_cpu_var(v))
#define put_cpumask_var(p, v) put_cpu_var(v)

+#else /* CONFIG_DEBUG_CPUMASK_VAR */
+#define DEFINE_PER_CPUMASK(v) DEFINE_PER_CPU(cpumask_t, v); \
+ DEFINE_PER_CPU(char, lock_##v)
+#define DECLARE_PER_CPUMASK(v) DECLARE_PER_CPU(cpumask_t, v); \
+ DECLARE_PER_CPU(char, lock_##v)
+
+#define get_cpumask_var(p, v) { \
+ char *lock = &get_cpu_var(lock_##v); \
+ if (*lock) { \
+ printk(KERN_NOTICE "get_cpumask_var(" v "): " \
+ "already locked!\n"); \
+ dump_stack(); \
+ BUG(); \
+ } \
+ *lock = 1; \
+ _get_cpumask_ptr(&(p), &get_cpu_var(v)) \
+ put_cpu_var(lock_##v); \
+}
+
+#define put_cpumask_var(p, v) { \
+ char *lock = &get_cpu_var(lock_##v); \
+ if (!*lock) { \
+ printk(KERN_NOTICE "put_cpumask_var(" v "): " \
+ "not locked!\n"); \
+ dump_stack(); \
+ } \
+ *lock = 0; \
+ put_cpu_var(lock_##v); \
+ put_cpu_var(v); \
+}
+#endif /* CONFIG_DEBUG_CPUMASK_VAR */
+
#endif /* NR_CPUS > BITS_PER_LONG */

#endif /* __LINUX_CPUMASK_PTR_H */

--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/