File: shmem_posix_component.c

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (193 lines) | stat: -rw-r--r-- 7,854 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2007-2015 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2010-2015 Los Alamos National Security, LLC.
 *                         All rights reserved.
 * Copyright (c) 2011      NVIDIA Corporation.  All rights reserved.
 * Copyright (c) 2016      Intel, Inc. All rights reserved.
 * Copyright (c) 2019      Triad National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2022      IBM Corporation. All rights reserved
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 *
 * These symbols are in a file by themselves to provide nice linker
 * semantics.  Since linkers generally pull in symbols by object
 * files, keeping these symbols as the only symbols in this file
 * prevents utility programs such as "ompi_info" from having to import
 * entire components just to query their version and parameters.
 */

#include "opal_config.h"

#include <errno.h>
#include <string.h>
#ifdef HAVE_SYS_MMAN_H
#    include <sys/mman.h>
#endif /* HAVE_SYS_MMAN_H */
#ifdef HAVE_UNISTD_H
#    include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_NETDB_H
#    include <netdb.h>
#endif /* HAVE_NETDB_H */

#include "opal/constants.h"
#include "opal/mca/shmem/base/base.h"
#include "opal/mca/shmem/shmem.h"
#include "opal/runtime/opal.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "shmem_posix.h"
#include "shmem_posix_common_utils.h"

/* public string showing the shmem ompi_posix component version number */
const char *opal_shmem_posix_component_version_string
    = "OPAL posix shmem MCA component version " OPAL_VERSION;

/* local functions */
static int posix_register(void);
static int posix_open(void);
static int posix_query(mca_base_module_t **module, int *priority);
static int posix_runtime_query(mca_base_module_t **module, int *priority, const char *hint);

/* local variables */
static bool rt_successful = false;

/* instantiate the public struct with all of our public information
 * and pointers to our public functions in it
 */
opal_shmem_posix_component_t mca_shmem_posix_component = {
    .super =
        {
            .base_version = {OPAL_SHMEM_BASE_VERSION_2_0_0,

                             /* component name and version */
                             .mca_component_name = "posix",
                             MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION,
                                                   OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION),

                             .mca_open_component = posix_open, .mca_query_component = posix_query,
                             .mca_register_component_params = posix_register},
            /* MCA v2.0.0 component meta data */
            .base_data =
                {/* the component is checkpoint ready */
                 MCA_BASE_METADATA_PARAM_CHECKPOINT},
            .runtime_query = posix_runtime_query,
        },
};

/* ////////////////////////////////////////////////////////////////////////// */
static int posix_register(void)
{
    /* ////////////////////////////////////////////////////////////////////// */
    /* (default) priority - set lower than mmap's priority */
    mca_shmem_posix_component.priority = 40;
    (void) mca_base_component_var_register(&mca_shmem_posix_component.super.base_version,
                                           "priority",
                                           "Priority for the shmem posix "
                                           "component (default: 40)",
                                           MCA_BASE_VAR_TYPE_INT, NULL, 0,
                                           MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3,
                                           MCA_BASE_VAR_SCOPE_ALL_EQ,
                                           &mca_shmem_posix_component.priority);

    return OPAL_SUCCESS;
}

/* ////////////////////////////////////////////////////////////////////////// */

static int posix_open(void)
{
    return OPAL_SUCCESS;
}

/* ////////////////////////////////////////////////////////////////////////// */
/**
 * this routine performs a test that indicates whether or not posix shared
 * memory can safely be used during this run.
 * note: that we want to run this test as few times as possible.
 *
 * @return OPAL_SUCCESS when posix can safely be used.
 */
static int posix_runtime_query(mca_base_module_t **module, int *priority, const char *hint)
{
    char tmp_buff[OPAL_SHMEM_POSIX_FILE_LEN_MAX];
    int fd = -1;

    *priority = 0;
    *module = NULL;

    /* if hint isn't null, then someone else already figured out who is the
     * best runnable component is AND the caller is relaying that info so we
     * don't have to perform a run-time query.
     */
    if (NULL != hint) {
        OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output,
                             "shmem: posix: runtime_query: "
                             "attempting to use runtime hint (%s)\n",
                             hint));
        /* was i selected? if so, then we are done.
         * otherwise, disqualify myself.
         */
        if (0
            == strcasecmp(hint, mca_shmem_posix_component.super.base_version.mca_component_name)) {
            *priority = mca_shmem_posix_component.priority;
            *module = (mca_base_module_t *) &opal_shmem_posix_module.super;
            return OPAL_SUCCESS;
        } else {
            *priority = 0;
            *module = NULL;
            return OPAL_SUCCESS;
        }
    }
    /* if we are here, then perform a run-time query because we didn't get a
     * hint.  it's either up to us to figure it out, or the caller wants us to
     * re-run the runtime query.
     */
    OPAL_OUTPUT_VERBOSE((70, opal_shmem_base_framework.framework_output,
                         "shmem: posix: runtime_query: NO HINT PROVIDED:"
                         "starting run-time test...\n"));
    /* shmem_posix_shm_open successfully shm_opened - we can use posix sm! */
    if (-1 != (fd = opal_shmem_posix_shm_open(tmp_buff, OPAL_SHMEM_POSIX_FILE_LEN_MAX - 1))) {
        /* free up allocated resources before we return */
        if (0 != shm_unlink(tmp_buff)) {
            int err = errno;
            const char *hn;
            hn = opal_gethostname();
            opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn, "shm_unlink(2)", "",
                           strerror(err), err);
            /* something strange happened, so consider this a run-time test
             * failure even though shmem_posix_shm_open was successful */
        }
        /* all is well */
        else {
            *priority = mca_shmem_posix_component.priority;
            *module = (mca_base_module_t *) &opal_shmem_posix_module.super;
            rt_successful = true;
        }
    }

    return OPAL_SUCCESS;
}

/* ////////////////////////////////////////////////////////////////////////// */
static int posix_query(mca_base_module_t **module, int *priority)
{
    *priority = mca_shmem_posix_component.priority;
    *module = (mca_base_module_t *) &opal_shmem_posix_module.super;
    return OPAL_SUCCESS;
}