aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/sock.h
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2007-11-21 09:08:50 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:54:40 -0500
commitebb53d75657f86587ac8cf3e38ab0c860a8e3d4f (patch)
tree2b1d63cb8ee54b19589d6d13a693147001e642ad /include/net/sock.h
parentde4d1db369785c29d68915edfee0cb70e8199f4c (diff)
[NET] proto: Use pcounters for the inuse field
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/sock.h')
-rw-r--r--include/net/sock.h59
1 files changed, 8 insertions, 51 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 9c55af8e5f81..e329d05f7995 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -47,6 +47,7 @@
47#include <linux/module.h> 47#include <linux/module.h>
48#include <linux/lockdep.h> 48#include <linux/lockdep.h>
49#include <linux/netdevice.h> 49#include <linux/netdevice.h>
50#include <linux/pcounter.h>
50#include <linux/skbuff.h> /* struct sk_buff */ 51#include <linux/skbuff.h> /* struct sk_buff */
51#include <linux/mm.h> 52#include <linux/mm.h>
52#include <linux/security.h> 53#include <linux/security.h>
@@ -565,14 +566,9 @@ struct proto {
565 void (*unhash)(struct sock *sk); 566 void (*unhash)(struct sock *sk);
566 int (*get_port)(struct sock *sk, unsigned short snum); 567 int (*get_port)(struct sock *sk, unsigned short snum);
567 568
568#ifdef CONFIG_SMP
569 /* Keeping track of sockets in use */ 569 /* Keeping track of sockets in use */
570 void (*inuse_add)(struct proto *prot, int inc); 570 struct pcounter inuse;
571 int (*inuse_getval)(const struct proto *prot); 571
572 int *inuse_ptr;
573#else
574 int inuse;
575#endif
576 /* Memory pressure */ 572 /* Memory pressure */
577 void (*enter_memory_pressure)(void); 573 void (*enter_memory_pressure)(void);
578 atomic_t *memory_allocated; /* Current allocated memory. */ 574 atomic_t *memory_allocated; /* Current allocated memory. */
@@ -607,35 +603,8 @@ struct proto {
607#endif 603#endif
608}; 604};
609 605
610/* 606#define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME)
611 * Special macros to let protos use a fast version of inuse{get|add} 607#define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse)
612 * using a static percpu variable per proto instead of an allocated one,
613 * saving one dereference.
614 * This might be changed if/when dynamic percpu vars become fast.
615 */
616#ifdef CONFIG_SMP
617# define DEFINE_PROTO_INUSE(NAME) \
618static DEFINE_PER_CPU(int, NAME##_inuse); \
619static void NAME##_inuse_add(struct proto *prot, int inc) \
620{ \
621 __get_cpu_var(NAME##_inuse) += inc; \
622} \
623 \
624static int NAME##_inuse_getval(const struct proto *prot)\
625{ \
626 int res = 0, cpu; \
627 \
628 for_each_possible_cpu(cpu) \
629 res += per_cpu(NAME##_inuse, cpu); \
630 return res; \
631}
632# define REF_PROTO_INUSE(NAME) \
633 .inuse_add = NAME##_inuse_add, \
634 .inuse_getval = NAME##_inuse_getval,
635#else
636# define DEFINE_PROTO_INUSE(NAME)
637# define REF_PROTO_INUSE(NAME)
638#endif
639 608
640extern int proto_register(struct proto *prot, int alloc_slab); 609extern int proto_register(struct proto *prot, int alloc_slab);
641extern void proto_unregister(struct proto *prot); 610extern void proto_unregister(struct proto *prot);
@@ -668,29 +637,17 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
668/* Called with local bh disabled */ 637/* Called with local bh disabled */
669static __inline__ void sock_prot_inc_use(struct proto *prot) 638static __inline__ void sock_prot_inc_use(struct proto *prot)
670{ 639{
671#ifdef CONFIG_SMP 640 pcounter_add(&prot->inuse, 1);
672 prot->inuse_add(prot, 1);
673#else
674 prot->inuse++;
675#endif
676} 641}
677 642
678static __inline__ void sock_prot_dec_use(struct proto *prot) 643static __inline__ void sock_prot_dec_use(struct proto *prot)
679{ 644{
680#ifdef CONFIG_SMP 645 pcounter_add(&prot->inuse, -1);
681 prot->inuse_add(prot, -1);
682#else
683 prot->inuse--;
684#endif
685} 646}
686 647
687static __inline__ int sock_prot_inuse(struct proto *proto) 648static __inline__ int sock_prot_inuse(struct proto *proto)
688{ 649{
689#ifdef CONFIG_SMP 650 return pcounter_getval(&proto->inuse);
690 return proto->inuse_getval(proto);
691#else
692 return proto->inuse;
693#endif
694} 651}
695 652
696/* With per-bucket locks this operation is not-atomic, so that 653/* With per-bucket locks this operation is not-atomic, so that