#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <ofi_xpmem.h>
#if HAVE_XPMEM
static int xpmem_cache_add_region(struct ofi_mr_cache *cache, struct ofi_mr_entry *entry)
{
struct xpmem_addr *xpmem_addr = (struct xpmem_addr *) entry->info.handle;
entry->info.mapped_addr = xpmem_attach(*xpmem_addr,
entry->info.iov.iov_len, NULL);
if (entry->info.mapped_addr == (void *) -1)
return -FI_EIO;
return FI_SUCCESS;
}
static void xpmem_cache_delete_region(struct ofi_mr_cache *cache,
struct ofi_mr_entry *entry)
{
xpmem_detach(entry->info.mapped_addr);
}
int ofi_xpmem_cache_open(struct ofi_mr_cache **cache)
{
struct ofi_mem_monitor *memory_monitors[OFI_HMEM_MAX] = {0};
int ret;
memory_monitors[FI_HMEM_SYSTEM] = xpmem_monitor;
*cache = calloc(1, sizeof(*(*cache)));
if (!*cache) {
ret = -FI_ENOMEM;
goto out;
}
(*cache)->add_region = xpmem_cache_add_region;
(*cache)->delete_region = xpmem_cache_delete_region;
ret = ofi_mr_cache_init(NULL, memory_monitors,
*cache);
if (ret)
goto cleanup;
FI_INFO(&core_prov, FI_LOG_CORE,
"xpmem cache enabled, max_cnt: %zu max_size: %zu\n",
cache_params.max_cnt, cache_params.max_size);
return FI_SUCCESS;
cleanup:
free(*cache);
*cache = NULL;
out:
return ret;
}
void ofi_xpmem_cache_destroy(struct ofi_mr_cache *cache)
{
ofi_mr_cache_cleanup(cache);
free(cache);
}
int ofi_xpmem_cache_search(struct ofi_mr_cache *cache, struct iovec *iov,
uint64_t peer_id, struct ofi_mr_entry **mr_entry,
struct xpmem_client *xpmem)
{
int ret;
struct ofi_mr_info info;
struct ofi_mr_entry *entry;
struct xpmem_addr xpmem_addr;
xpmem_addr.apid = xpmem->apid;
xpmem_addr.offset = (uintptr_t)iov->iov_base;
memcpy(&info.iov, iov, sizeof(*iov));
info.iface = FI_HMEM_SYSTEM;
info.peer_id = peer_id;
memcpy(&info.handle, &xpmem_addr, sizeof(xpmem_addr));
ret = ofi_mr_cache_search(cache, &info, &entry);
if (ret)
goto out;
*mr_entry = entry;
out:
return ret;
}
#else
int ofi_xpmem_cache_search(struct ofi_mr_cache *cache, struct iovec *iov,
uint64_t peer_id, struct ofi_mr_entry **mr_entry,
struct xpmem_client *xpmem)
{
return -FI_ENOSYS;
}
int ofi_xpmem_cache_open(struct ofi_mr_cache **cache)
{
*cache = NULL;
return FI_SUCCESS;
}
void ofi_xpmem_cache_destroy(struct ofi_mr_cache *cache)
{
}
#endif