This source file includes following definitions.
- lk_fetch_add32
- lk_add32
- lk_fetch32
- start_exclusive
- end_exclusive
- start_shared
- end_shared
- ompi_osc_sm_lock
- ompi_osc_sm_unlock
- ompi_osc_sm_lock_all
- ompi_osc_sm_unlock_all
- ompi_osc_sm_sync
- ompi_osc_sm_flush
- ompi_osc_sm_flush_all
- ompi_osc_sm_flush_local
- ompi_osc_sm_flush_local_all
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include "ompi_config.h"
15
16 #include "ompi/mca/osc/osc.h"
17 #include "ompi/mca/osc/base/base.h"
18 #include "ompi/mca/osc/base/osc_base_obj_convert.h"
19
20 #include "osc_sm.h"
21
22
23 static inline uint32_t
24 lk_fetch_add32(ompi_osc_sm_module_t *module,
25 int target,
26 size_t offset,
27 uint32_t delta)
28 {
29
30
31 return opal_atomic_add_fetch_32((opal_atomic_int32_t *) ((char*) &module->node_states[target].lock + offset),
32 delta) - delta;
33 }
34
35
36 static inline void
37 lk_add32(ompi_osc_sm_module_t *module,
38 int target,
39 size_t offset,
40 uint32_t delta)
41 {
42 opal_atomic_add_fetch_32((opal_atomic_int32_t *) ((char*) &module->node_states[target].lock + offset),
43 delta);
44 }
45
46
47 static inline uint32_t
48 lk_fetch32(ompi_osc_sm_module_t *module,
49 int target,
50 size_t offset)
51 {
52 opal_atomic_mb ();
53 return *((uint32_t *)((char*) &module->node_states[target].lock + offset));
54 }
55
56
57 static inline int
58 start_exclusive(ompi_osc_sm_module_t *module,
59 int target)
60 {
61 uint32_t me = lk_fetch_add32(module, target,
62 offsetof(ompi_osc_sm_lock_t, counter), 1);
63
64 while (me != lk_fetch32(module, target,
65 offsetof(ompi_osc_sm_lock_t, write))) {
66 opal_progress();
67 }
68
69 return OMPI_SUCCESS;
70 }
71
72
73 static inline int
74 end_exclusive(ompi_osc_sm_module_t *module,
75 int target)
76 {
77 lk_add32(module, target, offsetof(ompi_osc_sm_lock_t, write), 1);
78 lk_add32(module, target, offsetof(ompi_osc_sm_lock_t, read), 1);
79
80 return OMPI_SUCCESS;
81 }
82
83
84 static inline int
85 start_shared(ompi_osc_sm_module_t *module,
86 int target)
87 {
88 uint32_t me = lk_fetch_add32(module, target,
89 offsetof(ompi_osc_sm_lock_t, counter), 1);
90
91 while (me != lk_fetch32(module, target,
92 offsetof(ompi_osc_sm_lock_t, read))) {
93 opal_progress();
94 }
95
96 lk_add32(module, target, offsetof(ompi_osc_sm_lock_t, read), 1);
97
98 return OMPI_SUCCESS;
99 }
100
101
102 static inline int
103 end_shared(ompi_osc_sm_module_t *module,
104 int target)
105 {
106 lk_add32(module, target, offsetof(ompi_osc_sm_lock_t, write), 1);
107
108 return OMPI_SUCCESS;
109 }
110
111
112 int
113 ompi_osc_sm_lock(int lock_type,
114 int target,
115 int assert,
116 struct ompi_win_t *win)
117 {
118 ompi_osc_sm_module_t *module =
119 (ompi_osc_sm_module_t*) win->w_osc_module;
120 int ret;
121
122 if (lock_none != module->outstanding_locks[target]) {
123 return OMPI_ERR_RMA_SYNC;
124 }
125
126 if (0 == (assert & MPI_MODE_NOCHECK)) {
127 if (MPI_LOCK_EXCLUSIVE == lock_type) {
128 module->outstanding_locks[target] = lock_exclusive;
129 ret = start_exclusive(module, target);
130 } else {
131 module->outstanding_locks[target] = lock_shared;
132 ret = start_shared(module, target);
133 }
134 } else {
135 module->outstanding_locks[target] = lock_nocheck;
136 ret = OMPI_SUCCESS;
137 }
138
139 return ret;
140 }
141
142
143 int
144 ompi_osc_sm_unlock(int target,
145 struct ompi_win_t *win)
146 {
147 ompi_osc_sm_module_t *module =
148 (ompi_osc_sm_module_t*) win->w_osc_module;
149 int ret;
150
151
152 opal_atomic_mb();
153
154 switch (module->outstanding_locks[target]) {
155 case lock_none:
156 return OMPI_ERR_RMA_SYNC;
157
158 case lock_nocheck:
159 ret = OMPI_SUCCESS;
160 break;
161
162 case lock_exclusive:
163 ret = end_exclusive(module, target);
164 break;
165
166 case lock_shared:
167 ret = end_shared(module, target);
168 break;
169
170 default:
171
172 assert(module->outstanding_locks[target] == lock_none ||
173 module->outstanding_locks[target] == lock_nocheck ||
174 module->outstanding_locks[target] == lock_exclusive ||
175 module->outstanding_locks[target] == lock_shared);
176
177
178
179 opal_output(0, "Unknown lock type in ompi_osc_sm_unlock -- this is an OMPI programming error");
180 ret = OMPI_ERR_BAD_PARAM;
181 break;
182 }
183
184 module->outstanding_locks[target] = lock_none;
185
186 return ret;
187 }
188
189
190 int
191 ompi_osc_sm_lock_all(int assert,
192 struct ompi_win_t *win)
193 {
194 ompi_osc_sm_module_t *module =
195 (ompi_osc_sm_module_t*) win->w_osc_module;
196 int ret, i, comm_size;
197
198 comm_size = ompi_comm_size(module->comm);
199 for (i = 0 ; i < comm_size ; ++i) {
200 ret = ompi_osc_sm_lock(MPI_LOCK_SHARED, i, assert, win);
201 if (OMPI_SUCCESS != ret) return ret;
202 }
203
204 return OMPI_SUCCESS;
205 }
206
207
208 int
209 ompi_osc_sm_unlock_all(struct ompi_win_t *win)
210 {
211 ompi_osc_sm_module_t *module =
212 (ompi_osc_sm_module_t*) win->w_osc_module;
213 int ret, i, comm_size;
214
215 comm_size = ompi_comm_size(module->comm);
216 for (i = 0 ; i < comm_size ; ++i) {
217 ret = ompi_osc_sm_unlock(i, win);
218 if (OMPI_SUCCESS != ret) return ret;
219 }
220
221 return OMPI_SUCCESS;
222 }
223
224
225 int
226 ompi_osc_sm_sync(struct ompi_win_t *win)
227 {
228 opal_atomic_mb();
229
230 return OMPI_SUCCESS;
231 }
232
233
234 int
235 ompi_osc_sm_flush(int target,
236 struct ompi_win_t *win)
237 {
238 opal_atomic_mb();
239
240 return OMPI_SUCCESS;
241 }
242
243
244 int
245 ompi_osc_sm_flush_all(struct ompi_win_t *win)
246 {
247 opal_atomic_mb();
248
249 return OMPI_SUCCESS;
250 }
251
252
253 int
254 ompi_osc_sm_flush_local(int target,
255 struct ompi_win_t *win)
256 {
257 opal_atomic_mb();
258
259 return OMPI_SUCCESS;
260 }
261
262
263 int
264 ompi_osc_sm_flush_local_all(struct ompi_win_t *win)
265 {
266 opal_atomic_mb();
267
268 return OMPI_SUCCESS;
269 }