to use this, you do the following: 1. add this line to /etc/sysctl.conf: kern.allowkmem=1 2. and then you can: # pstat -dld net_cycles net_packets net_cycles at 0xffffffff822b93c0: 154766140 net_packets at 0xffffffff822b93c8: 1979 3. then you can work out the average cycles per packet. Index: net/if.c =================================================================== RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.611 diff -u -p -r1.611 if.c --- net/if.c 30 Jun 2020 09:31:38 -0000 1.611 +++ net/if.c 6 Jul 2020 00:23:03 -0000 @@ -908,10 +956,14 @@ if_ih_input(struct ifnet *ifp, struct mb m_freem(m); } +unsigned long net_cycles; +unsigned long net_packets; + void if_input_process(struct ifnet *ifp, struct mbuf_list *ml) { struct mbuf *m; + unsigned long tic, toc, pkts = 0; if (ml_empty(ml)) return; @@ -932,9 +984,18 @@ if_input_process(struct ifnet *ifp, stru * lists and the socket layer. */ NET_LOCK(); - while ((m = ml_dequeue(ml)) != NULL) + atomic_setbits_int(&curproc->p_flag, P_CANTSLEEP); + tic = rdtsc(); + while ((m = ml_dequeue(ml)) != NULL) { + pkts++; if_ih_input(ifp, m); + } + toc = rdtsc(); + atomic_clearbits_int(&curproc->p_flag, P_CANTSLEEP); NET_UNLOCK(); + + atomic_add_long(&net_cycles, toc - tic); + atomic_add_long(&net_packets, pkts); } void Index: netinet/ip_input.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_input.c,v retrieving revision 1.348 diff -u -p -r1.348 ip_input.c --- netinet/ip_input.c 12 Apr 2020 11:56:52 -0000 1.348 +++ netinet/ip_input.c 6 Jul 2020 00:23:03 -0000 @@ -216,6 +216,29 @@ ipv4_input(struct ifnet *ifp, struct mbu KASSERT(nxt == IPPROTO_DONE); } +uint16_t +ip_cksum(const struct ip *ip) +{ + const uint32_t *w = (const uint32_t *)ip; + uint64_t s; + unsigned int i; + + s = (uint64_t)w[0] + + (uint64_t)w[1] + + (uint64_t)w[2] + + (uint64_t)w[3] + + (uint64_t)w[4]; + + for (i = 5; i < ip->ip_hl; i++) + s += (uint64_t)w[i]; + + do { + s = (s >> 16) + (s & 0xffff); + } while (s >> 16); + + return (~s); +} + int ip_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) { @@ -267,7 +290,7 @@ ip_input_if(struct mbuf **mp, int *offp, } ipstat_inc(ips_inswcsum); - if (in_cksum(m, hlen) != 0) { + if (ip_cksum(ip) != 0x0000) { ipstat_inc(ips_badsum); goto bad; }