2005-06-30 18:17:17 +00:00
|
|
|
/*
|
2007-03-16 23:11:45 +00:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2005-11-05 19:57:48 +00:00
|
|
|
* 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.
|
2006-06-07 23:21:23 +00:00
|
|
|
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
|
2005-06-30 18:17:17 +00:00
|
|
|
* 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 "ompi_config.h"
|
|
|
|
#include <string.h>
|
2005-07-03 23:31:27 +00:00
|
|
|
#include "opal/util/output.h"
|
2005-06-30 18:17:17 +00:00
|
|
|
#include "mpool_gm.h"
|
2005-09-27 02:01:21 +00:00
|
|
|
#include "ompi/mca/rcache/rcache.h"
|
|
|
|
#include "ompi/mca/rcache/base/base.h"
|
|
|
|
#include "ompi/mca/mpool/base/base.h"
|
|
|
|
|
2005-09-29 21:28:54 +00:00
|
|
|
uint64_t mca_mpool_gm_mem_registered;
|
2005-06-30 18:17:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the mpool module.
|
|
|
|
*/
|
|
|
|
void mca_mpool_gm_module_init(mca_mpool_gm_module_t* mpool)
|
|
|
|
{
|
|
|
|
mpool->super.mpool_component = &mca_mpool_gm_component.super;
|
|
|
|
mpool->super.mpool_base = NULL; /* no base .. */
|
|
|
|
mpool->super.mpool_alloc = mca_mpool_gm_alloc;
|
|
|
|
mpool->super.mpool_realloc = mca_mpool_gm_realloc;
|
|
|
|
mpool->super.mpool_free = mca_mpool_gm_free;
|
|
|
|
mpool->super.mpool_register = mca_mpool_gm_register;
|
|
|
|
mpool->super.mpool_deregister = mca_mpool_gm_deregister;
|
2005-09-14 02:59:31 +00:00
|
|
|
mpool->super.mpool_find = mca_mpool_gm_find;
|
|
|
|
mpool->super.mpool_retain = mca_mpool_gm_retain;
|
|
|
|
mpool->super.mpool_release = mca_mpool_gm_release;
|
2005-06-30 18:17:17 +00:00
|
|
|
mpool->super.mpool_finalize = NULL;
|
2007-03-16 23:11:45 +00:00
|
|
|
mpool->super.mpool_ft_event = mca_mpool_gm_ft_event;
|
2005-09-12 22:28:23 +00:00
|
|
|
mpool->super.rcache =
|
|
|
|
mca_rcache_base_module_create(mca_mpool_gm_component.rcache_name);
|
2005-09-16 22:22:03 +00:00
|
|
|
mpool->super.flags = MCA_MPOOL_FLAGS_MPI_ALLOC_MEM;
|
2005-09-29 21:28:54 +00:00
|
|
|
mca_mpool_gm_mem_registered = 0;
|
2005-06-30 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allocate function
|
|
|
|
*/
|
|
|
|
void* mca_mpool_gm_alloc(
|
|
|
|
mca_mpool_base_module_t* mpool,
|
|
|
|
size_t size,
|
|
|
|
size_t align,
|
2005-09-12 22:28:23 +00:00
|
|
|
uint32_t flags,
|
2005-06-30 18:17:17 +00:00
|
|
|
mca_mpool_base_registration_t** registration)
|
|
|
|
{
|
2005-07-07 16:56:58 +00:00
|
|
|
void *addr = malloc(size+align);
|
|
|
|
if(NULL == addr)
|
|
|
|
return NULL;
|
2005-09-12 22:28:23 +00:00
|
|
|
if(OMPI_SUCCESS != mca_mpool_gm_register(mpool,addr,size+align, flags, registration)) {
|
2005-07-07 16:56:58 +00:00
|
|
|
free(addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return addr;
|
2005-06-30 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register memory
|
|
|
|
*/
|
|
|
|
int mca_mpool_gm_register(
|
|
|
|
mca_mpool_base_module_t* mpool,
|
|
|
|
void *addr,
|
|
|
|
size_t size,
|
2005-09-12 22:28:23 +00:00
|
|
|
uint32_t flags,
|
2005-06-30 18:17:17 +00:00
|
|
|
mca_mpool_base_registration_t** registration)
|
|
|
|
{
|
|
|
|
mca_mpool_gm_module_t * gm_mpool = (mca_mpool_gm_module_t*) mpool;
|
|
|
|
mca_mpool_base_registration_t* reg = OBJ_NEW(mca_mpool_base_registration_t);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if(NULL == reg) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
reg->mpool = mpool;
|
2005-09-27 18:10:44 +00:00
|
|
|
reg->base = down_align_addr(addr, mca_mpool_base_page_size_log);
|
2005-09-21 20:04:56 +00:00
|
|
|
reg->flags = flags;
|
2005-09-30 22:58:09 +00:00
|
|
|
reg->bound = up_align_addr((void*) ((unsigned long) addr + size -1)
|
2005-09-27 18:10:44 +00:00
|
|
|
, mca_mpool_base_page_size_log);
|
2005-09-27 02:01:21 +00:00
|
|
|
|
2005-09-27 21:43:41 +00:00
|
|
|
|
|
|
|
if((rc = gm_register_memory(gm_mpool->port, reg->base, reg->bound - reg->base + 1)) != GM_SUCCESS) {
|
|
|
|
opal_output(0, "[%s:%d] error(%d) registering gm memory\n", __FILE__, __LINE__, rc);
|
2005-09-29 21:28:54 +00:00
|
|
|
assert(0);
|
2005-09-27 21:43:41 +00:00
|
|
|
OBJ_RELEASE(reg);
|
2005-09-28 20:19:33 +00:00
|
|
|
|
2005-09-27 21:43:41 +00:00
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2005-09-29 21:28:54 +00:00
|
|
|
mca_mpool_gm_mem_registered += reg->bound - reg->base + 1;
|
|
|
|
|
2005-09-27 21:43:41 +00:00
|
|
|
|
2005-09-21 20:04:56 +00:00
|
|
|
OPAL_THREAD_ADD32(®->ref_count,1);
|
|
|
|
|
2005-09-12 22:28:23 +00:00
|
|
|
if(flags & (MCA_MPOOL_FLAGS_CACHE | MCA_MPOOL_FLAGS_PERSIST)) {
|
|
|
|
mpool->rcache->rcache_insert(mpool->rcache,
|
|
|
|
(mca_mpool_base_registration_t*) reg,
|
|
|
|
flags);
|
|
|
|
}
|
2005-06-30 18:17:17 +00:00
|
|
|
*registration = reg;
|
2005-09-28 20:19:33 +00:00
|
|
|
/* opal_output(0,"registered memory from %p to %p\n", reg->base, reg->bound); */
|
2005-06-30 18:17:17 +00:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* deregister memory
|
|
|
|
*/
|
2005-09-12 22:28:23 +00:00
|
|
|
int mca_mpool_gm_deregister(mca_mpool_base_module_t* mpool,
|
2005-06-30 18:17:17 +00:00
|
|
|
mca_mpool_base_registration_t* reg)
|
|
|
|
{
|
2005-09-29 21:28:54 +00:00
|
|
|
int rc;
|
2005-09-12 22:28:23 +00:00
|
|
|
if(reg->flags & (MCA_MPOOL_FLAGS_CACHE | MCA_MPOOL_FLAGS_PERSIST)) {
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache,
|
|
|
|
reg,
|
|
|
|
reg->flags);
|
|
|
|
}
|
2005-09-29 21:28:54 +00:00
|
|
|
if((rc = mca_mpool_gm_release(mpool, reg)) != GM_SUCCESS) {
|
|
|
|
opal_output(0, "[%s:%d] error(%d) deregistering gm memory\n", __FILE__, __LINE__, rc);
|
|
|
|
assert(0);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
2005-06-30 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* realloc function
|
|
|
|
*/
|
|
|
|
void* mca_mpool_gm_realloc(
|
|
|
|
mca_mpool_base_module_t* mpool,
|
|
|
|
void* addr,
|
|
|
|
size_t size,
|
|
|
|
mca_mpool_base_registration_t** registration)
|
|
|
|
{
|
2005-09-12 22:28:23 +00:00
|
|
|
void *new_addr = mca_mpool_gm_alloc(mpool,size,0, (*registration)->flags, registration);
|
2005-07-07 16:56:58 +00:00
|
|
|
if(new_addr == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(new_addr,addr,size);
|
|
|
|
mca_mpool_gm_free(mpool,addr,*registration);
|
|
|
|
return new_addr;
|
2005-06-30 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* free function
|
|
|
|
*/
|
|
|
|
void mca_mpool_gm_free(mca_mpool_base_module_t* mpool, void * addr,
|
|
|
|
mca_mpool_base_registration_t* registration)
|
|
|
|
{
|
2006-05-16 22:04:31 +00:00
|
|
|
if(registration){
|
|
|
|
mpool->mpool_deregister(mpool, registration);
|
|
|
|
}
|
2006-06-07 23:21:23 +00:00
|
|
|
free(addr);
|
2005-06-30 18:17:17 +00:00
|
|
|
}
|
|
|
|
|
2005-09-12 22:28:23 +00:00
|
|
|
int mca_mpool_gm_find(
|
2005-09-21 20:04:56 +00:00
|
|
|
struct mca_mpool_base_module_t* mpool,
|
|
|
|
void* addr,
|
|
|
|
size_t size,
|
|
|
|
ompi_pointer_array_t *regs,
|
|
|
|
uint32_t *cnt)
|
|
|
|
{
|
2005-09-12 22:28:23 +00:00
|
|
|
return mpool->rcache->rcache_find(mpool->rcache,
|
|
|
|
addr,
|
|
|
|
size,
|
|
|
|
regs,
|
|
|
|
cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mca_mpool_gm_release(
|
2005-09-21 20:04:56 +00:00
|
|
|
struct mca_mpool_base_module_t* mpool,
|
|
|
|
mca_mpool_base_registration_t* reg)
|
|
|
|
{
|
|
|
|
mca_mpool_gm_module_t * mpool_gm = (mca_mpool_gm_module_t*) mpool;
|
|
|
|
if(0 == OPAL_THREAD_ADD32(®->ref_count, -1)) {
|
|
|
|
int rc = gm_deregister_memory(
|
|
|
|
mpool_gm->port,
|
|
|
|
reg->base,
|
|
|
|
reg->bound - reg->base + 1);
|
|
|
|
if(GM_SUCCESS != rc) {
|
|
|
|
opal_output(0, "[%s:%d] error(%d) deregistering gm memory\n", __FILE__, __LINE__, rc);
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2005-09-28 20:19:33 +00:00
|
|
|
/* opal_output(0,"deregistering gm memory\n"); */
|
2005-09-29 21:28:54 +00:00
|
|
|
mca_mpool_gm_mem_registered -= reg->bound - reg->base + 1;
|
2005-09-21 20:04:56 +00:00
|
|
|
OBJ_RELEASE(reg);
|
2005-09-12 22:28:23 +00:00
|
|
|
}
|
2005-09-28 20:19:33 +00:00
|
|
|
else {
|
|
|
|
/* opal_output(0, "release says ref_count is %d\n", reg->ref_count); */
|
|
|
|
}
|
2005-09-29 21:28:54 +00:00
|
|
|
|
2005-09-12 22:28:23 +00:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-09-21 20:04:56 +00:00
|
|
|
int mca_mpool_gm_retain(
|
|
|
|
struct mca_mpool_base_module_t* mpool,
|
|
|
|
mca_mpool_base_registration_t* registration)
|
|
|
|
{
|
2005-09-12 22:28:23 +00:00
|
|
|
OPAL_THREAD_ADD32(®istration->ref_count, 1);
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-03-16 23:11:45 +00:00
|
|
|
int mca_mpool_gm_ft_event(int state) {
|
|
|
|
if(OPAL_CRS_CHECKPOINT == state) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if(OPAL_CRS_CONTINUE == state) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if(OPAL_CRS_RESTART == state) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if(OPAL_CRS_TERM == state ) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
;
|
|
|
|
}
|
2005-09-12 22:28:23 +00:00
|
|
|
|
2007-03-16 23:11:45 +00:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|