Hi,

When running tcpbench -su, a lot of them are counted as "missed PCB
cache".

I reboot the computer then netstat -sp udp gives

udp:
        10 datagrams received
        0 with incomplete header
        0 with bad data length field
        0 with bad checksum
        0 with no checksum
        0 input packets software-checksummed
        0 output packets software-checksummed
        0 dropped due to no socket
        0 broadcast/multicast datagrams dropped due to no socket
        0 dropped due to missing IPsec protection
        0 dropped due to full socket buffers
        10 delivered
        14 datagrams output
        0 missed PCB cache

I run tcpbench -su and use a client and I netstat -sp udp again :

udp:
        1086364 datagrams received
        0 with incomplete header
        0 with bad data length field
        0 with bad checksum
        0 with no checksum
        0 input packets software-checksummed
        0 output packets software-checksummed
        0 dropped due to no socket
        3 broadcast/multicast datagrams dropped due to no socket
        0 dropped due to missing IPsec protection
        1201 dropped due to full socket buffers
        1085160 delivered
        14 datagrams output
        1086351 missed PCB cache

After the bind(2), a PCB is created with a wildcard source address which
is not a direct match for incoming packets which means that we need to
perform a second lookup to find the "listener PCB". And the connect(2)
creates a new PCB for this connection thus avoiding a second lookup.

Patch with (a lot of) help from mikeb@

Reboot the laptop and run the test again:

udp:
        1074985 datagrams received
        0 with incomplete header
        0 with bad data length field
        0 with bad checksum
        0 with no checksum
        0 input packets software-checksummed
        0 output packets software-checksummed
        0 dropped due to no socket
        1 broadcast/multicast datagram dropped due to no socket
        0 dropped due to missing IPsec protection
        1295 dropped due to full socket buffers
        1073689 delivered
        14 datagrams output
        6 missed PCB cache

Index: tcpbench.c
===================================================================
RCS file: /cvs/src/usr.bin/tcpbench/tcpbench.c,v
retrieving revision 1.42
diff -u -p -r1.42 tcpbench.c
--- tcpbench.c  19 Aug 2014 03:28:53 -0000      1.42
+++ tcpbench.c  29 Aug 2014 14:22:35 -0000
@@ -610,8 +610,17 @@ udp_server_handle_sc(int fd, short event
 {
        ssize_t n;
        struct statctx *sc = v_sc;
+       struct sockaddr_storage ss;
+       socklen_t slen;
 
-       n = read(fd, ptb->dummybuf, ptb->dummybuf_len);
+       /* If this was our first packet, perform a connect */
+       if (mainstats.peak_mbps == 0) {
+               n = recvfrom(fd, ptb->dummybuf, ptb->dummybuf_len, 0,
+                   (struct sockaddr *)&ss, &slen);
+               if (n > 0 && connect(fd, (const struct sockaddr *)&ss, slen))
+                       warn("fail to connect");
+       } else
+               n = read(fd, ptb->dummybuf, ptb->dummybuf_len);
        if (n == 0)
                return;
        else if (n == -1) {

Reply via email to