aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-01-29 06:54:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-01-29 06:54:01 -0500
commit0ba6c33bcddc64a54b5f1c25a696c4767dc76292 (patch)
tree62e616f97a4762d8e75bf732e4827af2d15d52c5 /lib
parent21af0297c7e56024a5ccc4d8ad2a590f9ec371ba (diff)
parent85040bcb4643cba578839e953f25e2d1965d83d0 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.25
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.25: (1470 commits) [IPV6] ADDRLABEL: Fix double free on label deletion. [PPP]: Sparse warning fixes. [IPV4] fib_trie: remove unneeded NULL check [IPV4] fib_trie: More whitespace cleanup. [NET_SCHED]: Use nla_policy for attribute validation in ematches [NET_SCHED]: Use nla_policy for attribute validation in actions [NET_SCHED]: Use nla_policy for attribute validation in classifiers [NET_SCHED]: Use nla_policy for attribute validation in packet schedulers [NET_SCHED]: sch_api: introduce constant for rate table size [NET_SCHED]: Use typeful attribute parsing helpers [NET_SCHED]: Use typeful attribute construction helpers [NET_SCHED]: Use NLA_PUT_STRING for string dumping [NET_SCHED]: Use nla_nest_start/nla_nest_end [NET_SCHED]: Propagate nla_parse return value [NET_SCHED]: act_api: use PTR_ERR in tcf_action_init/tcf_action_get [NET_SCHED]: act_api: use nlmsg_parse [NET_SCHED]: act_api: fix netlink API conversion bug [NET_SCHED]: sch_netem: use nla_parse_nested_compat [NET_SCHED]: sch_atm: fix format string warning [NETNS]: Add namespace for ICMP replying code. ...
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile1
-rw-r--r--lib/pcounter.c58
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 89841dc9d91c..543f2502b60a 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
61obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o 61obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o
62obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o 62obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o
63obj-$(CONFIG_SMP) += percpu_counter.o 63obj-$(CONFIG_SMP) += percpu_counter.o
64obj-$(CONFIG_SMP) += pcounter.o
64obj-$(CONFIG_AUDIT_GENERIC) += audit.o 65obj-$(CONFIG_AUDIT_GENERIC) += audit.o
65 66
66obj-$(CONFIG_SWIOTLB) += swiotlb.o 67obj-$(CONFIG_SWIOTLB) += swiotlb.o
diff --git a/lib/pcounter.c b/lib/pcounter.c
new file mode 100644
index 000000000000..9b56807da93b
--- /dev/null
+++ b/lib/pcounter.c
@@ -0,0 +1,58 @@
1/*
2 * Define default pcounter functions
3 * Note that often used pcounters use dedicated functions to get a speed increase.
4 * (see DEFINE_PCOUNTER/REF_PCOUNTER_MEMBER)
5 */
6
7#include <linux/module.h>
8#include <linux/pcounter.h>
9#include <linux/smp.h>
10#include <linux/cpumask.h>
11
12static void pcounter_dyn_add(struct pcounter *self, int inc)
13{
14 per_cpu_ptr(self->per_cpu_values, smp_processor_id())[0] += inc;
15}
16
17static int pcounter_dyn_getval(const struct pcounter *self, int cpu)
18{
19 return per_cpu_ptr(self->per_cpu_values, cpu)[0];
20}
21
22int pcounter_getval(const struct pcounter *self)
23{
24 int res = 0, cpu;
25
26 for_each_possible_cpu(cpu)
27 res += self->getval(self, cpu);
28
29 return res;
30}
31EXPORT_SYMBOL_GPL(pcounter_getval);
32
33int pcounter_alloc(struct pcounter *self)
34{
35 int rc = 0;
36 if (self->add == NULL) {
37 self->per_cpu_values = alloc_percpu(int);
38 if (self->per_cpu_values != NULL) {
39 self->add = pcounter_dyn_add;
40 self->getval = pcounter_dyn_getval;
41 } else
42 rc = 1;
43 }
44 return rc;
45}
46EXPORT_SYMBOL_GPL(pcounter_alloc);
47
48void pcounter_free(struct pcounter *self)
49{
50 if (self->per_cpu_values != NULL) {
51 free_percpu(self->per_cpu_values);
52 self->per_cpu_values = NULL;
53 self->getval = NULL;
54 self->add = NULL;
55 }
56}
57EXPORT_SYMBOL_GPL(pcounter_free);
58