Skip to content

Commit

Permalink
[svn-r4429] fixes #29: In tcp, we're calling poll only once in a long…
Browse files Browse the repository at this point in the history
… while until we notice network activity (a connect request or something from the listener socket), then we poll more frequently (but still not every time). This will improve shared memory performance if the network is not being used.
  • Loading branch information
Darius Buntinas committed May 7, 2009
1 parent b615540 commit 888cb39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/mpid/ch3/channels/nemesis/nemesis/include/mpid_nem_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,7 @@ MPID_nem_mpich2_test_recv (MPID_nem_cell_ptr_t *cell, int *in_fbox)
if (poll_fboxes(cell)) goto fbox_l;
#endif/* USE_FASTBOX */

/* FIXME the ext_procs bit is an optimization for the all-local-procs case.
This has been commented out for now because it breaks dynamic processes.
Some other solution should be implemented eventually, possibly using a
flag that is set whenever a port is opened. [goodell@ 2008-06-18] */
if ((MPID_nem_num_netmods) /*&& (MPID_nem_mem_region.ext_procs > 0)*/)
if (MPID_nem_num_netmods)
{
mpi_errno = MPID_nem_network_poll();
if (mpi_errno) MPIU_ERR_POP (mpi_errno);
Expand Down Expand Up @@ -970,11 +966,7 @@ MPID_nem_mpich2_test_recv_wait (MPID_nem_cell_ptr_t *cell, int *in_fbox, int tim
if (poll_fboxes(cell)) goto fbox_l;
#endif/* USE_FASTBOX */

/* FIXME the ext_procs bit is an optimization for the all-local-procs case.
This has been commented out for now because it breaks dynamic processes.
Some other solution should be implemented eventually, possibly using a
flag that is set whenever a port is opened. [goodell@ 2008-06-18] */
if ((MPID_nem_num_netmods) /*&& (MPID_nem_mem_region.ext_procs > 0)*/)
if (MPID_nem_num_netmods)
{
mpi_errno = MPID_nem_network_poll();
if (mpi_errno) MPIU_ERR_POP (mpi_errno);
Expand Down Expand Up @@ -1061,11 +1053,7 @@ MPID_nem_mpich2_blocking_recv(MPID_nem_cell_ptr_t *cell, int *in_fbox)
if (poll_fboxes(cell)) goto fbox_l;
#endif /*USE_FASTBOX */

/* FIXME the ext_procs bit is an optimization for the all-local-procs case.
This has been commented out for now because it breaks dynamic processes.
Some other solution should be implemented eventually, possibly using a
flag that is set whenever a port is opened. [goodell@ 2008-06-18] */
if ((MPID_nem_num_netmods) /*&& (MPID_nem_mem_region.ext_procs > 0)*/)
if (MPID_nem_num_netmods)
{
mpi_errno = MPID_nem_network_poll();
if (mpi_errno) MPIU_ERR_POP (mpi_errno);
Expand All @@ -1080,11 +1068,7 @@ MPID_nem_mpich2_blocking_recv(MPID_nem_cell_ptr_t *cell, int *in_fbox)
if (poll_fboxes(cell)) goto fbox_l;
#endif /*USE_FASTBOX */

/* FIXME the ext_procs bit is an optimization for the all-local-procs case.
This has been commented out for now because it breaks dynamic processes.
Some other solution should be implemented eventually, possibly using a
flag that is set whenever a port is opened. [goodell@ 2008-06-18] */
if ((MPID_nem_num_netmods) /*&& (MPID_nem_mem_region.ext_procs > 0)*/)
if (MPID_nem_num_netmods)
{
mpi_errno = MPID_nem_network_poll();
if (mpi_errno) MPIU_ERR_POP (mpi_errno);
Expand Down
19 changes: 19 additions & 0 deletions src/mpid/ch3/channels/nemesis/nemesis/netmod/tcp/socksm.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pollfd_t MPID_nem_tcp_g_lstn_plfd = {0};
unused */
static MPID_nem_tcp_vc_area *dummy_vc_area ATTRIBUTE((unused, used)) = NULL;

#define MAX_SKIP_POLLS_INACTIVE (1<<22) /* something big */
#define MAX_SKIP_POLLS_ACTIVE (128) /* something small */
static int MPID_nem_tcp_skip_polls = MAX_SKIP_POLLS_INACTIVE;

/* Debug function to dump the sockconn table. This is intended to be
called from a debugger. The 'unused' attribute keeps the compiler
from complaining. The 'used' attribute makes sure the function is
Expand Down Expand Up @@ -753,6 +757,9 @@ int MPID_nem_tcp_connect(struct MPIDI_VC *const vc)

MPIU_Assert(vc != NULL);

/* We have an active connection, start polling more often */
MPID_nem_tcp_skip_polls = MAX_SKIP_POLLS_ACTIVE;

MPIDI_CHANGE_VC_STATE(vc, ACTIVE);

if (((MPIDI_CH3I_VC *)vc->channel_private)->state == MPID_NEM_TCP_VC_STATE_DISCONNECTED) {
Expand Down Expand Up @@ -1113,6 +1120,7 @@ static int state_c_ranksent_handler(pollfd_t *const plfd, sockconn_t *const sc)
if (pkt_type == MPIDI_NEM_TCP_PKT_ID_ACK) {
CHANGE_STATE(sc, CONN_STATE_TS_COMMRDY);
ASSIGN_SC_TO_VC(sc->vc, sc);

MPID_nem_tcp_conn_est (sc->vc);
MPIU_DBG_MSG_FMT(NEM_SOCK_DET, VERBOSE, (MPIU_DBG_FDEST, "c_ranksent_handler(): connection established (sc=%p, sc->vc=%p, fd=%d)", sc, sc->vc, sc->fd));
}
Expand Down Expand Up @@ -1188,6 +1196,9 @@ static int state_l_cntd_handler(pollfd_t *const plfd, sockconn_t *const sc)
goto fn_exit;
}

/* We have an active connection, start polling more often */
MPID_nem_tcp_skip_polls = MAX_SKIP_POLLS_ACTIVE;

if (IS_READABLE(plfd)) {
mpi_errno = recv_id_or_tmpvc_info(sc, &got_sc_eof);
if (mpi_errno == MPI_SUCCESS) {
Expand Down Expand Up @@ -1620,11 +1631,19 @@ Evaluate the need for it by testing and then do it, if needed.
int MPID_nem_tcp_connpoll()
{
int mpi_errno = MPI_SUCCESS, n, i;
static int num_skipped_polls = 0;

/* num_polled is needed b/c the call to it_sc->handler() can change the
size of the table, which leads to iterating over invalid revents. */
int num_polled = g_tbl_size;

/* To improve shared memory performance, we don't call the poll()
* systemcall every time. The MPID_nem_tcp_skip_polls value is
* changed depending on whether we have any active connections. */
if (num_skipped_polls++ < MPID_nem_tcp_skip_polls)
goto fn_exit;
num_skipped_polls = 0;

CHECK_EINTR(n, poll(MPID_nem_tcp_plfd_tbl, num_polled, 0));
MPIU_ERR_CHKANDJUMP1 (n == -1, mpi_errno, MPI_ERR_OTHER,
"**poll", "**poll %s", strerror (errno));
Expand Down

0 comments on commit 888cb39

Please sign in to comment.