Skip to content

Commit

Permalink
core: Handle dmabuf for ofi_mr_cache* functions.
Browse files Browse the repository at this point in the history
Convert dmabuf to iov for ofi_mr_info in ofi_mr_cache_find
and ofi_mr_cache_reg.

When constructing ofi_mr_info from mr_attr for ofi_mr_cache_search.
Convert dmabuf to iov if the flags has FI_MR_DMABUF.

Signed-off-by: Shi Jin <sjina@amazon.com>
  • Loading branch information
shijin-aws committed Nov 5, 2023
1 parent 6a00291 commit 5c1e891
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
16 changes: 14 additions & 2 deletions include/ofi_mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ void ofi_mr_get_iov_from_dmabuf(struct iovec *iov,
}
}

static inline
void ofi_mr_info_get_iov_from_mr_attr(struct ofi_mr_info *info,
const struct fi_mr_attr *attr,
uint64_t flags)
{
if (flags & FI_MR_DMABUF)
ofi_mr_get_iov_from_dmabuf(&info->iov, attr->dmabuf, 1);
else
info->iov = *attr->mr_iov;
}

void ofi_mr_update_attr(uint32_t user_version, uint64_t caps,
const struct fi_mr_attr *user_attr,
struct fi_mr_attr *cur_abi_attr,
Expand Down Expand Up @@ -428,9 +439,10 @@ int ofi_mr_cache_search(struct ofi_mr_cache *cache,
* with the cache.
*/
struct ofi_mr_entry *ofi_mr_cache_find(struct ofi_mr_cache *cache,
const struct fi_mr_attr *attr);
const struct fi_mr_attr *attr,
uint64_t flags);
int ofi_mr_cache_reg(struct ofi_mr_cache *cache, const struct fi_mr_attr *attr,
struct ofi_mr_entry **entry);
struct ofi_mr_entry **entry, uint64_t flags);
void ofi_mr_cache_delete(struct ofi_mr_cache *cache, struct ofi_mr_entry *entry);


Expand Down
2 changes: 1 addition & 1 deletion prov/efa/src/efa_mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static int efa_mr_cache_regattr(struct fid *fid, const struct fi_mr_attr *attr,
util_domain.domain_fid.fid);

assert(attr->iov_count == 1);
info.iov = *attr->mr_iov;
ofi_mr_info_get_iov_from_mr_attr(&info, attr, flags);
info.iface = attr->iface;
info.device = attr->device.reserved;
ret = ofi_mr_cache_search(domain->cache, &info, &entry);
Expand Down
9 changes: 5 additions & 4 deletions prov/util/src/util_mr_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ int ofi_mr_cache_search(struct ofi_mr_cache *cache, const struct ofi_mr_info *in
}

struct ofi_mr_entry *ofi_mr_cache_find(struct ofi_mr_cache *cache,
const struct fi_mr_attr *attr)
const struct fi_mr_attr *attr,
uint64_t flags)
{
struct ofi_mr_info info;
struct ofi_mr_entry *entry;
Expand All @@ -410,7 +411,7 @@ struct ofi_mr_entry *ofi_mr_cache_find(struct ofi_mr_cache *cache,
cache->search_cnt++;

info.peer_id = 0;
info.iov = *attr->mr_iov;
ofi_mr_info_get_iov_from_mr_attr(&info, attr, flags);
entry = ofi_mr_rbt_find(&cache->tree, &info);
if (!entry) {
goto unlock;
Expand All @@ -436,7 +437,7 @@ struct ofi_mr_entry *ofi_mr_cache_find(struct ofi_mr_cache *cache,
}

int ofi_mr_cache_reg(struct ofi_mr_cache *cache, const struct fi_mr_attr *attr,
struct ofi_mr_entry **entry)
struct ofi_mr_entry **entry, uint64_t flags)
{
int ret;

Expand All @@ -453,7 +454,7 @@ int ofi_mr_cache_reg(struct ofi_mr_cache *cache, const struct fi_mr_attr *attr,
cache->uncached_size += attr->mr_iov->iov_len;
pthread_mutex_unlock(&mm_lock);

(*entry)->info.iov = *attr->mr_iov;
ofi_mr_info_get_iov_from_mr_attr(&(*entry)->info, attr, flags);
(*entry)->use_cnt = 1;
(*entry)->node = NULL;

Expand Down
4 changes: 2 additions & 2 deletions prov/verbs/src/verbs_mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ vrb_mr_cache_reg(struct vrb_domain *domain, const void *buf, size_t len,
attr.iface = iface;
attr.device.reserved = device;
assert(attr.iov_count == 1);
info.iov = iov;
ofi_mr_info_get_iov_from_mr_attr(&info, &attr, flags);
info.iface = iface;
info.device = device;

ret = (flags & OFI_MR_NOCACHE) ?
ofi_mr_cache_reg(&domain->cache, &attr, &entry) :
ofi_mr_cache_reg(&domain->cache, &attr, &entry, flags) :
ofi_mr_cache_search(&domain->cache, &info, &entry);
if (OFI_UNLIKELY(ret))
return ret;
Expand Down

0 comments on commit 5c1e891

Please sign in to comment.