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>
This commit is contained in:
committed by
David S. Miller
parent
f3eb62d2cc
commit
4ce3c183fc
@@ -1427,6 +1427,42 @@ unsigned long snmp_fold_field(void __percpu *mib[], int offt)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snmp_fold_field);
|
||||
|
||||
#if BITS_PER_LONG==32
|
||||
|
||||
u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_offset)
|
||||
{
|
||||
u64 res = 0;
|
||||
int cpu;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
void *bhptr, *userptr;
|
||||
struct u64_stats_sync *syncp;
|
||||
u64 v_bh, v_user;
|
||||
unsigned int start;
|
||||
|
||||
/* first mib used by softirq context, we must use _bh() accessors */
|
||||
bhptr = per_cpu_ptr(SNMP_STAT_BHPTR(mib), cpu);
|
||||
syncp = (struct u64_stats_sync *)(bhptr + syncp_offset);
|
||||
do {
|
||||
start = u64_stats_fetch_begin_bh(syncp);
|
||||
v_bh = *(((u64 *) bhptr) + offt);
|
||||
} while (u64_stats_fetch_retry_bh(syncp, start));
|
||||
|
||||
/* second mib used in USER context */
|
||||
userptr = per_cpu_ptr(SNMP_STAT_USRPTR(mib), cpu);
|
||||
syncp = (struct u64_stats_sync *)(userptr + syncp_offset);
|
||||
do {
|
||||
start = u64_stats_fetch_begin(syncp);
|
||||
v_user = *(((u64 *) userptr) + offt);
|
||||
} while (u64_stats_fetch_retry(syncp, start));
|
||||
|
||||
res += v_bh + v_user;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snmp_fold_field64);
|
||||
#endif
|
||||
|
||||
int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align)
|
||||
{
|
||||
BUG_ON(ptr == NULL);
|
||||
|
Reference in New Issue
Block a user