tcp: Implement asynchronous pru_connect
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 20 Aug 2013 12:52:35 +0000 (20:52 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 28 Aug 2013 04:49:39 +0000 (12:49 +0800)
commite368a6e95e2cd9556a3e0fc43167d2dcf3a8253f
tree3a925b3767c22171cf35ec92800281c175401187
parent33657a95890d8c7139cd236399bde4e85ee2b99a
tcp: Implement asynchronous pru_connect

This is mainly used to improve TCP nonblocking connect(2) performance.

Before this commit the user space thread uses nonblocking connect(2)
will have to wait for the netisr completes the SYN output.  This could
be performance hit for nonblocking connect(2).  First, the user space
thread is put into sleep, even if the connect(2) is nonblocking.
Second, it does not make too much sense for nonblocking connect(2) to
wait for the SYN output.

TCP's asynchronous pru_connect implementation will set ISCONNECTING
before dispatching netmsg to netisr0.  The errors like EADDRNOTAVAIL,
i.e. out of local port space, will be notified through kevent(2) or
getsockopt(2) SOL_SOCKET/SO_ERROR.

NFS and other kernel code still use old synchronized pru_connect.  This
commit only affects connect(2) syscall.

Sysctl node kern.ipc.soconnect_async is added to enable and disable
asynchronous pru_connect.  It is enabled by default.

The performance measurement (i7-2600 w/ bnx(4)), using
tools/tools/netrate/accept_connect/kq_connect_client:

    kq_connect_client -4 SERVADDR -p SERVPORT -i 8 -c 32 -l 30
    (8 processes, each creates 32 connections simultaniously, run 30 secs)

16 runs average:

    asynchronous pru_connect        synchronized pru_connect
        220979.89 conns/s               189106.88 conns/s

This commit gives ~16% performance improvement for nonblocking connect(2)
17 files changed:
sys/kern/uipc_msg.c
sys/kern/uipc_socket.c
sys/kern/uipc_syscalls.c
sys/net/netisr.c
sys/net/netmsg.h
sys/netgraph/ksocket/ng_ksocket.c
sys/netgraph7/bluetooth/socket/ng_btsocket_rfcomm.c
sys/netgraph7/ksocket/ng_ksocket.c
sys/netinet/in_proto.c
sys/netinet/tcp_usrreq.c
sys/netinet/udp_usrreq.c
sys/netproto/ncp/ncp_sock.c
sys/netproto/smb/smb_trantcp.c
sys/sys/protosw.h
sys/sys/socketops.h
sys/sys/socketvar.h
sys/vfs/nfs/nfs_socket.c