Name: Use local_t for linux_mib network counters Author: Rusty Russell Status: Experimental D: Uses local_t for linux_mib network counters. Index: linux-2.6.10-rc2-bk13-Percpu/include/net/ip.h =================================================================== --- linux-2.6.10-rc2-bk13-Percpu.orig/include/net/ip.h 2004-11-16 15:30:08.000000000 +1100 +++ linux-2.6.10-rc2-bk13-Percpu/include/net/ip.h 2004-12-02 12:49:22.791979352 +1100 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include Index: linux-2.6.10-rc2-bk13-Percpu/net/ipv4/af_inet.c =================================================================== --- linux-2.6.10-rc2-bk13-Percpu.orig/net/ipv4/af_inet.c 2004-11-30 12:45:23.000000000 +1100 +++ linux-2.6.10-rc2-bk13-Percpu/net/ipv4/af_inet.c 2004-12-02 12:49:22.792979200 +1100 @@ -113,7 +113,7 @@ #include #endif -DEFINE_SNMP_STAT(struct linux_mib, net_statistics); +DEFINE_PER_CPU(struct linux_mib, net_statistics); #ifdef INET_REFCNT_DEBUG atomic_t inet_sock_nr; @@ -976,7 +976,7 @@ udp_statistics[0] = alloc_percpu(struct udp_mib); udp_statistics[1] = alloc_percpu(struct udp_mib); if (! - (net_statistics[0] && net_statistics[1] && ip_statistics[0] + (ip_statistics[0] && ip_statistics[1] && tcp_statistics[0] && tcp_statistics[1] && udp_statistics[0] && udp_statistics[1])) return -ENOMEM; Index: linux-2.6.10-rc2-bk13-Percpu/include/net/snmp.h =================================================================== --- linux-2.6.10-rc2-bk13-Percpu.orig/include/net/snmp.h 2004-09-28 16:22:18.000000000 +1000 +++ linux-2.6.10-rc2-bk13-Percpu/include/net/snmp.h 2004-12-02 13:02:35.593455208 +1100 @@ -23,6 +23,7 @@ #include #include +#include /* * Mibs are stored in array of unsigned long. @@ -53,93 +54,63 @@ * count on the 20Gb/s + networks people expect in a few years time! */ -/* - * The rule for padding: - * Best is power of two because then the right structure can be found by a - * simple shift. The structure should be always cache line aligned. - * gcc needs n=alignto(cachelinesize, popcnt(sizeof(bla_mib))) shift/add - * instructions to emulate multiply in case it is not power-of-two. - * Currently n is always <=3 for all sizes so simple cache line alignment - * is enough. - * - * The best solution would be a global CPU local area , especially on 64 - * and 128byte cacheline machine it makes a *lot* of sense -AK - */ - -#define __SNMP_MIB_ALIGN__ ____cacheline_aligned - /* IPstats */ #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX struct ipstats_mib { - unsigned long mibs[IPSTATS_MIB_MAX]; -} __SNMP_MIB_ALIGN__; + local_t mibs[IPSTATS_MIB_MAX]; +}; /* ICMP */ #define ICMP_MIB_DUMMY __ICMP_MIB_MAX #define ICMP_MIB_MAX (__ICMP_MIB_MAX + 1) struct icmp_mib { - unsigned long mibs[ICMP_MIB_MAX]; -} __SNMP_MIB_ALIGN__; + local_t mibs[ICMP_MIB_MAX]; +}; /* ICMP6 (IPv6-ICMP) */ #define ICMP6_MIB_MAX __ICMP6_MIB_MAX struct icmpv6_mib { - unsigned long mibs[ICMP6_MIB_MAX]; -} __SNMP_MIB_ALIGN__; + local_t mibs[ICMP6_MIB_MAX]; +}; /* TCP */ #define TCP_MIB_MAX __TCP_MIB_MAX struct tcp_mib { - unsigned long mibs[TCP_MIB_MAX]; -} __SNMP_MIB_ALIGN__; + local_t mibs[TCP_MIB_MAX]; +}; /* UDP */ #define UDP_MIB_MAX __UDP_MIB_MAX struct udp_mib { - unsigned long mibs[UDP_MIB_MAX]; -} __SNMP_MIB_ALIGN__; + local_t mibs[UDP_MIB_MAX]; +}; /* SCTP */ #define SCTP_MIB_MAX __SCTP_MIB_MAX struct sctp_mib { - unsigned long mibs[SCTP_MIB_MAX]; -} __SNMP_MIB_ALIGN__; + local_t mibs[SCTP_MIB_MAX]; +}; /* Linux */ #define LINUX_MIB_MAX __LINUX_MIB_MAX struct linux_mib { - unsigned long mibs[LINUX_MIB_MAX]; + local_t mibs[LINUX_MIB_MAX]; }; +#define DEFINE_SNMP_STAT(type, name) DEFINE_PER_CPU(type, name) +#define DECLARE_SNMP_STAT(type, name) DECLARE_PER_CPU(type, name) -/* - * FIXME: On x86 and some other CPUs the split into user and softirq parts - * is not needed because addl $1,memory is atomic against interrupts (but - * atomic_inc would be overkill because of the lock cycles). Wants new - * nonlocked_atomic_inc() primitives -AK - */ -#define DEFINE_SNMP_STAT(type, name) \ - __typeof__(type) *name[2] -#define DECLARE_SNMP_STAT(type, name) \ - extern __typeof__(type) *name[2] - -#define SNMP_STAT_BHPTR(name) (name[0]) -#define SNMP_STAT_USRPTR(name) (name[1]) - -#define SNMP_INC_STATS_BH(mib, field) \ - (per_cpu_ptr(mib[0], smp_processor_id())->mibs[field]++) -#define SNMP_INC_STATS_OFFSET_BH(mib, field, offset) \ - (per_cpu_ptr(mib[0], smp_processor_id())->mibs[field + (offset)]++) -#define SNMP_INC_STATS_USER(mib, field) \ - (per_cpu_ptr(mib[1], smp_processor_id())->mibs[field]++) -#define SNMP_INC_STATS(mib, field) \ - (per_cpu_ptr(mib[!in_softirq()], smp_processor_id())->mibs[field]++) -#define SNMP_DEC_STATS(mib, field) \ - (per_cpu_ptr(mib[!in_softirq()], smp_processor_id())->mibs[field]--) -#define SNMP_ADD_STATS_BH(mib, field, addend) \ - (per_cpu_ptr(mib[0], smp_processor_id())->mibs[field] += addend) -#define SNMP_ADD_STATS_USER(mib, field, addend) \ - (per_cpu_ptr(mib[1], smp_processor_id())->mibs[field] += addend) +#define SNMP_INC_STATS_BH(mib, offset) cpu_local_inc(mib.mibs[offset]) +#define SNMP_INC_STATS_OFFSET_BH(mib, offset, offset2) \ + cpu_local_inc(mib.mibs[(offset) + (offset2)]) +#define SNMP_INC_STATS_USER(mib, offset) cpu_local_inc(mib.mibs[offset]) +#define SNMP_INC_STATS(mib, offset) cpu_local_inc(mib.mibs[offset]) + +#define SNMP_DEC_STATS(mib, offset) cpu_local_dev(mib.mibs[offset]) +#define SNMP_ADD_STATS_BH(mib, offset, addend) \ + cpu_local_add(addend, mib.mibs[offset]) +#define SNMP_ADD_STATS_USER(mib, offset, addend) \ + cpu_local_add(addend, mib.mibs[offset]) #endif