Skip to content

Commit 4a4857b

Browse files
hejianetdavem330
authored andcommitted
proc: Reduce cache miss in snmp6_seq_show
This is to use the generic interfaces snmp_get_cpu_field{,64}_batch to aggregate the data by going through all the items of each cpu sequentially. Signed-off-by: Jia He <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f22d5c4 commit 4a4857b

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

net/ipv6/proc.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#include <net/transp_v6.h>
3131
#include <net/ipv6.h>
3232

33+
#define MAX4(a, b, c, d) \
34+
max_t(u32, max_t(u32, a, b), max_t(u32, c, d))
35+
#define SNMP_MIB_MAX MAX4(UDP_MIB_MAX, TCP_MIB_MAX, \
36+
IPSTATS_MIB_MAX, ICMP_MIB_MAX)
37+
3338
static int sockstat6_seq_show(struct seq_file *seq, void *v)
3439
{
3540
struct net *net = seq->private;
@@ -191,25 +196,34 @@ static void snmp6_seq_show_item(struct seq_file *seq, void __percpu *pcpumib,
191196
atomic_long_t *smib,
192197
const struct snmp_mib *itemlist)
193198
{
199+
unsigned long buff[SNMP_MIB_MAX];
194200
int i;
195-
unsigned long val;
196201

197-
for (i = 0; itemlist[i].name; i++) {
198-
val = pcpumib ?
199-
snmp_fold_field(pcpumib, itemlist[i].entry) :
200-
atomic_long_read(smib + itemlist[i].entry);
201-
seq_printf(seq, "%-32s\t%lu\n", itemlist[i].name, val);
202+
if (pcpumib) {
203+
memset(buff, 0, sizeof(unsigned long) * SNMP_MIB_MAX);
204+
205+
snmp_get_cpu_field_batch(buff, itemlist, pcpumib);
206+
for (i = 0; itemlist[i].name; i++)
207+
seq_printf(seq, "%-32s\t%lu\n",
208+
itemlist[i].name, buff[i]);
209+
} else {
210+
for (i = 0; itemlist[i].name; i++)
211+
seq_printf(seq, "%-32s\t%lu\n", itemlist[i].name,
212+
atomic_long_read(smib + itemlist[i].entry));
202213
}
203214
}
204215

205216
static void snmp6_seq_show_item64(struct seq_file *seq, void __percpu *mib,
206217
const struct snmp_mib *itemlist, size_t syncpoff)
207218
{
219+
u64 buff64[SNMP_MIB_MAX];
208220
int i;
209221

222+
memset(buff64, 0, sizeof(unsigned long) * SNMP_MIB_MAX);
223+
224+
snmp_get_cpu_field64_batch(buff64, itemlist, mib, syncpoff);
210225
for (i = 0; itemlist[i].name; i++)
211-
seq_printf(seq, "%-32s\t%llu\n", itemlist[i].name,
212-
snmp_fold_field64(mib, itemlist[i].entry, syncpoff));
226+
seq_printf(seq, "%-32s\t%llu\n", itemlist[i].name, buff64[i]);
213227
}
214228

215229
static int snmp6_seq_show(struct seq_file *seq, void *v)

0 commit comments

Comments
 (0)