From 99b3506ef52eb2feaaa0907f47f364fbda2bb516 Mon Sep 17 00:00:00 2001 From: Rich Graham Date: Wed, 18 Aug 2004 15:02:21 +0000 Subject: [PATCH] rename data structure for clarifications, remove code in favor of using aspintf, fix a file naming bug. This commit was SVN r2199. --- src/mca/common/sm/common_sm_mmap.c | 13 ++++++------ src/mca/common/sm/common_sm_mmap.h | 11 ++++++---- src/mca/ptl/sm/src/ptl_sm.c | 34 ++++++++++++------------------ src/mca/ptl/sm/src/ptl_sm.h | 7 +++--- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/mca/common/sm/common_sm_mmap.c b/src/mca/common/sm/common_sm_mmap.c index 1959802367..eda3cf467b 100644 --- a/src/mca/common/sm/common_sm_mmap.c +++ b/src/mca/common/sm/common_sm_mmap.c @@ -65,7 +65,7 @@ static int mca_common_sm_mmap_open(char* path) * * @param size_ctl_structure size of the control structure at * the head of the file. The control structure - * is assumed to have mca_common_sm_segment_t + * is assumed to have mca_common_sm_file_header_t * as its first segment (IN) * * @param data_set_alignment alignment of the data segment. this @@ -77,16 +77,17 @@ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name, { int fd,return_code=OMPI_SUCCESS; bool file_previously_opened; - mca_common_sm_segment_t* seg; + mca_common_sm_file_header_t* seg; mca_common_sm_mmap_t* map; struct stat s_stat; unsigned char *addr; size_t tmp,mem_offset; /* input parameter error checks */ - if( (size < sizeof(mca_common_sm_segment_t) ) || + if( (size < sizeof(mca_common_sm_file_header_t) ) || ( file_name == NULL ) || - ( size_ctl_structure < sizeof(mca_common_sm_segment_t ) ) || + ( size_ctl_structure < + sizeof(mca_common_sm_file_header_t ) ) || ( data_seg_alignment == 0 ) ) { return NULL; } @@ -142,7 +143,7 @@ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name, map = OBJ_NEW(mca_common_sm_mmap_t); strncpy(map->map_path, file_name, PATH_MAX); /* the first entry in the file is the control strcuture. the first - entry in the control structure is an mca_common_sm_segment_t + entry in the control structure is an mca_common_sm_file_header_t element */ map->map_seg = seg; @@ -197,7 +198,7 @@ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name, void* mca_common_sm_mmap_alloc(size_t* size) { mca_common_sm_mmap_t* map = mca_common_sm_mmap; - mca_common_sm_segment_t* seg = map->map_seg; + mca_common_sm_file_header_t* seg = map->map_seg; void* addr; spinlock(&seg->seg_lock); diff --git a/src/mca/common/sm/common_sm_mmap.h b/src/mca/common/sm/common_sm_mmap.h index 02bbc96a74..cf0f8c4cdb 100644 --- a/src/mca/common/sm/common_sm_mmap.h +++ b/src/mca/common/sm/common_sm_mmap.h @@ -5,7 +5,7 @@ #include "os/atomic.h" #include "class/ompi_list.h" -struct mca_common_sm_segment_t { +struct mca_common_sm_file_header_t { /* lock to control atomic access */ ompi_lock_data_t seg_lock; /* is the segment ready for use */ @@ -15,13 +15,14 @@ struct mca_common_sm_segment_t { /* total size of the segment */ size_t seg_size; }; -typedef struct mca_common_sm_segment_t mca_common_sm_segment_t; +typedef struct mca_common_sm_file_header_t mca_common_sm_file_header_t; struct mca_common_sm_mmap_t { /* double link list element */ ompi_list_item_t map_item; - mca_common_sm_segment_t* map_seg; + /* pointer to header imbeded in the shared memory file */ + mca_common_sm_file_header_t* map_seg; /* base address of the mmap'ed file */ unsigned char *map_addr; /* base address of data segment */ @@ -46,11 +47,13 @@ OBJ_CLASS_DECLARATION(mca_common_sm_mmap_t); * * @param size_ctl_structure size of the control structure at * the head of the file. The control structure - * is assumed to have mca_common_sm_segment_t + * is assumed to have mca_common_sm_file_header_t * as its first segment (IN) * * @param data_set_alignment alignment of the data segment. this * follows the control structure (IN) + * + * @returnvalue pointer to control structure at head of file. */ mca_common_sm_mmap_t* mca_common_sm_mmap_init(size_t size, char *file_name, diff --git a/src/mca/ptl/sm/src/ptl_sm.c b/src/mca/ptl/sm/src/ptl_sm.c index 565f759fac..eea8ffc48e 100644 --- a/src/mca/ptl/sm/src/ptl_sm.c +++ b/src/mca/ptl/sm/src/ptl_sm.c @@ -3,6 +3,8 @@ */ #include +#include + #include "util/output.h" #include "util/if.h" #include "mca/pml/pml.h" @@ -156,31 +158,16 @@ int mca_ptl_sm_add_procs( * data structure. This will reside in shared memory */ /* Create backing file */ - len=strlen(ompi_process_info.job_session_dir) + - strlen(ompi_system_info.nodename)+ - /* length of fixed-string name part */ - 23; - memset(&(file_name[0]),0,PATH_MAX); - if( PATH_MAX <= len ) { - ompi_output(0, "mca_ptl_sm_add_procs: name of backing file too long %ld \n", - len); - return_code=OMPI_ERROR; - goto CLEANUP; - } - mca_ptl_sm_component.sm_resouce_ctl_file= (char *) - malloc(len+1); - if( NULL == mca_ptl_sm_component.sm_resouce_ctl_file ){ - return_code=OMPI_ERR_OUT_OF_RESOURCE; + /* set file name */ + len=asprintf(&(mca_ptl_sm_component.sm_resouce_ctl_file), + "%s/shared_mem_ptl_module.%s",ompi_process_info.job_session_dir, + ompi_system_info.nodename); + if( 0 > len ) { goto CLEANUP; } - memset(mca_ptl_sm_component.sm_resouce_ctl_file,0,len+1); - sprintf(mca_ptl_sm_component.sm_resouce_ctl_file, - "%s/shared_mem_ptl_module.%s", - ompi_process_info.job_session_dir, - ompi_system_info.nodename); size=sizeof(mca_ptl_sm_module_resource_t); if(NULL == - (mca_ptl_sm_component.resource_ctl = + (mca_ptl_sm_component.mmap_file = mca_common_sm_mmap_init(size, mca_ptl_sm_component.sm_resouce_ctl_file, sizeof(mca_ptl_sm_module_resource_t), 8 ))) @@ -196,9 +183,14 @@ int mca_ptl_sm_add_procs( * make this array growable, but then one would need to uses mutexes * for any access to these queues to ensure data consistancy when * the array is grown */ + if(0 == ptl_sm->my_smp_rank ) { + mca_ptl_sm_component.mmap_file->map_seg->seg_inited=true; + } /* Note: Need to make sure that proc 0 initializes control * structures before any of the other procs can progress */ + if( 0 != ptl_sm->my_smp_rank ) { + } /* Initizlize queue data structures * - proc with lowest local rank does this diff --git a/src/mca/ptl/sm/src/ptl_sm.h b/src/mca/ptl/sm/src/ptl_sm.h index 4431940dd8..19c91132bf 100644 --- a/src/mca/ptl/sm/src/ptl_sm.h +++ b/src/mca/ptl/sm/src/ptl_sm.h @@ -21,7 +21,7 @@ * Shared Memory resource managment */ struct mca_ptl_sm_module_resource_t { - mca_common_sm_segment_t segment_header; + mca_common_sm_file_header_t segment_header; }; typedef struct mca_ptl_sm_module_resource_t mca_ptl_sm_module_resource_t; extern mca_ptl_sm_module_resource_t mca_ptl_sm_module_resource; @@ -44,9 +44,8 @@ struct mca_ptl_sm_component_t { ompi_mutex_t sm_lock; char* sm_resouce_ctl_file; /**< name of shared memory file used to coordinate resource usage */ - mca_ptl_sm_module_resource_t *resource_ctl; - /**< shared memory coordination data. - Resides in shared memory */ + mca_common_sm_mmap_t *mmap_file; /**< description of mmap'ed + file */ }; typedef struct mca_ptl_sm_component_t mca_ptl_sm_component_t; extern mca_ptl_sm_component_t mca_ptl_sm_component;