From owner-freebsd-net@FreeBSD.ORG Thu Apr 21 17:17:15 2005 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DC5D216A4CE for ; Thu, 21 Apr 2005 17:17:15 +0000 (GMT) Received: from mx.highway.ne.jp (pip7.usen.ad.jp [61.122.117.245]) by mx1.FreeBSD.org (Postfix) with ESMTP id C91E643D4C for ; Thu, 21 Apr 2005 17:17:14 +0000 (GMT) (envelope-from kaakun@highway.ne.jp) Received: from [219.195.104.17] (helo=[192.168.11.17]) by pop12.isp.us-com.jp with esmtp (Mail 4.20) id 1DOfIf-0007RF-Eq for freebsd-net@freebsd.org; Fri, 22 Apr 2005 02:17:13 +0900 Message-ID: <4267E009.6010102@highway.ne.jp> Date: Fri, 22 Apr 2005 02:16:57 +0900 From: Kazuaki Oda User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050401) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-net@freebsd.org Content-Type: multipart/mixed; boundary="------------010807040606030905060306" Subject: tcp output question X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2005 17:17:16 -0000 This is a multi-part message in MIME format. --------------010807040606030905060306 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Hi, list, I'm reading FreeBSD's network codes, and I have noticed that we call tcp_output() from tcp_usr_send() with tcbinfo locked. According to the comment in the tcp_usr_send(), we must call tcp_connect() or tcp_usrclosed() with tcbinfo locked. But it seems that we does not need to lock it to call tcp_output(). Is there any reason not to unlock it before calling tcp_output()? I have tried the attached patch, so I get about 10-20% performance up when running my test server program. ------------------- Kazuaki Oda --------------010807040606030905060306 Content-Type: text/x-patch; name="tcp_usrreq.c.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tcp_usrreq.c.patch" --- tcp_usrreq.c.orig Tue Mar 29 10:10:46 2005 +++ tcp_usrreq.c Wed Apr 20 17:32:16 2005 @@ -619,7 +619,7 @@ int error = 0; struct inpcb *inp; struct tcpcb *tp; - const int inirw = INI_WRITE; + int unlocked = 0; #ifdef INET6 int isipv6; #endif @@ -694,6 +694,8 @@ socantsendmore(so); tp = tcp_usrclosed(tp); } + INP_INFO_WUNLOCK(&tcbinfo); + unlocked = 1; if (tp != NULL) { if (flags & PRUS_MORETOCOME) tp->t_flags |= TF_MORETOCOME; @@ -742,8 +744,13 @@ error = tcp_output(tp); tp->t_force = 0; } - COMMON_END((flags & PRUS_OOB) ? PRU_SENDOOB : - ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND)); +out: TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB : + ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND)); + if (tp) + INP_UNLOCK(inp); + if (!unlocked) + INP_INFO_WUNLOCK(&tcbinfo); + return error; } /* --------------010807040606030905060306--