This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch, master, updated. glibc-2.15-526-gc030f70


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  c030f70c8796c7743c3aa97d6beff3bd5b8dcd5d (commit)
      from  1d39e35923d086a0248f1934adfe31d8f6c813c0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c030f70c8796c7743c3aa97d6beff3bd5b8dcd5d

commit c030f70c8796c7743c3aa97d6beff3bd5b8dcd5d
Author: Ulrich Drepper <drepper@gmail.com>
Date:   Fri Mar 30 07:42:29 2012 -0400

    Speed up DNS by avoiding a system call if possible

diff --git a/ChangeLog b/ChangeLog
index e8d7809..fd46252 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-03-30  Ulrich Drepper  <drepper@gmail.com>
 
+	* resolv/res_send.c (send_dg): Use sendmmsg if we have to write two
+	requests to save a system call.
+
 	* sysdeps/unix/sysv/linux/bits/socket.h (struct mmsghdr): Fix up
 	comments for sendmmsg.
 
diff --git a/resolv/res_send.c b/resolv/res_send.c
index a001c1e..0b5bc91 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -1013,8 +1013,9 @@ send_dg(res_state statp,
 		seconds /= statp->nscount;
 	if (seconds <= 0)
 		seconds = 1;
-	bool single_request = (statp->options & RES_SNGLKUP) != 0;
 	bool single_request_reopen = (statp->options & RES_SNGLKUPREOP) != 0;
+	bool single_request = (((statp->options & RES_SNGLKUP) != 0)
+			       | single_request_reopen);
 	int save_gotsomewhere = *gotsomewhere;
 
 	int retval;
@@ -1100,24 +1101,89 @@ send_dg(res_state statp,
 	}
 	__set_errno (0);
 	if (pfd[0].revents & POLLOUT) {
-		ssize_t sr;
-		if (nwritten != 0)
-		  sr = send (pfd[0].fd, buf2, buflen2, MSG_NOSIGNAL);
-		else
-		  sr = send (pfd[0].fd, buf, buflen, MSG_NOSIGNAL);
+#ifndef __ASSUME_SENDMMSG
+		static int have_sendmmsg;
+#else
+# define have_sendmmsg 1
+#endif
+		if (have_sendmmsg >= 0 && nwritten == 0 && buf2 != NULL
+		    && !single_request)
+		  {
+		    struct iovec iov[2];
+		    struct mmsghdr reqs[2];
+		    reqs[0].msg_hdr.msg_name = NULL;
+		    reqs[0].msg_hdr.msg_namelen = 0;
+		    reqs[0].msg_hdr.msg_iov = &iov[0];
+		    reqs[0].msg_hdr.msg_iovlen = 1;
+		    iov[0].iov_base = (void *) buf;
+		    iov[0].iov_len = buflen;
+		    reqs[0].msg_hdr.msg_control = NULL;
+		    reqs[0].msg_hdr.msg_controllen = 0;
+
+		    reqs[1].msg_hdr.msg_name = NULL;
+		    reqs[1].msg_hdr.msg_namelen = 0;
+		    reqs[1].msg_hdr.msg_iov = &iov[1];
+		    reqs[1].msg_hdr.msg_iovlen = 1;
+		    iov[1].iov_base = (void *) buf2;
+		    iov[1].iov_len = buflen2;
+		    reqs[1].msg_hdr.msg_control = NULL;
+		    reqs[1].msg_hdr.msg_controllen = 0;
+
+		    int ndg = sendmmsg (pfd[0].fd, reqs, 2, MSG_NOSIGNAL);
+		    if (__builtin_expect (ndg == 2, 1))
+		      {
+			assert (reqs[0].msg_len == buflen);
+			assert (reqs[1].msg_len == buflen2);
 
-		if (sr != buflen) {
-			if (errno == EINTR || errno == EAGAIN)
-				goto recompute_resend;
-			Perror(statp, stderr, "send", errno);
+			pfd[0].events = POLLIN;
+			nwritten += 2;
+		      }
+		    else if (ndg == 1 && reqs[0].msg_len == buflen)
+		      goto just_one;
+		    else if (errno == EINTR || errno == EAGAIN)
+		      goto recompute_resend;
+		    else
+		      {
+#ifndef __ASSUME_SENDMMSG
+			if (have_sendmmsg == 0)
+			  {
+			    if (errno == ENOSYS)
+			      {
+				have_sendmmsg = -1;
+				goto try_send;
+			      }
+			    have_sendmmsg = 1;
+			  }
+#endif
+
+			Perror(statp, stderr, "sendmmsg", errno);
 			goto err_out;
-		}
-		if (nwritten != 0 || buf2 == NULL
-		    || single_request || single_request_reopen)
-		  pfd[0].events = POLLIN;
+		      }
+		  }
 		else
-		  pfd[0].events = POLLIN | POLLOUT;
-		++nwritten;
+		  {
+		    ssize_t sr;
+#ifndef __ASSUME_SENDMMSG
+		  try_send:
+#endif
+		    if (nwritten != 0)
+		      sr = send (pfd[0].fd, buf2, buflen2, MSG_NOSIGNAL);
+		    else
+		      sr = send (pfd[0].fd, buf, buflen, MSG_NOSIGNAL);
+
+		    if (sr != buflen) {
+		      if (errno == EINTR || errno == EAGAIN)
+			goto recompute_resend;
+		      Perror(statp, stderr, "send", errno);
+		      goto err_out;
+		    }
+		  just_one:
+		    if (nwritten != 0 || buf2 == NULL || single_request)
+		      pfd[0].events = POLLIN;
+		    else
+		      pfd[0].events = POLLIN | POLLOUT;
+		    ++nwritten;
+		  }
 		goto wait;
 	} else if (pfd[0].revents & POLLIN) {
 		int *thisanssizp;
@@ -1327,7 +1393,7 @@ send_dg(res_state statp,
 			recvresp2 = 1;
 		/* Repeat waiting if we have a second answer to arrive.  */
 		if ((recvresp1 & recvresp2) == 0) {
-			if (single_request || single_request_reopen) {
+			if (single_request) {
 				pfd[0].events = POLLOUT;
 				if (single_request_reopen) {
 					__res_iclose (statp, false);

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog         |    3 ++
 resolv/res_send.c |  100 ++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 86 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]