root/oshmem/mca/sshmem/sysv/sshmem_sysv_component.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sysv_runtime_query
  2. sysv_register
  3. sysv_open
  4. sysv_query

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2014      Mellanox Technologies, Inc.
   4  *                         All rights reserved.
   5  * Copyright (c) 2014      Research Organization for Information Science
   6  *                         and Technology (RIST). All rights reserved.
   7  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
   8  *                         reserved.
   9  * $COPYRIGHT$
  10  *
  11  * Additional copyrights may follow
  12  *
  13  * $HEADER$
  14  */
  15 
  16 #include "oshmem_config.h"
  17 
  18 #ifdef HAVE_SYS_MMAN_H
  19 #include <sys/mman.h>
  20 #endif /* HAVE_SYS_MMAN_H */
  21 #include <string.h>
  22 #ifdef HAVE_UNISTD_H
  23 #include <unistd.h>
  24 #endif /* HAVE_UNISTD_H */
  25 
  26 #ifdef HAVE_SYS_IPC_H
  27 #include <sys/ipc.h>
  28 #endif /* HAVE_SYS_IPC_H */
  29 #if HAVE_SYS_SHM_H
  30 #include <sys/shm.h>
  31 #endif /* HAVE_SYS_SHM_H */
  32 #if HAVE_SYS_STAT_H
  33 #include <sys/stat.h>
  34 #endif /* HAVE_SYS_STAT_H */
  35 
  36 #include "opal/constants.h"
  37 #include "opal/util/show_help.h"
  38 #include "opal/util/output.h"
  39 #include "opal/util/sys_limits.h"
  40 
  41 #include "oshmem/mca/sshmem/sshmem.h"
  42 #include "oshmem/mca/sshmem/base/base.h"
  43 
  44 #include "sshmem_sysv.h"
  45 
  46 /* public string showing the shmem ompi_sysv component version number */
  47 const char *mca_sshmem_sysv_component_version_string =
  48     "OSHMEM sysv sshmem MCA component version " OSHMEM_VERSION;
  49 
  50 /* local functions */
  51 static int sysv_register (void);
  52 static int sysv_open(void);
  53 static int sysv_query(mca_base_module_t **module, int *priority);
  54 static int sysv_runtime_query(mca_base_module_t **module,
  55                               int *priority,
  56                               const char *hint);
  57 
  58 /* instantiate the public struct with all of our public information
  59  * and pointers to our public functions in it
  60  */
  61 mca_sshmem_sysv_component_t mca_sshmem_sysv_component = {
  62     /* ////////////////////////////////////////////////////////////////////// */
  63     /* super */
  64     /* ////////////////////////////////////////////////////////////////////// */
  65     {
  66         /* common MCA component data */
  67         .base_version = {
  68             MCA_SSHMEM_BASE_VERSION_2_0_0,
  69 
  70             /* component name and version */
  71             .mca_component_name = "sysv",
  72             MCA_BASE_MAKE_VERSION(component, OSHMEM_MAJOR_VERSION, OSHMEM_MINOR_VERSION,
  73                                   OSHMEM_RELEASE_VERSION),
  74 
  75             .mca_open_component = sysv_open,
  76             .mca_query_component = sysv_query,
  77             .mca_register_component_params = sysv_register,
  78         },
  79         /* MCA v2.0.0 component meta data */
  80         .base_data = {
  81             /* the component is checkpoint ready */
  82             MCA_BASE_METADATA_PARAM_CHECKPOINT
  83         },
  84         .runtime_query = sysv_runtime_query,
  85     },
  86     /* ////////////////////////////////////////////////////////////////////// */
  87     /* sysv component-specific information */
  88     /* see: shmem_sysv.h for more information */
  89 };
  90 
  91 /* ////////////////////////////////////////////////////////////////////////// */
  92 static int
  93 sysv_runtime_query(mca_base_module_t **module,
  94                    int *priority,
  95                    const char *hint)
  96 {
  97     char c     = 'j';
  98     int shmid  = -1;
  99     char *a    = NULL;
 100     char *addr = NULL;
 101     struct shmid_ds tmp_buff;
 102     int flags;
 103     int ret;
 104 
 105     ret = OSHMEM_SUCCESS;
 106 
 107     *priority = 0;
 108     *module = NULL;
 109 
 110     /* if we are here, then let the run-time test games begin */
 111 
 112 #if defined (SHM_HUGETLB)
 113     if (mca_sshmem_sysv_component.use_hp != 0) {
 114          flags = IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | SHM_HUGETLB;
 115         if (-1 == (shmid = shmget(IPC_PRIVATE, sshmem_sysv_gethugepagesize(), flags))) {
 116             if (mca_sshmem_sysv_component.use_hp == 1) {
 117                 mca_sshmem_sysv_component.use_hp = 0;
 118                 ret = OSHMEM_ERR_NOT_AVAILABLE;
 119                 goto out;
 120             }
 121             mca_sshmem_sysv_component.use_hp = 0;
 122         }
 123         else if ((void *)-1 == (addr = shmat(shmid, NULL, 0))) {
 124             shmctl(shmid, IPC_RMID, NULL);
 125             if (mca_sshmem_sysv_component.use_hp == 1) {
 126                 mca_sshmem_sysv_component.use_hp = 0;
 127                 ret = OSHMEM_ERR_NOT_AVAILABLE;
 128                 goto out;
 129             }
 130             mca_sshmem_sysv_component.use_hp = 0;
 131         }
 132     }
 133 #else
 134     if (mca_sshmem_sysv_component.use_hp == 1) {
 135         mca_sshmem_sysv_component.use_hp = 0;
 136         ret = OSHMEM_ERR_NOT_AVAILABLE;
 137         goto out;
 138     }
 139     mca_sshmem_sysv_component.use_hp = 0;
 140 #endif
 141 
 142     if (0 == mca_sshmem_sysv_component.use_hp) {
 143         flags = IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR;
 144         if (-1 == (shmid = shmget(IPC_PRIVATE, (size_t)(opal_getpagesize()), flags))) {
 145             ret = OSHMEM_ERR_NOT_AVAILABLE;
 146             goto out;
 147         }
 148         else if ((void *)-1 == (addr = shmat(shmid, NULL, 0))) {
 149             shmctl(shmid, IPC_RMID, NULL);
 150             ret = OSHMEM_ERR_NOT_AVAILABLE;
 151             goto out;
 152         }
 153     }
 154 
 155     /* protect against lazy establishment - may not be needed, but can't hurt */
 156     a = addr;
 157     *a = c;
 158 
 159     if (-1 == shmctl(shmid, IPC_RMID, NULL)) {
 160         goto out;
 161     }
 162     else if (-1 == shmctl(shmid, IPC_STAT, &tmp_buff)) {
 163         goto out;
 164     }
 165     /* all is well - rainbows and butterflies */
 166     else {
 167         *priority = mca_sshmem_sysv_component.priority;
 168         *module = (mca_base_module_t *)&mca_sshmem_sysv_module.super;
 169     }
 170 
 171   out:
 172     if ((char *)-1 != addr) {
 173         shmdt(addr);
 174     }
 175     return ret;
 176 }
 177 
 178 /* ////////////////////////////////////////////////////////////////////////// */
 179 static int
 180 sysv_register(void)
 181 {
 182     /* ////////////////////////////////////////////////////////////////////// */
 183     /* (default) priority - set lower than mmap's priority */
 184     mca_sshmem_sysv_component.priority = 30;
 185     (void) mca_base_component_var_register(&mca_sshmem_sysv_component.super.base_version,
 186                                            "priority", "Priority for the sshmem sysv "
 187                                            "component (default: 30)", MCA_BASE_VAR_TYPE_INT,
 188                                            NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
 189                                            OPAL_INFO_LVL_3,
 190                                            MCA_BASE_VAR_SCOPE_ALL_EQ,
 191                                            &mca_sshmem_sysv_component.priority);
 192 
 193     mca_sshmem_sysv_component.use_hp = -1;
 194     mca_base_component_var_register (&mca_sshmem_sysv_component.super.base_version,
 195                                            "use_hp", "Huge pages usage "
 196                                            "[0 - off, 1 - on, -1 - auto] (default: -1)", MCA_BASE_VAR_TYPE_INT,
 197                                            NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
 198                                            OPAL_INFO_LVL_4,
 199                                            MCA_BASE_VAR_SCOPE_ALL_EQ,
 200                                            &mca_sshmem_sysv_component.use_hp);
 201 
 202     return OSHMEM_SUCCESS;
 203 }
 204 
 205 /* ////////////////////////////////////////////////////////////////////////// */
 206 static int
 207 sysv_open(void)
 208 {
 209     return OSHMEM_SUCCESS;
 210 }
 211 
 212 /* ////////////////////////////////////////////////////////////////////////// */
 213 static int
 214 sysv_query(mca_base_module_t **module, int *priority)
 215 {
 216     *priority = mca_sshmem_sysv_component.priority;
 217     *module = (mca_base_module_t *)&mca_sshmem_sysv_module.super;
 218     return OSHMEM_SUCCESS;
 219 }
 220 

/* [<][>][^][v][top][bottom][index][help] */