2 * Fast batching percpu counters.
5 #include <linux/percpu_counter.h>
6 #include <linux/module.h>
8 void percpu_counter_mod(struct percpu_counter
*fbc
, s32 amount
)
14 pcount
= per_cpu_ptr(fbc
->counters
, cpu
);
15 count
= *pcount
+ amount
;
16 if (count
>= FBC_BATCH
|| count
<= -FBC_BATCH
) {
17 spin_lock(&fbc
->lock
);
20 spin_unlock(&fbc
->lock
);
26 EXPORT_SYMBOL(percpu_counter_mod
);
29 * Add up all the per-cpu counts, return the result. This is a more accurate
30 * but much slower version of percpu_counter_read_positive()
32 s64
percpu_counter_sum(struct percpu_counter
*fbc
)
37 spin_lock(&fbc
->lock
);
39 for_each_possible_cpu(cpu
) {
40 s32
*pcount
= per_cpu_ptr(fbc
->counters
, cpu
);
43 spin_unlock(&fbc
->lock
);
44 return ret
< 0 ? 0 : ret
;
46 EXPORT_SYMBOL(percpu_counter_sum
);