Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Apr 2005 02:16:57 +0900
From:      Kazuaki Oda <kaakun@highway.ne.jp>
To:        freebsd-net@freebsd.org
Subject:   tcp output question
Message-ID:  <4267E009.6010102@highway.ne.jp>

next in thread | raw e-mail | index | archive | help
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--



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