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.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index b255b939bc1b..aeaa6d734447 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -9,10 +9,8 @@
9#include <linux/cpu.h> 9#include <linux/cpu.h>
10#include <linux/module.h> 10#include <linux/module.h>
11 11
12#ifdef CONFIG_HOTPLUG_CPU
13static LIST_HEAD(percpu_counters); 12static LIST_HEAD(percpu_counters);
14static DEFINE_MUTEX(percpu_counters_lock); 13static DEFINE_MUTEX(percpu_counters_lock);
15#endif
16 14
17void percpu_counter_set(struct percpu_counter *fbc, s64 amount) 15void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
18{ 16{
@@ -68,11 +66,11 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)
68} 66}
69EXPORT_SYMBOL(__percpu_counter_sum); 67EXPORT_SYMBOL(__percpu_counter_sum);
70 68
71static struct lock_class_key percpu_counter_irqsafe; 69int __percpu_counter_init(struct percpu_counter *fbc, s64 amount,
72 70 struct lock_class_key *key)
73int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
74{ 71{
75 spin_lock_init(&fbc->lock); 72 spin_lock_init(&fbc->lock);
73 lockdep_set_class(&fbc->lock, key);
76 fbc->count = amount; 74 fbc->count = amount;
77 fbc->counters = alloc_percpu(s32); 75 fbc->counters = alloc_percpu(s32);
78 if (!fbc->counters) 76 if (!fbc->counters)
@@ -84,17 +82,7 @@ int percpu_counter_init(struct percpu_counter *fbc, s64 amount)
84#endif 82#endif
85 return 0; 83 return 0;
86} 84}
87EXPORT_SYMBOL(percpu_counter_init); 85EXPORT_SYMBOL(__percpu_counter_init);
88
89int percpu_counter_init_irq(struct percpu_counter *fbc, s64 amount)
90{
91 int err;
92
93 err = percpu_counter_init(fbc, amount);
94 if (!err)
95 lockdep_set_class(&fbc->lock, &percpu_counter_irqsafe);
96 return err;
97}
98 86
99void percpu_counter_destroy(struct percpu_counter *fbc) 87void percpu_counter_destroy(struct percpu_counter *fbc)
100{ 88{
@@ -111,13 +99,24 @@ void percpu_counter_destroy(struct percpu_counter *fbc)
111} 99}
112EXPORT_SYMBOL(percpu_counter_destroy); 100EXPORT_SYMBOL(percpu_counter_destroy);
113 101
114#ifdef CONFIG_HOTPLUG_CPU 102int percpu_counter_batch __read_mostly = 32;
103EXPORT_SYMBOL(percpu_counter_batch);
104
105static void compute_batch_value(void)
106{
107 int nr = num_online_cpus();
108
109 percpu_counter_batch = max(32, nr*2);
110}
111
115static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, 112static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
116 unsigned long action, void *hcpu) 113 unsigned long action, void *hcpu)
117{ 114{
115#ifdef CONFIG_HOTPLUG_CPU
118 unsigned int cpu; 116 unsigned int cpu;
119 struct percpu_counter *fbc; 117 struct percpu_counter *fbc;
120 118
119 compute_batch_value();
121 if (action != CPU_DEAD) 120 if (action != CPU_DEAD)
122 return NOTIFY_OK; 121 return NOTIFY_OK;
123 122
@@ -134,13 +133,14 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
134 spin_unlock_irqrestore(&fbc->lock, flags); 133 spin_unlock_irqrestore(&fbc->lock, flags);
135 } 134 }
136 mutex_unlock(&percpu_counters_lock); 135 mutex_unlock(&percpu_counters_lock);
136#endif
137 return NOTIFY_OK; 137 return NOTIFY_OK;
138} 138}
139 139
140static int __init percpu_counter_startup(void) 140static int __init percpu_counter_startup(void)
141{ 141{
142 compute_batch_value();
142 hotcpu_notifier(percpu_counter_hotcpu_callback, 0); 143 hotcpu_notifier(percpu_counter_hotcpu_callback, 0);
143 return 0; 144 return 0;
144} 145}
145module_init(percpu_counter_startup); 146module_init(percpu_counter_startup);
146#endif