Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Sep 2014 14:00:09 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        net@freebsd.org
Cc:        Robert Watson <rwatson@freebsd.org>
Subject:   [PATCH] Only lock send buffer in sopoll() if needed
Message-ID:  <201409301400.09999.jhb@freebsd.org>

next in thread | raw e-mail | index | archive | help
Right now sopoll() always locks both socket buffers.  The receive socket 
buffer lock is always needed, but the send socket buffer lock is only needed 
while polling for writing (there is a potential test of SBS_CANTSENDMORE 
without the lock, but I think this might be ok).  What do folks think?

Index: uipc_socket.c
===================================================================
--- uipc_socket.c       (revision 272305)
+++ uipc_socket.c       (working copy)
@@ -3003,7 +3003,12 @@ sopoll_generic(struct socket *so, int events, stru
 {
        int revents = 0;
 
-       SOCKBUF_LOCK(&so->so_snd);
+       if (events & (POLLOUT | POLLWRNORM))
+               SOCKBUF_LOCK(&so->so_snd);
+       /*
+        * The so_rcv lock doubles as SOCK_LOCK so it it is needed for
+        * all requests.
+        */
        SOCKBUF_LOCK(&so->so_rcv);
        if (events & (POLLIN | POLLRDNORM))
                if (soreadabledata(so))
@@ -3038,7 +3043,8 @@ sopoll_generic(struct socket *so, int events, stru
        }
 
        SOCKBUF_UNLOCK(&so->so_rcv);
-       SOCKBUF_UNLOCK(&so->so_snd);
+       if (events & (POLLOUT | POLLWRNORM))
+               SOCKBUF_UNLOCK(&so->so_snd);
        return (revents);
 }

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409301400.09999.jhb>