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) 2012-2014 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2014-01-09 07:57:55 +04:00
|
|
|
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
2014-03-28 03:25:31 +04:00
|
|
|
* Copyright (c) 2014 Research Organization for Information Science
|
|
|
|
* and Technology (RIST). All rights reserved.
|
2012-08-16 23:11:35 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2014-01-09 07:57:55 +04:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
#include "ompi/proc/proc.h"
|
2013-02-06 01:52:55 +04:00
|
|
|
#include "ompi/patterns/comm/coll_ops.h"
|
2014-05-19 19:21:58 +04:00
|
|
|
#include "opal/align.h"
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
#include "opal/dss/dss.h"
|
|
|
|
#include "opal/util/error.h"
|
|
|
|
#include "opal/util/output.h"
|
|
|
|
#include "opal/class/opal_list.h"
|
|
|
|
#include "opal/class/opal_hash_table.h"
|
|
|
|
|
|
|
|
#include "bcol_basesmuma.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SM_BACKING_FILE_NAME_MAX_LEN 256
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
static bcol_basesmuma_smcm_mmap_t * bcol_basesmuma_smcm_reg_mmap(void *in_ptr, int fd, size_t length,
|
|
|
|
size_t addr_offset, size_t alignment,
|
|
|
|
char *file_name);
|
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
struct file_info_t {
|
|
|
|
uint32_t vpid;
|
|
|
|
uint32_t jobid;
|
|
|
|
uint64_t file_size;
|
|
|
|
uint64_t size_ctl_structure;
|
|
|
|
uint64_t data_seg_alignment;
|
|
|
|
char file_name[SM_BACKING_FILE_NAME_MAX_LEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* need to allocate space for the peer */
|
2014-05-13 21:00:31 +04:00
|
|
|
static void bcol_basesmuma_smcm_proc_item_t_construct (bcol_basesmuma_smcm_proc_item_t * item)
|
|
|
|
{
|
|
|
|
memset ((char *) item + sizeof (item->item), 0, sizeof (*item) - sizeof (item->item));
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* need to free the space for the peer */
|
2014-05-13 21:00:31 +04:00
|
|
|
static void bcol_basesmuma_smcm_proc_item_t_destruct (bcol_basesmuma_smcm_proc_item_t * item)
|
|
|
|
{
|
|
|
|
if (item->sm_mmap) {
|
2014-05-27 22:40:41 +04:00
|
|
|
OBJ_RELEASE(item->sm_mmap);
|
2014-05-13 21:00:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item->sm_file.file_name) {
|
|
|
|
free (item->sm_file.file_name);
|
|
|
|
item->sm_file.file_name = NULL;
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(bcol_basesmuma_smcm_proc_item_t,
|
2014-02-03 21:01:46 +04:00
|
|
|
opal_list_item_t,
|
|
|
|
bcol_basesmuma_smcm_proc_item_t_construct,
|
|
|
|
bcol_basesmuma_smcm_proc_item_t_destruct);
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
static void bcol_basesmuma_smcm_mmap_construct (bcol_basesmuma_smcm_mmap_t *smcm_mmap)
|
2012-08-16 23:11:35 +04:00
|
|
|
{
|
2014-05-27 22:40:41 +04:00
|
|
|
memset ((char *) smcm_mmap + sizeof (smcm_mmap->super), 0, sizeof (*smcm_mmap) - sizeof (smcm_mmap->super));
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
static void bcol_basesmuma_smcm_mmap_destruct (bcol_basesmuma_smcm_mmap_t *smcm_mmap)
|
|
|
|
{
|
|
|
|
if (smcm_mmap->map_seg) {
|
|
|
|
munmap (smcm_mmap->map_seg, smcm_mmap->map_size);
|
|
|
|
smcm_mmap->map_seg = NULL;
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
if (smcm_mmap->map_path) {
|
|
|
|
free (smcm_mmap->map_path);
|
|
|
|
smcm_mmap->map_path = NULL;
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
OBJ_CLASS_INSTANCE(bcol_basesmuma_smcm_mmap_t, opal_list_item_t,
|
|
|
|
bcol_basesmuma_smcm_mmap_construct,
|
|
|
|
bcol_basesmuma_smcm_mmap_destruct);
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* smcm_allgather_connection:
|
|
|
|
This function is called when a shared memory subgroup wants to establish shared memory "connections" among
|
|
|
|
a group of processes.
|
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
This function DOES NOT create any shared memory backing files, it only mmaps already existing files. Shared
|
2014-02-03 21:01:46 +04:00
|
|
|
memory files are created by the shared memory registration function
|
2012-08-16 23:11:35 +04:00
|
|
|
-----------------------------------------------------------------------------------------------------------
|
|
|
|
Input params:
|
|
|
|
|
|
|
|
- sbgp module The subgrouping module contains the list of ranks to wire up.
|
|
|
|
|
|
|
|
- peer_list An opal list containing a list of bcol_basesmuma_smcm_proc_item_t types. This
|
2014-02-03 21:01:46 +04:00
|
|
|
contains a list of peers whose shared memory files I have already mapped.
|
2012-08-16 23:11:35 +04:00
|
|
|
Upon completion of the allgather exchange with all members of the group and depending on the
|
|
|
|
value of "map_all", my peers' shared memory files are mapped into my local virtual memory
|
2014-02-03 21:01:46 +04:00
|
|
|
space, with all pertinent information being stored in an bcol_basesmuma_smcm_proc_item_t which is
|
|
|
|
subsequently appended onto the "peer_list".
|
|
|
|
|
|
|
|
- comm The ompi_communicator_t communicator.
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
- input A data struct that caches the information about my shared memory file.
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
- map_all Bool that determines whether or not to go ahead and map the files from all of the peers
|
2012-08-16 23:11:35 +04:00
|
|
|
defined in the sbgp-ing module. If map_all == true, then go ahead and mmap all of the files
|
|
|
|
obtained in the exchange and append the information to the "peer_list". If map_all == false
|
2014-02-03 21:01:46 +04:00
|
|
|
then make a check and only mmap those peers' files whose vpid/jobid/filename combination do
|
|
|
|
not already exist in the "peer_list". Once mapping is completed, append this peer's information
|
2012-08-16 23:11:35 +04:00
|
|
|
to the "peer_list".
|
|
|
|
-----------------------------------------------------------------------------------------------------------
|
2014-02-03 21:01:46 +04:00
|
|
|
*
|
|
|
|
*/
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
int bcol_basesmuma_smcm_allgather_connection(
|
2014-02-03 21:01:46 +04:00
|
|
|
mca_bcol_basesmuma_module_t *sm_bcol_module,
|
|
|
|
mca_sbgp_base_module_t *module,
|
|
|
|
opal_list_t *peer_list,
|
|
|
|
bcol_basesmuma_smcm_proc_item_t ***back_files,
|
|
|
|
ompi_communicator_t *comm,
|
|
|
|
bcol_basesmuma_smcm_file_t input,
|
|
|
|
char *base_fname,
|
|
|
|
bool map_all)
|
2012-08-16 23:11:35 +04:00
|
|
|
{
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* define local variables */
|
|
|
|
|
2014-02-08 01:39:24 +04:00
|
|
|
int rc, i, fd;
|
2014-02-03 21:01:46 +04:00
|
|
|
ptrdiff_t mem_offset;
|
|
|
|
ompi_proc_t *proc_temp, *my_id;
|
|
|
|
bcol_basesmuma_smcm_proc_item_t *temp;
|
|
|
|
bcol_basesmuma_smcm_proc_item_t *item_ptr;
|
|
|
|
bcol_basesmuma_smcm_proc_item_t **backing_files;
|
|
|
|
struct file_info_t local_file;
|
|
|
|
struct file_info_t *all_files=NULL;
|
2014-05-27 22:40:41 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* sanity check */
|
|
|
|
if (strlen(input.file_name) > SM_BACKING_FILE_NAME_MAX_LEN-1) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "backing file name too long: %s len :: %d",
|
2014-02-03 21:01:46 +04:00
|
|
|
input.file_name, (int) strlen(input.file_name));
|
|
|
|
return OMPI_ERR_BAD_PARAM;
|
2014-01-22 19:39:19 +04:00
|
|
|
}
|
2014-02-03 21:01:46 +04:00
|
|
|
|
|
|
|
backing_files = (bcol_basesmuma_smcm_proc_item_t **)
|
|
|
|
calloc(module->group_size, sizeof(bcol_basesmuma_smcm_proc_item_t *));
|
|
|
|
if (!backing_files) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
2014-03-28 03:25:31 +04:00
|
|
|
/* FIXME *back_files might have been already allocated
|
|
|
|
* so free it in order to avoid a memory leak */
|
|
|
|
if (NULL != *back_files) {
|
|
|
|
free (*back_files);
|
|
|
|
}
|
2014-02-03 21:01:46 +04:00
|
|
|
*back_files = backing_files;
|
|
|
|
|
|
|
|
my_id = ompi_proc_local();
|
|
|
|
|
|
|
|
/* Phase One:
|
|
|
|
gather a list of processes that will participate in the allgather - I'm
|
|
|
|
preparing this list from the sbgp-ing module that was passed into the function */
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* fill in local file information */
|
|
|
|
local_file.vpid=my_id->proc_name.vpid;
|
|
|
|
local_file.jobid=my_id->proc_name.jobid;
|
|
|
|
local_file.file_size=input.size;
|
|
|
|
local_file.size_ctl_structure=input.size_ctl_structure;
|
|
|
|
local_file.data_seg_alignment=input.data_seg_alignment;
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
strcpy (local_file.file_name, input.file_name);
|
|
|
|
|
|
|
|
/* will exchange this data type as a string of characters -
|
|
|
|
* this routine is first called before MPI_init() completes
|
|
|
|
* and before error handling is setup, so can't use the
|
|
|
|
* MPI data types to send this data */
|
|
|
|
all_files = (struct file_info_t *) calloc(module->group_size,
|
|
|
|
sizeof (struct file_info_t));
|
|
|
|
if (!all_files) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exchange data */
|
|
|
|
rc = comm_allgather_pml(&local_file,all_files,sizeof(struct file_info_t), MPI_CHAR,
|
|
|
|
sm_bcol_module->super.sbgp_partner_module->my_index,
|
|
|
|
sm_bcol_module->super.sbgp_partner_module->group_size,
|
|
|
|
sm_bcol_module->super.sbgp_partner_module->group_list,
|
|
|
|
sm_bcol_module->super.sbgp_partner_module->group_comm);
|
|
|
|
if( OMPI_SUCCESS != rc ) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "failed in comm_allgather_pml. Error code: %d", rc);
|
2014-02-03 21:01:46 +04:00
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Phase four:
|
|
|
|
loop through the receive buffer, unpack the data recieved from remote peers */
|
|
|
|
|
|
|
|
for (i = 0; i < module->group_size; i++) {
|
|
|
|
struct file_info_t *rem_file = all_files + i;
|
|
|
|
|
|
|
|
/* check if this is my index or if the file is already mapped (set above). ther
|
|
|
|
* is no reason to look through the peer list again because no two members of
|
|
|
|
* the group will have the same vpid/jobid pair. ignore this previously found
|
|
|
|
* mapping if map_all was requested (NTH: not sure why exactly since we re-map
|
|
|
|
* and already mapped file) */
|
2014-02-08 01:39:24 +04:00
|
|
|
if (sm_bcol_module->super.sbgp_partner_module->my_index == i) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
proc_temp = ompi_comm_peer_lookup(comm,module->group_list[i]);
|
|
|
|
|
|
|
|
OPAL_LIST_FOREACH(item_ptr, peer_list, bcol_basesmuma_smcm_proc_item_t) {
|
|
|
|
/* if the vpid/jobid/filename combination already exists in the list,
|
|
|
|
then do not map this peer's file --- because you already have */
|
|
|
|
if (proc_temp->proc_name.vpid == item_ptr->peer.vpid &&
|
|
|
|
proc_temp->proc_name.jobid == item_ptr->peer.jobid &&
|
|
|
|
0 == strcmp (item_ptr->sm_file.file_name, rem_file->file_name)) {
|
2014-05-13 21:00:31 +04:00
|
|
|
++item_ptr->refcnt;
|
2014-02-08 01:39:24 +04:00
|
|
|
/* record file data */
|
|
|
|
backing_files[i] = item_ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!map_all && backing_files[i]) {
|
2014-02-03 21:01:46 +04:00
|
|
|
continue;
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
2014-02-03 21:01:46 +04:00
|
|
|
|
|
|
|
temp = OBJ_NEW(bcol_basesmuma_smcm_proc_item_t);
|
|
|
|
if (!temp) {
|
|
|
|
rc = OMPI_ERR_OUT_OF_RESOURCE;
|
2012-08-16 23:11:35 +04:00
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
temp->peer.vpid = rem_file->vpid;
|
|
|
|
temp->peer.jobid = rem_file->jobid;
|
|
|
|
|
|
|
|
temp->sm_file.file_name = strdup (rem_file->file_name);
|
|
|
|
if (!temp->sm_file.file_name) {
|
|
|
|
rc = OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
OBJ_RELEASE(temp);
|
2012-08-16 23:11:35 +04:00
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
temp->sm_file.size = (size_t) rem_file->file_size;
|
|
|
|
temp->sm_file.mpool_size = (size_t) rem_file->file_size;
|
|
|
|
temp->sm_file.size_ctl_structure = (size_t) rem_file->size_ctl_structure;
|
|
|
|
temp->sm_file.data_seg_alignment = (size_t) rem_file->data_seg_alignment;
|
2014-05-13 21:00:31 +04:00
|
|
|
temp->refcnt = 1;
|
2014-02-03 21:01:46 +04:00
|
|
|
|
|
|
|
/* Phase Five:
|
|
|
|
If map_all == true, then we map every peer's file
|
|
|
|
else we check to see if I have already mapped this
|
|
|
|
vpid/jobid/filename combination and if I have, then
|
|
|
|
I do not mmap this peer's file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fd = open(temp->sm_file.file_name, O_RDWR, 0600);
|
|
|
|
if (0 > fd) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "SMCM Allgather failed to open sm backing file %s. errno = %d",
|
|
|
|
temp->sm_file.file_name, errno);
|
2014-02-03 21:01:46 +04:00
|
|
|
rc = OMPI_ERROR;
|
|
|
|
goto Error;
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* map the file */
|
2014-05-27 22:40:41 +04:00
|
|
|
temp->sm_mmap = bcol_basesmuma_smcm_reg_mmap (NULL, fd, temp->sm_file.size,
|
|
|
|
temp->sm_file.size_ctl_structure,
|
|
|
|
temp->sm_file.data_seg_alignment,
|
|
|
|
temp->sm_file.file_name);
|
|
|
|
close (fd);
|
2014-02-03 21:01:46 +04:00
|
|
|
if (NULL == temp->sm_mmap) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "mmapping failed to map remote peer's file");
|
2014-02-03 21:01:46 +04:00
|
|
|
OBJ_RELEASE(temp);
|
|
|
|
rc = OMPI_ERROR;
|
|
|
|
goto Error;
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* compute memory offset */
|
|
|
|
mem_offset = (ptrdiff_t) temp->sm_mmap->data_addr -
|
|
|
|
(ptrdiff_t) temp->sm_mmap->map_seg;
|
|
|
|
temp->sm_mmap->map_seg->seg_offset = mem_offset;
|
|
|
|
temp->sm_mmap->map_seg->seg_size = temp->sm_file.size - mem_offset;
|
|
|
|
/* more stuff to follow */
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* append this peer's info, including shared memory map addr, onto the
|
|
|
|
peer_list */
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* record file data */
|
|
|
|
backing_files[i] = (bcol_basesmuma_smcm_proc_item_t *) temp;
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
opal_list_append(peer_list, (opal_list_item_t*) temp);
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
rc = OMPI_SUCCESS;
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
Error:
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* error clean-up and return */
|
|
|
|
if (NULL != all_files) {
|
|
|
|
free(all_files);
|
|
|
|
}
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
return rc;
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:00:31 +04:00
|
|
|
int bcol_basesmuma_smcm_release_connections (mca_bcol_basesmuma_module_t *sm_bcol_module,
|
|
|
|
mca_sbgp_base_module_t *sbgp_module, opal_list_t *peer_list,
|
|
|
|
bcol_basesmuma_smcm_proc_item_t ***back_files)
|
|
|
|
{
|
|
|
|
bcol_basesmuma_smcm_proc_item_t **smcm_procs = *back_files;
|
|
|
|
|
|
|
|
for (int i = 0 ; i < sbgp_module->group_size ; ++i) {
|
|
|
|
if (smcm_procs[i] && 0 == --smcm_procs[i]->refcnt) {
|
|
|
|
opal_list_remove_item (peer_list, (opal_list_item_t *) smcm_procs[i]);
|
|
|
|
OBJ_RELEASE(smcm_procs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free (smcm_procs);
|
|
|
|
*back_files = NULL;
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mmap the specified file as a shared file. No information exchange with other
|
|
|
|
* processes takes place within this routine.
|
|
|
|
* This function assumes that the memory has already been allocated, and only the
|
|
|
|
* mmap needs to be done.
|
|
|
|
*/
|
|
|
|
bcol_basesmuma_smcm_mmap_t *bcol_basesmuma_smcm_mem_reg(void *in_ptr,
|
2014-02-03 21:01:46 +04:00
|
|
|
size_t length,
|
|
|
|
size_t alignment,
|
|
|
|
char* file_name)
|
2012-08-16 23:11:35 +04:00
|
|
|
{
|
2014-02-03 21:01:46 +04:00
|
|
|
/* local variables */
|
|
|
|
int fd = -1;
|
|
|
|
bcol_basesmuma_smcm_mmap_t *map = NULL;
|
2014-05-19 19:21:58 +04:00
|
|
|
int rc;
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* if pointer is not allocated - return error. We have no clue how the user will allocate or
|
|
|
|
* free this memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* open the shared memory backing file */
|
|
|
|
|
|
|
|
fd = open(file_name, O_CREAT|O_RDWR,0600);
|
|
|
|
if (fd < 0) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "basesmuma shared memory allocation open failed with errno: %d",
|
2014-02-03 21:01:46 +04:00
|
|
|
errno);
|
|
|
|
} else if (0 != ftruncate(fd,length)) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "basesmuma shared memory allocation ftruncate failed with errno: %d",
|
2014-02-03 21:01:46 +04:00
|
|
|
errno);
|
|
|
|
} else {
|
2014-05-19 19:21:58 +04:00
|
|
|
/* ensure there is enough space for the backing store */
|
|
|
|
rc = ftruncate (fd, length);
|
|
|
|
if (0 > rc) {
|
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "failed to truncate the file to be mapped. errno: %d", errno);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-03 21:01:46 +04:00
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
map = bcol_basesmuma_smcm_reg_mmap(in_ptr, fd, length, 0, alignment, file_name);
|
2014-02-03 21:01:46 +04:00
|
|
|
if (NULL == map) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-05-01 02:28:08 +04:00
|
|
|
/* no longer need this file descriptor. close it */
|
|
|
|
close (fd);
|
2014-02-03 21:01:46 +04:00
|
|
|
|
|
|
|
/* takes us to the top of the control structure */
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
2012-08-16 23:11:35 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
static bcol_basesmuma_smcm_mmap_t * bcol_basesmuma_smcm_reg_mmap(void *in_ptr, int fd, size_t length,
|
|
|
|
size_t addr_offset, size_t alignment,
|
|
|
|
char *file_name)
|
2012-08-16 23:11:35 +04:00
|
|
|
{
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* local variables */
|
|
|
|
bcol_basesmuma_smcm_mmap_t *map;
|
|
|
|
bcol_basesmuma_smcm_file_header_t *seg;
|
|
|
|
unsigned char* myaddr = NULL;
|
2014-05-26 11:18:31 +04:00
|
|
|
int flags = MAP_SHARED;
|
2012-08-16 23:11:35 +04:00
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
/* set up the map object */
|
|
|
|
map = OBJ_NEW(bcol_basesmuma_smcm_mmap_t);
|
|
|
|
if (OPAL_UNLIKELY(NULL == map)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-03 21:01:46 +04:00
|
|
|
/* map the file and initialize the segment state */
|
2014-05-26 11:18:31 +04:00
|
|
|
if (NULL != in_ptr) {
|
|
|
|
flags |= MAP_FIXED;
|
|
|
|
}
|
2014-02-03 21:01:46 +04:00
|
|
|
seg = (bcol_basesmuma_smcm_file_header_t *)
|
2014-05-26 11:18:31 +04:00
|
|
|
mmap(in_ptr, length, PROT_READ|PROT_WRITE, flags, fd, 0);
|
2014-02-03 21:01:46 +04:00
|
|
|
if((void*)-1 == seg) {
|
2014-05-27 22:40:41 +04:00
|
|
|
OBJ_RELEASE(map);
|
2014-02-03 21:01:46 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
map->map_path = strdup (file_name);
|
2014-02-03 21:01:46 +04:00
|
|
|
|
|
|
|
/* the first entry in the file is the control structure. the first entry
|
|
|
|
in the control structure is an mca_common_sm_file_header_t element */
|
|
|
|
map->map_seg = seg;
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
myaddr = (unsigned char *) seg + addr_offset;
|
2014-02-03 21:01:46 +04:00
|
|
|
/* if we have a data segment (i.e. if 0 != data_seg_alignement) */
|
|
|
|
|
2014-05-27 22:40:41 +04:00
|
|
|
if (alignment) {
|
2014-02-03 21:01:46 +04:00
|
|
|
myaddr = OPAL_ALIGN_PTR(myaddr, alignment, unsigned char*);
|
|
|
|
|
|
|
|
/* is addr past the end of the file? */
|
|
|
|
if ((unsigned char *) seg+length < myaddr) {
|
2014-05-13 21:00:31 +04:00
|
|
|
opal_output (ompi_bcol_base_framework.framework_output, "mca_bcol_basesmuma_sm_alloc_mmap: memory region too small len %lu add %p",
|
2014-02-03 21:01:46 +04:00
|
|
|
(unsigned long) length, myaddr);
|
2014-05-27 22:40:41 +04:00
|
|
|
OBJ_RELEASE(map);
|
|
|
|
munmap (seg, length);
|
2014-02-03 21:01:46 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map->data_addr = (unsigned char*) myaddr;
|
|
|
|
map->map_addr = (unsigned char*) seg;
|
|
|
|
map->map_size = length;
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|