diff options
Diffstat (limited to 'lib/percpu_counter.c')
-rw-r--r-- | lib/percpu_counter.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index b255b939bc1b..a60bd8046095 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 | ||
13 | static LIST_HEAD(percpu_counters); | 12 | static LIST_HEAD(percpu_counters); |
14 | static DEFINE_MUTEX(percpu_counters_lock); | 13 | static DEFINE_MUTEX(percpu_counters_lock); |
15 | #endif | ||
16 | 14 | ||
17 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount) | 15 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount) |
18 | { | 16 | { |
@@ -111,13 +109,24 @@ void percpu_counter_destroy(struct percpu_counter *fbc) | |||
111 | } | 109 | } |
112 | EXPORT_SYMBOL(percpu_counter_destroy); | 110 | EXPORT_SYMBOL(percpu_counter_destroy); |
113 | 111 | ||
114 | #ifdef CONFIG_HOTPLUG_CPU | 112 | int percpu_counter_batch __read_mostly = 32; |
113 | EXPORT_SYMBOL(percpu_counter_batch); | ||
114 | |||
115 | static void compute_batch_value(void) | ||
116 | { | ||
117 | int nr = num_online_cpus(); | ||
118 | |||
119 | percpu_counter_batch = max(32, nr*2); | ||
120 | } | ||
121 | |||
115 | static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, | 122 | static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, |
116 | unsigned long action, void *hcpu) | 123 | unsigned long action, void *hcpu) |
117 | { | 124 | { |
125 | #ifdef CONFIG_HOTPLUG_CPU | ||
118 | unsigned int cpu; | 126 | unsigned int cpu; |
119 | struct percpu_counter *fbc; | 127 | struct percpu_counter *fbc; |
120 | 128 | ||
129 | compute_batch_value(); | ||
121 | if (action != CPU_DEAD) | 130 | if (action != CPU_DEAD) |
122 | return NOTIFY_OK; | 131 | return NOTIFY_OK; |
123 | 132 | ||
@@ -134,13 +143,14 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, | |||
134 | spin_unlock_irqrestore(&fbc->lock, flags); | 143 | spin_unlock_irqrestore(&fbc->lock, flags); |
135 | } | 144 | } |
136 | mutex_unlock(&percpu_counters_lock); | 145 | mutex_unlock(&percpu_counters_lock); |
146 | #endif | ||
137 | return NOTIFY_OK; | 147 | return NOTIFY_OK; |
138 | } | 148 | } |
139 | 149 | ||
140 | static int __init percpu_counter_startup(void) | 150 | static int __init percpu_counter_startup(void) |
141 | { | 151 | { |
152 | compute_batch_value(); | ||
142 | hotcpu_notifier(percpu_counter_hotcpu_callback, 0); | 153 | hotcpu_notifier(percpu_counter_hotcpu_callback, 0); |
143 | return 0; | 154 | return 0; |
144 | } | 155 | } |
145 | module_init(percpu_counter_startup); | 156 | module_init(percpu_counter_startup); |
146 | #endif | ||