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.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index a8663890a88c..4bb0ed350e73 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -62,20 +62,17 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
62 for_each_online_cpu(cpu) { 62 for_each_online_cpu(cpu) {
63 s32 *pcount = per_cpu_ptr(fbc->counters, cpu); 63 s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
64 ret += *pcount; 64 ret += *pcount;
65 *pcount = 0;
66 } 65 }
67 fbc->count = ret;
68
69 spin_unlock(&fbc->lock); 66 spin_unlock(&fbc->lock);
70 return ret; 67 return ret;
71} 68}
72EXPORT_SYMBOL(__percpu_counter_sum); 69EXPORT_SYMBOL(__percpu_counter_sum);
73 70
74static struct lock_class_key percpu_counter_irqsafe; 71int __percpu_counter_init(struct percpu_counter *fbc, s64 amount,
75 72 struct lock_class_key *key)
76int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
77{ 73{
78 spin_lock_init(&fbc->lock); 74 spin_lock_init(&fbc->lock);
75 lockdep_set_class(&fbc->lock, key);
79 fbc->count = amount; 76 fbc->count = amount;
80 fbc->counters = alloc_percpu(s32); 77 fbc->counters = alloc_percpu(s32);
81 if (!fbc->counters) 78 if (!fbc->counters)
@@ -87,30 +84,20 @@ int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
87#endif 84#endif
88 return 0; 85 return 0;
89} 86}
90EXPORT_SYMBOL(percpu_counter_init); 87EXPORT_SYMBOL(__percpu_counter_init);
91
92int percpu_counter_init_irq(struct percpu_counter *fbc, s64 amount)
93{
94 int err;
95
96 err = percpu_counter_init(fbc, amount);
97 if (!err)
98 lockdep_set_class(&fbc->lock, &percpu_counter_irqsafe);
99 return err;
100}
101 88
102void percpu_counter_destroy(struct percpu_counter *fbc) 89void percpu_counter_destroy(struct percpu_counter *fbc)
103{ 90{
104 if (!fbc->counters) 91 if (!fbc->counters)
105 return; 92 return;
106 93
107 free_percpu(fbc->counters);
108 fbc->counters = NULL;
109#ifdef CONFIG_HOTPLUG_CPU 94#ifdef CONFIG_HOTPLUG_CPU
110 mutex_lock(&percpu_counters_lock); 95 mutex_lock(&percpu_counters_lock);
111 list_del(&fbc->list); 96 list_del(&fbc->list);
112 mutex_unlock(&percpu_counters_lock); 97 mutex_unlock(&percpu_counters_lock);
113#endif 98#endif
99 free_percpu(fbc->counters);
100 fbc->counters = NULL;
114} 101}
115EXPORT_SYMBOL(percpu_counter_destroy); 102EXPORT_SYMBOL(percpu_counter_destroy);
116 103