From aac0dadddbe9c8b102b6be7dbea7f3fa89b8ea8a Mon Sep 17 00:00:00 2001 From: Galen Shipman Date: Tue, 21 Jun 2005 21:20:23 +0000 Subject: [PATCH] Further work on moving checking if the user buffer is pinned to the pml level. This commit was SVN r6125. --- src/class/ompi_circular_buffer_fifo.h | 12 ++++----- src/class/ompi_fifo.h | 2 +- src/mca/bmi/ib/bmi_ib.c | 6 ++++- src/mca/bmi/ib/bmi_ib.h | 4 +++ src/mca/bmi/ib/bmi_ib_component.c | 6 ++++- src/mca/bmi/ib/bmi_ib_endpoint.h | 11 ++++++--- src/mca/mpool/base/base.h | 2 +- src/mca/mpool/base/mpool_base_alloc.c | 34 ++++++++++++++------------ src/mca/mpool/base/mpool_base_init.c | 2 +- src/mca/mpool/mpool.h | 8 +++--- src/mca/mpool/sm/mpool_sm.h | 3 ++- src/mca/mpool/sm/mpool_sm_module.c | 3 ++- src/mca/mpool/vapi/mpool_vapi.h | 14 ++++++----- src/mca/mpool/vapi/mpool_vapi_module.c | 15 +++++++++--- 14 files changed, 78 insertions(+), 44 deletions(-) diff --git a/src/class/ompi_circular_buffer_fifo.h b/src/class/ompi_circular_buffer_fifo.h index 3df3730d52..7df0727349 100644 --- a/src/class/ompi_circular_buffer_fifo.h +++ b/src/class/ompi_circular_buffer_fifo.h @@ -227,14 +227,14 @@ static inline int ompi_cb_fifo_free( ompi_cb_fifo_t *fifo, /* free fifo array */ if( OMPI_CB_NULL != fifo->queue ){ ptr=(char *)(fifo->queue)+(size_t)(memory_allocator->mpool_base(memory_allocator)); - memory_allocator->mpool_free(memory_allocator, ptr); + memory_allocator->mpool_free(memory_allocator, ptr, NULL); fifo->queue=OMPI_CB_NULL; } /* free head control structure */ if( OMPI_CB_NULL != fifo->head) { ptr=(char *)(fifo->head)+(size_t)(memory_allocator->mpool_base(memory_allocator)); - memory_allocator->mpool_free(memory_allocator, ptr); + memory_allocator->mpool_free(memory_allocator, ptr, NULL); fifo->head=OMPI_CB_NULL; } @@ -242,7 +242,7 @@ static inline int ompi_cb_fifo_free( ompi_cb_fifo_t *fifo, /* free tail control structure */ if( OMPI_CB_NULL != fifo->tail) { ptr=(char *)(fifo->tail)+(size_t)(memory_allocator->mpool_base(memory_allocator)); - memory_allocator->mpool_free(memory_allocator, ptr); + memory_allocator->mpool_free(memory_allocator, ptr, NULL); fifo->tail=OMPI_CB_NULL; } @@ -550,14 +550,14 @@ static inline int ompi_cb_fifo_free_same_base_addr( ompi_cb_fifo_t *fifo, /* free fifo array */ if( OMPI_CB_NULL != fifo->head ){ ptr=(char *)(fifo->queue); - memory_allocator->mpool_free(memory_allocator, ptr); + memory_allocator->mpool_free(memory_allocator, ptr, NULL); fifo->queue=OMPI_CB_NULL; } /* free head control structure */ if( OMPI_CB_NULL != fifo->head) { ptr=(char *)(fifo->head); - memory_allocator->mpool_free(memory_allocator, ptr); + memory_allocator->mpool_free(memory_allocator, ptr, NULL); fifo->head=OMPI_CB_NULL; } @@ -565,7 +565,7 @@ static inline int ompi_cb_fifo_free_same_base_addr( ompi_cb_fifo_t *fifo, /* free tail control structure */ if( OMPI_CB_NULL != fifo->tail) { ptr=(char *)(fifo->tail); - memory_allocator->mpool_free(memory_allocator, ptr); + memory_allocator->mpool_free(memory_allocator, ptr, NULL); fifo->tail=OMPI_CB_NULL; } diff --git a/src/class/ompi_fifo.h b/src/class/ompi_fifo.h index 1c25f97e27..804f212d5e 100644 --- a/src/class/ompi_fifo.h +++ b/src/class/ompi_fifo.h @@ -182,7 +182,7 @@ static inline int ompi_fifo_free( ompi_fifo_t *fifo, ff_tmp=(ompi_cb_fifo_wrapper_t *)ff->next_fifo_wrapper; /* free the element */ - memory_allocator->mpool_free(memory_allocator, ff); + memory_allocator->mpool_free(memory_allocator, ff, NULL); ff=ff_tmp; diff --git a/src/mca/bmi/ib/bmi_ib.c b/src/mca/bmi/ib/bmi_ib.c index 524b14132d..7e4673b6a6 100644 --- a/src/mca/bmi/ib/bmi_ib.c +++ b/src/mca/bmi/ib/bmi_ib.c @@ -69,7 +69,7 @@ int mca_bmi_ib_add_procs( int i, rc; for(i = 0; i < (int) nprocs; i++) { - + struct ompi_proc_t* ompi_proc = ompi_procs[i]; mca_bmi_ib_proc_t* ib_proc; mca_bmi_base_endpoint_t* ib_peer; @@ -130,8 +130,12 @@ int mca_bmi_ib_register( { /* TODO add register stuff here... */ mca_bmi_ib_module_t* ib_bmi = (mca_bmi_ib_module_t*) bmi; + + + OMPI_THREAD_LOCK(&ib->bmi.ib_lock); ib_bmi->ib_reg[tag].cbfunc = cbfunc; ib_bmi->ib_reg[tag].cbdata = cbdata; + OMPI_THREAD_UNLOCK(&ib->bmi.ib_lock); return OMPI_SUCCESS; } diff --git a/src/mca/bmi/ib/bmi_ib.h b/src/mca/bmi/ib/bmi_ib.h index 4b67a1ca64..75a9a1e654 100644 --- a/src/mca/bmi/ib/bmi_ib.h +++ b/src/mca/bmi/ib/bmi_ib.h @@ -131,8 +131,12 @@ struct mca_bmi_ib_module_t { ompi_list_t repost; /**< list of buffers to repost */ + ompi_mutex_t ib_lock; /**< module level lock */ + + mca_mpool_base_module_t* ib_pool; /**< ib memory pool */ + uint32_t rr_posted_high; /**< number of high priority rr posted to the nic*/ uint32_t rr_posted_low; /**< number of low priority rr posted to the nic*/ diff --git a/src/mca/bmi/ib/bmi_ib_component.c b/src/mca/bmi/ib/bmi_ib_component.c index 43ddb79599..a98cfd615d 100644 --- a/src/mca/bmi/ib/bmi_ib_component.c +++ b/src/mca/bmi/ib/bmi_ib_component.c @@ -276,7 +276,9 @@ mca_bmi_base_module_t** mca_bmi_ib_component_init(int *num_bmi_modules, a distinct bmi module for each hca port */ OBJ_CONSTRUCT(&bmi_list, ompi_list_t); - + OBJ_CONSTRUCT(&mca_bmi_ib_component.ib_lock, ompi_mutex_t); + + for(i = 0; i < num_hcas; i++){ vapi_ret = EVAPI_get_hca_hndl(hca_ids[i], &hca_hndl); if(VAPI_OK != vapi_ret) { @@ -351,6 +353,8 @@ mca_bmi_base_module_t** mca_bmi_ib_component_init(int *num_bmi_modules, /* Initialize module state */ + + OBJ_CONSTRUCT(&ib_bmi->ib_lock, ompi_mutex_t); OBJ_CONSTRUCT(&ib_bmi->send_free_eager, ompi_free_list_t); OBJ_CONSTRUCT(&ib_bmi->send_free_max, ompi_free_list_t); OBJ_CONSTRUCT(&ib_bmi->send_free_frag, ompi_free_list_t); diff --git a/src/mca/bmi/ib/bmi_ib_endpoint.h b/src/mca/bmi/ib/bmi_ib_endpoint.h index 933b02c744..b601980e5f 100644 --- a/src/mca/bmi/ib/bmi_ib_endpoint.h +++ b/src/mca/bmi/ib/bmi_ib_endpoint.h @@ -162,6 +162,7 @@ static inline int mca_bmi_ib_endpoint_post_rr_sub(int cnt, static inline int mca_bmi_ib_endpoint_post_rr( mca_bmi_ib_endpoint_t * endpoint, int additional){ mca_bmi_ib_module_t * ib_bmi = endpoint->endpoint_bmi; int rc; + OMPI_THREAD_LOCK(&ib_bmi->ib_lock); if(ib_bmi->rr_posted_high <= mca_bmi_ib_component.ib_rr_buf_min+additional && ib_bmi->rr_posted_high < mca_bmi_ib_component.ib_rr_buf_max){ @@ -172,9 +173,10 @@ static inline int mca_bmi_ib_endpoint_post_rr( mca_bmi_ib_endpoint_t * endpoint, ib_bmi->nic, endpoint->lcl_qp_hndl_high ); - if(rc != OMPI_SUCCESS) + if(rc != OMPI_SUCCESS){ + OMPI_THREAD_UNLOCK(&ib_bmi->ib_lock); return rc; - + } } if(ib_bmi->rr_posted_low <= mca_bmi_ib_component.ib_rr_buf_min+additional && ib_bmi->rr_posted_low < mca_bmi_ib_component.ib_rr_buf_max){ @@ -185,10 +187,13 @@ static inline int mca_bmi_ib_endpoint_post_rr( mca_bmi_ib_endpoint_t * endpoint, ib_bmi->nic, endpoint->lcl_qp_hndl_low ); - if(rc != OMPI_SUCCESS) + if(rc != OMPI_SUCCESS) { + OMPI_THREAD_UNLOCK(&ib_bmi->ib_lock); return rc; + } } + OMPI_THREAD_UNLOCK(&ib_bmi->ib_lock); return OMPI_SUCCESS; diff --git a/src/mca/mpool/base/base.h b/src/mca/mpool/base/base.h index 00a9a56d29..020824f590 100644 --- a/src/mca/mpool/base/base.h +++ b/src/mca/mpool/base/base.h @@ -107,7 +107,7 @@ OMPI_DECLSPEC extern ompi_list_t mca_mpool_base_components; OMPI_DECLSPEC extern ompi_list_t mca_mpool_base_modules; OMPI_DECLSPEC extern ompi_free_list_t mca_mpool_base_mem_list; OMPI_DECLSPEC extern ompi_rb_tree_t mca_mpool_base_tree; -OMPI_DECLSPEC extern ompi_mutex_t tree_lock; +OMPI_DECLSPEC extern ompi_mutex_t mca_mpool_base_tree_lock; #if defined(c_plusplus) || defined(__cplusplus) } diff --git a/src/mca/mpool/base/mpool_base_alloc.c b/src/mca/mpool/base/mpool_base_alloc.c index db734d9a17..468b2831bf 100644 --- a/src/mca/mpool/base/mpool_base_alloc.c +++ b/src/mca/mpool/base/mpool_base_alloc.c @@ -27,7 +27,7 @@ ompi_rb_tree_t mca_mpool_base_tree; ompi_free_list_t mca_mpool_base_mem_list; -ompi_mutex_t tree_lock; +ompi_mutex_t mca_mpool_base_tree_lock; /** @@ -72,10 +72,10 @@ int mca_mpool_base_insert(void * addr, size_t size, ((mca_mpool_base_chunk_t *) item)->key.top = (void *) ((char *) addr + size - 1); - OMPI_THREAD_LOCK(tree_lock); + OMPI_THREAD_LOCK(mca_mpool_base_tree_lock); rc = ompi_rb_tree_insert(&mca_mpool_base_tree, &((mca_mpool_base_chunk_t *)item)->key, item); - OMPI_THREAD_UNLOCK(tree_lock); + OMPI_THREAD_UNLOCK(mca_mpool_base_tree_lock); if(rc != OMPI_SUCCESS) return rc; @@ -101,9 +101,9 @@ int mca_mpool_base_remove(void * base) return OMPI_ERR_BAD_PARAM; } - OMPI_THREAD_LOCK(tree_lock); + OMPI_THREAD_LOCK(mca_mpool_base_tree_lock); rc = ompi_rb_tree_delete(&mca_mpool_base_tree, &chunk->key); - OMPI_THREAD_UNLOCK(tree_lock); + OMPI_THREAD_UNLOCK(mca_mpool_base_tree_lock); if(OMPI_SUCCESS == rc) return OMPI_SUCCESS; @@ -228,11 +228,11 @@ void * mca_mpool_base_alloc(size_t size, ompi_info_t * info) ((mca_mpool_base_chunk_t *) item)->key.bottom = mem; ((mca_mpool_base_chunk_t *) item)->key.top = (void *) ((char *) mem + size - 1); - OMPI_THREAD_LOCK(tree_lock); + OMPI_THREAD_LOCK(mca_mpool_base_tree_lock); ompi_rb_tree_insert(&mca_mpool_base_tree, &((mca_mpool_base_chunk_t *)item)->key, item); - OMPI_THREAD_UNLOCK(tree_lock); + OMPI_THREAD_UNLOCK(mca_mpool_base_tree_lock); return mem; } @@ -296,11 +296,11 @@ void * mca_mpool_base_alloc(size_t size, ompi_info_t * info) { ((mca_mpool_base_chunk_t *) item)->mpools[num_modules].mpool = NULL; } - OMPI_THREAD_LOCK(tree_lock); + OMPI_THREAD_LOCK(mca_mpool_base_tree_lock); ompi_rb_tree_insert(&mca_mpool_base_tree, &((mca_mpool_base_chunk_t *)item)->key, item); - OMPI_THREAD_UNLOCK(tree_lock); + OMPI_THREAD_UNLOCK(mca_mpool_base_tree_lock); free(has_reg_function); return mem; @@ -331,9 +331,9 @@ int mca_mpool_base_free(void * base) free(chunk->key.bottom); OMPI_FREE_LIST_RETURN(&mca_mpool_base_mem_list, (ompi_list_item_t*) chunk); - OMPI_THREAD_LOCK(tree_lock); + OMPI_THREAD_LOCK(mca_mpool_base_tree_lock); rc = ompi_rb_tree_delete(&mca_mpool_base_tree, &chunk->key); - OMPI_THREAD_UNLOCK(tree_lock); + OMPI_THREAD_UNLOCK(mca_mpool_base_tree_lock); if(OMPI_SUCCESS == rc) return OMPI_SUCCESS; @@ -347,15 +347,17 @@ int mca_mpool_base_free(void * base) for( ; i > 0; i--) { chunk->mpools[i].mpool->mpool_deregister(chunk->mpools[i].mpool, - chunk->key.bottom, - ((char *) chunk->key.top - (char *) chunk->key.bottom + 1)); + chunk->key.bottom, + ((char *) chunk->key.top - (char *) chunk->key.bottom + 1), + chunk->mpools[i].bmi_registration + ); } - chunk->mpools[i].mpool->mpool_free(chunk->mpools[i].mpool, chunk->key.bottom); + chunk->mpools[i].mpool->mpool_free(chunk->mpools[i].mpool, chunk->key.bottom, chunk->mpools[i].bmi_registration); OMPI_FREE_LIST_RETURN(&mca_mpool_base_mem_list, (ompi_list_item_t *) chunk); - OMPI_THREAD_LOCK(tree_lock); + OMPI_THREAD_LOCK(mca_mpool_base_tree_lock); rc = ompi_rb_tree_delete(&mca_mpool_base_tree, &chunk->key); - OMPI_THREAD_UNLOCK(tree_lock); + OMPI_THREAD_UNLOCK(mca_mpool_base_tree_lock); if(OMPI_SUCCESS == rc) return OMPI_SUCCESS; diff --git a/src/mca/mpool/base/mpool_base_init.c b/src/mca/mpool/base/mpool_base_init.c index 3e2090be81..ef24587226 100644 --- a/src/mca/mpool/base/mpool_base_init.c +++ b/src/mca/mpool/base/mpool_base_init.c @@ -48,7 +48,7 @@ int mca_mpool_base_init(bool enable_progress_threads, bool enable_mpi_threads) ompi_free_list_init(&mca_mpool_base_mem_list, sizeof(mca_mpool_base_chunk_t), OBJ_CLASS(mca_mpool_base_chunk_t), 0, -1 , 128, NULL); OBJ_CONSTRUCT(&mca_mpool_base_tree, ompi_rb_tree_t); - OBJ_CONSTRUCT(&tree_lock, ompi_mutex_t); + OBJ_CONSTRUCT(&mca_mpool_base_tree_lock, ompi_mutex_t); return ompi_rb_tree_init(&mca_mpool_base_tree, mca_mpool_base_tree_node_compare); } diff --git a/src/mca/mpool/mpool.h b/src/mca/mpool/mpool.h index 3b03a5c9ab..a0cb0aadcc 100644 --- a/src/mca/mpool/mpool.h +++ b/src/mca/mpool/mpool.h @@ -56,7 +56,8 @@ typedef void* (*mca_mpool_base_module_realloc_fn_t)( */ typedef void (*mca_mpool_base_module_free_fn_t)( struct mca_mpool_base_module_t* mpool, - void *); + void *, + struct mca_mpool_base_registration_t* registration); /** * register memory @@ -73,7 +74,8 @@ typedef int (*mca_mpool_base_module_register_fn_t)( typedef int (*mca_mpool_base_module_deregister_fn_t)( struct mca_mpool_base_module_t* mpool, void * addr, - size_t size); + size_t size, + struct mca_bmi_base_registration_t* registration); /** * if appropriate - returns base address of memory pool @@ -155,7 +157,7 @@ OMPI_DECLSPEC void * mca_mpool_base_alloc(size_t size, ompi_info_t * info); * @retval OMPI_SUCCESS * @retval OMPI_ERR_BAD_PARAM if the passed base pointer was invalid */ -OMPI_DECLSPEC int mca_mpool_base_free(void * base); +OMPI_DECLSPEC int mca_mpool_base_free(void * base); /** * Function for the red black tree to compare 2 keys diff --git a/src/mca/mpool/sm/mpool_sm.h b/src/mca/mpool/sm/mpool_sm.h index 7d7a34d2f9..407815a198 100644 --- a/src/mca/mpool/sm/mpool_sm.h +++ b/src/mca/mpool/sm/mpool_sm.h @@ -82,7 +82,8 @@ void* mca_mpool_sm_realloc( */ void mca_mpool_sm_free( mca_mpool_base_module_t* mpool, - void *); + void * addr, + struct mca_bmi_base_registration_t* registration); #if defined(c_plusplus) || defined(__cplusplus) diff --git a/src/mca/mpool/sm/mpool_sm_module.c b/src/mca/mpool/sm/mpool_sm_module.c index 4241995515..2e0e51cc3a 100644 --- a/src/mca/mpool/sm/mpool_sm_module.c +++ b/src/mca/mpool/sm/mpool_sm_module.c @@ -74,7 +74,8 @@ void* mca_mpool_sm_realloc( /** * free function */ -void mca_mpool_sm_free(mca_mpool_base_module_t* mpool, void * addr) +void mca_mpool_sm_free(mca_mpool_base_module_t* mpool, void * addr, + struct mca_bmi_base_registration_t* registration) { mca_mpool_sm_module_t* mpool_sm = (mca_mpool_sm_module_t*)mpool; mpool_sm->sm_allocator->alc_free(mpool_sm->sm_allocator, addr); diff --git a/src/mca/mpool/vapi/mpool_vapi.h b/src/mca/mpool/vapi/mpool_vapi.h index 7fc13ae5d6..8feecb2cc0 100644 --- a/src/mca/mpool/vapi/mpool_vapi.h +++ b/src/mca/mpool/vapi/mpool_vapi.h @@ -53,10 +53,9 @@ typedef struct mca_mpool_vapi_component_t mca_mpool_vapi_component_t; OMPI_COMP_EXPORT extern mca_mpool_vapi_component_t mca_mpool_vapi_component; struct mca_mpool_vapi_module_t { - mca_mpool_base_module_t super; - mca_allocator_base_module_t * vapi_allocator; - mca_bmi_base_resources_t hca_pd; - mca_bmi_base_registration_t mem_hndl; + mca_mpool_base_module_t super; + mca_allocator_base_module_t * vapi_allocator; + mca_bmi_base_resources_t hca_pd; }; typedef struct mca_mpool_vapi_module_t mca_mpool_vapi_module_t; /* @@ -100,13 +99,16 @@ int mca_mpool_vapi_register( int mca_mpool_vapi_deregister( mca_mpool_base_module_t* mpool, void *addr, - size_t size); + size_t size, + struct mca_bmi_base_registration_t* ); /** * free function typedef */ -void mca_mpool_vapi_free(mca_mpool_base_module_t* mpool, void *); +void mca_mpool_vapi_free(mca_mpool_base_module_t* mpool, + void * addr, + struct mca_bmi_base_registration_t* registration); void* mca_common_vapi_segment_alloc( struct mca_mpool_base_module_t* module, diff --git a/src/mca/mpool/vapi/mpool_vapi_module.c b/src/mca/mpool/vapi/mpool_vapi_module.c index 24b1752111..a1338e4a49 100644 --- a/src/mca/mpool/vapi/mpool_vapi_module.c +++ b/src/mca/mpool/vapi/mpool_vapi_module.c @@ -105,20 +105,22 @@ int mca_mpool_vapi_register(mca_mpool_base_module_t* mpool, void *addr, size_t s /* * deregister memory */ -int mca_mpool_vapi_deregister(mca_mpool_base_module_t* mpool, void *addr, size_t size){ +int mca_mpool_vapi_deregister(mca_mpool_base_module_t* mpool, void *addr, size_t size, + struct mca_bmi_base_registration_t* registration){ VAPI_ret_t ret; mca_mpool_vapi_module_t * mpool_vapi = (mca_mpool_vapi_module_t*) mpool; ret = VAPI_deregister_mr( mpool_vapi->hca_pd.hca, - mpool_vapi->mem_hndl.hndl + registration->hndl ); if(VAPI_OK != ret){ ompi_output(0, "%s: error unpinning vapi memory\n", __func__); return OMPI_ERROR; } + free(registration); return OMPI_SUCCESS; } @@ -138,10 +140,15 @@ void* mca_mpool_vapi_realloc( /** * free function */ -void mca_mpool_vapi_free(mca_mpool_base_module_t* mpool, void * addr) +void mca_mpool_vapi_free(mca_mpool_base_module_t* mpool, void * addr, + struct mca_bmi_base_registration_t* registration) { + mca_mpool_vapi_module_t* mpool_vapi = (mca_mpool_vapi_module_t*)mpool; + mpool_vapi->super.mpool_deregister(mpool, addr, 0, registration); mpool_vapi->vapi_allocator->alc_free(mpool_vapi->vapi_allocator, addr); + + } @@ -161,4 +168,6 @@ void mca_mpool_vapi_free(mca_mpool_base_module_t* mpool, void * addr) + +