Skip to content

Commit

Permalink
prov/shm: import shm as device host memory
Browse files Browse the repository at this point in the history
Use HMEM iface host register calls to register/import shm into the iface

Signed-off-by: Alexia Ingerson <[email protected]>
  • Loading branch information
aingerson committed Dec 12, 2022
1 parent db4491b commit 13adbf2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
6 changes: 3 additions & 3 deletions include/ofi_shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ size_t smr_calculate_size_offsets(size_t tx_count, size_t rx_count,
void smr_cma_check(struct smr_region *region, struct smr_region *peer_region);
void smr_cleanup(void);
int smr_map_create(const struct fi_provider *prov, int peer_count,
uint16_t flags, struct smr_map **map);
int smr_map_to_region(const struct fi_provider *prov,
struct smr_peer *peer_buf);
uint16_t caps, struct smr_map **map);
int smr_map_to_region(const struct fi_provider *prov, struct smr_map *map,
int64_t id);
void smr_map_to_endpoint(struct smr_region *region, int64_t id);
void smr_unmap_from_endpoint(struct smr_region *region, int64_t id);
void smr_exchange_all_peers(struct smr_region *region);
Expand Down
2 changes: 1 addition & 1 deletion prov/shm/src/smr_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ int64_t smr_verify_peer(struct smr_ep *ep, fi_addr_t fi_addr)
return id;

if (ep->region->map->peers[id].peer.id < 0) {
ret = smr_map_to_region(&smr_prov, &ep->region->map->peers[id]);
ret = smr_map_to_region(&smr_prov, ep->region->map, id);
if (ret == -ENOENT)
return -1;

Expand Down
2 changes: 1 addition & 1 deletion prov/shm/src/smr_progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ static void smr_progress_connreq(struct smr_ep *ep, struct smr_cmd *cmd)
//TODO track and update/complete in error any transfers
//to or from old mapping
munmap(peer_smr, peer_smr->total_size);
smr_map_to_region(&smr_prov, &ep->region->map->peers[idx]);
smr_map_to_region(&smr_prov, ep->region->map, idx);
peer_smr = smr_peer_region(ep->region, idx);
}
smr_peer_data(peer_smr)[cmd->msg.hdr.id].addr.id = idx;
Expand Down
27 changes: 24 additions & 3 deletions prov/util/src/util_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ int smr_create(const struct fi_provider *prov, struct smr_map *map,

close(fd);

if (attr->flags & SMR_FLAG_HMEM_ENABLED) {
ret = ofi_hmem_host_register(mapped_addr, total_size);
if (ret)
FI_WARN(prov, FI_LOG_EP_CTRL,
"unable to register shm with iface\n");
}

ep_name->region = mapped_addr;
pthread_mutex_unlock(&ep_list_lock);

Expand Down Expand Up @@ -323,6 +330,8 @@ int smr_create(const struct fi_provider *prov, struct smr_map *map,

void smr_free(struct smr_region *smr)
{
if (smr->flags & SMR_FLAG_HMEM_ENABLED)
(void) ofi_hmem_host_unregister(smr);
shm_unlink(smr_name(smr));
munmap(smr, smr->total_size);
}
Expand Down Expand Up @@ -366,8 +375,10 @@ static int smr_match_name(struct dlist_entry *item, const void *args)
(char *) args);
}

int smr_map_to_region(const struct fi_provider *prov, struct smr_peer *peer_buf)
int smr_map_to_region(const struct fi_provider *prov, struct smr_map *map,
int64_t id)
{
struct smr_peer *peer_buf = &map->peers[id];
struct smr_region *peer;
size_t size;
int fd, ret = 0;
Expand Down Expand Up @@ -428,6 +439,13 @@ int smr_map_to_region(const struct fi_provider *prov, struct smr_peer *peer_buf)
peer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
peer_buf->region = peer;

if (map->flags & SMR_FLAG_HMEM_ENABLED) {
ret = ofi_hmem_host_register(peer, peer->total_size);
if (ret)
FI_WARN(prov, FI_LOG_EP_CTRL,
"unable to register shm with iface\n");
}

out:
close(fd);
return ret;
Expand Down Expand Up @@ -511,7 +529,7 @@ int smr_map_add(const struct fi_provider *prov, struct smr_map *map,
map->peers[*id].peer.name[SMR_NAME_MAX - 1] = '\0';
map->peers[*id].region = NULL;

ret = smr_map_to_region(prov, &map->peers[*id]);
ret = smr_map_to_region(prov, map, *id);
if (!ret)
map->peers[*id].peer.id = *id;

Expand All @@ -533,8 +551,11 @@ void smr_map_del(struct smr_map *map, int64_t id)
pthread_mutex_unlock(&ep_list_lock);

ofi_spin_lock(&map->lock);
if (!entry)
if (!entry) {
if (map->flags & SMR_FLAG_HMEM_ENABLED)
(void) ofi_hmem_host_unregister(map->peers[id].region);
munmap(map->peers[id].region, map->peers[id].region->total_size);
}

(void) ofi_rbmap_find_delete(&map->rbmap,
(void *) map->peers[id].peer.name);
Expand Down

0 comments on commit 13adbf2

Please sign in to comment.