diff options
Diffstat (limited to 'lib/percpu_counter.c')
-rw-r--r-- | lib/percpu_counter.c | 36 |
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 | ||
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 | { |
@@ -68,11 +66,11 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc) | |||
68 | } | 66 | } |
69 | EXPORT_SYMBOL(__percpu_counter_sum); | 67 | EXPORT_SYMBOL(__percpu_counter_sum); |
70 | 68 | ||
71 | static struct lock_class_key percpu_counter_irqsafe; | 69 | int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, |
72 | 70 | struct lock_class_key *key) | |
73 | int 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 | } |
87 | EXPORT_SYMBOL(percpu_counter_init); | 85 | EXPORT_SYMBOL(__percpu_counter_init); |
88 | |||
89 | int 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 | ||
99 | void percpu_counter_destroy(struct percpu_counter *fbc) | 87 | void percpu_counter_destroy(struct percpu_counter *fbc) |
100 | { | 88 | { |
@@ -111,13 +99,24 @@ void percpu_counter_destroy(struct percpu_counter *fbc) | |||
111 | } | 99 | } |
112 | EXPORT_SYMBOL(percpu_counter_destroy); | 100 | EXPORT_SYMBOL(percpu_counter_destroy); |
113 | 101 | ||
114 | #ifdef CONFIG_HOTPLUG_CPU | 102 | int percpu_counter_batch __read_mostly = 32; |
103 | EXPORT_SYMBOL(percpu_counter_batch); | ||
104 | |||
105 | static void compute_batch_value(void) | ||
106 | { | ||
107 | int nr = num_online_cpus(); | ||
108 | |||
109 | percpu_counter_batch = max(32, nr*2); | ||
110 | } | ||
111 | |||
115 | static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, | 112 | static 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 | ||
140 | static int __init percpu_counter_startup(void) | 140 | static 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 | } |
145 | module_init(percpu_counter_startup); | 146 | module_init(percpu_counter_startup); |
146 | #endif | ||