Skip to content

Commit 817b8bd

Browse files
committed
Residual locks and more shuffling.
1 parent 9d7af02 commit 817b8bd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

ompi/mca/osc/rdma/osc_rdma_dynamic.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ int ompi_osc_rdma_attach (struct ompi_win_t *win, void *base, size_t len)
185185
OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "attach: %s, %p, %lu", win->w_name, base, (unsigned long) len);
186186

187187
OPAL_THREAD_LOCK(&module->lock);
188+
ompi_osc_rdma_lock_acquire_exclusive (module, my_peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
188189

189190
region_count = module->state->region_count & 0xffffffffL;
190191
region_id = module->state->region_count >> 32;
@@ -208,12 +209,11 @@ int ompi_osc_rdma_attach (struct ompi_win_t *win, void *base, size_t len)
208209
/* validates that the region does not overlap with an existing region even if they are on the same page */
209210
ret = ompi_osc_rdma_add_attachment (module->dynamic_handles[region_index], (intptr_t) base, len);
210211
OPAL_THREAD_UNLOCK(&module->lock);
212+
ompi_osc_rdma_lock_release_exclusive (module, my_peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
211213
/* no need to invalidate remote caches */
212214
return ret;
213215
}
214216

215-
ompi_osc_rdma_lock_acquire_exclusive (module, my_peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
216-
217217
/* do a binary seach for where the region should be inserted */
218218
if (region_count) {
219219
region = find_insertion_point ((ompi_osc_rdma_region_t *) module->state->regions, 0, region_count - 1,
@@ -248,6 +248,7 @@ int ompi_osc_rdma_attach (struct ompi_win_t *win, void *base, size_t len)
248248
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
249249
OPAL_THREAD_UNLOCK(&module->lock);
250250
OBJ_RELEASE(rdma_region_handle);
251+
ompi_osc_rdma_lock_release_exclusive (module, my_peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
251252
return OMPI_ERR_RMA_ATTACH;
252253
}
253254

@@ -325,11 +326,14 @@ int ompi_osc_rdma_detach (struct ompi_win_t *win, const void *base)
325326
if (region_index == region_count) {
326327
OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "could not find dynamic memory attachment for %p", base);
327328
OPAL_THREAD_UNLOCK(&module->lock);
329+
ompi_osc_rdma_lock_release_exclusive (module, &my_peer->super, offsetof (ompi_osc_rdma_state_t, regions_lock));
328330
return OMPI_ERR_BASE;
329331
}
330332

331333
if (!opal_list_is_empty (&rdma_region_handle->attachments)) {
332334
/* another region is referencing this attachment */
335+
OPAL_THREAD_UNLOCK(&module->lock);
336+
ompi_osc_rdma_lock_release_exclusive (module, &my_peer->super, offsetof (ompi_osc_rdma_state_t, regions_lock));
333337
return OMPI_SUCCESS;
334338
}
335339

@@ -456,16 +460,18 @@ int ompi_osc_rdma_find_dynamic_region (ompi_osc_rdma_module_t *module, ompi_osc_
456460
ompi_osc_rdma_peer_dynamic_t *dy_peer = (ompi_osc_rdma_peer_dynamic_t *) peer;
457461
intptr_t bound = (intptr_t) base + len;
458462
ompi_osc_rdma_region_t *regions;
459-
int ret, region_count;
463+
int ret = OMPI_SUCCESS, region_count;
460464

461465
OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "locating dynamic memory region matching: {%" PRIx64 ", %" PRIx64 "}"
462466
" (len %lu)", base, base + len, (unsigned long) len);
463467

468+
OPAL_THREAD_LOCK(&module->lock);
464469
// Make sure region isn't being touched.
465470
ompi_osc_rdma_lock_acquire_exclusive (module, peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
466471
if (!ompi_osc_rdma_peer_local_state (peer)) {
467472
ret = ompi_osc_rdma_refresh_dynamic_region (module, dy_peer);
468473
if (OMPI_SUCCESS != ret) {
474+
ompi_osc_rdma_lock_release_exclusive (module, peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
469475
return ret;
470476
}
471477

@@ -476,13 +482,14 @@ int ompi_osc_rdma_find_dynamic_region (ompi_osc_rdma_module_t *module, ompi_osc_
476482
regions = (ompi_osc_rdma_region_t *) peer_state->regions;
477483
region_count = peer_state->region_count;
478484
}
479-
ompi_osc_rdma_lock_release_exclusive (module, peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
480485

481486
*region = ompi_osc_rdma_find_region_containing (regions, 0, region_count - 1, (intptr_t) base, bound, module->region_size, NULL);
482487
if (!*region) {
483-
return OMPI_ERR_RMA_RANGE;
488+
ret = OMPI_ERR_RMA_RANGE;
484489
}
490+
OPAL_THREAD_UNLOCK(&module->lock);
491+
ompi_osc_rdma_lock_release_exclusive (module, peer, offsetof (ompi_osc_rdma_state_t, regions_lock));
485492

486493
/* round a matching region */
487-
return OMPI_SUCCESS;
494+
return ret;
488495
}

0 commit comments

Comments
 (0)