[前][次][番号順一覧][スレッド一覧]

ruby-changes:32864

From: usa <ko1@a...>
Date: Fri, 14 Feb 2014 15:24:14 +0900 (JST)
Subject: [ruby-changes:32864] usa:r44943 (ruby_1_9_3): merge revision(s) 44643: [Backport #9039]

usa	2014-02-14 15:24:08 +0900 (Fri, 14 Feb 2014)

  New Revision: 44943

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44943

  Log:
    merge revision(s) 44643: [Backport #9039]
    
    * ext/socket: Avoid unnecessary ppoll/select on Linux.
      Patch by Eric Wong.  [ruby-core:57950] [Bug #9039]

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ext/socket/basicsocket.c
    branches/ruby_1_9_3/ext/socket/init.c
    branches/ruby_1_9_3/ext/socket/rubysocket.h
    branches/ruby_1_9_3/ext/socket/udpsocket.c
    branches/ruby_1_9_3/version.h
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 44942)
+++ ruby_1_9_3/ChangeLog	(revision 44943)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Fri Feb 14 15:23:43 2014  Tanaka Akira  <akr@f...>
+
+	* ext/socket: Avoid unnecessary ppoll/select on Linux.
+	  Patch by Eric Wong.  [ruby-core:57950] [Bug #9039]
+
 Fri Feb 14 15:21:21 2014  Eric Wong <e@8...>
 
 	* benchmark/driver: avoid large alloc in driver process
Index: ruby_1_9_3/ext/socket/rubysocket.h
===================================================================
--- ruby_1_9_3/ext/socket/rubysocket.h	(revision 44942)
+++ ruby_1_9_3/ext/socket/rubysocket.h	(revision 44943)
@@ -306,4 +306,20 @@ void rsock_init_addrinfo(void); https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/rubysocket.h#L306
 void rsock_init_sockopt(void);
 void rsock_init_socket_init(void);
 
+/*
+ * It is safe on Linux to attempt using a socket without waiting on it in
+ * all cases.  For some syscalls (e.g. accept/accept4), blocking on the
+ * syscall instead of relying on select/poll allows the kernel to use
+ * "wake-one" behavior and avoid the thundering herd problem.
+ * This is likely safe on all other *nix-like systems, so this whitelist
+ * can be expanded by interested parties.
+ */
+#if defined(__linux__)
+static inline int rsock_maybe_fd_writable(int fd) { return 1; }
+static inline void rsock_maybe_wait_fd(int fd) { }
+#else /* some systems (mswin/mingw) need these.  ref: r36946 */
+#  define rsock_maybe_fd_writable(fd) rb_thread_fd_writable((fd))
+#  define rsock_maybe_wait_fd(fd) rb_thread_wait_fd((fd))
+#endif
+
 #endif
Index: ruby_1_9_3/ext/socket/udpsocket.c
===================================================================
--- ruby_1_9_3/ext/socket/udpsocket.c	(revision 44942)
+++ ruby_1_9_3/ext/socket/udpsocket.c	(revision 44943)
@@ -176,7 +176,7 @@ udp_send(int argc, VALUE *argv, VALUE so https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/udpsocket.c#L176
       retry:
 	arg.to = res->ai_addr;
 	arg.tolen = res->ai_addrlen;
-	rb_thread_fd_writable(arg.fd);
+	rsock_maybe_fd_writable(arg.fd);
 	n = (int)BLOCKING_REGION_FD(rsock_sendto_blocking, &arg);
 	if (n >= 0) {
 	    freeaddrinfo(res0);
Index: ruby_1_9_3/ext/socket/init.c
===================================================================
--- ruby_1_9_3/ext/socket/init.c	(revision 44942)
+++ ruby_1_9_3/ext/socket/init.c	(revision 44943)
@@ -129,7 +129,7 @@ rsock_s_recvfrom(VALUE sock, int argc, V https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/init.c#L129
     RBASIC(str)->klass = 0;
 
     while (rb_io_check_closed(fptr),
-	   rb_thread_wait_fd(arg.fd),
+	   rsock_maybe_wait_fd(arg.fd),
 	   (slen = BLOCKING_REGION_FD(recvfrom_blocking, &arg)) < 0) {
         if (!rb_io_wait_readable(fptr->fd)) {
             rb_sys_fail("recvfrom(2)");
@@ -503,7 +503,7 @@ rsock_s_accept(VALUE klass, int fd, stru https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/init.c#L503
     arg.sockaddr = sockaddr;
     arg.len = len;
   retry:
-    rb_thread_wait_fd(fd);
+    rsock_maybe_wait_fd(fd);
     fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
     if (fd2 < 0) {
 	switch (errno) {
Index: ruby_1_9_3/ext/socket/basicsocket.c
===================================================================
--- ruby_1_9_3/ext/socket/basicsocket.c	(revision 44942)
+++ ruby_1_9_3/ext/socket/basicsocket.c	(revision 44943)
@@ -566,7 +566,7 @@ rsock_bsock_send(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/basicsocket.c#L566
     GetOpenFile(sock, fptr);
     arg.fd = fptr->fd;
     arg.flags = NUM2INT(flags);
-    while (rb_thread_fd_writable(arg.fd),
+    while (rsock_maybe_fd_writable(arg.fd),
 	   (n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
 	if (rb_io_wait_writable(arg.fd)) {
 	    continue;
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 44942)
+++ ruby_1_9_3/version.h	(revision 44943)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 524
+#define RUBY_PATCHLEVEL 525
 
 #define RUBY_RELEASE_DATE "2014-02-14"
 #define RUBY_RELEASE_YEAR 2014

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44643


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]