aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Kconfig.debug8
-rw-r--r--lib/percpu_counter.c48
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 69a32664c289..0d5c762532a5 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -317,6 +317,14 @@ config DEBUG_OBJECTS_RCU_HEAD
317 help 317 help
318 Enable this to turn on debugging of RCU list heads (call_rcu() usage). 318 Enable this to turn on debugging of RCU list heads (call_rcu() usage).
319 319
320config DEBUG_OBJECTS_PERCPU_COUNTER
321 bool "Debug percpu counter objects"
322 depends on DEBUG_OBJECTS
323 help
324 If you say Y here, additional code will be inserted into the
325 percpu counter routines to track the life time of percpu counter
326 objects and validate the percpu counter operations.
327
320config DEBUG_OBJECTS_ENABLE_DEFAULT 328config DEBUG_OBJECTS_ENABLE_DEFAULT
321 int "debug_objects bootup default value (0-1)" 329 int "debug_objects bootup default value (0-1)"
322 range 0 1 330 range 0 1
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 209448e1d2b9..1d954ea72331 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -8,10 +8,53 @@
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/cpu.h> 9#include <linux/cpu.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/debugobjects.h>
11 12
12static LIST_HEAD(percpu_counters); 13static LIST_HEAD(percpu_counters);
13static DEFINE_MUTEX(percpu_counters_lock); 14static DEFINE_MUTEX(percpu_counters_lock);
14 15
16#ifdef CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER
17
18static struct debug_obj_descr percpu_counter_debug_descr;
19
20static int percpu_counter_fixup_free(void *addr, enum debug_obj_state state)
21{
22 struct percpu_counter *fbc = addr;
23
24 switch (state) {
25 case ODEBUG_STATE_ACTIVE:
26 percpu_counter_destroy(fbc);
27 debug_object_free(fbc, &percpu_counter_debug_descr);
28 return 1;
29 default:
30 return 0;
31 }
32}
33
34static struct debug_obj_descr percpu_counter_debug_descr = {
35 .name = "percpu_counter",
36 .fixup_free = percpu_counter_fixup_free,
37};
38
39static inline void debug_percpu_counter_activate(struct percpu_counter *fbc)
40{
41 debug_object_init(fbc, &percpu_counter_debug_descr);
42 debug_object_activate(fbc, &percpu_counter_debug_descr);
43}
44
45static inline void debug_percpu_counter_deactivate(struct percpu_counter *fbc)
46{
47 debug_object_deactivate(fbc, &percpu_counter_debug_descr);
48 debug_object_free(fbc, &percpu_counter_debug_descr);
49}
50
51#else /* CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER */
52static inline void debug_percpu_counter_activate(struct percpu_counter *fbc)
53{ }
54static inline void debug_percpu_counter_deactivate(struct percpu_counter *fbc)
55{ }
56#endif /* CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER */
57
15void percpu_counter_set(struct percpu_counter *fbc, s64 amount) 58void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
16{ 59{
17 int cpu; 60 int cpu;
@@ -75,6 +118,9 @@ int __percpu_counter_init(struct percpu_counter *fbc, s64 amount,
75 fbc->counters = alloc_percpu(s32); 118 fbc->counters = alloc_percpu(s32);
76 if (!fbc->counters) 119 if (!fbc->counters)
77 return -ENOMEM; 120 return -ENOMEM;
121
122 debug_percpu_counter_activate(fbc);
123
78#ifdef CONFIG_HOTPLUG_CPU 124#ifdef CONFIG_HOTPLUG_CPU
79 INIT_LIST_HEAD(&fbc->list); 125 INIT_LIST_HEAD(&fbc->list);
80 mutex_lock(&percpu_counters_lock); 126 mutex_lock(&percpu_counters_lock);
@@ -90,6 +136,8 @@ void percpu_counter_destroy(struct percpu_counter *fbc)
90 if (!fbc->counters) 136 if (!fbc->counters)
91 return; 137 return;
92 138
139 debug_percpu_counter_deactivate(fbc);
140
93#ifdef CONFIG_HOTPLUG_CPU 141#ifdef CONFIG_HOTPLUG_CPU
94 mutex_lock(&percpu_counters_lock); 142 mutex_lock(&percpu_counters_lock);
95 list_del(&fbc->list); 143 list_del(&fbc->list);