This source file includes following definitions.
- sysv_runtime_query
- sysv_register
- sysv_open
- sysv_query
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include "oshmem_config.h"
17
18 #ifdef HAVE_SYS_MMAN_H
19 #include <sys/mman.h>
20 #endif
21 #include <string.h>
22 #ifdef HAVE_UNISTD_H
23 #include <unistd.h>
24 #endif
25
26 #ifdef HAVE_SYS_IPC_H
27 #include <sys/ipc.h>
28 #endif
29 #if HAVE_SYS_SHM_H
30 #include <sys/shm.h>
31 #endif
32 #if HAVE_SYS_STAT_H
33 #include <sys/stat.h>
34 #endif
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
47 const char *mca_sshmem_sysv_component_version_string =
48 "OSHMEM sysv sshmem MCA component version " OSHMEM_VERSION;
49
50
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
59
60
61 mca_sshmem_sysv_component_t mca_sshmem_sysv_component = {
62
63
64
65 {
66
67 .base_version = {
68 MCA_SSHMEM_BASE_VERSION_2_0_0,
69
70
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
80 .base_data = {
81
82 MCA_BASE_METADATA_PARAM_CHECKPOINT
83 },
84 .runtime_query = sysv_runtime_query,
85 },
86
87
88
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
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
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
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
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