aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2008-03-28 19:38:43 -0400
committerDavid S. Miller <davem@davemloft.net>2008-03-28 19:38:43 -0400
commit1338d466d9c3f8a65cc6d83c629cd906f2a989f8 (patch)
tree2f30913c1c9c6d3c0616ac593e79b0431cc150d3 /net/core
parent13ff3d6fa4e6d8b6ee7c64245a0078e6a0e6f977 (diff)
[SOCK]: Introduce a percpu inuse counters array (v2).
And redirect sock_prot_inuse_add and _get to use one. As far as the dereferences are concerned. Before the patch we made 1 dereference to proto->inuse.add call, the call itself and then called the __get_cpu_var() on a static variable. After the patch we make a direct call, then one dereference to proto->inuse_idx and then the same __get_cpu_var() on a still static variable. So this patch doesn't seem to produce performance penalty on SMP. This is not per-net yet, but I will deliberately make NET_NS=y case separated from NET_NS=n one, since it'll cost us one-or-two more dereferences to get the struct net and the inuse counter. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Acked-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/sock.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index 7d2c8add5f5a..174c64bc7a43 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1942,8 +1942,30 @@ static LIST_HEAD(proto_list);
1942 1942
1943#ifdef CONFIG_PROC_FS 1943#ifdef CONFIG_PROC_FS
1944#define PROTO_INUSE_NR 64 /* should be enough for the first time */ 1944#define PROTO_INUSE_NR 64 /* should be enough for the first time */
1945struct prot_inuse {
1946 int val[PROTO_INUSE_NR];
1947};
1945 1948
1946static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR); 1949static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
1950static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
1951
1952void sock_prot_inuse_add(struct proto *prot, int val)
1953{
1954 __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
1955}
1956EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
1957
1958int sock_prot_inuse_get(struct proto *prot)
1959{
1960 int cpu, idx = prot->inuse_idx;
1961 int res = 0;
1962
1963 for_each_possible_cpu(cpu)
1964 res += per_cpu(prot_inuse, cpu).val[idx];
1965
1966 return res >= 0 ? res : 0;
1967}
1968EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
1947 1969
1948static void assign_proto_idx(struct proto *prot) 1970static void assign_proto_idx(struct proto *prot)
1949{ 1971{