2005-09-04 04:17:00 +00:00
|
|
|
/*
|
2005-11-05 19:57:48 +00:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2007-12-21 06:02:00 +00:00
|
|
|
* Copyright (c) 2004-2007 The University of Tennessee and The University
|
2005-11-05 19:57:48 +00:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-09-04 04:17:00 +00: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.
|
|
|
|
* All rights reserved.
|
2010-05-11 21:43:19 +00:00
|
|
|
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
|
2012-04-06 14:23:13 +00:00
|
|
|
* Copyright (c) 2011-2012 Los Alamos National Security, LLC.
|
|
|
|
* All rights reserved.
|
2005-09-04 04:17:00 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2006-08-24 16:38:08 +00:00
|
|
|
#include "ompi_config.h"
|
2010-05-11 21:43:19 +00:00
|
|
|
|
|
|
|
#include MCA_memory_IMPLEMENTATION_HEADER
|
|
|
|
#include "opal/mca/memory/memory.h"
|
2005-09-27 02:01:21 +00:00
|
|
|
#include "ompi/mca/rcache/rcache.h"
|
2005-09-04 04:17:00 +00:00
|
|
|
#include "rcache_rb.h"
|
|
|
|
#include "rcache_rb_tree.h"
|
|
|
|
#include "rcache_rb_mru.h"
|
2005-09-28 02:11:35 +00:00
|
|
|
#include "ompi/mca/mpool/base/base.h"
|
|
|
|
|
2005-09-04 04:17:00 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2006-05-18 09:35:11 +00:00
|
|
|
OBJ_CONSTRUCT(&rcache->base.lock, opal_mutex_t);
|
2005-09-07 20:37:17 +00:00
|
|
|
mca_rcache_rb_tree_init(rcache);
|
2005-09-12 22:28:23 +00:00
|
|
|
mca_rcache_rb_mru_init(rcache);
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
2005-09-12 22:28:23 +00:00
|
|
|
|
2007-12-21 06:02:00 +00:00
|
|
|
int mca_rcache_rb_find( struct mca_rcache_base_module_t* rcache,
|
2005-09-04 04:17:00 +00:00
|
|
|
void* addr,
|
|
|
|
size_t size,
|
2007-12-21 06:02:00 +00:00
|
|
|
opal_pointer_array_t* regs,
|
|
|
|
uint32_t *cnt )
|
|
|
|
{
|
2006-01-23 22:51:50 +00:00
|
|
|
int rc = OMPI_SUCCESS;
|
2005-09-30 03:13:51 +00:00
|
|
|
mca_rcache_rb_tree_item_t* tree_item = NULL;
|
2005-09-28 02:11:35 +00:00
|
|
|
void* base_addr;
|
|
|
|
void* bound_addr;
|
|
|
|
if(size == 0) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_LOCK(&rcache->lock);
|
2005-09-12 22:28:23 +00:00
|
|
|
*cnt = 0;
|
2006-07-20 14:01:57 +00:00
|
|
|
|
2010-05-11 21:43:19 +00:00
|
|
|
/* Check to ensure that the cache is valid */
|
|
|
|
if (OPAL_UNLIKELY(opal_memory_changed() &&
|
|
|
|
NULL != opal_memory->memoryc_process &&
|
|
|
|
OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-07-20 14:01:57 +00:00
|
|
|
if(ompi_rb_tree_size(&((mca_rcache_rb_module_t*)rcache)->rb_tree) == 0) {
|
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-09-28 02:11:35 +00:00
|
|
|
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);
|
2009-01-27 19:00:03 +00:00
|
|
|
|
2006-01-23 22:51:50 +00:00
|
|
|
while(base_addr <= bound_addr) {
|
2005-09-28 02:11:35 +00:00
|
|
|
tree_item = mca_rcache_rb_tree_find( (mca_rcache_rb_module_t*) rcache, base_addr );
|
|
|
|
if(NULL != tree_item) {
|
2007-12-21 06:02:00 +00:00
|
|
|
opal_pointer_array_add(regs, (void*) tree_item->reg);
|
2006-01-23 22:51:50 +00:00
|
|
|
if( tree_item->reg->flags & MCA_MPOOL_FLAGS_CACHE ) {
|
|
|
|
rc = mca_rcache_rb_mru_touch((mca_rcache_rb_module_t*)rcache,
|
|
|
|
tree_item->reg);
|
|
|
|
if(OMPI_SUCCESS != rc) {
|
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OPAL_THREAD_ADD32((int32_t*) &tree_item->reg->ref_count, 1);
|
|
|
|
(*cnt)++;
|
|
|
|
assert(tree_item->reg->bound - tree_item->reg->base >= 0);
|
|
|
|
assert(((void*) tree_item->reg->bound) >= addr);
|
|
|
|
base_addr = tree_item->reg->bound + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
base_addr =(void*) ((unsigned long) base_addr + mca_mpool_base_page_size);
|
2005-09-28 02:11:35 +00:00
|
|
|
}
|
2005-09-27 02:01:21 +00:00
|
|
|
}
|
2009-01-27 19:00:03 +00:00
|
|
|
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
2006-01-23 22:51:50 +00:00
|
|
|
return OMPI_SUCCESS;
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mca_rcache_rb_insert (
|
|
|
|
struct mca_rcache_base_module_t* rcache,
|
|
|
|
mca_mpool_base_registration_t* reg,
|
|
|
|
uint32_t flags
|
2009-01-27 19:00:03 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_LOCK(&rcache->lock);
|
2005-09-24 20:48:14 +00:00
|
|
|
reg->flags = flags;
|
2010-05-11 21:43:19 +00:00
|
|
|
|
|
|
|
/* Check to ensure that the cache is valid */
|
|
|
|
if (OPAL_UNLIKELY(opal_memory_changed() &&
|
|
|
|
NULL != opal_memory->memoryc_process &&
|
|
|
|
OPAL_SUCCESS != (rc = opal_memory->memoryc_process()))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-09-24 00:24:49 +00:00
|
|
|
if(flags & MCA_MPOOL_FLAGS_CACHE) {
|
2005-09-04 04:17:00 +00:00
|
|
|
rc = mca_rcache_rb_mru_insert( (mca_rcache_rb_module_t*) rcache, reg);
|
2005-09-12 22:28:23 +00:00
|
|
|
if(OMPI_SUCCESS != rc) {
|
2012-04-06 14:23:13 +00:00
|
|
|
if(OMPI_ERR_TEMP_OUT_OF_RESOURCE == rc) {
|
2009-01-27 19:00:03 +00:00
|
|
|
/*
|
|
|
|
* If the registration is too big for the rcache,
|
|
|
|
* don't cache it and reset the flags so the upper level
|
|
|
|
* handles things appropriately
|
|
|
|
*/
|
2006-02-22 14:35:47 +00:00
|
|
|
reg->flags = 0;
|
2009-01-27 19:00:03 +00:00
|
|
|
rc = OMPI_SUCCESS;
|
2006-02-22 14:35:47 +00:00
|
|
|
}
|
2009-01-27 19:00:03 +00:00
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
2005-09-12 22:28:23 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2005-09-24 00:24:49 +00:00
|
|
|
OPAL_THREAD_ADD32((int32_t*)®->ref_count, 1);
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
2005-09-24 00:24:49 +00:00
|
|
|
rc = mca_rcache_rb_tree_insert((mca_rcache_rb_module_t*)rcache, reg);
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_ADD32((int32_t*) ®->ref_count, 1);
|
2010-05-11 21:43:19 +00:00
|
|
|
|
|
|
|
if (OPAL_LIKELY(OMPI_SUCCESS == rc)) {
|
|
|
|
/* If we successfully registered, then tell the memory manager
|
|
|
|
to start monitoring this region */
|
|
|
|
opal_memory->memoryc_register(reg->base,
|
|
|
|
(uint64_t) reg->bound - reg->base + 1,
|
|
|
|
(uint64_t) reg);
|
|
|
|
}
|
|
|
|
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
2005-09-12 22:28:23 +00:00
|
|
|
return rc;
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mca_rcache_rb_delete (
|
|
|
|
struct mca_rcache_base_module_t* rcache,
|
|
|
|
mca_mpool_base_registration_t* reg,
|
|
|
|
uint32_t flags
|
2009-01-27 19:00:03 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2005-09-24 00:24:49 +00:00
|
|
|
assert(reg->ref_count >= 1);
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_LOCK(&rcache->lock);
|
2010-05-11 21:43:19 +00:00
|
|
|
/* Tell the memory manager that we no longer care about this
|
|
|
|
region */
|
|
|
|
opal_memory->memoryc_deregister(reg->base,
|
|
|
|
(uint64_t) (reg->bound - reg->base),
|
|
|
|
(uint64_t) reg);
|
2005-09-24 00:24:49 +00:00
|
|
|
if(flags & MCA_MPOOL_FLAGS_CACHE) {
|
|
|
|
assert(reg->ref_count >= 2);
|
|
|
|
OPAL_THREAD_ADD32((int32_t*)®->ref_count, -1);
|
2005-09-04 04:17:00 +00:00
|
|
|
rc = mca_rcache_rb_mru_delete( (mca_rcache_rb_module_t*) rcache, reg);
|
2009-01-27 19:00:03 +00:00
|
|
|
if(OMPI_SUCCESS != rc) {
|
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
2005-09-07 20:37:17 +00:00
|
|
|
reg->flags = 0;
|
2005-09-24 00:24:49 +00:00
|
|
|
OPAL_THREAD_ADD32((int32_t*)®->ref_count, -1);
|
2005-09-12 22:28:23 +00:00
|
|
|
rc = mca_rcache_rb_tree_delete((mca_rcache_rb_module_t*)rcache, reg );
|
2005-09-13 22:06:44 +00:00
|
|
|
OPAL_THREAD_UNLOCK(&rcache->lock);
|
2009-01-27 19:00:03 +00:00
|
|
|
return rc;
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* finalize
|
|
|
|
*/
|
|
|
|
void mca_rcache_rb_finalize(
|
|
|
|
struct mca_rcache_base_module_t* rcache
|
2009-01-27 19:00:03 +00:00
|
|
|
)
|
|
|
|
{
|
2005-09-04 04:17:00 +00:00
|
|
|
}
|
|
|
|
|