2005-09-04 08:17:00 +04:00
|
|
|
/**
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-24 20:38:08 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-09-04 08:17:00 +04:00
|
|
|
* 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.
|
2005-09-24 20:45:34 +04:00
|
|
|
* All rights reserved.5A
|
2005-09-04 08:17:00 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Description of the Registration Cache framework
|
|
|
|
*/
|
|
|
|
|
2006-08-24 20:38:08 +04:00
|
|
|
#include "ompi_config.h"
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/mca/mca.h"
|
2005-09-04 08:17:00 +04:00
|
|
|
#include "rcache_rb_tree.h"
|
|
|
|
|
|
|
|
|
2006-06-12 20:44:00 +04:00
|
|
|
OBJ_CLASS_INSTANCE(mca_rcache_rb_tree_item_t, ompi_free_list_item_t, NULL, NULL);
|
2005-09-08 00:37:17 +04:00
|
|
|
|
2006-01-24 01:51:50 +03:00
|
|
|
|
2005-09-09 01:34:26 +04:00
|
|
|
int mca_rcache_rb_tree_node_compare(void * key1, void * key2);
|
|
|
|
|
2005-09-08 00:37:17 +04:00
|
|
|
int mca_rcache_rb_tree_init(mca_rcache_rb_module_t* rcache) {
|
|
|
|
OBJ_CONSTRUCT(&rcache->rb_tree, ompi_rb_tree_t);
|
2005-09-09 01:34:26 +04:00
|
|
|
OBJ_CONSTRUCT(&rcache->rb_tree_item_list, ompi_free_list_t);
|
2007-11-02 02:38:50 +03:00
|
|
|
ompi_free_list_init_new(&rcache->rb_tree_item_list,
|
|
|
|
sizeof(mca_rcache_rb_tree_item_t),
|
|
|
|
CACHE_LINE_SIZE,
|
|
|
|
OBJ_CLASS(mca_rcache_rb_tree_item_t),
|
|
|
|
0,CACHE_LINE_SIZE,
|
|
|
|
0, -1, 32, NULL);
|
2005-09-09 01:34:26 +04:00
|
|
|
|
|
|
|
return ompi_rb_tree_init(&rcache->rb_tree,
|
|
|
|
mca_rcache_rb_tree_node_compare);
|
2005-09-08 00:37:17 +04:00
|
|
|
}
|
2005-09-04 08:17:00 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches the mpool to see if it has allocated the memory that is passed in.
|
|
|
|
* If so it returns an array of mpools the memory is registered with.
|
|
|
|
*
|
|
|
|
* @param base pointer to the memory to lookup
|
|
|
|
*
|
|
|
|
* @retval NULL if the memory is not in any mpool
|
|
|
|
* @retval pointer to an array of type mca_mpool_base_reg_mpool_t
|
|
|
|
*/
|
|
|
|
struct mca_rcache_rb_tree_item_t * mca_rcache_rb_tree_find(
|
2005-09-13 02:28:23 +04:00
|
|
|
mca_rcache_rb_module_t* rcache,
|
2005-09-04 08:17:00 +04:00
|
|
|
void * base
|
|
|
|
)
|
|
|
|
{
|
2005-09-24 04:24:49 +04:00
|
|
|
mca_rcache_rb_tree_item_t* found = NULL;
|
2005-09-13 02:28:23 +04:00
|
|
|
mca_rcache_rb_tree_key_t key;
|
2005-09-24 04:24:49 +04:00
|
|
|
|
2005-09-13 02:28:23 +04:00
|
|
|
|
|
|
|
key.base = base;
|
|
|
|
key.bound = base;
|
|
|
|
found = (mca_rcache_rb_tree_item_t *)
|
|
|
|
ompi_rb_tree_find(&rcache->rb_tree, &key);
|
2006-01-24 01:51:50 +03:00
|
|
|
if(found) {
|
2005-09-28 06:11:35 +04:00
|
|
|
assert((void*)found->reg->bound >= base);
|
2006-01-24 01:51:50 +03:00
|
|
|
}
|
2005-09-13 02:28:23 +04:00
|
|
|
return found;
|
2005-09-04 08:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Memory Pool Registration
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for the red black tree to compare 2 keys
|
|
|
|
*
|
|
|
|
* @param key1 a pointer to the 1st key
|
|
|
|
* @param key2 a pointer to the second key
|
|
|
|
*
|
|
|
|
* @retval -1 if key1 is below key2
|
|
|
|
* @retval 1 if key 1 is above key2
|
|
|
|
* @retval 0 if the keys are the same
|
|
|
|
*/
|
2005-09-09 01:34:26 +04:00
|
|
|
|
2005-09-04 08:17:00 +04:00
|
|
|
int mca_rcache_rb_tree_node_compare(void * key1, void * key2)
|
|
|
|
{
|
|
|
|
if(((mca_rcache_rb_tree_key_t *) key1)->base <
|
|
|
|
((mca_rcache_rb_tree_key_t *) key2)->base)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(((mca_rcache_rb_tree_key_t *) key1)->base >
|
|
|
|
((mca_rcache_rb_tree_key_t *) key2)->bound)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int mca_rcache_rb_tree_insert(
|
|
|
|
mca_rcache_rb_module_t* rb_module,
|
|
|
|
mca_mpool_base_registration_t* reg
|
|
|
|
)
|
|
|
|
{
|
2006-06-12 20:44:00 +04:00
|
|
|
ompi_free_list_item_t *item;
|
2005-09-04 08:17:00 +04:00
|
|
|
int rc;
|
|
|
|
mca_rcache_rb_tree_item_t* rb_tree_item;
|
2006-01-24 01:51:50 +03:00
|
|
|
|
2005-09-04 08:17:00 +04:00
|
|
|
OMPI_FREE_LIST_GET(&rb_module->rb_tree_item_list, item, rc);
|
2006-02-02 20:14:49 +03:00
|
|
|
if(OMPI_SUCCESS != rc) {
|
2005-09-04 08:17:00 +04:00
|
|
|
return rc;
|
2006-02-02 20:14:49 +03:00
|
|
|
}
|
2005-09-04 08:17:00 +04:00
|
|
|
rb_tree_item = (mca_rcache_rb_tree_item_t*) item;
|
|
|
|
|
2005-09-27 22:10:44 +04:00
|
|
|
rb_tree_item->key.base = reg->base;
|
|
|
|
rb_tree_item->key.bound = reg->bound;
|
2005-09-04 08:17:00 +04:00
|
|
|
rb_tree_item->reg = reg;
|
|
|
|
|
|
|
|
rc = ompi_rb_tree_insert(&rb_module->rb_tree,
|
|
|
|
(void*) &rb_tree_item->key, item);
|
2005-09-13 02:28:23 +04:00
|
|
|
|
2005-09-04 08:17:00 +04:00
|
|
|
if(OMPI_SUCCESS != rc) {
|
|
|
|
OMPI_FREE_LIST_RETURN(&rb_module->rb_tree_item_list, item);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to remove previously memory from the tree without freeing it
|
|
|
|
*
|
|
|
|
* @param base pointer to the memory to free
|
|
|
|
*
|
|
|
|
* @retval OMPI_SUCCESS
|
|
|
|
* @retval OMPI_ERR_BAD_PARAM if the passed base pointer was invalid
|
|
|
|
*/
|
|
|
|
int mca_rcache_rb_tree_delete(mca_rcache_rb_module_t* rb_module,
|
|
|
|
mca_mpool_base_registration_t* reg)
|
|
|
|
{
|
|
|
|
int rc;
|
2006-01-24 01:51:50 +03:00
|
|
|
mca_rcache_rb_tree_item_t *tree_item;
|
2005-09-04 08:17:00 +04:00
|
|
|
tree_item = mca_rcache_rb_tree_find(rb_module,
|
|
|
|
reg->base);
|
|
|
|
if(NULL == tree_item) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2006-01-24 01:51:50 +03:00
|
|
|
assert(reg == tree_item->reg);
|
2005-09-04 08:17:00 +04:00
|
|
|
rc = ompi_rb_tree_delete(&rb_module->rb_tree, &tree_item->key);
|
2006-01-24 01:51:50 +03:00
|
|
|
|
2006-06-13 02:09:03 +04:00
|
|
|
OMPI_FREE_LIST_RETURN(&rb_module->rb_tree_item_list,
|
|
|
|
(ompi_free_list_item_t*) tree_item);
|
2006-01-24 01:51:50 +03:00
|
|
|
|
2005-09-04 08:17:00 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|