- shared memory pool init
- allocator base cleanup This commit was SVN r1327.
Этот коммит содержится в:
родитель
d7c221e6d1
Коммит
19ed014922
@ -18,8 +18,7 @@ headers = \
|
||||
libmca_allocator_base_la_SOURCES = \
|
||||
$(headers) \
|
||||
allocator_base_open.c \
|
||||
allocator_base_close.c \
|
||||
allocator_base_init.c
|
||||
allocator_base_close.c
|
||||
|
||||
# Conditionally install the header files
|
||||
|
||||
|
@ -15,28 +15,10 @@
|
||||
|
||||
int mca_allocator_base_close(void)
|
||||
{
|
||||
ompi_list_item_t *item;
|
||||
mca_allocator_base_selected_module_t *sm;
|
||||
|
||||
/* Finalize all the allocator modules and free their list items */
|
||||
|
||||
for (item = ompi_list_remove_first(&mca_allocator_base_modules);
|
||||
NULL != item;
|
||||
item = ompi_list_remove_first(&mca_allocator_base_modules)) {
|
||||
sm = (mca_allocator_base_selected_module_t *) item;
|
||||
|
||||
/* Blatently ignore the return code (what would we do to recover,
|
||||
anyway? This module is going away, so errors don't matter
|
||||
anymore) */
|
||||
|
||||
sm->allocator_module->alc_finalize(sm->allocator_module);
|
||||
OBJ_RELEASE(sm);
|
||||
}
|
||||
|
||||
/* Close all remaining available modules (may be one if this is a
|
||||
OMPI RTE program, or [possibly] multiple if this is ompi_info) */
|
||||
|
||||
mca_base_modules_close(mca_allocator_base_output, &mca_allocator_base_modules, NULL);
|
||||
mca_base_modules_close(mca_allocator_base_output, &mca_allocator_base_components, NULL);
|
||||
|
||||
/* All done */
|
||||
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#include "ompi_config.h"
|
||||
|
||||
#include "mca/mca.h"
|
||||
#include "mca/base/base.h"
|
||||
#include "mca/allocator/base/base.h"
|
||||
|
||||
|
||||
/**
|
||||
* Function for weeding out allocator modules that don't want to run.
|
||||
*
|
||||
* Call the init function on all available modules to find out if they
|
||||
* want to run. Select all modules that don't fail. Failing modules
|
||||
* will be closed and unloaded. The selected modules will be returned
|
||||
* to the caller in a ompi_list_t.
|
||||
*/
|
||||
int mca_allocator_base_init(bool *allow_multi_user_threads)
|
||||
{
|
||||
#if 0
|
||||
int i, num_allocators;
|
||||
ompi_list_item_t *item;
|
||||
mca_base_module_list_item_t *mli;
|
||||
mca_allocator_base_module_t *module;
|
||||
mca_allocator_t **actions;
|
||||
mca_allocator_base_selected_module_t *sm;
|
||||
|
||||
/* Traverse the list of available modules; call their init
|
||||
functions. */
|
||||
|
||||
for (item = ompi_list_get_first(&mca_allocator_base_modules_available);
|
||||
ompi_list_get_end(&mca_allocator_base_modules_available) != item;
|
||||
item = ompi_list_get_next(item)) {
|
||||
mli = (mca_base_module_list_item_t *) item;
|
||||
module = (mca_allocator_base_module_t *) mli->mli_module;
|
||||
|
||||
ompi_output_verbose(10, mca_allocator_base_output,
|
||||
"select: initializing %s module %s",
|
||||
module->allocatorm_version.mca_type_name,
|
||||
module->allocatorm_version.mca_module_name);
|
||||
if (NULL == module->allocatorm_init) {
|
||||
ompi_output_verbose(10, mca_allocator_base_output,
|
||||
"select: no init function; ignoring module");
|
||||
} else {
|
||||
actions = module->allocatorm_init(&num_allocators, &user_threads,
|
||||
&hidden_threads);
|
||||
|
||||
/* If the module didn't initialize, unload it */
|
||||
|
||||
if (NULL == actions) {
|
||||
ompi_output_verbose(10, mca_allocator_base_output,
|
||||
"select: init returned failure");
|
||||
|
||||
mca_base_module_repository_release((mca_base_module_t *) module);
|
||||
ompi_output_verbose(10, mca_allocator_base_output,
|
||||
"select: module %s unloaded",
|
||||
module->allocatorm_version.mca_module_name);
|
||||
}
|
||||
|
||||
/* Otherwise, it initialized properly. Save it. */
|
||||
|
||||
else {
|
||||
*allow_multi_user_threads |= user_threads;
|
||||
*have_hidden_threads |= hidden_threads;
|
||||
|
||||
ompi_output_verbose(10, mca_allocator_base_output,
|
||||
"select: init returned success");
|
||||
|
||||
for (i = 0; i < num_allocators; ++i) {
|
||||
sm = malloc(sizeof(mca_allocator_base_selected_module_t));
|
||||
if (NULL == sm) {
|
||||
return OMPI_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
OBJ_CONSTRUCT(sm, ompi_list_item_t);
|
||||
sm->pbsm_module = module;
|
||||
sm->pbsm_actions = actions[i];
|
||||
ompi_list_append(&mca_allocator_base_modules_initialized,
|
||||
(ompi_list_item_t*) sm);
|
||||
}
|
||||
free(actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Finished querying all modules. Check for the bozo case. */
|
||||
|
||||
if (0 == ompi_list_get_size(&mca_allocator_base_modules_initialized)) {
|
||||
/* JMS Replace with show_help */
|
||||
ompi_abort(1, "No allocator module available. This shouldn't happen.");
|
||||
}
|
||||
|
||||
/* All done */
|
||||
|
||||
#endif
|
||||
return OMPI_SUCCESS;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
* Global variables
|
||||
*/
|
||||
ompi_list_t mca_allocator_base_components;
|
||||
ompi_list_t mca_allocator_base_modules;
|
||||
int mca_allocator_base_output = -1;
|
||||
|
||||
/**
|
||||
@ -35,13 +34,8 @@ int mca_allocator_base_output = -1;
|
||||
int mca_allocator_base_open(void)
|
||||
{
|
||||
/* Open up all available modules */
|
||||
|
||||
if (OMPI_SUCCESS !=
|
||||
mca_base_modules_open("allocator", 0, mca_allocator_base_static_modules,
|
||||
&mca_allocator_base_components)) {
|
||||
return OMPI_ERROR;
|
||||
}
|
||||
/* All done */
|
||||
return OMPI_SUCCESS;
|
||||
return mca_base_modules_open("allocator", 0, mca_allocator_base_static_modules,
|
||||
&mca_allocator_base_components);
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,9 +32,8 @@ OBJ_CLASS_DECLARATION(mca_mpool_base_selected_module_t);
|
||||
extern "C" {
|
||||
#endif
|
||||
int mca_allocator_base_open(void);
|
||||
int mca_allocator_base_init(bool *allow_multi_user_threads);
|
||||
int mca_allocator_base_close(void);
|
||||
mca_allocator_base_module_t* mca_allocator_module_lookup(const char* name);
|
||||
mca_allocator_base_module_t* mca_allocator_component_lookup(const char* name);
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@ -44,8 +43,6 @@ extern "C" {
|
||||
* Globals
|
||||
*/
|
||||
|
||||
|
||||
extern ompi_list_t mca_allocator_base_components;
|
||||
extern ompi_list_t mca_allocator_base_modules;
|
||||
|
||||
#endif /* MCA_ALLOCATOR_BASE_H */
|
||||
|
@ -22,7 +22,8 @@ struct mca_mpool_sm_component_t {
|
||||
size_t sm_max_size;
|
||||
size_t sm_size;
|
||||
size_t sm_segment;
|
||||
ompi_list_t sm_mmap;
|
||||
ompi_list_t sm_mmaps;
|
||||
struct mca_mpool_sm_mmap_t *sm_mmap;
|
||||
};
|
||||
typedef struct mca_mpool_sm_component_t mca_mpool_sm_component_t;
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
#include "util/output.h"
|
||||
#include "mca/base/base.h"
|
||||
#include "mca/base/mca_base_param.h"
|
||||
#include "mca/mpool/sm/mpool_sm.h"
|
||||
#include "mca/allocator/base/base.h"
|
||||
#include "mpool_sm.h"
|
||||
#include "mpool_sm_mmap.h"
|
||||
|
||||
|
||||
mca_mpool_sm_component_t mca_mpool_sm_module = {
|
||||
@ -83,6 +87,41 @@ int mca_mpool_sm_close(void)
|
||||
|
||||
mca_mpool_t* mca_mpool_sm_init(bool *allow_multi_user_threads)
|
||||
{
|
||||
mca_allocator_base_module_t* allocator_component = mca_allocator_component_lookup(
|
||||
mca_mpool_sm_module.sm_allocator_name);
|
||||
|
||||
/* if specified allocator cannout be loaded - look for an alternative */
|
||||
if(NULL == allocator_component) {
|
||||
if(ompi_list_get_size(&mca_allocator_base_components) == 0) {
|
||||
mca_base_module_list_item_t* item = (mca_base_module_list_item_t*)
|
||||
ompi_list_get_first(&mca_allocator_base_components);
|
||||
allocator_component = (mca_allocator_base_module_t*)item->mli_module;
|
||||
ompi_output(0, "mca_mpool_sm_init: unable to locate allocator: %s - using %s\n",
|
||||
mca_mpool_sm_module.sm_allocator_name, allocator_component->allocator_version.mca_module_name);
|
||||
} else {
|
||||
ompi_output(0, "mca_mpool_sm_init: unable to locate allocator: %s\n",
|
||||
mca_mpool_sm_module.sm_allocator_name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* create initial shared memory mapping */
|
||||
if(NULL == (mca_mpool_sm_module.sm_mmap = mca_mpool_sm_mmap_init(mca_mpool_sm_module.sm_min_size))) {
|
||||
ompi_output(0, "mca_mpool_sm_init: unable to create shared memory mapping");
|
||||
return NULL;
|
||||
}
|
||||
ompi_list_append(&mca_mpool_sm_module.sm_mmaps, &mca_mpool_sm_module.sm_mmap);
|
||||
|
||||
/* setup allocator */
|
||||
mca_mpool_sm_module.sm_allocator = allocator_component->allocator_init(
|
||||
allow_multi_user_threads,
|
||||
mca_mpool_sm_mmap_alloc,
|
||||
NULL
|
||||
);
|
||||
if(NULL == mca_mpool_sm_module.sm_allocator) {
|
||||
ompi_output(0, "mca_mpool_sm_init: unable to initialize allocator");
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ static mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_open(char* path)
|
||||
mca_mpool_sm_mmap_t* map;
|
||||
mca_mpool_sm_segment_t* seg;
|
||||
int fd = -1;
|
||||
struct stat sbuf;
|
||||
|
||||
while(fd < 0) {
|
||||
struct timespec ts;
|
||||
@ -41,8 +42,13 @@ static mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_open(char* path)
|
||||
nanosleep(&ts,NULL);
|
||||
}
|
||||
|
||||
if(fstat(fd, &sbuf) != 0) {
|
||||
ompi_output(0, "mca_mpool_sm_mmap_open: fstat failed with errno=%d\n", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* map the file and initialize segment state */
|
||||
seg = mmap(NULL, mca_mpool_sm_module.sm_min_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
seg = mmap(NULL, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if(NULL == seg) {
|
||||
ompi_output(0, "mca_mpool_sm_mmap_open: mmap failed with errno=%d\n", errno);
|
||||
return NULL;
|
||||
@ -69,7 +75,7 @@ mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_init(size_t size)
|
||||
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
sprintf(path, "/tmp/%s.%s.%d", hostname, job_handle,
|
||||
ompi_list_get_size(&mca_mpool_sm_module.sm_mmap)+1);
|
||||
ompi_list_get_size(&mca_mpool_sm_module.sm_mmaps)+1);
|
||||
fd = open(path, O_CREAT|O_RDWR, 0000);
|
||||
if(fd < 0) {
|
||||
if(errno == EACCES)
|
||||
@ -79,7 +85,7 @@ mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_init(size_t size)
|
||||
}
|
||||
|
||||
/* truncate the file to the requested size */
|
||||
if(ftruncate(fd, mca_mpool_sm_module.sm_min_size) != 0) {
|
||||
if(ftruncate(fd, size) != 0) {
|
||||
ompi_output(0, "mca_mpool_sm_mmap_init: ftruncate failed with errno=%d\n", errno);
|
||||
return NULL;
|
||||
}
|
||||
@ -115,7 +121,6 @@ mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_init(size_t size)
|
||||
|
||||
void* mca_mpool_sm_mmap_alloc(size_t* size)
|
||||
{
|
||||
#if 0
|
||||
mca_mpool_sm_mmap_t* map = mca_mpool_sm_module.sm_mmap;
|
||||
mca_mpool_sm_segment_t* seg = map->map_seg;
|
||||
void* addr;
|
||||
@ -124,13 +129,10 @@ void* mca_mpool_sm_mmap_alloc(size_t* size)
|
||||
if(seg->seg_offset + *size > seg->seg_size) {
|
||||
addr = NULL;
|
||||
} else {
|
||||
addr = map->sm_addr + seg->seg_offset;
|
||||
addr = map->map_addr + seg->seg_offset;
|
||||
seg->seg_offset += *size;
|
||||
}
|
||||
spinunlock(&seg->seg_lock);
|
||||
return addr;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user