diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-29 22:54:01 +1100 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-29 22:54:01 +1100 |
commit | 0ba6c33bcddc64a54b5f1c25a696c4767dc76292 (patch) | |
tree | 62e616f97a4762d8e75bf732e4827af2d15d52c5 /lib | |
parent | 21af0297c7e56024a5ccc4d8ad2a590f9ec371ba (diff) | |
parent | 85040bcb4643cba578839e953f25e2d1965d83d0 (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/Makefile | 1 | ||||
-rw-r--r-- | lib/pcounter.c | 58 |
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 obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o +obj-$(CONFIG_SMP) += pcounter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o obj-$(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 @@ +/* + * Define default pcounter functions + * Note that often used pcounters use dedicated functions to get a speed increase. + * (see DEFINE_PCOUNTER/REF_PCOUNTER_MEMBER) + */ + +#include <linux/module.h> +#include <linux/pcounter.h> +#include <linux/smp.h> +#include <linux/cpumask.h> + +static void pcounter_dyn_add(struct pcounter *self, int inc) +{ + per_cpu_ptr(self->per_cpu_values, smp_processor_id())[0] += inc; +} + +static int pcounter_dyn_getval(const struct pcounter *self, int cpu) +{ + return per_cpu_ptr(self->per_cpu_values, cpu)[0]; +} + +int pcounter_getval(const struct pcounter *self) +{ + int res = 0, cpu; + + for_each_possible_cpu(cpu) + res += self->getval(self, cpu); + + return res; +} +EXPORT_SYMBOL_GPL(pcounter_getval); + +int pcounter_alloc(struct pcounter *self) +{ + int rc = 0; + if (self->add == NULL) { + self->per_cpu_values = alloc_percpu(int); + if (self->per_cpu_values != NULL) { + self->add = pcounter_dyn_add; + self->getval = pcounter_dyn_getval; + } else + rc = 1; + } + return rc; +} +EXPORT_SYMBOL_GPL(pcounter_alloc); + +void pcounter_free(struct pcounter *self) +{ + if (self->per_cpu_values != NULL) { + free_percpu(self->per_cpu_values); + self->per_cpu_values = NULL; + self->getval = NULL; + self->add = NULL; + } +} +EXPORT_SYMBOL_GPL(pcounter_free); + |