Skip to content

Commit 18b8c5c

Browse files
committed
merge revision(s) 44643: [Backport ruby#9039]
* ext/socket: Avoid unnecessary ppoll/select on Linux. Patch by Eric Wong. [ruby-core:57950] [Bug ruby#9039] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent df77755 commit 18b8c5c

6 files changed

Lines changed: 26 additions & 5 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Feb 14 15:23:43 2014 Tanaka Akira <akr@fsij.org>
2+
3+
* ext/socket: Avoid unnecessary ppoll/select on Linux.
4+
Patch by Eric Wong. [ruby-core:57950] [Bug #9039]
5+
16
Fri Feb 14 15:21:21 2014 Eric Wong <e@80x24.org>
27

38
* benchmark/driver: avoid large alloc in driver process

ext/socket/basicsocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ rsock_bsock_send(int argc, VALUE *argv, VALUE sock)
566566
GetOpenFile(sock, fptr);
567567
arg.fd = fptr->fd;
568568
arg.flags = NUM2INT(flags);
569-
while (rb_thread_fd_writable(arg.fd),
569+
while (rsock_maybe_fd_writable(arg.fd),
570570
(n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
571571
if (rb_io_wait_writable(arg.fd)) {
572572
continue;

ext/socket/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
129129
RBASIC(str)->klass = 0;
130130

131131
while (rb_io_check_closed(fptr),
132-
rb_thread_wait_fd(arg.fd),
132+
rsock_maybe_wait_fd(arg.fd),
133133
(slen = BLOCKING_REGION_FD(recvfrom_blocking, &arg)) < 0) {
134134
if (!rb_io_wait_readable(fptr->fd)) {
135135
rb_sys_fail("recvfrom(2)");
@@ -503,7 +503,7 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
503503
arg.sockaddr = sockaddr;
504504
arg.len = len;
505505
retry:
506-
rb_thread_wait_fd(fd);
506+
rsock_maybe_wait_fd(fd);
507507
fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
508508
if (fd2 < 0) {
509509
switch (errno) {

ext/socket/rubysocket.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,20 @@ void rsock_init_addrinfo(void);
306306
void rsock_init_sockopt(void);
307307
void rsock_init_socket_init(void);
308308

309+
/*
310+
* It is safe on Linux to attempt using a socket without waiting on it in
311+
* all cases. For some syscalls (e.g. accept/accept4), blocking on the
312+
* syscall instead of relying on select/poll allows the kernel to use
313+
* "wake-one" behavior and avoid the thundering herd problem.
314+
* This is likely safe on all other *nix-like systems, so this whitelist
315+
* can be expanded by interested parties.
316+
*/
317+
#if defined(__linux__)
318+
static inline int rsock_maybe_fd_writable(int fd) { return 1; }
319+
static inline void rsock_maybe_wait_fd(int fd) { }
320+
#else /* some systems (mswin/mingw) need these. ref: r36946 */
321+
# define rsock_maybe_fd_writable(fd) rb_thread_fd_writable((fd))
322+
# define rsock_maybe_wait_fd(fd) rb_thread_wait_fd((fd))
323+
#endif
324+
309325
#endif

ext/socket/udpsocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ udp_send(int argc, VALUE *argv, VALUE sock)
176176
retry:
177177
arg.to = res->ai_addr;
178178
arg.tolen = res->ai_addrlen;
179-
rb_thread_fd_writable(arg.fd);
179+
rsock_maybe_fd_writable(arg.fd);
180180
n = (int)BLOCKING_REGION_FD(rsock_sendto_blocking, &arg);
181181
if (n >= 0) {
182182
freeaddrinfo(res0);

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define RUBY_VERSION "1.9.3"
2-
#define RUBY_PATCHLEVEL 524
2+
#define RUBY_PATCHLEVEL 525
33

44
#define RUBY_RELEASE_DATE "2014-02-14"
55
#define RUBY_RELEASE_YEAR 2014

0 commit comments

Comments
 (0)