9fe5844071
add misc asserts to check for proper reference counting. ugly hack 1 -- use mallopt to never release memory ala sbrk - this is commented out in mca_btl_mvapi_component_init ugly hack 2 -- test registrations comming out of the tree via rcache_find, for an unknown reason the tree is returning registrations where the address is not within the base or bound of the registration. If this happens, we return NULL. comment out code to enable mem hooks if leave_pinned is set, note we can do this via an mca param and will default it to leave_pinned with mem_hooks when we iron out these issues. I am adding a unit test for the rcache. Note that we have a unit test for the rb tree but the compare function is significantly different than that used for registrations. After we have tracked down the issues with rcache_rb we will remove the above hacks. This commit was SVN r7499.
137 строки
4.1 KiB
C
137 строки
4.1 KiB
C
/*
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
* All rights reserved.
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
* All rights reserved.
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
* University of Stuttgart. All rights reserved.
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
* All rights reserved.
|
|
* $COPYRIGHT$
|
|
*
|
|
* Additional copyrights may follow
|
|
*
|
|
* $HEADER$
|
|
*/
|
|
|
|
#include "mca/rcache/rcache.h"
|
|
#include "rcache_rb.h"
|
|
#include "rcache_rb_tree.h"
|
|
#include "rcache_rb_mru.h"
|
|
|
|
|
|
/**
|
|
* Initialize the rcache
|
|
*/
|
|
|
|
void mca_rcache_rb_module_init( mca_rcache_rb_module_t* rcache ) {
|
|
|
|
rcache->base.rcache_find = mca_rcache_rb_find;
|
|
rcache->base.rcache_insert = mca_rcache_rb_insert;
|
|
rcache->base.rcache_delete = mca_rcache_rb_delete;
|
|
rcache->base.rcache_finalize = mca_rcache_rb_finalize;
|
|
mca_rcache_rb_tree_init(rcache);
|
|
mca_rcache_rb_mru_init(rcache);
|
|
}
|
|
|
|
int mca_rcache_rb_find (
|
|
struct mca_rcache_base_module_t* rcache,
|
|
void* addr,
|
|
size_t size,
|
|
ompi_pointer_array_t* regs,
|
|
uint32_t *cnt
|
|
){
|
|
|
|
int rc = OMPI_SUCCESS;
|
|
mca_rcache_rb_tree_item_t* tree_item;
|
|
OPAL_THREAD_LOCK(&rcache->lock);
|
|
*cnt = 0;
|
|
tree_item = mca_rcache_rb_tree_find( (mca_rcache_rb_module_t*) rcache, addr );
|
|
if(NULL == tree_item) {
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
return OMPI_ERROR;
|
|
}
|
|
|
|
|
|
rc = ompi_pointer_array_add(regs, (void*) tree_item->reg);
|
|
if(OMPI_SUCCESS != rc) {
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
return rc;
|
|
}
|
|
|
|
if( tree_item->reg->flags & MCA_MPOOL_FLAGS_CACHE ) {
|
|
rc = mca_rcache_rb_mru_touch((mca_rcache_rb_module_t*)rcache,
|
|
tree_item->reg);
|
|
}
|
|
OPAL_THREAD_ADD32((int32_t*) &tree_item->reg->ref_count, 1);
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
if(rc == OMPI_SUCCESS) {
|
|
*cnt = 1;
|
|
}
|
|
assert(tree_item->reg->bound - tree_item->reg->base > 0);
|
|
assert(tree_item->reg->base <= addr);
|
|
assert(tree_item->reg->bound >= addr);
|
|
return rc;
|
|
}
|
|
|
|
int mca_rcache_rb_insert (
|
|
struct mca_rcache_base_module_t* rcache,
|
|
mca_mpool_base_registration_t* reg,
|
|
uint32_t flags
|
|
) {
|
|
int rc = OMPI_SUCCESS;
|
|
OPAL_THREAD_LOCK(&rcache->lock);
|
|
if(flags & MCA_MPOOL_FLAGS_CACHE) {
|
|
rc = mca_rcache_rb_mru_insert( (mca_rcache_rb_module_t*) rcache, reg);
|
|
if(OMPI_SUCCESS != rc) {
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
return rc;
|
|
}
|
|
OPAL_THREAD_ADD32((int32_t*)®->ref_count, 1);
|
|
}
|
|
rc = mca_rcache_rb_tree_insert((mca_rcache_rb_module_t*)rcache, reg);
|
|
OPAL_THREAD_ADD32((int32_t*) ®->ref_count, 1);
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
return rc;
|
|
}
|
|
|
|
int mca_rcache_rb_delete (
|
|
struct mca_rcache_base_module_t* rcache,
|
|
mca_mpool_base_registration_t* reg,
|
|
uint32_t flags
|
|
) {
|
|
int rc = OMPI_SUCCESS;
|
|
assert(reg->ref_count >= 1);
|
|
OPAL_THREAD_LOCK(&rcache->lock);
|
|
if(flags & MCA_MPOOL_FLAGS_CACHE) {
|
|
assert(reg->ref_count >= 2);
|
|
OPAL_THREAD_ADD32((int32_t*)®->ref_count, -1);
|
|
rc = mca_rcache_rb_mru_delete( (mca_rcache_rb_module_t*) rcache, reg);
|
|
}
|
|
if(OMPI_SUCCESS != rc) {
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
return rc;
|
|
}
|
|
reg->flags = 0;
|
|
OPAL_THREAD_ADD32((int32_t*)®->ref_count, -1);
|
|
rc = mca_rcache_rb_tree_delete((mca_rcache_rb_module_t*)rcache, reg );
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
return rc;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* finalize
|
|
*/
|
|
void mca_rcache_rb_finalize(
|
|
struct mca_rcache_base_module_t* rcache
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|