diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-06-30 16:31:19 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-06-30 16:31:19 -0400 |
commit | 4ce3c183fcade7f4b30a33dae90cd774c3d9e094 (patch) | |
tree | 84d5a130da50096fdbeb7fffea596dffe2cebd80 /include/net | |
parent | f3eb62d2cc7da7bea4b394dd06f6bc738aa284e7 (diff) |
snmp: 64bit ipstats_mib for all arches
/proc/net/snmp and /proc/net/netstat expose SNMP counters.
Width of these counters is either 32 or 64 bits, depending on the size
of "unsigned long" in kernel.
This means user program parsing these files must already be prepared to
deal with 64bit values, regardless of user program being 32 or 64 bit.
This patch introduces 64bit snmp values for IPSTAT mib, where some
counters can wrap pretty fast if they are 32bit wide.
# netstat -s|egrep "InOctets|OutOctets"
InOctets: 244068329096
OutOctets: 244069348848
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/ip.h | 20 | ||||
-rw-r--r-- | include/net/ipv6.h | 12 | ||||
-rw-r--r-- | include/net/snmp.h | 75 |
3 files changed, 91 insertions, 16 deletions
diff --git a/include/net/ip.h b/include/net/ip.h index 3b524df7dddb..890f9725d681 100644 --- a/include/net/ip.h +++ b/include/net/ip.h | |||
@@ -165,12 +165,12 @@ struct ipv4_config { | |||
165 | }; | 165 | }; |
166 | 166 | ||
167 | extern struct ipv4_config ipv4_config; | 167 | extern struct ipv4_config ipv4_config; |
168 | #define IP_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.ip_statistics, field) | 168 | #define IP_INC_STATS(net, field) SNMP_INC_STATS64((net)->mib.ip_statistics, field) |
169 | #define IP_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.ip_statistics, field) | 169 | #define IP_INC_STATS_BH(net, field) SNMP_INC_STATS64_BH((net)->mib.ip_statistics, field) |
170 | #define IP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.ip_statistics, field, val) | 170 | #define IP_ADD_STATS(net, field, val) SNMP_ADD_STATS64((net)->mib.ip_statistics, field, val) |
171 | #define IP_ADD_STATS_BH(net, field, val) SNMP_ADD_STATS_BH((net)->mib.ip_statistics, field, val) | 171 | #define IP_ADD_STATS_BH(net, field, val) SNMP_ADD_STATS64_BH((net)->mib.ip_statistics, field, val) |
172 | #define IP_UPD_PO_STATS(net, field, val) SNMP_UPD_PO_STATS((net)->mib.ip_statistics, field, val) | 172 | #define IP_UPD_PO_STATS(net, field, val) SNMP_UPD_PO_STATS64((net)->mib.ip_statistics, field, val) |
173 | #define IP_UPD_PO_STATS_BH(net, field, val) SNMP_UPD_PO_STATS_BH((net)->mib.ip_statistics, field, val) | 173 | #define IP_UPD_PO_STATS_BH(net, field, val) SNMP_UPD_PO_STATS64_BH((net)->mib.ip_statistics, field, val) |
174 | #define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field) | 174 | #define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field) |
175 | #define NET_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.net_statistics, field) | 175 | #define NET_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.net_statistics, field) |
176 | #define NET_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->mib.net_statistics, field) | 176 | #define NET_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->mib.net_statistics, field) |
@@ -178,6 +178,14 @@ extern struct ipv4_config ipv4_config; | |||
178 | #define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd) | 178 | #define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd) |
179 | 179 | ||
180 | extern unsigned long snmp_fold_field(void __percpu *mib[], int offt); | 180 | extern unsigned long snmp_fold_field(void __percpu *mib[], int offt); |
181 | #if BITS_PER_LONG==32 | ||
182 | extern u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t sync_off); | ||
183 | #else | ||
184 | static inline u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_off) | ||
185 | { | ||
186 | return snmp_fold_field(mib, offt); | ||
187 | } | ||
188 | #endif | ||
181 | extern int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align); | 189 | extern int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align); |
182 | extern void snmp_mib_free(void __percpu *ptr[2]); | 190 | extern void snmp_mib_free(void __percpu *ptr[2]); |
183 | 191 | ||
diff --git a/include/net/ipv6.h b/include/net/ipv6.h index f5808d596aab..1f8412410998 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h | |||
@@ -136,17 +136,17 @@ extern struct ctl_path net_ipv6_ctl_path[]; | |||
136 | /* MIBs */ | 136 | /* MIBs */ |
137 | 137 | ||
138 | #define IP6_INC_STATS(net, idev,field) \ | 138 | #define IP6_INC_STATS(net, idev,field) \ |
139 | _DEVINC(net, ipv6, , idev, field) | 139 | _DEVINC(net, ipv6, 64, idev, field) |
140 | #define IP6_INC_STATS_BH(net, idev,field) \ | 140 | #define IP6_INC_STATS_BH(net, idev,field) \ |
141 | _DEVINC(net, ipv6, _BH, idev, field) | 141 | _DEVINC(net, ipv6, 64_BH, idev, field) |
142 | #define IP6_ADD_STATS(net, idev,field,val) \ | 142 | #define IP6_ADD_STATS(net, idev,field,val) \ |
143 | _DEVADD(net, ipv6, , idev, field, val) | 143 | _DEVADD(net, ipv6, 64, idev, field, val) |
144 | #define IP6_ADD_STATS_BH(net, idev,field,val) \ | 144 | #define IP6_ADD_STATS_BH(net, idev,field,val) \ |
145 | _DEVADD(net, ipv6, _BH, idev, field, val) | 145 | _DEVADD(net, ipv6, 64_BH, idev, field, val) |
146 | #define IP6_UPD_PO_STATS(net, idev,field,val) \ | 146 | #define IP6_UPD_PO_STATS(net, idev,field,val) \ |
147 | _DEVUPD(net, ipv6, , idev, field, val) | 147 | _DEVUPD(net, ipv6, 64, idev, field, val) |
148 | #define IP6_UPD_PO_STATS_BH(net, idev,field,val) \ | 148 | #define IP6_UPD_PO_STATS_BH(net, idev,field,val) \ |
149 | _DEVUPD(net, ipv6, _BH, idev, field, val) | 149 | _DEVUPD(net, ipv6, 64_BH, idev, field, val) |
150 | #define ICMP6_INC_STATS(net, idev, field) \ | 150 | #define ICMP6_INC_STATS(net, idev, field) \ |
151 | _DEVINC(net, icmpv6, , idev, field) | 151 | _DEVINC(net, icmpv6, , idev, field) |
152 | #define ICMP6_INC_STATS_BH(net, idev, field) \ | 152 | #define ICMP6_INC_STATS_BH(net, idev, field) \ |
diff --git a/include/net/snmp.h b/include/net/snmp.h index 899003d18db9..a0e61806d480 100644 --- a/include/net/snmp.h +++ b/include/net/snmp.h | |||
@@ -47,15 +47,16 @@ struct snmp_mib { | |||
47 | } | 47 | } |
48 | 48 | ||
49 | /* | 49 | /* |
50 | * We use all unsigned longs. Linux will soon be so reliable that even | 50 | * We use unsigned longs for most mibs but u64 for ipstats. |
51 | * these will rapidly get too small 8-). Seriously consider the IpInReceives | ||
52 | * count on the 20Gb/s + networks people expect in a few years time! | ||
53 | */ | 51 | */ |
52 | #include <linux/u64_stats_sync.h> | ||
54 | 53 | ||
55 | /* IPstats */ | 54 | /* IPstats */ |
56 | #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX | 55 | #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX |
57 | struct ipstats_mib { | 56 | struct ipstats_mib { |
58 | unsigned long mibs[IPSTATS_MIB_MAX]; | 57 | /* mibs[] must be first field of struct ipstats_mib */ |
58 | u64 mibs[IPSTATS_MIB_MAX]; | ||
59 | struct u64_stats_sync syncp; | ||
59 | }; | 60 | }; |
60 | 61 | ||
61 | /* ICMP */ | 62 | /* ICMP */ |
@@ -155,4 +156,70 @@ struct linux_xfrm_mib { | |||
155 | ptr->mibs[basefield##PKTS]++; \ | 156 | ptr->mibs[basefield##PKTS]++; \ |
156 | ptr->mibs[basefield##OCTETS] += addend;\ | 157 | ptr->mibs[basefield##OCTETS] += addend;\ |
157 | } while (0) | 158 | } while (0) |
159 | |||
160 | |||
161 | #if BITS_PER_LONG==32 | ||
162 | |||
163 | #define SNMP_ADD_STATS64_BH(mib, field, addend) \ | ||
164 | do { \ | ||
165 | __typeof__(*mib[0]) *ptr = __this_cpu_ptr((mib)[0]); \ | ||
166 | u64_stats_update_begin(&ptr->syncp); \ | ||
167 | ptr->mibs[field] += addend; \ | ||
168 | u64_stats_update_end(&ptr->syncp); \ | ||
169 | } while (0) | ||
170 | #define SNMP_ADD_STATS64_USER(mib, field, addend) \ | ||
171 | do { \ | ||
172 | __typeof__(*mib[0]) *ptr; \ | ||
173 | preempt_disable(); \ | ||
174 | ptr = __this_cpu_ptr((mib)[1]); \ | ||
175 | u64_stats_update_begin(&ptr->syncp); \ | ||
176 | ptr->mibs[field] += addend; \ | ||
177 | u64_stats_update_end(&ptr->syncp); \ | ||
178 | preempt_enable(); \ | ||
179 | } while (0) | ||
180 | #define SNMP_ADD_STATS64(mib, field, addend) \ | ||
181 | do { \ | ||
182 | __typeof__(*mib[0]) *ptr; \ | ||
183 | preempt_disable(); \ | ||
184 | ptr = __this_cpu_ptr((mib)[!in_softirq()]); \ | ||
185 | u64_stats_update_begin(&ptr->syncp); \ | ||
186 | ptr->mibs[field] += addend; \ | ||
187 | u64_stats_update_end(&ptr->syncp); \ | ||
188 | preempt_enable(); \ | ||
189 | } while (0) | ||
190 | #define SNMP_INC_STATS64_BH(mib, field) SNMP_ADD_STATS64_BH(mib, field, 1) | ||
191 | #define SNMP_INC_STATS64_USER(mib, field) SNMP_ADD_STATS64_USER(mib, field, 1) | ||
192 | #define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1) | ||
193 | #define SNMP_UPD_PO_STATS64(mib, basefield, addend) \ | ||
194 | do { \ | ||
195 | __typeof__(*mib[0]) *ptr; \ | ||
196 | preempt_disable(); \ | ||
197 | ptr = __this_cpu_ptr((mib)[!in_softirq()]); \ | ||
198 | u64_stats_update_begin(&ptr->syncp); \ | ||
199 | ptr->mibs[basefield##PKTS]++; \ | ||
200 | ptr->mibs[basefield##OCTETS] += addend; \ | ||
201 | u64_stats_update_end(&ptr->syncp); \ | ||
202 | preempt_enable(); \ | ||
203 | } while (0) | ||
204 | #define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) \ | ||
205 | do { \ | ||
206 | __typeof__(*mib[0]) *ptr; \ | ||
207 | ptr = __this_cpu_ptr((mib)[!in_softirq()]); \ | ||
208 | u64_stats_update_begin(&ptr->syncp); \ | ||
209 | ptr->mibs[basefield##PKTS]++; \ | ||
210 | ptr->mibs[basefield##OCTETS] += addend; \ | ||
211 | u64_stats_update_end(&ptr->syncp); \ | ||
212 | } while (0) | ||
213 | #else | ||
214 | #define SNMP_INC_STATS64_BH(mib, field) SNMP_INC_STATS_BH(mib, field) | ||
215 | #define SNMP_INC_STATS64_USER(mib, field) SNMP_INC_STATS_USER(mib, field) | ||
216 | #define SNMP_INC_STATS64(mib, field) SNMP_INC_STATS(mib, field) | ||
217 | #define SNMP_DEC_STATS64(mib, field) SNMP_DEC_STATS(mib, field) | ||
218 | #define SNMP_ADD_STATS64_BH(mib, field, addend) SNMP_ADD_STATS_BH(mib, field, addend) | ||
219 | #define SNMP_ADD_STATS64_USER(mib, field, addend) SNMP_ADD_STATS_USER(mib, field, addend) | ||
220 | #define SNMP_ADD_STATS64(mib, field, addend) SNMP_ADD_STATS(mib, field, addend) | ||
221 | #define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend) | ||
222 | #define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) SNMP_UPD_PO_STATS_BH(mib, basefield, addend) | ||
223 | #endif | ||
224 | |||
158 | #endif | 225 | #endif |