1
1

* Move Gleb's rcache work from the gleb-rcache branch to the trunk

This commit was SVN r11198.
Этот коммит содержится в:
David Daniel 2006-08-15 18:40:08 +00:00
родитель 7d8d5d0c75
Коммит 59f2d86c36
13 изменённых файлов: 1149 добавлений и 12 удалений

Просмотреть файл

@ -169,16 +169,16 @@ int ompi_rb_tree_insert(ompi_rb_tree_t *tree, void * key, void * value)
return OMPI_SUCCESS;
}
/* Finds the node in the tree based on the key */
void * ompi_rb_tree_find(ompi_rb_tree_t *tree, void *key)
void * ompi_rb_tree_find_with(ompi_rb_tree_t *tree, void *key,
ompi_rb_tree_comp_fn_t compfn)
{
ompi_rb_tree_node_t * node;
int compvalue;
node = tree->root_ptr->left;
while (node != tree->nill) {
compvalue = tree->comp(key, node->key);
compvalue = compfn(key, node->key);
/* if the result of the comparison function is 0, we found it */
if (compvalue == 0) {
return(node->value);

Просмотреть файл

@ -143,6 +143,19 @@ OMPI_DECLSPEC int ompi_rb_tree_init(ompi_rb_tree_t * tree, ompi_rb_tree_comp_fn_
*/
OMPI_DECLSPEC int ompi_rb_tree_insert(ompi_rb_tree_t *tree, void * key, void * value);
/**
* finds a value in the tree based on the passed key using passed
* compare function
*
* @param tree a pointer to the tree data structure
* @param key a pointer to the key
* @param compare function
*
* @retval pointer to the value if found
* @retval NULL if not found
*/
OMPI_DECLSPEC void * ompi_rb_tree_find_with(ompi_rb_tree_t *tree, void *key, ompi_rb_tree_comp_fn_t compfn);
/**
* finds a value in the tree based on the passed key
*
@ -152,7 +165,10 @@ OMPI_DECLSPEC int ompi_rb_tree_insert(ompi_rb_tree_t *tree, void * key, void * v
* @retval pointer to the value if found
* @retval NULL if not found
*/
OMPI_DECLSPEC void * ompi_rb_tree_find(ompi_rb_tree_t *tree, void *key);
static inline void * ompi_rb_tree_find(ompi_rb_tree_t *tree, void *key)
{
return ompi_rb_tree_find_with(tree, key, tree->comp);
}
/**
* deletes a node based on its key

Просмотреть файл

@ -98,13 +98,6 @@ OBJ_CLASS_INSTANCE(
static int mca_mpool_openib_open(void)
{
return OMPI_SUCCESS;
}
static mca_mpool_base_module_t* mca_mpool_openib_init(
struct mca_mpool_base_resources_t* resources)
{
mca_mpool_openib_module_t* mpool_module;
mca_base_param_reg_string(&mca_mpool_openib_component.super.mpool_version,
"rcache_name",
"The name of the registration cache the mpool should use",
@ -112,7 +105,13 @@ static mca_mpool_base_module_t* mca_mpool_openib_init(
false,
"rb",
&(mca_mpool_openib_component.rcache_name));
return OMPI_SUCCESS;
}
static mca_mpool_base_module_t* mca_mpool_openib_init(
struct mca_mpool_base_resources_t* resources)
{
mca_mpool_openib_module_t* mpool_module;
mpool_module = (mca_mpool_openib_module_t*)malloc(sizeof(mca_mpool_openib_module_t));

Просмотреть файл

@ -35,6 +35,7 @@ mca_rcache_base_module_t* mca_rcache_base_module_create(const char* name)
mca_rcache_base_module_t* module = NULL;
opal_list_item_t* item;
mca_rcache_base_selected_module_t *sm;
bool found = false;
for (item = opal_list_get_first(&mca_rcache_base_components);
item != opal_list_get_end(&mca_rcache_base_components);
@ -44,11 +45,12 @@ mca_rcache_base_module_t* mca_rcache_base_module_create(const char* name)
component =
(mca_rcache_base_component_t *) cli->cli_component;
if(0 == strcmp(component->rcache_version.mca_component_name, name)) {
found = true;
break;
}
}
if (NULL == component) {
if (!found) {
return NULL;
}
module = component->rcache_init();

61
ompi/mca/rcache/vma/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,61 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. 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$
#
# Use the top-level Makefile.options
include $(top_ompi_srcdir)/config/Makefile.options
sources = \
rcache_vma.c \
rcache_vma.h \
rcache_vma_component.c \
rcache_vma_tree.c \
rcache_vma_tree.h \
rcache_vma_mru.c \
rcache_vma_mru.h
# Make the output library in this directory, and name it either
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds).
if OMPI_BUILD_rcache_vma_DSO
lib =
lib_sources =
component = mca_rcache_vma.la
component_sources = $(sources)
else
lib = libmca_rcache_vma.la
lib_sources = $(sources)
component =
component_sources =
endif
mcacomponentdir = $(libdir)/openmpi
mcacomponent_LTLIBRARIES = $(component)
mca_rcache_vma_la_SOURCES = $(component_sources)
mca_rcache_vma_la_LDFLAGS = -module -avoid-version $(rcache_vma_LDFLAGS)
mca_rcache_vma_la_LIBADD = \
$(rcache_vma_LIBS) \
$(top_ompi_builddir)/ompi/libmpi.la \
$(top_ompi_builddir)/orte/liborte.la \
$(top_ompi_builddir)/opal/libopal.la
noinst_LTLIBRARIES = $(lib)
libmca_rcache_vma_la_SOURCES = $(lib_sources)
libmca_rcache_vma_la_LDFLAGS = -module -avoid-version$ $(rcache_vma_LDFLAGS)
libmca_rcache_vma_la_LIBADD = $(rcache_vma_LIBS)

22
ompi/mca/rcache/vma/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,22 @@
# -*- shell-script -*-
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. 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$
#
# Specific to this module
PARAM_CONFIG_FILES="Makefile"

168
ompi/mca/rcache/vma/rcache_vma.c Обычный файл
Просмотреть файл

@ -0,0 +1,168 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi/mca/rcache/rcache.h"
#include "rcache_vma.h"
#include "rcache_vma_tree.h"
#include "rcache_vma_mru.h"
#include "opal/util/output.h"
#include "ompi/mca/mpool/base/base.h"
extern unsigned int mca_mpool_base_page_size;
extern unsigned int mca_mpool_base_page_size_log;
/**
* Initialize the rcache
*/
void mca_rcache_vma_module_init( mca_rcache_vma_module_t* rcache ) {
rcache->base.rcache_find = mca_rcache_vma_find;
rcache->base.rcache_insert = mca_rcache_vma_insert;
rcache->base.rcache_delete = mca_rcache_vma_delete;
rcache->base.rcache_finalize = mca_rcache_vma_finalize;
OBJ_CONSTRUCT(&rcache->base.lock, opal_mutex_t);
mca_rcache_vma_tree_init(rcache);
mca_rcache_vma_mru_init(rcache);
}
int mca_rcache_vma_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_mpool_base_registration_t *reg;
void* base_addr;
void* bound_addr;
if(size == 0) {
return OMPI_ERROR;
}
OPAL_THREAD_LOCK(&rcache->lock);
*cnt = 0;
base_addr = down_align_addr(addr, mca_mpool_base_page_size_log);
bound_addr = up_align_addr((void*) ((unsigned long) addr + size - 1), mca_mpool_base_page_size_log);
reg = mca_rcache_vma_tree_find((mca_rcache_vma_module_t*)rcache, base_addr,
bound_addr);
if (reg != NULL) {
ompi_pointer_array_add(regs, (void*) reg);
if(reg->flags & MCA_MPOOL_FLAGS_CACHE) {
rc = mca_rcache_vma_mru_touch((mca_rcache_vma_module_t*)rcache, reg);
if(OMPI_SUCCESS != rc) {
OPAL_THREAD_UNLOCK(&rcache->lock);
return OMPI_ERROR;
}
}
OPAL_THREAD_ADD32((int32_t*) &reg->ref_count, 1);
(*cnt)++;
assert(((void*)reg->bound) >= addr);
}
OPAL_THREAD_UNLOCK(&rcache->lock);
return OMPI_SUCCESS;
}
int mca_rcache_vma_insert (
struct mca_rcache_base_module_t* rcache,
mca_mpool_base_registration_t* reg,
uint32_t flags
) {
size_t reg_size = reg->bound - reg->base + 1;
mca_mpool_base_registration_t* old_reg;
OPAL_THREAD_LOCK(&rcache->lock);
if((flags & MCA_MPOOL_FLAGS_CACHE) &&
reg_size > ((mca_rcache_vma_module_t*)rcache)->reg_max_mru_size)
{
OPAL_THREAD_UNLOCK(&rcache->lock);
/* if the registration is too big for the rcache,
don't cache it and reset the flags so the upper level
handles things appropriatly */
reg->flags = 0;
return OMPI_SUCCESS;
}
reg->flags = flags;
while(mca_rcache_vma_tree_insert((mca_rcache_vma_module_t*)rcache, reg) ==
OMPI_ERR_TEMP_OUT_OF_RESOURCE) {
/* call deregister - which removes the registration from
* the tree and mru list. memory will be deregistered when
* the reference count goes to zero.
*/
old_reg = (mca_mpool_base_registration_t*)opal_list_get_first(&((mca_rcache_vma_module_t*)rcache)->mru_list);
/* we need to retain first, because we only want the registration
removed from the tree and the mru */
old_reg->mpool->mpool_retain(old_reg->mpool, old_reg);
old_reg->mpool->mpool_deregister(old_reg->mpool, old_reg);
}
OPAL_THREAD_ADD32((int32_t*) &reg->ref_count, 1);
if(flags & MCA_MPOOL_FLAGS_CACHE) {
mca_rcache_vma_mru_insert((mca_rcache_vma_module_t*)rcache, reg);
OPAL_THREAD_ADD32((int32_t*)&reg->ref_count, 1);
}
OPAL_THREAD_UNLOCK(&rcache->lock);
return OMPI_SUCCESS;
}
int mca_rcache_vma_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*)&reg->ref_count, -1);
rc = mca_rcache_vma_mru_delete((mca_rcache_vma_module_t*)rcache, reg);
}
if(OMPI_SUCCESS != rc) {
OPAL_THREAD_UNLOCK(&rcache->lock);
return rc;
}
reg->flags = 0;
OPAL_THREAD_ADD32((int32_t*)&reg->ref_count, -1);
rc = mca_rcache_vma_tree_delete((mca_rcache_vma_module_t*)rcache, reg );
OPAL_THREAD_UNLOCK(&rcache->lock);
return rc;
}
/**
* finalize
*/
void mca_rcache_vma_finalize(
struct mca_rcache_base_module_t* rcache
) {
}

91
ompi/mca/rcache/vma/rcache_vma.h Обычный файл
Просмотреть файл

@ -0,0 +1,91 @@
/**
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/**
* @file
* Description of the Registration Cache framework
*/
#ifndef MCA_RCACHE_VMA_H
#define MCA_RCACHE_VMA_H
#include "opal/mca/mca.h"
#include "ompi/info/info.h"
#include "opal/class/opal_list.h"
#include "ompi/class/ompi_rb_tree.h"
#include "ompi/mca/rcache/rcache.h"
struct mca_rcache_vma_module_t {
mca_rcache_base_module_t base;
ompi_rb_tree_t rb_tree;
opal_list_t vma_list;
opal_list_t mru_list;
size_t reg_mru_len;
size_t reg_max_mru_size;
size_t reg_cur_mru_size;
};
typedef struct mca_rcache_vma_module_t mca_rcache_vma_module_t;
struct mca_rcache_vma_component_t {
mca_rcache_base_component_t super;
size_t reg_mru_len;
size_t reg_max_mru_size;
}; typedef struct mca_rcache_vma_component_t mca_rcache_vma_component_t;
OMPI_COMP_EXPORT extern mca_rcache_vma_component_t mca_rcache_vma_component;
void mca_rcache_vma_module_init( mca_rcache_vma_module_t* rcache );
int mca_rcache_vma_find (
mca_rcache_base_module_t* rcache,
void* addr,
size_t size,
ompi_pointer_array_t* regs,
uint32_t *cnt
);
int mca_rcache_vma_insert (
struct mca_rcache_base_module_t* rcache,
mca_mpool_base_registration_t* registration,
uint32_t flags
);
int mca_rcache_vma_delete (
struct mca_rcache_base_module_t* rcache,
mca_mpool_base_registration_t* registration,
uint32_t flags
);
/**
* init/finalize
*/
void mca_rcache_vma_module_init( mca_rcache_vma_module_t* rcache );
void mca_rcache_vma_finalize(
struct mca_rcache_base_module_t*
);
#endif /* MCA_RCACHE_VMA_H */

75
ompi/mca/rcache/vma/rcache_vma_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,75 @@
/*
* Copyright (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal/mca/base/mca_base_param.h"
#include "ompi/mca/rcache/rcache.h"
#include "rcache_vma.h"
static int mca_rcache_vma_component_open(void);
static mca_rcache_base_module_t* mca_rcache_vma_component_init( void );
mca_rcache_vma_component_t mca_rcache_vma_component = {
{
{
/* Indicate that we are a rcache v1.0.0 component (which also
implies a specific MCA version) */
MCA_RCACHE_BASE_VERSION_1_0_0,
"vma", /* MCA component name */
OMPI_MAJOR_VERSION, /* MCA component major version */
OMPI_MINOR_VERSION, /* MCA component minor version */
OMPI_RELEASE_VERSION, /* MCA component release version */
mca_rcache_vma_component_open, /* component open */
NULL
},
/* Next the MCA v1.0.0 component meta data */
{
/* Whether the component is checkpointable or not */
false
},
mca_rcache_vma_component_init
}
};
static int mca_rcache_vma_component_open(void)
{
mca_base_param_reg_int(&mca_rcache_vma_component.super.rcache_version,
"mru_len",
"The maximum size IN ENTRIES of the MRU (most recently used) rcache list",
false,
false,
256,
(int*)&(mca_rcache_vma_component.reg_mru_len));
mca_base_param_reg_int(&mca_rcache_vma_component.super.rcache_version,
"mru_size",
"The maximum size IN BYTES of the MRU (most recently used) rcache list",
false,
false,
1*1024*1024*1024, /* default to 1GB? */
(int*)&(mca_rcache_vma_component.reg_max_mru_size));
return OMPI_SUCCESS;
}
mca_rcache_base_module_t* mca_rcache_vma_component_init(void) {
mca_rcache_vma_module_t* rcache;
rcache = (mca_rcache_vma_module_t*) malloc(sizeof(mca_rcache_vma_module_t));
mca_rcache_vma_module_init(rcache);
rcache->reg_mru_len = mca_rcache_vma_component.reg_mru_len;
rcache->reg_max_mru_size = mca_rcache_vma_component.reg_max_mru_size;
return &rcache->base;
}

98
ompi/mca/rcache/vma/rcache_vma_mru.c Обычный файл
Просмотреть файл

@ -0,0 +1,98 @@
/**
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/**
* @file
* Description of the Registration Cache framework
*/
#include "opal/mca/mca.h"
#include "rcache_vma_mru.h"
#include "ompi/mca/mpool/mpool.h"
/*
* initialize the vma mru
*/
int mca_rcache_vma_mru_init(mca_rcache_vma_module_t* rcache){
OBJ_CONSTRUCT(&rcache->mru_list, opal_list_t);
return OMPI_SUCCESS;
}
/*
* insert an item in the vma mru
*/
int mca_rcache_vma_mru_insert(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
) {
mca_mpool_base_registration_t* old_reg;
if(rcache->reg_mru_len <= rcache->mru_list.opal_list_length) {
/* call deregister - which removes the registration from
* the tree and mru list. memory will be deregistered when
* the reference count goes to zero.
*/
old_reg = (mca_mpool_base_registration_t*)
opal_list_get_first(&rcache->mru_list);
/* we need to retain first, because we only want the registration
removed from the tree and the mru */
old_reg->mpool->mpool_retain(old_reg->mpool, old_reg);
old_reg->mpool->mpool_deregister(old_reg->mpool, old_reg);
}
opal_list_append(&rcache->mru_list,(opal_list_item_t*) reg);
return OMPI_SUCCESS;
}
/*
* remove an item from the vma mru
*/
int mca_rcache_vma_mru_delete(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t *reg
){
int rc;
if(NULL == opal_list_remove_item(&rcache->mru_list,
(opal_list_item_t*)reg)) {
rc = OMPI_ERROR;
} else {
rc = OMPI_SUCCESS;
}
return rc;
}
/*
* touch an item in the mru list
*/
int mca_rcache_vma_mru_touch(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
){
int rc;
if(NULL == opal_list_remove_item(&rcache->mru_list,
(opal_list_item_t*)reg)) {
rc = OMPI_ERROR;
} else {
opal_list_append(&rcache->mru_list, (opal_list_item_t*)reg);
rc = OMPI_SUCCESS;
}
return rc;
}

62
ompi/mca/rcache/vma/rcache_vma_mru.h Обычный файл
Просмотреть файл

@ -0,0 +1,62 @@
/**
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/**
* @file
* Description of the Registration Cache framework
*/
#ifndef MCA_RCACHE_VMA_MRU_H
#define MCA_RCACHE_VMA_MRU_H
#include "opal/mca/mca.h"
#include "ompi/info/info.h"
#include "opal/class/opal_list.h"
#include "rcache_vma.h"
/*
* initialize the rb mru
*/
int mca_rcache_vma_mru_init(mca_rcache_vma_module_t* rcache);
/*
* insert an item in the rb mru
*/
int mca_rcache_vma_mru_insert(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
);
/*
* remove an item from the rb mru
*/
int mca_rcache_vma_mru_delete(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
);
int mca_rcache_vma_mru_touch(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
);
#endif /* MCA_RCACHE_VMA_MRU_H */

451
ompi/mca/rcache/vma/rcache_vma_tree.c Обычный файл
Просмотреть файл

@ -0,0 +1,451 @@
/**
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/**
* @file
* Description of the Registration Cache framework
*/
#include "opal/mca/mca.h"
#include "rcache_vma_tree.h"
OBJ_CLASS_INSTANCE(mca_rcache_vma_reg_list_item_t, opal_list_item_t, NULL, NULL);
static void mca_rcache_vma_construct(opal_object_t *object)
{
mca_rcache_vma_t *vma = (mca_rcache_vma_t*)object;
OBJ_CONSTRUCT(&vma->reg_list, opal_list_t);
}
static void mca_rcache_vma_destruct(opal_object_t *object)
{
mca_rcache_vma_t *vma = (mca_rcache_vma_t*)object;
OBJ_DESTRUCT(&vma->reg_list);
}
OBJ_CLASS_INSTANCE(mca_rcache_vma_t, ompi_free_list_item_t,
mca_rcache_vma_construct, mca_rcache_vma_destruct);
/**
* 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
*/
static int mca_rcache_vma_tree_node_compare(void *key1, void *key2)
{
mca_rcache_vma_t *vma1 = (mca_rcache_vma_t*)key1,
*vma2 = (mca_rcache_vma_t*)key2;
if(vma1->start < vma2->start)
return -1;
if(vma1->start > vma2->start)
return 1;
return 0;
}
static int mca_rcache_vma_tree_node_compare_search(void *key1, void *key2)
{
mca_rcache_vma_t *vma = (mca_rcache_vma_t*)key2;
uintptr_t addr = (uintptr_t)key1;
if(vma->end < addr)
return 1;
if(vma->start <= addr)
return 0;
return -1;
}
static int mca_rcache_vma_tree_node_compare_closest(void *key1, void *key2)
{
mca_rcache_vma_t *vma = (mca_rcache_vma_t*)key2, *prev_vma;
uintptr_t addr = (uintptr_t)key1;
if(vma->end < addr)
return 1;
if(vma->start <= addr)
return 0;
prev_vma = (mca_rcache_vma_t *)opal_list_get_prev(&vma->super.super);
if(NULL == prev_vma || prev_vma->end < addr)
return 0;
return -1;
}
static inline mca_rcache_vma_t *mca_rcache_vma_new(ompi_rb_tree_t *tree,
uintptr_t start,
uintptr_t end)
{
int rc;
mca_rcache_vma_t *vma = OBJ_NEW(mca_rcache_vma_t);
if(NULL == vma)
return NULL;
vma->start = start;
vma->end = end;
rc = ompi_rb_tree_insert(tree, vma, vma);
return vma;
}
static inline void mca_rcache_vma_destroy(mca_rcache_vma_t *vma)
{
opal_list_item_t *item;
while ((item = opal_list_remove_first(&vma->reg_list)))
OBJ_RELEASE(item);
OBJ_RELEASE(vma);
}
static inline int mca_rcache_vma_compare_regs(
mca_mpool_base_registration_t *reg1,
mca_mpool_base_registration_t *reg2)
{
if (reg1->bound != reg2->bound)
return (int)(reg1->bound - reg2->bound);
/* tie breaker */
return (int)((uintptr_t)reg1 - (uintptr_t)reg2);
}
static inline int mca_rcache_vma_add_reg(mca_rcache_vma_t *vma,
mca_mpool_base_registration_t *reg)
{
opal_list_item_t *i;
mca_rcache_vma_reg_list_item_t *item, *entry;
entry = OBJ_NEW(mca_rcache_vma_reg_list_item_t);
if(!entry)
return -1;
entry->reg = reg;
for(i = opal_list_get_first(&vma->reg_list);
i != opal_list_get_end(&vma->reg_list);
i = opal_list_get_next(i)) {
item = (mca_rcache_vma_reg_list_item_t*)i;
if(mca_rcache_vma_compare_regs(item->reg, reg) > 0)
continue;
opal_list_insert_pos(&vma->reg_list, &item->super, &entry->super);
return 0;
}
opal_list_append(&vma->reg_list, &entry->super);
return 0;
}
static inline void mca_rcache_vma_remove_reg(mca_rcache_vma_t *vma,
mca_mpool_base_registration_t *reg)
{
opal_list_item_t *i;
mca_rcache_vma_reg_list_item_t *item;
for(i = opal_list_get_first(&vma->reg_list);
i != opal_list_get_end(&vma->reg_list);
i = opal_list_get_next(i)) {
item = (mca_rcache_vma_reg_list_item_t*)i;
if(item->reg == reg) {
opal_list_remove_item(&vma->reg_list, &item->super);
OBJ_RELEASE(item);
break;
}
}
}
static inline int mca_rcache_vma_copy_reg_list(mca_rcache_vma_t *to,
mca_rcache_vma_t *from)
{
opal_list_item_t *i;
mca_rcache_vma_reg_list_item_t *item_f, *item_t;
for(i = opal_list_get_first(&from->reg_list);
i != opal_list_get_end(&from->reg_list);
i = opal_list_get_next(i)) {
item_f = (mca_rcache_vma_reg_list_item_t*)i;
item_t = OBJ_NEW(mca_rcache_vma_reg_list_item_t);
if(NULL == item_t)
return 0;
item_t->reg = item_f->reg;
opal_list_append(&to->reg_list, &item_t->super);
}
return OMPI_SUCCESS;
}
/* returns 1 iff two lists contain the same entries */
static inline int mca_rcache_vma_compare_reg_lists(mca_rcache_vma_t *vma1,
mca_rcache_vma_t *vma2)
{
mca_rcache_vma_reg_list_item_t *i1, *i2;
if (!vma1 || !vma2)
return 0;
if(opal_list_get_size(&vma1->reg_list) !=
opal_list_get_size(&vma2->reg_list))
return 0;
i1 = (mca_rcache_vma_reg_list_item_t*)opal_list_get_first(&vma1->reg_list);
i2 = (mca_rcache_vma_reg_list_item_t*)opal_list_get_first(&vma2->reg_list);
do {
if(i1 == (mca_rcache_vma_reg_list_item_t*)opal_list_get_end(&vma1->reg_list) ||
i2 == (mca_rcache_vma_reg_list_item_t*)opal_list_get_end(&vma2->reg_list))
return 1;
if(i1->reg != i2->reg)
break;
i1 = (mca_rcache_vma_reg_list_item_t*)opal_list_get_next(i1);
i2 = (mca_rcache_vma_reg_list_item_t*)opal_list_get_next(i2);
} while(1);
return 0;
}
int mca_rcache_vma_tree_init(mca_rcache_vma_module_t* rcache)
{
OBJ_CONSTRUCT(&rcache->rb_tree, ompi_rb_tree_t);
OBJ_CONSTRUCT(&rcache->vma_list, opal_list_t);
rcache->reg_cur_mru_size = 0;
return ompi_rb_tree_init(&rcache->rb_tree,
mca_rcache_vma_tree_node_compare);
}
mca_mpool_base_registration_t *mca_rcache_vma_tree_find(
mca_rcache_vma_module_t* vma_rcache, unsigned char *base,
unsigned char *bound)
{
mca_rcache_vma_t *vma;
mca_rcache_vma_reg_list_item_t *item;
vma = ompi_rb_tree_find_with(&vma_rcache->rb_tree, base,
mca_rcache_vma_tree_node_compare_search);
if(!vma)
return NULL;
item = (mca_rcache_vma_reg_list_item_t*)opal_list_get_first(&vma->reg_list);
if(item->reg->bound >= bound)
return item->reg;
return NULL;
}
static inline int mca_rcache_vma_can_insert(
mca_rcache_vma_module_t *vma_rcache,
uint32_t reg_flags,
size_t nbytes)
{
if(0 == vma_rcache->reg_max_mru_size ||
!(reg_flags & MCA_MPOOL_FLAGS_CACHE))
return 1;
if(vma_rcache->reg_cur_mru_size + nbytes <=
vma_rcache->reg_max_mru_size)
return 1;
return 0;
}
static inline void mca_rcache_vma_update_byte_count(
mca_rcache_vma_module_t* vma_rcache,
size_t nbytes)
{
vma_rcache->reg_cur_mru_size += nbytes;
}
int mca_rcache_vma_tree_insert(
mca_rcache_vma_module_t* vma_rcache,
mca_mpool_base_registration_t* reg
)
{
mca_rcache_vma_t *i;
uintptr_t begin = (uintptr_t)reg->base, end = (uintptr_t)reg->bound;
i = (mca_rcache_vma_t*)ompi_rb_tree_find_with(&vma_rcache->rb_tree,
(void*)begin, mca_rcache_vma_tree_node_compare_closest);
if(!i)
i = (mca_rcache_vma_t*)opal_list_get_end(&vma_rcache->vma_list);
while (begin <= end) {
mca_rcache_vma_t *vma;
if((mca_rcache_vma_t*)opal_list_get_end(&vma_rcache->vma_list) == i) {
vma = NULL;
if(mca_rcache_vma_can_insert(vma_rcache, reg->flags, end - begin + 1))
vma = mca_rcache_vma_new(&vma_rcache->rb_tree, begin, end);
if(!vma)
goto remove;
mca_rcache_vma_update_byte_count(vma_rcache, end - begin + 1);
opal_list_append(&vma_rcache->vma_list, &vma->super);
begin = vma->end + 1;
mca_rcache_vma_add_reg(vma, reg);
} else if(i->start > begin) {
uintptr_t tend = (i->start <= end)?(i->start - 1):end;
vma = NULL;
if(mca_rcache_vma_can_insert(vma_rcache, reg->flags, tend - begin + 1))
vma = mca_rcache_vma_new(&vma_rcache->rb_tree, begin, tend);
if(!vma)
goto remove;
mca_rcache_vma_update_byte_count(vma_rcache, tend - begin + 1);
/* insert before */
opal_list_insert_pos(&vma_rcache->vma_list, &i->super, &vma->super);
i = vma;
begin = vma->end + 1;
mca_rcache_vma_add_reg(vma, reg);
} else if(i->start == begin) {
if (i->end > end) {
vma = mca_rcache_vma_new(&vma_rcache->rb_tree, end+1, i->end);
if(!vma)
goto remove;
i->end = end;
mca_rcache_vma_copy_reg_list(vma, i);
/* add after */
opal_list_insert_pos(&vma_rcache->vma_list,
opal_list_get_next(&i->super),
&vma->super);
mca_rcache_vma_add_reg(i, reg);
begin = end + 1;
} else {
mca_rcache_vma_add_reg(i, reg);
begin = i->end + 1;
}
} else {
vma = mca_rcache_vma_new(&vma_rcache->rb_tree, begin, i->end);
if(!vma)
goto remove;
i->end = begin - 1;
mca_rcache_vma_copy_reg_list(vma, i);
/* add after */
opal_list_insert_pos(&vma_rcache->vma_list,
opal_list_get_next(&i->super),
&vma->super);
}
i = (mca_rcache_vma_t*)opal_list_get_next(&i->super);
}
return 0;
remove:
mca_rcache_vma_tree_delete(vma_rcache, reg);
return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
}
/**
* 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_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
mca_mpool_base_registration_t* reg)
{
mca_rcache_vma_t *vma;
vma = ompi_rb_tree_find_with(&vma_rcache->rb_tree, reg->base,
mca_rcache_vma_tree_node_compare_search);
if(!vma)
return OMPI_ERROR;
while(vma != (mca_rcache_vma_t*)opal_list_get_end(&vma_rcache->vma_list)
&& vma->start <= (uintptr_t)reg->base) {
mca_rcache_vma_remove_reg(vma, reg);
if(opal_list_is_empty(&vma->reg_list)) {
mca_rcache_vma_t *next = (mca_rcache_vma_t*)opal_list_get_next(&vma->super);
ompi_rb_tree_delete(&vma_rcache->rb_tree, vma);
mca_rcache_vma_update_byte_count(vma_rcache,
vma->start - vma->end - 1);
opal_list_remove_item(&vma_rcache->vma_list, &vma->super);
mca_rcache_vma_destroy(vma);
vma = next;
} else {
int merged;
do {
mca_rcache_vma_t *prev = NULL, *next = NULL;
if(opal_list_get_begin(&vma_rcache->vma_list) !=
opal_list_get_prev(vma))
prev = (mca_rcache_vma_t*)opal_list_get_prev(vma);
merged = 0;
if(prev && vma->start == prev->end + 1 &&
mca_rcache_vma_compare_reg_lists(vma, prev)) {
prev->end = vma->end;
opal_list_remove_item(&vma_rcache->vma_list, &vma->super);
ompi_rb_tree_delete(&vma_rcache->rb_tree, vma);
mca_rcache_vma_destroy(vma);
vma = prev;
merged = 1;
}
if(opal_list_get_end(&vma_rcache->vma_list) !=
opal_list_get_next(vma))
next = (mca_rcache_vma_t*)opal_list_get_next(vma);
if(next && vma->end + 1 == next->start &&
mca_rcache_vma_compare_reg_lists(vma, next)) {
vma->end = next->end;
opal_list_remove_item(&vma_rcache->vma_list, &next->super);
ompi_rb_tree_delete(&vma_rcache->rb_tree, next);
mca_rcache_vma_destroy(next);
merged = 1;
}
} while(merged);
vma = (mca_rcache_vma_t*)opal_list_get_next(vma);
}
}
return 0;
}

92
ompi/mca/rcache/vma/rcache_vma_tree.h Обычный файл
Просмотреть файл

@ -0,0 +1,92 @@
/**
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. 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 (c) 2006 Voltaire. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/**
* @file
* Description of the Registration Cache framework
*/
#ifndef MCA_RCACHE_VMA_TREE_H
#define MCA_RCACHE_VMA_TREE_H
#include "opal/mca/mca.h"
#include "ompi/info/info.h"
#include "ompi/class/ompi_free_list.h"
#include "ompi/mca/mpool/mpool.h"
#include "rcache_vma.h"
/*
* Data structures for the tree of allocated memory
*/
struct mca_rcache_vma_reg_list_item_t
{
opal_list_item_t super;
mca_mpool_base_registration_t *reg;
};
typedef struct mca_rcache_vma_reg_list_item_t mca_rcache_vma_reg_list_item_t;
OBJ_CLASS_DECLARATION(mca_rcache_vma_reg_list_item_t);
/**
* The item in the vma_tree itself
*/
struct mca_rcache_vma_t
{
opal_list_item_t super; /**< the parent class */
uintptr_t start; /**< the base of the memory range */
uintptr_t end; /**< the bound of the memory range */
opal_list_t reg_list; /**< list of regs on this vma */
};
typedef struct mca_rcache_vma_t mca_rcache_vma_t;
OBJ_CLASS_DECLARATION(mca_rcache_vma_t);
/*
* initialize the vma tree
*/
int mca_rcache_vma_tree_init(mca_rcache_vma_module_t* rcache);
/**
* Returns the item in the vma tree
*/
mca_mpool_base_registration_t* mca_rcache_vma_tree_find(
mca_rcache_vma_module_t* rcache,
unsigned char* base,
unsigned char *bound
);
/*
* insert an item in the vma tree
*/
int mca_rcache_vma_tree_insert(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
);
/*
* remove an item from the vma tree
*/
int mca_rcache_vma_tree_delete(
mca_rcache_vma_module_t* rcache,
mca_mpool_base_registration_t* reg
);
#endif /* MCA_RCACHE_VMA_TREE_H */