aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/sock.h13
-rw-r--r--net/core/sock.c22
2 files changed, 27 insertions, 8 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index abc6341f536f..ebf9552664b2 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -639,18 +639,15 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
639# define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME) 639# define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME)
640# define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse) 640# define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse)
641/* Called with local bh disabled */ 641/* Called with local bh disabled */
642static inline void sock_prot_inuse_add(struct proto *prot, int inc) 642extern void sock_prot_inuse_add(struct proto *prot, int inc);
643{ 643
644 pcounter_add(&prot->inuse, inc);
645}
646static inline int sock_prot_inuse_init(struct proto *proto) 644static inline int sock_prot_inuse_init(struct proto *proto)
647{ 645{
648 return pcounter_alloc(&proto->inuse); 646 return pcounter_alloc(&proto->inuse);
649} 647}
650static inline int sock_prot_inuse_get(struct proto *proto) 648
651{ 649extern int sock_prot_inuse_get(struct proto *proto);
652 return pcounter_getval(&proto->inuse); 650
653}
654static inline void sock_prot_inuse_free(struct proto *proto) 651static inline void sock_prot_inuse_free(struct proto *proto)
655{ 652{
656 pcounter_free(&proto->inuse); 653 pcounter_free(&proto->inuse);
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{