diff options
Diffstat (limited to 'include/net/sock.h')
-rw-r--r-- | include/net/sock.h | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 20de3fa7ae40..5504fb9fa88a 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -560,6 +560,14 @@ struct proto { | |||
560 | void (*unhash)(struct sock *sk); | 560 | void (*unhash)(struct sock *sk); |
561 | int (*get_port)(struct sock *sk, unsigned short snum); | 561 | int (*get_port)(struct sock *sk, unsigned short snum); |
562 | 562 | ||
563 | #ifdef CONFIG_SMP | ||
564 | /* Keeping track of sockets in use */ | ||
565 | void (*inuse_add)(struct proto *prot, int inc); | ||
566 | int (*inuse_getval)(const struct proto *prot); | ||
567 | int *inuse_ptr; | ||
568 | #else | ||
569 | int inuse; | ||
570 | #endif | ||
563 | /* Memory pressure */ | 571 | /* Memory pressure */ |
564 | void (*enter_memory_pressure)(void); | 572 | void (*enter_memory_pressure)(void); |
565 | atomic_t *memory_allocated; /* Current allocated memory. */ | 573 | atomic_t *memory_allocated; /* Current allocated memory. */ |
@@ -592,12 +600,38 @@ struct proto { | |||
592 | #ifdef SOCK_REFCNT_DEBUG | 600 | #ifdef SOCK_REFCNT_DEBUG |
593 | atomic_t socks; | 601 | atomic_t socks; |
594 | #endif | 602 | #endif |
595 | struct { | ||
596 | int inuse; | ||
597 | u8 __pad[SMP_CACHE_BYTES - sizeof(int)]; | ||
598 | } stats[NR_CPUS]; | ||
599 | }; | 603 | }; |
600 | 604 | ||
605 | /* | ||
606 | * Special macros to let protos use a fast version of inuse{get|add} | ||
607 | * using a static percpu variable per proto instead of an allocated one, | ||
608 | * saving one dereference. | ||
609 | * This might be changed if/when dynamic percpu vars become fast. | ||
610 | */ | ||
611 | #ifdef CONFIG_SMP | ||
612 | # define DEFINE_PROTO_INUSE(NAME) \ | ||
613 | static DEFINE_PER_CPU(int, NAME##_inuse); \ | ||
614 | static void NAME##_inuse_add(struct proto *prot, int inc) \ | ||
615 | { \ | ||
616 | __get_cpu_var(NAME##_inuse) += inc; \ | ||
617 | } \ | ||
618 | \ | ||
619 | static int NAME##_inuse_getval(const struct proto *prot)\ | ||
620 | { \ | ||
621 | int res = 0, cpu; \ | ||
622 | \ | ||
623 | for_each_possible_cpu(cpu) \ | ||
624 | res += per_cpu(NAME##_inuse, cpu); \ | ||
625 | return res; \ | ||
626 | } | ||
627 | # define REF_PROTO_INUSE(NAME) \ | ||
628 | .inuse_add = NAME##_inuse_add, \ | ||
629 | .inuse_getval = NAME##_inuse_getval, | ||
630 | #else | ||
631 | # define DEFINE_PROTO_INUSE(NAME) | ||
632 | # define REF_PROTO_INUSE(NAME) | ||
633 | #endif | ||
634 | |||
601 | extern int proto_register(struct proto *prot, int alloc_slab); | 635 | extern int proto_register(struct proto *prot, int alloc_slab); |
602 | extern void proto_unregister(struct proto *prot); | 636 | extern void proto_unregister(struct proto *prot); |
603 | 637 | ||
@@ -629,12 +663,29 @@ static inline void sk_refcnt_debug_release(const struct sock *sk) | |||
629 | /* Called with local bh disabled */ | 663 | /* Called with local bh disabled */ |
630 | static __inline__ void sock_prot_inc_use(struct proto *prot) | 664 | static __inline__ void sock_prot_inc_use(struct proto *prot) |
631 | { | 665 | { |
632 | prot->stats[smp_processor_id()].inuse++; | 666 | #ifdef CONFIG_SMP |
667 | prot->inuse_add(prot, 1); | ||
668 | #else | ||
669 | prot->inuse++; | ||
670 | #endif | ||
633 | } | 671 | } |
634 | 672 | ||
635 | static __inline__ void sock_prot_dec_use(struct proto *prot) | 673 | static __inline__ void sock_prot_dec_use(struct proto *prot) |
636 | { | 674 | { |
637 | prot->stats[smp_processor_id()].inuse--; | 675 | #ifdef CONFIG_SMP |
676 | prot->inuse_add(prot, -1); | ||
677 | #else | ||
678 | prot->inuse--; | ||
679 | #endif | ||
680 | } | ||
681 | |||
682 | static __inline__ int sock_prot_inuse(struct proto *proto) | ||
683 | { | ||
684 | #ifdef CONFIG_SMP | ||
685 | return proto->inuse_getval(proto); | ||
686 | #else | ||
687 | return proto->inuse; | ||
688 | #endif | ||
638 | } | 689 | } |
639 | 690 | ||
640 | /* With per-bucket locks this operation is not-atomic, so that | 691 | /* With per-bucket locks this operation is not-atomic, so that |