mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
![Mingming Cao](/assets/img/avatar_default.png)
The percpu counter data type are changed in this set of patches to support more users like ext3 who need more than 32 bit to store the free blocks total in the filesystem. - Generic perpcu counters data type changes. The size of the global counter and local counter were explictly specified using s64 and s32. The global counter is changed from long to s64, while the local counter is changed from long to s32, so we could avoid doing 64 bit update in most cases. - Users of the percpu counters are updated to make use of the new percpu_counter_init() routine now taking an additional parameter to allow users to pass the initial value of the global counter. Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
46 lines
964 B
C
46 lines
964 B
C
/*
|
|
* Fast batching percpu counters.
|
|
*/
|
|
|
|
#include <linux/percpu_counter.h>
|
|
#include <linux/module.h>
|
|
|
|
void percpu_counter_mod(struct percpu_counter *fbc, s32 amount)
|
|
{
|
|
long count;
|
|
s32 *pcount;
|
|
int cpu = get_cpu();
|
|
|
|
pcount = per_cpu_ptr(fbc->counters, cpu);
|
|
count = *pcount + amount;
|
|
if (count >= FBC_BATCH || count <= -FBC_BATCH) {
|
|
spin_lock(&fbc->lock);
|
|
fbc->count += count;
|
|
*pcount = 0;
|
|
spin_unlock(&fbc->lock);
|
|
} else {
|
|
*pcount = count;
|
|
}
|
|
put_cpu();
|
|
}
|
|
EXPORT_SYMBOL(percpu_counter_mod);
|
|
|
|
/*
|
|
* Add up all the per-cpu counts, return the result. This is a more accurate
|
|
* but much slower version of percpu_counter_read_positive()
|
|
*/
|
|
s64 percpu_counter_sum(struct percpu_counter *fbc)
|
|
{
|
|
s64 ret;
|
|
int cpu;
|
|
|
|
spin_lock(&fbc->lock);
|
|
ret = fbc->count;
|
|
for_each_possible_cpu(cpu) {
|
|
s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
|
|
ret += *pcount;
|
|
}
|
|
spin_unlock(&fbc->lock);
|
|
return ret < 0 ? 0 : ret;
|
|
}
|
|
EXPORT_SYMBOL(percpu_counter_sum);
|