Skip to content

Commit

Permalink
Merge branch 'snmp-optimizations'
Browse files Browse the repository at this point in the history
Eric Dumazet says:

====================
net: snmp: minor optimizations

Fetching many SNMP counters on hosts with large number of cpus
takes a lot of time. mptcp still uses the old non-batched
fashion which is not cache friendly.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 30, 2021
2 parents dee3b2d + acbd0c8 commit b051730
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 5 additions & 1 deletion include/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb,
#define NET_ADD_STATS(net, field, adnd) SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)
#define __NET_ADD_STATS(net, field, adnd) __SNMP_ADD_STATS((net)->mib.net_statistics, field, adnd)

u64 snmp_get_cpu_field(void __percpu *mib, int cpu, int offct);
static inline u64 snmp_get_cpu_field(void __percpu *mib, int cpu, int offt)
{
return *(((unsigned long *)per_cpu_ptr(mib, cpu)) + offt);
}

unsigned long snmp_fold_field(void __percpu *mib, int offt);
#if BITS_PER_LONG==32
u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offct,
Expand Down
6 changes: 0 additions & 6 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,12 +1662,6 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
}
EXPORT_SYMBOL_GPL(inet_ctl_sock_create);

u64 snmp_get_cpu_field(void __percpu *mib, int cpu, int offt)
{
return *(((unsigned long *)per_cpu_ptr(mib, cpu)) + offt);
}
EXPORT_SYMBOL_GPL(snmp_get_cpu_field);

unsigned long snmp_fold_field(void __percpu *mib, int offt)
{
unsigned long res = 0;
Expand Down
17 changes: 7 additions & 10 deletions net/mptcp/mib.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ bool mptcp_mib_alloc(struct net *net)

void mptcp_seq_show(struct seq_file *seq)
{
unsigned long sum[ARRAY_SIZE(mptcp_snmp_list) - 1];
struct net *net = seq->private;
int i;

Expand All @@ -81,17 +82,13 @@ void mptcp_seq_show(struct seq_file *seq)

seq_puts(seq, "\nMPTcpExt:");

if (!net->mib.mptcp_statistics) {
for (i = 0; mptcp_snmp_list[i].name; i++)
seq_puts(seq, " 0");

seq_putc(seq, '\n');
return;
}
memset(sum, 0, sizeof(sum));
if (net->mib.mptcp_statistics)
snmp_get_cpu_field_batch(sum, mptcp_snmp_list,
net->mib.mptcp_statistics);

for (i = 0; mptcp_snmp_list[i].name; i++)
seq_printf(seq, " %lu",
snmp_fold_field(net->mib.mptcp_statistics,
mptcp_snmp_list[i].entry));
seq_printf(seq, " %lu", sum[i]);

seq_putc(seq, '\n');
}

0 comments on commit b051730

Please sign in to comment.