From 99627319f07311e4c6ee27801cea3289e48a116e Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Wed, 25 May 2016 14:27:34 -0600 Subject: [PATCH] btl/ugni: reduce overhead of progress function This commit reduces the overhead of calling the ugni progress function. It does the following: - Check for new connections once every eight calls. - Do not call remote smsg progress unless we are connected to at least one remote peer. - Do not call rdma progress unless at least one rdma fragment is outstanding. - Check endpoint wait list size before obtaining a lock. Signed-off-by: Nathan Hjelm --- opal/mca/btl/ugni/btl_ugni.h | 2 ++ opal/mca/btl/ugni/btl_ugni_component.c | 24 +++++++++++++++++++----- opal/mca/btl/ugni/btl_ugni_endpoint.c | 2 ++ opal/mca/btl/ugni/btl_ugni_frag.h | 2 ++ opal/mca/btl/ugni/btl_ugni_module.c | 2 ++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/opal/mca/btl/ugni/btl_ugni.h b/opal/mca/btl/ugni/btl_ugni.h index bc9c6b67b5..e6487c7cd0 100644 --- a/opal/mca/btl/ugni/btl_ugni.h +++ b/opal/mca/btl/ugni/btl_ugni.h @@ -129,6 +129,8 @@ typedef struct mca_btl_ugni_module_t { int nlocal_procs; volatile int active_send_count; + volatile int64_t connected_peer_count; + volatile int64_t active_rdma_count; mca_rcache_base_module_t *rcache; } mca_btl_ugni_module_t; diff --git a/opal/mca/btl/ugni/btl_ugni_component.c b/opal/mca/btl/ugni/btl_ugni_component.c index 04076a16d6..aa27bb97e5 100644 --- a/opal/mca/btl/ugni/btl_ugni_component.c +++ b/opal/mca/btl/ugni/btl_ugni_component.c @@ -613,6 +613,10 @@ mca_btl_ugni_progress_wait_list (mca_btl_ugni_module_t *ugni_module) mca_btl_base_endpoint_t *endpoint = NULL; int count; + if (0 == opal_list_get_size(&ugni_module->ep_wait_list)) { + return 0; + } + OPAL_THREAD_LOCK(&ugni_module->ep_wait_list_lock); count = opal_list_get_size(&ugni_module->ep_wait_list); @@ -636,18 +640,28 @@ mca_btl_ugni_progress_wait_list (mca_btl_ugni_module_t *ugni_module) static int mca_btl_ugni_component_progress (void) { mca_btl_ugni_module_t *ugni_module; + static int64_t call_count = 0; + int64_t cur_call_count = OPAL_THREAD_ADD64(&call_count, 1); unsigned int i; int count = 0; for (i = 0 ; i < mca_btl_ugni_component.ugni_num_btls ; ++i) { ugni_module = mca_btl_ugni_component.modules + i; - mca_btl_ugni_progress_wait_list (ugni_module); + if ((cur_call_count & 0x7) == 0) { + count += mca_btl_ugni_progress_datagram (ugni_module); + } + + if (ugni_module->connected_peer_count) { + mca_btl_ugni_progress_wait_list (ugni_module); + count += mca_btl_ugni_progress_local_smsg (ugni_module); + count += mca_btl_ugni_progress_remote_smsg (ugni_module); + } + + if (ugni_module->active_rdma_count) { + count += mca_btl_ugni_progress_rdma (ugni_module, 0); + } - count += mca_btl_ugni_progress_datagram (ugni_module); - count += mca_btl_ugni_progress_local_smsg (ugni_module); - count += mca_btl_ugni_progress_remote_smsg (ugni_module); - count += mca_btl_ugni_progress_rdma (ugni_module, 0); if (mca_btl_ugni_component.progress_thread_enabled) { count += mca_btl_ugni_progress_rdma (ugni_module, 1); } diff --git a/opal/mca/btl/ugni/btl_ugni_endpoint.c b/opal/mca/btl/ugni/btl_ugni_endpoint.c index fdaafffd5a..55be865057 100644 --- a/opal/mca/btl/ugni/btl_ugni_endpoint.c +++ b/opal/mca/btl/ugni/btl_ugni_endpoint.c @@ -81,6 +81,7 @@ int mca_btl_ugni_ep_disconnect (mca_btl_base_endpoint_t *ep, bool send_disconnec } ep->state = MCA_BTL_UGNI_EP_STATE_INIT; + (void) opal_atomic_add_64 (&ep->btl->connected_peer_count, -11); return OPAL_SUCCESS; } @@ -152,6 +153,7 @@ static inline int mca_btl_ugni_ep_connect_finish (mca_btl_base_endpoint_t *ep) { ep->rmt_irq_mem_hndl = ep->remote_attr.rmt_irq_mem_hndl; ep->state = MCA_BTL_UGNI_EP_STATE_CONNECTED; + (void) opal_atomic_add_64 (&ep->btl->connected_peer_count, 1); /* send all pending messages */ BTL_VERBOSE(("endpoint connected. posting %u sends", (unsigned int) opal_list_get_size (&ep->frag_wait_list))); diff --git a/opal/mca/btl/ugni/btl_ugni_frag.h b/opal/mca/btl/ugni/btl_ugni_frag.h index 8257ee2d70..5faa0061b0 100644 --- a/opal/mca/btl/ugni/btl_ugni_frag.h +++ b/opal/mca/btl/ugni/btl_ugni_frag.h @@ -112,12 +112,14 @@ static inline void mca_btl_ugni_alloc_post_descriptor (mca_btl_base_endpoint_t * (*desc)->cbdata = cbdata; (*desc)->local_handle = local_handle; (*desc)->endpoint = endpoint; + (void) OPAL_THREAD_ADD64(&endpoint->btl->active_rdma_count, 1); } } static inline void mca_btl_ugni_return_post_descriptor (mca_btl_ugni_module_t *module, mca_btl_ugni_post_descriptor_t *desc) { + (void) OPAL_THREAD_ADD64(&module->active_rdma_count, -1); opal_free_list_return (&module->post_descriptors, &desc->super); } diff --git a/opal/mca/btl/ugni/btl_ugni_module.c b/opal/mca/btl/ugni/btl_ugni_module.c index a884ef59f9..d9d9861c16 100644 --- a/opal/mca/btl/ugni/btl_ugni_module.c +++ b/opal/mca/btl/ugni/btl_ugni_module.c @@ -76,6 +76,8 @@ mca_btl_ugni_module_init (mca_btl_ugni_module_t *ugni_module, ugni_module->initialized = false; ugni_module->nlocal_procs = 0; ugni_module->active_send_count = 0; + ugni_module->connected_peer_count = 0; + ugni_module->active_rdma_count = 0; OBJ_CONSTRUCT(&ugni_module->failed_frags, opal_list_t); OBJ_CONSTRUCT(&ugni_module->failed_frags_lock, opal_mutex_t);