From: Julian Seward Date: Sat, 13 Apr 2002 04:09:07 +0000 (+0000) Subject: poll_for_read_fds(): don't waste time calling select() if there are X-Git-Tag: svn/VALGRIND_1_0_3~386 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe80d439036888161f94b09f81578abb72d4da56;p=thirdparty%2Fvalgrind.git poll_for_read_fds(): don't waste time calling select() if there are no waiting fds. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@60 --- diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index ff1697c4d2..ecf44668aa 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -42,16 +42,14 @@ anyone at all! - properly save scheduler private state in signal delivery frames. -- fd-poll optimisation (don't select with empty sets) - - signals interrupting read/write and nanosleep, and take notice of SA_RESTART or not - when a thread is done mark its stack as noaccess -- make signal return and .fini call be detected via request mechanism +- 0xDEADBEEF syscall errors ... fix. - */ +*/ /* --------------------------------------------------------------------- @@ -688,10 +686,11 @@ void poll_for_ready_fds ( void ) Bool rd_ok, wr_ok, ex_ok; Char msg_buf[100]; + struct vki_timespec* rem; + ULong t_now; + /* Awaken any sleeping threads whose sleep has expired. */ - { - struct vki_timespec * rem; - ULong t_now = VG_(read_microsecond_timer)(); + t_now = VG_(read_microsecond_timer)(); for (tid = 0; tid < VG_N_THREADS; tid++) { if (vg_threads[tid].status != VgTs_Sleeping) continue; @@ -715,8 +714,9 @@ void poll_for_ready_fds ( void ) } } } - } + /* And look for threads waiting on file descriptors which are now + ready for I/O.*/ timeout.tv_sec = 0; timeout.tv_usec = 0; @@ -731,6 +731,7 @@ void poll_for_ready_fds ( void ) continue; fd = vg_waiting_fds[i].fd; /* VG_(printf)("adding QUERY for fd %d\n", fd); */ + vg_assert(fd >= 0); if (fd > fd_max) fd_max = fd; tid = vg_waiting_fds[i].tid; @@ -748,6 +749,10 @@ void poll_for_ready_fds ( void ) } } + /* Short cut: if no fds are waiting, give up now. */ + if (fd_max == -1) + return; + /* BLOCK ALL SIGNALS. We don't want the complication of select() getting interrupted. */ VG_(block_all_host_signals)( &saved_procmask ); diff --git a/vg_scheduler.c b/vg_scheduler.c index ff1697c4d2..ecf44668aa 100644 --- a/vg_scheduler.c +++ b/vg_scheduler.c @@ -42,16 +42,14 @@ anyone at all! - properly save scheduler private state in signal delivery frames. -- fd-poll optimisation (don't select with empty sets) - - signals interrupting read/write and nanosleep, and take notice of SA_RESTART or not - when a thread is done mark its stack as noaccess -- make signal return and .fini call be detected via request mechanism +- 0xDEADBEEF syscall errors ... fix. - */ +*/ /* --------------------------------------------------------------------- @@ -688,10 +686,11 @@ void poll_for_ready_fds ( void ) Bool rd_ok, wr_ok, ex_ok; Char msg_buf[100]; + struct vki_timespec* rem; + ULong t_now; + /* Awaken any sleeping threads whose sleep has expired. */ - { - struct vki_timespec * rem; - ULong t_now = VG_(read_microsecond_timer)(); + t_now = VG_(read_microsecond_timer)(); for (tid = 0; tid < VG_N_THREADS; tid++) { if (vg_threads[tid].status != VgTs_Sleeping) continue; @@ -715,8 +714,9 @@ void poll_for_ready_fds ( void ) } } } - } + /* And look for threads waiting on file descriptors which are now + ready for I/O.*/ timeout.tv_sec = 0; timeout.tv_usec = 0; @@ -731,6 +731,7 @@ void poll_for_ready_fds ( void ) continue; fd = vg_waiting_fds[i].fd; /* VG_(printf)("adding QUERY for fd %d\n", fd); */ + vg_assert(fd >= 0); if (fd > fd_max) fd_max = fd; tid = vg_waiting_fds[i].tid; @@ -748,6 +749,10 @@ void poll_for_ready_fds ( void ) } } + /* Short cut: if no fds are waiting, give up now. */ + if (fd_max == -1) + return; + /* BLOCK ALL SIGNALS. We don't want the complication of select() getting interrupted. */ VG_(block_all_host_signals)( &saved_procmask );