int mca_mpool_grdma_deregister(struct mca_mpool_base_module_t *mpool, mca_mpool_base_registration_t *reg) { mca_mpool_grdma_module_t *mpool_grdma = (mca_mpool_grdma_module_t *) mpool; int rc = OPAL_SUCCESS; assert(reg->ref_count > 0); OPAL_THREAD_LOCK(&mpool->rcache->lock); reg->ref_count--; if(reg->ref_count > 0) { OPAL_THREAD_UNLOCK(&mpool->rcache->lock); return OPAL_SUCCESS; } if(registration_is_cacheable(reg)) { opal_list_append(&mpool_grdma->pool->lru_list, (opal_list_item_t *) reg); } else { rc = dereg_mem (reg); } OPAL_THREAD_UNLOCK(&mpool->rcache->lock); /* Cleanup any vmas that we have deferred deletion on */ mpool->rcache->rcache_clean(mpool->rcache); return rc; }
int mca_mpool_rgpusm_deregister(struct mca_mpool_base_module_t *mpool, mca_mpool_base_registration_t *reg) { mca_mpool_rgpusm_module_t *mpool_rgpusm = (mca_mpool_rgpusm_module_t*)mpool; int rc = OPAL_SUCCESS; assert(reg->ref_count > 0); opal_mutex_lock (&mpool->rcache->lock); reg->ref_count--; opal_output(-1, "Deregister: reg->ref_count=%d", (int)reg->ref_count); if(reg->ref_count > 0) { opal_mutex_unlock (&mpool->rcache->lock); return OPAL_SUCCESS; } if(mca_mpool_rgpusm_component.leave_pinned && registration_is_cacheable(reg)) { /* if leave_pinned is set don't deregister memory, but put it * on LRU list for future use */ opal_output_verbose(20, mca_mpool_rgpusm_component.output, "RGPUSM: Deregister: addr=%p, size=%d: cacheable and pinned, leave in cache, PUSH IN LRU", reg->base, (int)(reg->bound - reg->base + 1)); opal_list_prepend(&mpool_rgpusm->lru_list, (opal_list_item_t*)reg); } else { /* Remove from rcache first */ if(!(reg->flags & MCA_MPOOL_FLAGS_CACHE_BYPASS)) mpool->rcache->rcache_delete(mpool->rcache, reg); /* Drop the rcache lock before deregistring the memory */ opal_mutex_unlock (&mpool->rcache->lock); { mca_mpool_rgpusm_module_t *mpool_rgpusm = (mca_mpool_rgpusm_module_t *)mpool; assert(reg->ref_count == 0); rc = mpool_rgpusm->resources.deregister_mem(mpool_rgpusm->resources.reg_data, reg); } opal_mutex_lock (&mpool->rcache->lock); if(OPAL_SUCCESS == rc) { opal_free_list_return (&mpool_rgpusm->reg_list, (opal_free_list_item_t*)reg); } } opal_mutex_unlock (&mpool->rcache->lock); return rc; }
static int mca_rcache_grdma_check_cached (mca_rcache_base_registration_t *grdma_reg, void *ctx) { mca_rcache_base_find_args_t *args = (mca_rcache_base_find_args_t *) ctx; mca_rcache_grdma_module_t *rcache_grdma = args->rcache_grdma; if ((grdma_reg->flags & MCA_RCACHE_FLAGS_INVALID) || &rcache_grdma->super != grdma_reg->rcache || grdma_reg->base > args->base || grdma_reg->bound < args->bound) { return 0; } if (OPAL_UNLIKELY((args->access_flags & grdma_reg->access_flags) != args->access_flags)) { args->access_flags |= grdma_reg->access_flags; if (0 != grdma_reg->ref_count) { if (!(grdma_reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) { mca_rcache_base_vma_delete (rcache_grdma->cache->vma_module, grdma_reg); } /* mark the registration to go away when it is deregistered */ grdma_reg->flags |= MCA_RCACHE_FLAGS_INVALID | MCA_RCACHE_FLAGS_CACHE_BYPASS; } else { if (registration_is_cacheable(grdma_reg)) { opal_list_remove_item (&rcache_grdma->cache->lru_list, (opal_list_item_t *) grdma_reg); } dereg_mem (grdma_reg); } } else { if (0 == grdma_reg->ref_count) { /* Leave pinned must be set for this to still be in the rcache. */ opal_list_remove_item(&rcache_grdma->cache->lru_list, (opal_list_item_t *) grdma_reg); } /* This segment fits fully within an existing segment. */ rcache_grdma->stat_cache_hit++; int32_t ref_cnt = opal_atomic_add_32 (&grdma_reg->ref_count, 1); OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_TRACE, opal_rcache_base_framework.framework_output, "returning existing registration %p. references %d", (void *) grdma_reg, ref_cnt)); (void)ref_cnt; args->reg = grdma_reg; return 1; } /* can't use this registration */ return 0; }
static int iterate_dereg_finalize (mca_mpool_base_registration_t *rgpusm_reg, void *ctx) { mca_mpool_rgpusm_module_t *mpool_rgpusm = (mca_mpool_rgpusm_module_t *) ctx; if ((mca_mpool_base_module_t *) mpool_rgpusm != rgpusm_reg->mpool) { return 0; } if (registration_is_cacheable (rgpusm_reg)) { opal_list_remove_item (&mpool_rgpusm->lru_list, (opal_list_item_t *) rgpusm_reg); } /* set the reference count to 0 otherwise dereg will fail on assert */ rgpusm_reg->ref_count = 0; (void) mpool_rgpusm->resources.deregister_mem (mpool_rgpusm->resources.reg_data, rgpusm_reg); return 0; }
int mca_mpool_rgpusm_deregister_no_lock(struct mca_mpool_base_module_t *mpool, mca_mpool_base_registration_t *reg) { mca_mpool_rgpusm_module_t *mpool_rgpusm = (mca_mpool_rgpusm_module_t*)mpool; int rc = OPAL_SUCCESS; assert(reg->ref_count > 0); reg->ref_count--; opal_output(-1, "Deregister: reg->ref_count=%d", (int)reg->ref_count); if(reg->ref_count > 0) { return OPAL_SUCCESS; } if(mca_mpool_rgpusm_component.leave_pinned && registration_is_cacheable(reg)) { /* if leave_pinned is set don't deregister memory, but put it * on LRU list for future use */ opal_list_prepend(&mpool_rgpusm->lru_list, (opal_list_item_t*)reg); } else { /* Remove from rcache first */ if(!(reg->flags & MCA_MPOOL_FLAGS_CACHE_BYPASS)) mpool->rcache->rcache_delete(mpool->rcache, reg); { mca_mpool_rgpusm_module_t *mpool_rgpusm = (mca_mpool_rgpusm_module_t *)mpool; assert(reg->ref_count == 0); rc = mpool_rgpusm->resources.deregister_mem(mpool_rgpusm->resources.reg_data, reg); } if(OPAL_SUCCESS == rc) { opal_free_list_return (&mpool_rgpusm->reg_list, (opal_free_list_item_t*)reg); } } return rc; }