- shared memory init
This commit was SVN r1362.
Этот коммит содержится в:
родитель
e88c37e1f8
Коммит
14e0f8cf42
@ -19,7 +19,8 @@ libmca_mpool_base_la_SOURCES = \
|
|||||||
$(headers) \
|
$(headers) \
|
||||||
mpool_base_open.c \
|
mpool_base_open.c \
|
||||||
mpool_base_close.c \
|
mpool_base_close.c \
|
||||||
mpool_base_init.c
|
mpool_base_init.c \
|
||||||
|
mpool_base_lookup.c
|
||||||
|
|
||||||
# Conditionally install the header files
|
# Conditionally install the header files
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ extern "C" {
|
|||||||
int mca_mpool_base_open(void);
|
int mca_mpool_base_open(void);
|
||||||
int mca_mpool_base_init(bool *allow_multi_user_threads);
|
int mca_mpool_base_init(bool *allow_multi_user_threads);
|
||||||
int mca_mpool_base_close(void);
|
int mca_mpool_base_close(void);
|
||||||
mca_mpool_t* mca_mpool_lookup(const char* name);
|
mca_mpool_base_component_t* mca_mpool_component_lookup(const char* name);
|
||||||
void* mca_mpool_base_is_registered(void* addr, size_t size);
|
mca_mpool_t* mca_mpool_module_lookup(const char* name);
|
||||||
#if defined(c_plusplus) || defined(__cplusplus)
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -44,7 +44,7 @@ extern "C" {
|
|||||||
* Globals
|
* Globals
|
||||||
*/
|
*/
|
||||||
extern int mca_mpool_base_output;
|
extern int mca_mpool_base_output;
|
||||||
extern ompi_list_t mca_mpool_base_modules_available;
|
extern ompi_list_t mca_mpool_base_components;
|
||||||
extern ompi_list_t mca_mpool_base_modules_initialized;
|
extern ompi_list_t mca_mpool_base_modules;
|
||||||
|
|
||||||
#endif /* MCA_MEM_BASE_H */
|
#endif /* MCA_MEM_BASE_H */
|
||||||
|
@ -20,9 +20,9 @@ int mca_mpool_base_close(void)
|
|||||||
|
|
||||||
/* Finalize all the mpool modules and free their list items */
|
/* Finalize all the mpool modules and free their list items */
|
||||||
|
|
||||||
for (item = ompi_list_remove_first(&mca_mpool_base_modules_initialized);
|
for (item = ompi_list_remove_first(&mca_mpool_base_modules);
|
||||||
NULL != item;
|
NULL != item;
|
||||||
item = ompi_list_remove_first(&mca_mpool_base_modules_initialized)) {
|
item = ompi_list_remove_first(&mca_mpool_base_modules)) {
|
||||||
sm = (mca_mpool_base_selected_module_t *) item;
|
sm = (mca_mpool_base_selected_module_t *) item;
|
||||||
|
|
||||||
/* Blatently ignore the return code (what would we do to recover,
|
/* Blatently ignore the return code (what would we do to recover,
|
||||||
@ -36,8 +36,7 @@ int mca_mpool_base_close(void)
|
|||||||
/* Close all remaining available modules (may be one if this is a
|
/* Close all remaining available modules (may be one if this is a
|
||||||
OMPI RTE program, or [possibly] multiple if this is ompi_info) */
|
OMPI RTE program, or [possibly] multiple if this is ompi_info) */
|
||||||
|
|
||||||
mca_base_modules_close(mca_mpool_base_output,
|
mca_base_modules_close(mca_mpool_base_output, &mca_mpool_base_components, NULL);
|
||||||
&mca_mpool_base_modules_available, NULL);
|
|
||||||
|
|
||||||
/* All done */
|
/* All done */
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ OBJ_CLASS_INSTANCE(mca_mpool_base_selected_module_t, ompi_list_item_t, NULL, NUL
|
|||||||
/**
|
/**
|
||||||
* Function for weeding out mpool modules that don't want to run.
|
* Function for weeding out mpool modules that don't want to run.
|
||||||
*
|
*
|
||||||
* Call the init function on all available modules to find out if they
|
* Call the init function on all available components to find out if they
|
||||||
* want to run. Select all modules that don't fail. Failing modules
|
* want to run. Select all components that don't fail. Failing modules
|
||||||
* will be closed and unloaded. The selected modules will be returned
|
* will be closed and unloaded. The selected modules will be returned
|
||||||
* to the caller in a ompi_list_t.
|
* to the caller in a ompi_list_t.
|
||||||
*/
|
*/
|
||||||
@ -35,8 +35,8 @@ int mca_mpool_base_init(bool *allow_multi_user_threads)
|
|||||||
/* Traverse the list of available modules; call their init
|
/* Traverse the list of available modules; call their init
|
||||||
functions. */
|
functions. */
|
||||||
|
|
||||||
for (item = ompi_list_get_first(&mca_mpool_base_modules_available);
|
for (item = ompi_list_get_first(&mca_mpool_base_components);
|
||||||
ompi_list_get_end(&mca_mpool_base_modules_available) != item;
|
ompi_list_get_end(&mca_mpool_base_components) != item;
|
||||||
item = ompi_list_get_next(item)) {
|
item = ompi_list_get_next(item)) {
|
||||||
mli = (mca_base_module_list_item_t *) item;
|
mli = (mca_base_module_list_item_t *) item;
|
||||||
component = (mca_mpool_base_component_t *) mli->mli_module;
|
component = (mca_mpool_base_component_t *) mli->mli_module;
|
||||||
@ -67,17 +67,17 @@ int mca_mpool_base_init(bool *allow_multi_user_threads)
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
*allow_multi_user_threads &= user_threads;
|
*allow_multi_user_threads &= user_threads;
|
||||||
|
|
||||||
ompi_output_verbose(10, mca_mpool_base_output,
|
ompi_output_verbose(10, mca_mpool_base_output,
|
||||||
"select: init returned success");
|
"select: init returned success");
|
||||||
|
|
||||||
sm = OBJ_NEW(mca_mpool_base_selected_module_t);
|
sm = OBJ_NEW(mca_mpool_base_selected_module_t);
|
||||||
sm->mpool_component = component;
|
sm->mpool_component = component;
|
||||||
sm->mpool_module = module;
|
sm->mpool_module = module;
|
||||||
ompi_list_append(&mca_mpool_base_modules_initialized, (ompi_list_item_t*) sm);
|
ompi_list_append(&mca_mpool_base_modules, (ompi_list_item_t*) sm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OMPI_SUCCESS;
|
return OMPI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
45
src/mca/mpool/base/mpool_base_lookup.c
Обычный файл
45
src/mca/mpool/base/mpool_base_lookup.c
Обычный файл
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* $HEADER$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ompi_config.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "mca/mca.h"
|
||||||
|
#include "mca/base/base.h"
|
||||||
|
#include "mca/mpool/mpool.h"
|
||||||
|
#include "mca/mpool/base/base.h"
|
||||||
|
|
||||||
|
mca_mpool_base_component_t* mca_mpool_component_lookup(const char* name)
|
||||||
|
{
|
||||||
|
/* Traverse the list of available modules; call their init functions. */
|
||||||
|
ompi_list_item_t* item;
|
||||||
|
for (item = ompi_list_get_first(&mca_mpool_base_components);
|
||||||
|
item != ompi_list_get_end(&mca_mpool_base_components);
|
||||||
|
item = ompi_list_get_next(item)) {
|
||||||
|
mca_base_module_list_item_t *mli = (mca_base_module_list_item_t *) item;
|
||||||
|
mca_mpool_base_component_t* component = (mca_mpool_base_component_t *) mli->mli_module;
|
||||||
|
if(strcmp(component->mpool_version.mca_module_name,name) == 0) {
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mca_mpool_t* mca_mpool_module_lookup(const char* name)
|
||||||
|
{
|
||||||
|
/* Finalize all the mpool modules and free their list items */
|
||||||
|
ompi_list_item_t *item;
|
||||||
|
for(item = ompi_list_get_first(&mca_mpool_base_modules);
|
||||||
|
item != ompi_list_get_end(&mca_mpool_base_modules);
|
||||||
|
item = ompi_list_get_next(item)) {
|
||||||
|
mca_mpool_base_selected_module_t *sm = (mca_mpool_base_selected_module_t *) item;
|
||||||
|
if(strcmp(sm->mpool_component->mpool_version.mca_module_name,name) == 0) {
|
||||||
|
return sm->mpool_module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
@ -25,8 +25,8 @@
|
|||||||
* Global variables
|
* Global variables
|
||||||
*/
|
*/
|
||||||
int mca_mpool_base_output = -1;
|
int mca_mpool_base_output = -1;
|
||||||
ompi_list_t mca_mpool_base_modules_available;
|
ompi_list_t mca_mpool_base_components;
|
||||||
ompi_list_t mca_mpool_base_modules_initialized;
|
ompi_list_t mca_mpool_base_modules;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +39,7 @@ int mca_mpool_base_open(void)
|
|||||||
|
|
||||||
if (OMPI_SUCCESS !=
|
if (OMPI_SUCCESS !=
|
||||||
mca_base_modules_open("mpool", 0, mca_mpool_base_static_modules,
|
mca_base_modules_open("mpool", 0, mca_mpool_base_static_modules,
|
||||||
&mca_mpool_base_modules_available)) {
|
&mca_mpool_base_components)) {
|
||||||
return OMPI_ERROR;
|
return OMPI_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ int mca_mpool_base_open(void)
|
|||||||
iterate over it (even if it's empty, as in the case of
|
iterate over it (even if it's empty, as in the case of
|
||||||
ompi_info) */
|
ompi_info) */
|
||||||
|
|
||||||
OBJ_CONSTRUCT(&mca_mpool_base_modules_initialized, ompi_list_t);
|
OBJ_CONSTRUCT(&mca_mpool_base_modules, ompi_list_t);
|
||||||
|
|
||||||
/* All done */
|
/* All done */
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ mca_mpool_t mca_mpool_sm = {
|
|||||||
*/
|
*/
|
||||||
void* mca_mpool_sm_alloc(size_t size, size_t align)
|
void* mca_mpool_sm_alloc(size_t size, size_t align)
|
||||||
{
|
{
|
||||||
return mca_mpool_sm_module.sm_allocator->alc_alloc(
|
return mca_mpool_sm_module.sm_allocator->alc_alloc(mca_mpool_sm_module.sm_allocator, size, align);
|
||||||
mca_mpool_sm_module.sm_allocator, size, align);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,8 +30,7 @@ void* mca_mpool_sm_alloc(size_t size, size_t align)
|
|||||||
*/
|
*/
|
||||||
void* mca_mpool_sm_realloc(void* addr, size_t size)
|
void* mca_mpool_sm_realloc(void* addr, size_t size)
|
||||||
{
|
{
|
||||||
return mca_mpool_sm_module.sm_allocator->alc_realloc(
|
return mca_mpool_sm_module.sm_allocator->alc_realloc(mca_mpool_sm_module.sm_allocator, addr, size);
|
||||||
mca_mpool_sm_module.sm_allocator, addr, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +38,6 @@ void* mca_mpool_sm_realloc(void* addr, size_t size)
|
|||||||
*/
|
*/
|
||||||
void mca_mpool_sm_free(void * addr)
|
void mca_mpool_sm_free(void * addr)
|
||||||
{
|
{
|
||||||
mca_mpool_sm_module.sm_allocator->alc_free(
|
mca_mpool_sm_module.sm_allocator->alc_free(mca_mpool_sm_module.sm_allocator, addr);
|
||||||
mca_mpool_sm_module.sm_allocator, addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,7 @@ struct mca_mpool_sm_component_t {
|
|||||||
mca_mpool_base_component_t super;
|
mca_mpool_base_component_t super;
|
||||||
mca_allocator_t* sm_allocator;
|
mca_allocator_t* sm_allocator;
|
||||||
char* sm_allocator_name;
|
char* sm_allocator_name;
|
||||||
size_t sm_min_size;
|
|
||||||
size_t sm_max_size;
|
|
||||||
size_t sm_size;
|
size_t sm_size;
|
||||||
size_t sm_segment;
|
|
||||||
ompi_list_t sm_mmaps;
|
|
||||||
struct mca_mpool_sm_mmap_t *sm_mmap;
|
struct mca_mpool_sm_mmap_t *sm_mmap;
|
||||||
};
|
};
|
||||||
typedef struct mca_mpool_sm_component_t mca_mpool_sm_component_t;
|
typedef struct mca_mpool_sm_component_t mca_mpool_sm_component_t;
|
||||||
@ -30,7 +26,9 @@ typedef struct mca_mpool_sm_component_t mca_mpool_sm_component_t;
|
|||||||
extern mca_mpool_sm_component_t mca_mpool_sm_module;
|
extern mca_mpool_sm_component_t mca_mpool_sm_module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allocate function typedef
|
* returns a pointer to an mca_mpool_sm_allocation_t - the allocation
|
||||||
|
* will always be increased by the size of mca_mpool_sm_allocation_t -
|
||||||
|
* the allocated block follows this header
|
||||||
*/
|
*/
|
||||||
void* mca_mpool_sm_alloc(size_t size, size_t align);
|
void* mca_mpool_sm_alloc(size_t size, size_t align);
|
||||||
|
|
||||||
|
@ -67,14 +67,10 @@ static inline int mca_mpool_sm_param_register_int(
|
|||||||
int mca_mpool_sm_open(void)
|
int mca_mpool_sm_open(void)
|
||||||
{
|
{
|
||||||
/* register SM module parameters */
|
/* register SM module parameters */
|
||||||
mca_mpool_sm_module.sm_min_size =
|
mca_mpool_sm_module.sm_size =
|
||||||
mca_mpool_sm_param_register_int("min_size", 64*1024*1024);
|
mca_mpool_sm_param_register_int("size", 512*1024*1024);
|
||||||
mca_mpool_sm_module.sm_max_size =
|
|
||||||
mca_mpool_sm_param_register_int("max_size", 512*1024*1024);
|
|
||||||
mca_mpool_sm_module.sm_allocator_name =
|
mca_mpool_sm_module.sm_allocator_name =
|
||||||
mca_mpool_sm_param_register_string("allocator", "bucket");
|
mca_mpool_sm_param_register_string("allocator", "bucket");
|
||||||
mca_mpool_sm_module.sm_segment = 1;
|
|
||||||
mca_mpool_sm_module.sm_size = 0;
|
|
||||||
return OMPI_SUCCESS;
|
return OMPI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,11 +102,10 @@ mca_mpool_t* mca_mpool_sm_init(bool *allow_multi_user_threads)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* create initial shared memory mapping */
|
/* 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))) {
|
if(NULL == (mca_mpool_sm_module.sm_mmap = mca_mpool_sm_mmap_init(mca_mpool_sm_module.sm_size))) {
|
||||||
ompi_output(0, "mca_mpool_sm_init: unable to create shared memory mapping");
|
ompi_output(0, "mca_mpool_sm_init: unable to create shared memory mapping");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ompi_list_append(&mca_mpool_sm_module.sm_mmaps, &mca_mpool_sm_module.sm_mmap);
|
|
||||||
|
|
||||||
/* setup allocator */
|
/* setup allocator */
|
||||||
mca_mpool_sm_module.sm_allocator = allocator_component->allocator_init(
|
mca_mpool_sm_module.sm_allocator = allocator_component->allocator_init(
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "util/output.h"
|
#include "util/output.h"
|
||||||
|
#include "util/sys_info.h"
|
||||||
#include "mca/pcm/pcm.h"
|
#include "mca/pcm/pcm.h"
|
||||||
#include "mpool_sm.h"
|
#include "mpool_sm.h"
|
||||||
#include "mpool_sm_mmap.h"
|
#include "mpool_sm_mmap.h"
|
||||||
@ -66,16 +67,12 @@ static mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_open(char* path)
|
|||||||
|
|
||||||
mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_init(size_t size)
|
mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_init(size_t size)
|
||||||
{
|
{
|
||||||
ompi_job_handle_t job_handle = mca_pcm.pcm_handle_get();
|
|
||||||
char hostname[64];
|
|
||||||
int fd;
|
int fd;
|
||||||
mca_mpool_sm_segment_t* seg;
|
mca_mpool_sm_segment_t* seg;
|
||||||
mca_mpool_sm_mmap_t* map;
|
mca_mpool_sm_mmap_t* map;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
gethostname(hostname, sizeof(hostname));
|
sprintf(path, "%s/mmap.%s", ompi_system_info.session_dir, ompi_system_info.nodename);
|
||||||
sprintf(path, "/tmp/%s.%s.%d", hostname, job_handle,
|
|
||||||
ompi_list_get_size(&mca_mpool_sm_module.sm_mmaps)+1);
|
|
||||||
fd = open(path, O_CREAT|O_RDWR, 0000);
|
fd = open(path, O_CREAT|O_RDWR, 0000);
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
if(errno == EACCES)
|
if(errno == EACCES)
|
||||||
@ -104,7 +101,7 @@ mca_mpool_sm_mmap_t* mca_mpool_sm_mmap_init(size_t size)
|
|||||||
map = OBJ_NEW(mca_mpool_sm_mmap_t);
|
map = OBJ_NEW(mca_mpool_sm_mmap_t);
|
||||||
strncpy(map->map_path, path, PATH_MAX);
|
strncpy(map->map_path, path, PATH_MAX);
|
||||||
map->map_seg = seg;
|
map->map_seg = seg;
|
||||||
map->map_addr = (unsigned char*)(seg + 1);
|
map->map_addr = (unsigned char*)(seg+1);
|
||||||
map->map_size = size - sizeof(mca_mpool_sm_segment_t);
|
map->map_size = size - sizeof(mca_mpool_sm_segment_t);
|
||||||
|
|
||||||
/* enable access by other processes on this host */
|
/* enable access by other processes on this host */
|
||||||
@ -126,7 +123,7 @@ void* mca_mpool_sm_mmap_alloc(size_t* size)
|
|||||||
void* addr;
|
void* addr;
|
||||||
|
|
||||||
spinlock(&seg->seg_lock);
|
spinlock(&seg->seg_lock);
|
||||||
if(seg->seg_offset + *size > seg->seg_size) {
|
if(seg->seg_offset + *size > map->map_size) {
|
||||||
addr = NULL;
|
addr = NULL;
|
||||||
} else {
|
} else {
|
||||||
addr = map->map_addr + seg->seg_offset;
|
addr = map->map_addr + seg->seg_offset;
|
||||||
|
@ -16,7 +16,7 @@ typedef struct mca_mpool_sm_segment_t mca_mpool_sm_segment_t;
|
|||||||
struct mca_mpool_sm_mmap_t {
|
struct mca_mpool_sm_mmap_t {
|
||||||
ompi_list_item_t map_item;
|
ompi_list_item_t map_item;
|
||||||
mca_mpool_sm_segment_t* map_seg;
|
mca_mpool_sm_segment_t* map_seg;
|
||||||
unsigned char* map_addr;
|
unsigned char *map_addr;
|
||||||
size_t map_size;
|
size_t map_size;
|
||||||
char map_path[PATH_MAX];
|
char map_path[PATH_MAX];
|
||||||
};
|
};
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user