aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percpu_counter.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/percpu_counter.c')
-rw-r--r--lib/percpu_counter.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 28f2c33c6b53..f8a3f1a829b8 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -10,8 +10,10 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/debugobjects.h> 11#include <linux/debugobjects.h>
12 12
13#ifdef CONFIG_HOTPLUG_CPU
13static LIST_HEAD(percpu_counters); 14static LIST_HEAD(percpu_counters);
14static DEFINE_MUTEX(percpu_counters_lock); 15static DEFINE_MUTEX(percpu_counters_lock);
16#endif
15 17
16#ifdef CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER 18#ifdef CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER
17 19
@@ -59,13 +61,13 @@ void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
59{ 61{
60 int cpu; 62 int cpu;
61 63
62 spin_lock(&fbc->lock); 64 raw_spin_lock(&fbc->lock);
63 for_each_possible_cpu(cpu) { 65 for_each_possible_cpu(cpu) {
64 s32 *pcount = per_cpu_ptr(fbc->counters, cpu); 66 s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
65 *pcount = 0; 67 *pcount = 0;
66 } 68 }
67 fbc->count = amount; 69 fbc->count = amount;
68 spin_unlock(&fbc->lock); 70 raw_spin_unlock(&fbc->lock);
69} 71}
70EXPORT_SYMBOL(percpu_counter_set); 72EXPORT_SYMBOL(percpu_counter_set);
71 73
@@ -76,10 +78,10 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch)
76 preempt_disable(); 78 preempt_disable();
77 count = __this_cpu_read(*fbc->counters) + amount; 79 count = __this_cpu_read(*fbc->counters) + amount;
78 if (count >= batch || count <= -batch) { 80 if (count >= batch || count <= -batch) {
79 spin_lock(&fbc->lock); 81 raw_spin_lock(&fbc->lock);
80 fbc->count += count; 82 fbc->count += count;
81 __this_cpu_write(*fbc->counters, 0); 83 __this_cpu_write(*fbc->counters, 0);
82 spin_unlock(&fbc->lock); 84 raw_spin_unlock(&fbc->lock);
83 } else { 85 } else {
84 __this_cpu_write(*fbc->counters, count); 86 __this_cpu_write(*fbc->counters, count);
85 } 87 }
@@ -96,13 +98,13 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
96 s64 ret; 98 s64 ret;
97 int cpu; 99 int cpu;
98 100
99 spin_lock(&fbc->lock); 101 raw_spin_lock(&fbc->lock);
100 ret = fbc->count; 102 ret = fbc->count;
101 for_each_online_cpu(cpu) { 103 for_each_online_cpu(cpu) {
102 s32 *pcount = per_cpu_ptr(fbc->counters, cpu); 104 s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
103 ret += *pcount; 105 ret += *pcount;
104 } 106 }
105 spin_unlock(&fbc->lock); 107 raw_spin_unlock(&fbc->lock);
106 return ret; 108 return ret;
107} 109}
108EXPORT_SYMBOL(__percpu_counter_sum); 110EXPORT_SYMBOL(__percpu_counter_sum);
@@ -110,7 +112,7 @@ EXPORT_SYMBOL(__percpu_counter_sum);
110int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, 112int __percpu_counter_init(struct percpu_counter *fbc, s64 amount,
111 struct lock_class_key *key) 113 struct lock_class_key *key)
112{ 114{
113 spin_lock_init(&fbc->lock); 115 raw_spin_lock_init(&fbc->lock);
114 lockdep_set_class(&fbc->lock, key); 116 lockdep_set_class(&fbc->lock, key);
115 fbc->count = amount; 117 fbc->count = amount;
116 fbc->counters = alloc_percpu(s32); 118 fbc->counters = alloc_percpu(s32);
@@ -173,11 +175,11 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
173 s32 *pcount; 175 s32 *pcount;
174 unsigned long flags; 176 unsigned long flags;
175 177
176 spin_lock_irqsave(&fbc->lock, flags); 178 raw_spin_lock_irqsave(&fbc->lock, flags);
177 pcount = per_cpu_ptr(fbc->counters, cpu); 179 pcount = per_cpu_ptr(fbc->counters, cpu);
178 fbc->count += *pcount; 180 fbc->count += *pcount;
179 *pcount = 0; 181 *pcount = 0;
180 spin_unlock_irqrestore(&fbc->lock, flags); 182 raw_spin_unlock_irqrestore(&fbc->lock, flags);
181 } 183 }
182 mutex_unlock(&percpu_counters_lock); 184 mutex_unlock(&percpu_counters_lock);
183#endif 185#endif