forked from microsoft/WSL2-Linux-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] percpu_counters: create lib/percpu_counter.c
- Move percpu_counter routines from mm/swap.c to lib/percpu_counter.c Signed-off-by: Ravikiran Thirumalai <kiran@scalex86.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
- Loading branch information
Ravikiran G Thirumalai
authored and
Linus Torvalds
committed
Jun 23, 2006
1 parent
d09042d
commit 3cbc564
Showing
3 changed files
with
47 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Fast batching percpu counters. | ||
*/ | ||
|
||
#include <linux/percpu_counter.h> | ||
#include <linux/module.h> | ||
|
||
void percpu_counter_mod(struct percpu_counter *fbc, long amount) | ||
{ | ||
long count; | ||
long *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() | ||
*/ | ||
long percpu_counter_sum(struct percpu_counter *fbc) | ||
{ | ||
long ret; | ||
int cpu; | ||
|
||
spin_lock(&fbc->lock); | ||
ret = fbc->count; | ||
for_each_possible_cpu(cpu) { | ||
long *pcount = per_cpu_ptr(fbc->counters, cpu); | ||
ret += *pcount; | ||
} | ||
spin_unlock(&fbc->lock); | ||
return ret < 0 ? 0 : ret; | ||
} | ||
EXPORT_SYMBOL(percpu_counter_sum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters