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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
|
/*
* Copyright (c) 2011-2013 Sandia National Laboratories. All rights reserved.
* Copyright (c) 2014 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/mca/osc/base/base.h"
#include "ompi/mca/osc/base/osc_base_obj_convert.h"
#include "ompi/mca/osc/osc.h"
#include "osc_portals4.h"
enum locktype_t {
lock_nocheck,
lock_exclusive,
lock_shared
};
struct ompi_osc_portals4_outstanding_lock_t {
opal_list_item_t super;
int target;
enum locktype_t lock_type;
};
typedef struct ompi_osc_portals4_outstanding_lock_t ompi_osc_portals4_outstanding_lock_t;
OBJ_CLASS_INSTANCE(ompi_osc_portals4_outstanding_lock_t, opal_list_item_t,
NULL, NULL);
static inline int
lk_cas64(ompi_osc_portals4_module_t *module,
int target,
int64_t write_val,
int64_t comp_val,
int64_t *result_val)
{
int ret;
size_t offset = offsetof(ompi_osc_portals4_node_state_t, lock);
(void)opal_atomic_add_fetch_64(&module->opcount, 1);
ret = PtlSwap(module->md_h,
(ptl_size_t) result_val,
module->md_h,
(ptl_size_t) &write_val,
sizeof(int64_t),
ompi_osc_portals4_get_peer(module, target),
module->pt_idx,
module->match_bits | OSC_PORTALS4_MB_CONTROL,
offset,
NULL,
0,
&comp_val,
PTL_CSWAP,
PTL_INT64_T);
if (OMPI_SUCCESS != ret) {
return ret;
}
ret = ompi_osc_portals4_complete_all(module);
return ret;
}
static inline int
lk_write64(ompi_osc_portals4_module_t *module,
int target,
int64_t write_val)
{
int ret;
size_t offset = offsetof(ompi_osc_portals4_node_state_t, lock);
(void)opal_atomic_add_fetch_64(&module->opcount, 1);
ret = PtlPut(module->md_h,
(ptl_size_t) &write_val,
sizeof(int64_t),
PTL_ACK_REQ,
ompi_osc_portals4_get_peer(module, target),
module->pt_idx,
module->match_bits | OSC_PORTALS4_MB_CONTROL,
offset,
NULL,
0);
if (OMPI_SUCCESS != ret) {
return ret;
}
ret = ompi_osc_portals4_complete_all(module);
return ret;
}
static inline int
lk_add64(ompi_osc_portals4_module_t *module,
int target,
int64_t write_val,
int64_t *result_val)
{
int ret;
size_t offset = offsetof(ompi_osc_portals4_node_state_t, lock);
(void)opal_atomic_add_fetch_64(&module->opcount, 1);
ret = PtlFetchAtomic(module->md_h,
(ptl_size_t) result_val,
module->md_h,
(ptl_size_t) &write_val,
sizeof(int64_t),
ompi_osc_portals4_get_peer(module, target),
module->pt_idx,
module->match_bits | OSC_PORTALS4_MB_CONTROL,
offset,
NULL,
0,
PTL_SUM,
PTL_INT64_T);
if (OMPI_SUCCESS != ret) {
return ret;
}
ret = ompi_osc_portals4_complete_all(module);
return ret;
}
static inline int
start_exclusive(ompi_osc_portals4_module_t *module,
int target)
{
int64_t result;
int ret;
while (true) {
ret = lk_cas64(module, target, LOCK_EXCLUSIVE, 0, &result);
if (OMPI_SUCCESS != ret) return ret;
if (LOCK_ILLEGAL == (LOCK_ILLEGAL & result)) return OMPI_ERR_RMA_SYNC;
if (0 == result) break;
}
return OMPI_SUCCESS;
}
static inline int
end_exclusive(ompi_osc_portals4_module_t *module,
int target)
{
int ret;
ret = lk_write64(module, target, LOCK_UNLOCKED);
return ret;
}
static inline int
start_shared(ompi_osc_portals4_module_t *module,
int target)
{
int64_t result;
int ret;
while (true) {
ret = lk_add64(module, target, 1, &result);
if (OMPI_SUCCESS != ret) return ret;
if (result > (int64_t)LOCK_EXCLUSIVE) {
if (LOCK_ILLEGAL == (LOCK_ILLEGAL & result)) return OMPI_ERR_RMA_SYNC;
ret = lk_add64(module, target, -1, &result);
if (OMPI_SUCCESS != ret) return ret;
} else {
break;
}
}
return OMPI_SUCCESS;
}
static inline int
end_shared(ompi_osc_portals4_module_t *module,
int target)
{
int64_t result;
int ret;
ret = lk_add64(module, target, -1, &result);
return ret;
}
int
ompi_osc_portals4_lock(int lock_type,
int target,
int mpi_assert,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t* lock;
int ret;
module->passive_target_access_epoch = true;
lock = OBJ_NEW(ompi_osc_portals4_outstanding_lock_t);
lock->target = target;
if (0 == (mpi_assert & MPI_MODE_NOCHECK)) {
if (MPI_LOCK_EXCLUSIVE == lock_type) {
lock->lock_type = lock_exclusive;
ret = start_exclusive(module, target);
} else {
lock->lock_type = lock_shared;
ret = start_shared(module, target);
}
} else {
lock->lock_type = lock_nocheck;
ret = OMPI_SUCCESS;
}
if (OMPI_SUCCESS == ret) {
opal_list_append(&module->outstanding_locks, &lock->super);
} else {
OBJ_RELEASE(lock);
}
return ret;
}
int
ompi_osc_portals4_unlock(int target,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t *lock = NULL, *item;
int ret;
OPAL_LIST_FOREACH(item, &module->outstanding_locks,
ompi_osc_portals4_outstanding_lock_t) {
if (item->target == target) {
lock = item;
break;
}
}
if (NULL != item) {
opal_list_remove_item(&module->outstanding_locks, &lock->super);
} else {
return OMPI_ERR_RMA_SYNC;
}
ret = ompi_osc_portals4_complete_all(module);
if (ret != OMPI_SUCCESS) return ret;
if (lock->lock_type == lock_exclusive) {
ret = end_exclusive(module, target);
} else if (lock->lock_type == lock_shared) {
ret = end_shared(module, target);
} else {
ret = OMPI_SUCCESS;
}
module->passive_target_access_epoch = false;
OBJ_RELEASE(lock);
return ret;
}
int
ompi_osc_portals4_lock_all(int mpi_assert,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t* lock;
int ret = OMPI_SUCCESS;
module->passive_target_access_epoch = true;
lock = OBJ_NEW(ompi_osc_portals4_outstanding_lock_t);
lock->target = -1;
if (0 == (mpi_assert & MPI_MODE_NOCHECK)) {
int i, comm_size;
lock->lock_type = lock_shared;
comm_size = ompi_comm_size(module->comm);
for (i = 0 ; i < comm_size ; ++i) {
ret |= start_shared(module, i);
}
} else {
lock->lock_type = lock_nocheck;
ret = OMPI_SUCCESS;
}
if (OMPI_SUCCESS == ret) {
opal_list_append(&module->outstanding_locks, &lock->super);
} else {
OBJ_RELEASE(lock);
}
return ret;
}
int
ompi_osc_portals4_unlock_all(struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
ompi_osc_portals4_outstanding_lock_t *lock = NULL, *item;
int ret;
OPAL_LIST_FOREACH(item, &module->outstanding_locks,
ompi_osc_portals4_outstanding_lock_t) {
if (item->target == -1) {
lock = item;
break;
}
}
if (NULL != item) {
opal_list_remove_item(&module->outstanding_locks, &lock->super);
} else {
return OMPI_ERR_RMA_SYNC;
}
ret = ompi_osc_portals4_complete_all(module);
if (ret != OMPI_SUCCESS) return ret;
if (lock->lock_type == lock_shared) {
int i, comm_size;
comm_size = ompi_comm_size(module->comm);
for (i = 0 ; i < comm_size ; ++i) {
ret |= end_shared(module, i);
}
}
module->passive_target_access_epoch = false;
OBJ_RELEASE(lock);
return OMPI_SUCCESS;
}
int
ompi_osc_portals4_sync(struct ompi_win_t *win)
{
/* Not sure this is strictly necessary, but why not? */
opal_atomic_mb();
PtlAtomicSync();
return OMPI_SUCCESS;
}
int
ompi_osc_portals4_flush(int target,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
int
ompi_osc_portals4_flush_all(struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
int
ompi_osc_portals4_flush_local(int target,
struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
int
ompi_osc_portals4_flush_local_all(struct ompi_win_t *win)
{
ompi_osc_portals4_module_t *module =
(ompi_osc_portals4_module_t*) win->w_osc_module;
/* flush is only allowed from within a passive target epoch */
if (!module->passive_target_access_epoch) {
return OMPI_ERR_RMA_SYNC;
}
return ompi_osc_portals4_complete_all(module);
}
|