Revision 918d3f90e8d5657491024f64427e9a5ea632d284 authored by Shantanu Goel on 30 December 2006, 00:48:59 UTC, committed by Linus Torvalds on 30 December 2006, 18:56:43 UTC
Fix a rather obvious buglet. Noticed while instrumenting the VM using /proc/vmstat. Cc: Christoph Lameter <clameter@engr.sgi.com> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 463cab3
percpu_counter.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);
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...