2014-02-03 21:01:46 +04:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2012-08-16 23:11:35 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009-2012 Oak Ridge National Laboratory. All rights reserved.
|
|
|
|
* Copyright (c) 2009-2012 Mellanox Technologies. All rights reserved.
|
2014-02-03 21:01:46 +04:00
|
|
|
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2012-08-16 23:11:35 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include "bcol_basesmuma.h"
|
|
|
|
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* Shared memory registration function: Calls into the "shared memory
|
|
|
|
connection manager" (aka - smcm) and registers a chunk of memory by
|
2012-08-16 23:11:35 +04:00
|
|
|
opening and mmaping a file.
|
2014-02-03 21:01:46 +04:00
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
@input:
|
|
|
|
|
|
|
|
void *reg_data - shared memory specific data needed by the registration
|
2014-02-03 21:01:46 +04:00
|
|
|
function.
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
void *base - pointer to memory address.
|
|
|
|
|
|
|
|
size_t size - size of memory chunk to be registered with sm.
|
|
|
|
|
|
|
|
mca_mpool_base_registration_t *reg - registration data is cached here.
|
2014-02-03 21:01:46 +04:00
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
@output:
|
|
|
|
|
|
|
|
returns OMPI_SUCCESS on successful registration.
|
|
|
|
|
|
|
|
returns OMPI_ERROR on failure.
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
*/
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
int mca_bcol_basesmuma_register_sm(void *context_data, void *base, size_t size,
|
2014-02-03 21:01:46 +04:00
|
|
|
void **reg_desc)
|
2012-08-16 23:11:35 +04:00
|
|
|
{
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* local variables */
|
|
|
|
int ret = OMPI_SUCCESS;
|
|
|
|
mca_bcol_basesmuma_component_t *cs = &mca_bcol_basesmuma_component;
|
|
|
|
bcol_basesmuma_registration_data_t *sm_reg =
|
|
|
|
(bcol_basesmuma_registration_data_t*) context_data;
|
|
|
|
|
|
|
|
/* cache some info on sm_reg aka "context_data", you'll need it later */
|
|
|
|
sm_reg->base_addr = base;
|
|
|
|
sm_reg->size = size;
|
|
|
|
|
|
|
|
/* call into the shared memory registration function in smcm
|
|
|
|
* we need to be sure that the memory is page aligned in order
|
|
|
|
* to "map_fixed"
|
|
|
|
*/
|
|
|
|
sm_reg->sm_mmap = bcol_basesmuma_smcm_mem_reg(base, size,
|
|
|
|
sm_reg->data_seg_alignment,
|
|
|
|
sm_reg->file_name);
|
|
|
|
if(NULL == sm_reg->sm_mmap) {
|
|
|
|
opal_output (0, "Bcol_basesmuma memory registration error \n");
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't let other communicators re-register me! */
|
|
|
|
cs->mpool_inited = true;
|
|
|
|
/* alias back to component */
|
|
|
|
cs->sm_payload_structs = sm_reg->sm_mmap;
|
|
|
|
|
|
|
|
return ret;
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Shared memory deregistration function - deregisters memory by munmapping it and removing the
|
2014-02-03 21:01:46 +04:00
|
|
|
shared memory file.
|
|
|
|
|
|
|
|
Basic steps (please let me know if this is incompatible with your notion of deregistration
|
2012-08-16 23:11:35 +04:00
|
|
|
or if it causes problems on cleanup):
|
2014-02-03 21:01:46 +04:00
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
1. munmap the shared memory file.
|
|
|
|
2. set the base pointer to the mmaped memory to NULL.
|
|
|
|
3. permanently remove the shared memory file from the directory.
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
*/
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
int mca_bcol_basesmuma_deregister_sm(void *context_data, void *reg)
|
|
|
|
{
|
2014-02-03 21:01:46 +04:00
|
|
|
/* NTH -- code was disable. why? */
|
|
|
|
#if 0
|
|
|
|
/* local variables */
|
|
|
|
int ret;
|
|
|
|
bcol_basesmuma_registration_data_t *sm_reg =
|
|
|
|
(bcol_basesmuma_registration_data_t*) context_data;
|
|
|
|
|
|
|
|
/* unmap the shared memory file */
|
|
|
|
ret = munmap((void *) sm_reg->base_addr, sm_reg->size);
|
2012-08-16 23:11:35 +04:00
|
|
|
if( 0 > ret) {
|
2014-02-03 21:01:46 +04:00
|
|
|
opal_output (0, "Failed to munmap the shared memory file %s\n",sm_reg->file_name);
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* set the pointer to NULL */
|
|
|
|
sm_reg->base_addr = NULL;
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* remove the file */
|
|
|
|
ret = remove(sm_reg->file_name);
|
|
|
|
if( 0 > ret) {
|
|
|
|
opal_output (0, "Failed to remove the shared memory file %s. reason = %s\n",
|
|
|
|
sm_reg->file_name, strerror (errno));
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
return OMPI_SUCCESS;
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|