From c9d4b9b13f7a58890cf2fedb680a1b035fd4cce6 Mon Sep 17 00:00:00 2001 From: "Ravikiran G. Thirumalai" Date: Mon, 6 Jan 2003 10:19:16 -0800 Subject: [IPV4]: Convert mibstats to use kmalloc_percpu --- include/net/icmp.h | 15 ++++++++++++++- include/net/ip.h | 6 ++++-- include/net/snmp.h | 39 ++++++++++++++++++++++++++++----------- include/net/tcp.h | 6 ++++-- include/net/udp.h | 3 ++- 5 files changed, 52 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/net/icmp.h b/include/net/icmp.h index f757af415632..2e11a0b2355c 100644 --- a/include/net/icmp.h +++ b/include/net/icmp.h @@ -23,6 +23,7 @@ #include #include +#include #include struct icmp_err { @@ -31,10 +32,22 @@ struct icmp_err { }; extern struct icmp_err icmp_err_convert[]; -extern struct icmp_mib icmp_statistics[NR_CPUS*2]; +DECLARE_SNMP_STAT(struct icmp_mib, icmp_statistics); #define ICMP_INC_STATS(field) SNMP_INC_STATS(icmp_statistics, field) #define ICMP_INC_STATS_BH(field) SNMP_INC_STATS_BH(icmp_statistics, field) #define ICMP_INC_STATS_USER(field) SNMP_INC_STATS_USER(icmp_statistics, field) +#define ICMP_INC_STATS_FIELD(offt) \ + (*((unsigned long *) ((void *) \ + per_cpu_ptr(icmp_statistics[!in_softirq()],\ + smp_processor_id())) + offt))++; +#define ICMP_INC_STATS_BH_FIELD(offt) \ + (*((unsigned long *) ((void *) \ + per_cpu_ptr(icmp_statistics[0], \ + smp_processor_id())) + offt))++; +#define ICMP_INC_STATS_USER_FIELD(offt) \ + (*((unsigned long *) ((void *) \ + per_cpu_ptr(icmp_statistics[1], \ + smp_processor_id())) + offt))++; extern void icmp_send(struct sk_buff *skb_in, int type, int code, u32 info); extern int icmp_rcv(struct sk_buff *skb); diff --git a/include/net/ip.h b/include/net/ip.h index 7b365788fe00..f3c975e75409 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -149,14 +149,16 @@ struct ipv4_config }; extern struct ipv4_config ipv4_config; -extern struct ip_mib ip_statistics[NR_CPUS*2]; +DECLARE_SNMP_STAT(struct ip_mib, ip_statistics); #define IP_INC_STATS(field) SNMP_INC_STATS(ip_statistics, field) #define IP_INC_STATS_BH(field) SNMP_INC_STATS_BH(ip_statistics, field) #define IP_INC_STATS_USER(field) SNMP_INC_STATS_USER(ip_statistics, field) -extern struct linux_mib net_statistics[NR_CPUS*2]; +DECLARE_SNMP_STAT(struct linux_mib, net_statistics); #define NET_INC_STATS(field) SNMP_INC_STATS(net_statistics, field) #define NET_INC_STATS_BH(field) SNMP_INC_STATS_BH(net_statistics, field) #define NET_INC_STATS_USER(field) SNMP_INC_STATS_USER(net_statistics, field) +#define NET_ADD_STATS_BH(field, adnd) SNMP_ADD_STATS_BH(net_statistics, field, adnd) +#define NET_ADD_STATS_USER(field, adnd) SNMP_ADD_STATS_USER(net_statistics, field, adnd) extern int sysctl_local_port_range[2]; extern int sysctl_ip_default_ttl; diff --git a/include/net/snmp.h b/include/net/snmp.h index 553e8c0eedce..3b3ed7252d38 100644 --- a/include/net/snmp.h +++ b/include/net/snmp.h @@ -62,7 +62,7 @@ struct ip_mib unsigned long IpFragFails; unsigned long IpFragCreates; unsigned long __pad[0]; -} ____cacheline_aligned; +}; struct ipv6_mib { @@ -89,7 +89,7 @@ struct ipv6_mib unsigned long Ip6InMcastPkts; unsigned long Ip6OutMcastPkts; unsigned long __pad[0]; -} ____cacheline_aligned; +}; struct icmp_mib { @@ -121,7 +121,7 @@ struct icmp_mib unsigned long IcmpOutAddrMaskReps; unsigned long dummy; unsigned long __pad[0]; -} ____cacheline_aligned; +}; struct icmpv6_mib { @@ -159,7 +159,7 @@ struct icmpv6_mib unsigned long Icmp6OutGroupMembResponses; unsigned long Icmp6OutGroupMembReductions; unsigned long __pad[0]; -} ____cacheline_aligned; +}; struct tcp_mib { @@ -178,7 +178,7 @@ struct tcp_mib unsigned long TcpInErrs; unsigned long TcpOutRsts; unsigned long __pad[0]; -} ____cacheline_aligned; +}; struct udp_mib { @@ -187,7 +187,7 @@ struct udp_mib unsigned long UdpInErrors; unsigned long UdpOutDatagrams; unsigned long __pad[0]; -} ____cacheline_aligned; +}; /* draft-ietf-sigtran-sctp-mib-07.txt */ struct sctp_mib @@ -216,7 +216,7 @@ struct sctp_mib unsigned long SctpValCookieLife; unsigned long SctpMaxInitRetr; unsigned long __pad[0]; -} ____cacheline_aligned; +}; struct linux_mib { @@ -286,7 +286,7 @@ struct linux_mib unsigned long TCPAbortFailed; unsigned long TCPMemoryPressures; unsigned long __pad[0]; -} ____cacheline_aligned; +}; /* @@ -294,8 +294,25 @@ struct linux_mib * 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 SNMP_INC_STATS(mib, field) ((mib)[2*smp_processor_id()+!in_softirq()].field++) -#define SNMP_INC_STATS_BH(mib, field) ((mib)[2*smp_processor_id()].field++) -#define SNMP_INC_STATS_USER(mib, field) ((mib)[2*smp_processor_id()+1].field++) +#define DEFINE_SNMP_STAT(type, name) \ + __typeof__(type) *name[2] +#define DECLARE_SNMP_STAT(type, name) \ + extern __typeof__(type) *name[2] + +#define SNMP_STAT_USRPTR(name) (name[0]) +#define SNMP_STAT_BHPTR(name) (name[1]) + +#define SNMP_INC_STATS_BH(mib, field) \ + (per_cpu_ptr(mib[0], smp_processor_id())->field++) +#define SNMP_INC_STATS_USER(mib, field) \ + (per_cpu_ptr(mib[1], smp_processor_id())->field++) +#define SNMP_INC_STATS(mib, field) \ + (per_cpu_ptr(mib[!in_softirq()], smp_processor_id())->field++) +#define SNMP_DEC_STATS(mib, field) \ + (per_cpu_ptr(mib[!in_softirq()], smp_processor_id())->field--) +#define SNMP_ADD_STATS_BH(mib, field, addend) \ + (per_cpu_ptr(mib[0], smp_processor_id())->field += addend) +#define SNMP_ADD_STATS_USER(mib, field, addend) \ + (per_cpu_ptr(mib[1], smp_processor_id())->field += addend) #endif diff --git a/include/net/tcp.h b/include/net/tcp.h index 38cc0e90793b..052621f03bc8 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) @@ -630,10 +631,11 @@ extern __inline int between(__u32 seq1, __u32 seq2, __u32 seq3) extern struct proto tcp_prot; -extern struct tcp_mib tcp_statistics[NR_CPUS*2]; +DECLARE_SNMP_STAT(struct tcp_mib, tcp_statistics); #define TCP_INC_STATS(field) SNMP_INC_STATS(tcp_statistics, field) #define TCP_INC_STATS_BH(field) SNMP_INC_STATS_BH(tcp_statistics, field) #define TCP_INC_STATS_USER(field) SNMP_INC_STATS_USER(tcp_statistics, field) +#define TCP_DEC_STATS(field) SNMP_DEC_STATS(tcp_statistics, field) extern void tcp_put_port(struct sock *sk); extern void __tcp_put_port(struct sock *sk); @@ -1399,7 +1401,7 @@ static __inline__ void tcp_set_state(struct sock *sk, int state) /* fall through */ default: if (oldstate==TCP_ESTABLISHED) - tcp_statistics[smp_processor_id()*2+!in_softirq()].TcpCurrEstab--; + TCP_DEC_STATS(TcpCurrEstab); } /* Change state AFTER socket is unhashed to avoid closed diff --git a/include/net/udp.h b/include/net/udp.h index 63a24bdd3b06..4684cba23be2 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -25,6 +25,7 @@ #include #include #include +#include #define UDP_HTABLE_SIZE 128 @@ -71,7 +72,7 @@ extern int udp_rcv(struct sk_buff *skb); extern int udp_ioctl(struct sock *sk, int cmd, unsigned long arg); extern int udp_disconnect(struct sock *sk, int flags); -extern struct udp_mib udp_statistics[NR_CPUS*2]; +DECLARE_SNMP_STAT(struct udp_mib, udp_statistics); #define UDP_INC_STATS(field) SNMP_INC_STATS(udp_statistics, field) #define UDP_INC_STATS_BH(field) SNMP_INC_STATS_BH(udp_statistics, field) #define UDP_INC_STATS_USER(field) SNMP_INC_STATS_USER(udp_statistics, field) -- cgit v1.2.3