Skip to content

Commit

Permalink
include, prov: Change util_av lock to genlock
Browse files Browse the repository at this point in the history
The util_av lock will be held in the fast path in the EFA provider. With the
correct threading and progress models
(FI_THREAD_DOMAIN/FI_THREAD_COMPLETION and FI_PROGRESS_CONTROL_UNIFIED),
this lock should also be a no-op. Similar to the ep_list_lock.

This commit changes the mutex to a genlock that becomes a no-op for the
correct threading and progress models and a mutex otherwise.

Signed-off-by: Sai Sunku <sunkusa@amazon.com>
  • Loading branch information
sunkuamzn committed Feb 20, 2025
1 parent a07fe39 commit 08d885d
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 66 deletions.
2 changes: 1 addition & 1 deletion include/ofi_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ struct util_av {
struct fid_av av_fid;
struct util_domain *domain;
ofi_atomic32_t ref;
ofi_mutex_t lock;
struct ofi_genlock lock;
const struct fi_provider *prov;

struct util_av_entry *hash;
Expand Down
4 changes: 2 additions & 2 deletions prov/coll/src/coll_coll.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,10 @@ int coll_join_collective(struct fid_ep *ep, const void *addr,
av_set = container_of(set, struct util_av_set, av_set_fid);

if (coll_addr == FI_ADDR_NOTAVAIL) {
ofi_mutex_lock(&av_set->av->lock);
ofi_genlock_lock(&av_set->av->lock);
assert(av_set->av->av_set);
coll_mc = &av_set->av->av_set->coll_mc;
ofi_mutex_unlock(&av_set->av->lock);
ofi_genlock_unlock(&av_set->av->lock);
} else {
coll_mc = (struct util_coll_mc*) ((uintptr_t) coll_addr);
}
Expand Down
12 changes: 6 additions & 6 deletions prov/efa/src/efa_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ int efa_av_insert_one(struct efa_av *av, struct efa_ep_addr *addr,
if (av->ep_type == FI_EP_DGRAM)
addr->qkey = EFA_DGRAM_CONNID;

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
memset(raw_gid_str, 0, sizeof(raw_gid_str));
if (!inet_ntop(AF_INET6, addr->raw, raw_gid_str, INET6_ADDRSTRLEN)) {
EFA_WARN(FI_LOG_AV, "cannot convert address to string. errno: %d\n", errno);
Expand Down Expand Up @@ -629,7 +629,7 @@ int efa_av_insert_one(struct efa_av *av, struct efa_ep_addr *addr,
raw_gid_str, addr->qpn, addr->qkey, *fi_addr);
ret = 0;
out:
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
return ret;
}

Expand Down Expand Up @@ -742,7 +742,7 @@ static int efa_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
if (av->type != FI_AV_TABLE)
return -FI_EINVAL;

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
for (i = 0; i < count; i++) {
conn = efa_av_addr_to_conn(av, fi_addr[i]);
if (!conn) {
Expand All @@ -758,7 +758,7 @@ static int efa_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
assert(err);
}

ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
return err;
}

Expand All @@ -783,7 +783,7 @@ static void efa_av_close_reverse_av(struct efa_av *av)
struct efa_cur_reverse_av *cur_entry, *curtmp;
struct efa_prv_reverse_av *prv_entry, *prvtmp;

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);

HASH_ITER(hh, av->cur_reverse_av, cur_entry, curtmp) {
efa_conn_release(av, cur_entry->conn);
Expand All @@ -793,7 +793,7 @@ static void efa_av_close_reverse_av(struct efa_av *av)
efa_conn_release(av, prv_entry->conn);
}

ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
}

static int efa_av_close(struct fid *fid)
Expand Down
8 changes: 4 additions & 4 deletions prov/rxd/src/rxd_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static int rxd_av_insert(struct fid_av *av_fid, const void *addr, size_t count,
memset(sync_err, 0, sizeof(*sync_err) * count);
}

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
if (!av->dg_addrlen) {
ret = rxd_av_set_addrlen(av, addr);
if (ret)
Expand Down Expand Up @@ -255,7 +255,7 @@ static int rxd_av_insert(struct fid_av *av_fid, const void *addr, size_t count,
}
out:
av->dg_av_used += success_cnt;
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);

for (; i < count; i++) {
if (fi_addr)
Expand Down Expand Up @@ -291,7 +291,7 @@ static int rxd_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr, size_t count
struct rxd_av *av;

av = container_of(av_fid, struct rxd_av, util_av.av_fid);
ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
for (i = 0; i < count; i++) {
rxd_addr = (intptr_t)ofi_idx_lookup(&av->fi_addr_idx,
(int) RXD_IDX_OFFSET(fi_addr[i]));
Expand All @@ -307,7 +307,7 @@ static int rxd_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr, size_t count
if (ret)
FI_WARN(&rxd_prov, FI_LOG_AV, "Unable to remove address from AV\n");

ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
return ret;
}

Expand Down
8 changes: 4 additions & 4 deletions prov/shm/src/smr_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ static int smr_av_insert(struct fid_av *av_fid, const void *addr, size_t count,
ret = smr_map_add(&smr_prov, &smr_av->smr_map,
addr, &shm_id);
if (!ret) {
ofi_mutex_lock(&util_av->lock);
ofi_genlock_lock(&util_av->lock);
ret = ofi_av_insert_addr(util_av, &shm_id,
&util_addr);
ofi_mutex_unlock(&util_av->lock);
ofi_genlock_unlock(&util_av->lock);
}
} else {
FI_WARN(&smr_prov, FI_LOG_AV,
Expand Down Expand Up @@ -198,7 +198,7 @@ static int smr_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr, size_t count
util_av = container_of(av_fid, struct util_av, av_fid);
smr_av = container_of(util_av, struct smr_av, util_av);

ofi_mutex_lock(&util_av->lock);
ofi_genlock_lock(&util_av->lock);
for (i = 0; i < count; i++) {
FI_INFO(&smr_prov, FI_LOG_AV, "%" PRIu64 "\n", fi_addr[i]);
id = smr_addr_lookup(util_av, fi_addr[i]);
Expand All @@ -224,7 +224,7 @@ static int smr_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr, size_t count
smr_av->used--;
}

ofi_mutex_unlock(&util_av->lock);
ofi_genlock_unlock(&util_av->lock);
return ret;
}

Expand Down
14 changes: 7 additions & 7 deletions prov/sm2/src/sm2_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ static int sm2_av_insert(struct fid_av *av_fid, const void *addr, size_t count,
if (ret)
continue;

ofi_mutex_lock(&util_av->lock);
ofi_genlock_lock(&util_av->lock);
ret = ofi_av_insert_addr(util_av, &gid, &util_addr);

if (ret) {
ofi_mutex_unlock(&util_av->lock);
ofi_genlock_unlock(&util_av->lock);
continue;
}

Expand All @@ -110,7 +110,7 @@ static int sm2_av_insert(struct fid_av *av_fid, const void *addr, size_t count,
if (fi_addr)
fi_addr[i] = util_addr;

ofi_mutex_unlock(&util_av->lock);
ofi_genlock_unlock(&util_av->lock);
succ_count++;
}

Expand All @@ -137,7 +137,7 @@ static int sm2_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
util_av = container_of(av_fid, struct util_av, av_fid);
sm2_av = container_of(util_av, struct sm2_av, util_av);

ofi_mutex_lock(&util_av->lock);
ofi_genlock_lock(&util_av->lock);
for (i = 0; i < count; i++) {
gid = *((sm2_gid_t *) ofi_av_get_addr(util_av, fi_addr[i]));
if (gid > 0 && gid < SM2_MAX_UNIVERSE_SIZE)
Expand All @@ -151,7 +151,7 @@ static int sm2_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
}
}

ofi_mutex_unlock(&util_av->lock);
ofi_genlock_unlock(&util_av->lock);
return ret;
}

Expand All @@ -169,9 +169,9 @@ static int sm2_av_lookup(struct fid_av *av, fi_addr_t fi_addr, void *addr,
util_av = container_of(av, struct util_av, av_fid);
sm2_av = container_of(util_av, struct sm2_av, util_av);

ofi_mutex_lock(&util_av->lock);
ofi_genlock_lock(&util_av->lock);
gid = *((sm2_gid_t *) ofi_av_get_addr(util_av, fi_addr));
ofi_mutex_unlock(&util_av->lock);
ofi_genlock_unlock(&util_av->lock);

if (gid >= SM2_MAX_UNIVERSE_SIZE) {
FI_WARN(&sm2_prov, FI_LOG_EP_DATA,
Expand Down
4 changes: 2 additions & 2 deletions prov/tcp/src/xnet_rdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,9 @@ static int xnet_mplex_av_dup(struct util_ep *ep, struct xnet_mplex_av *mplex_av,
if (ret)
continue;

ofi_mutex_lock(&subav->lock);
ofi_genlock_lock(&subav->lock);
ret = ofi_av_insert_addr_at(subav, addr, i);
ofi_mutex_unlock(&subav->lock);
ofi_genlock_unlock(&subav->lock);
if (ret)
return ret;
}
Expand Down
42 changes: 21 additions & 21 deletions prov/util/src/rxm_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ size_t rxm_av_max_peers(struct rxm_av *av)
{
size_t cnt;

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
cnt = av->peer_pool->entry_cnt;
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
return cnt;
}

void *rxm_av_alloc_conn(struct rxm_av *av)
{
void *conn_ctx;
ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
conn_ctx = ofi_buf_alloc(av->conn_pool);
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
return conn_ctx;
}

void rxm_av_free_conn(struct rxm_av *av, void *conn_ctx)
{
ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
ofi_buf_free(conn_ctx);
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
}

static int rxm_addr_compare(struct ofi_rbmap *map, void *key, void *data)
Expand All @@ -71,7 +71,7 @@ rxm_alloc_peer(struct rxm_av *av, const void *addr)
{
struct util_peer_addr *peer;

assert(ofi_mutex_held(&av->util_av.lock));
assert(ofi_genlock_held(&av->util_av.lock));
peer = ofi_ibuf_alloc(av->peer_pool);
if (!peer)
return NULL;
Expand All @@ -92,7 +92,7 @@ rxm_alloc_peer(struct rxm_av *av, const void *addr)

static void rxm_free_peer(struct util_peer_addr *peer)
{
assert(ofi_mutex_held(&peer->av->util_av.lock));
assert(ofi_genlock_held(&peer->av->util_av.lock));
assert(!peer->refcnt);
ofi_rbmap_delete(&peer->av->addr_map, peer->node);
ofi_ibuf_free(peer);
Expand All @@ -104,7 +104,7 @@ util_get_peer(struct rxm_av *av, const void *addr)
struct util_peer_addr *peer;
struct ofi_rbnode *node;

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
node = ofi_rbmap_find(&av->addr_map, (void *) addr);
if (node) {
peer = node->data;
Expand All @@ -113,13 +113,13 @@ util_get_peer(struct rxm_av *av, const void *addr)
peer = rxm_alloc_peer(av, addr);
}

ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
return peer;
}

static void util_deref_peer(struct util_peer_addr *peer)
{
assert(ofi_mutex_held(&peer->av->util_av.lock));
assert(ofi_genlock_held(&peer->av->util_av.lock));
if (--peer->refcnt == 0)
rxm_free_peer(peer);
}
Expand All @@ -129,16 +129,16 @@ void util_put_peer(struct util_peer_addr *peer)
struct rxm_av *av;

av = peer->av;
ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
util_deref_peer(peer);
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
}

void rxm_ref_peer(struct util_peer_addr *peer)
{
ofi_mutex_lock(&peer->av->util_av.lock);
ofi_genlock_lock(&peer->av->util_av.lock);
peer->refcnt++;
ofi_mutex_unlock(&peer->av->util_av.lock);
ofi_genlock_unlock(&peer->av->util_av.lock);
}

static void
Expand Down Expand Up @@ -201,9 +201,9 @@ rxm_av_add_peers(struct rxm_av *av, const void *addr, size_t count,
cur_addr);
}
if (cur_fi_addr != FI_ADDR_NOTAVAIL) {
ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
rxm_put_peer_addr(av, cur_fi_addr);
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);
}
}
return -FI_ENOMEM;
Expand All @@ -230,7 +230,7 @@ static int rxm_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
* added -- i.e. fi_addr passed in here was also passed into insert.
* Thus, we walk through the array backwards.
*/
ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
for (i = count - 1; i >= 0; i--) {
FI_INFO(av->util_av.prov, FI_LOG_AV,
"fi_addr %" PRIu64 "\n", fi_addr[i]);
Expand All @@ -251,7 +251,7 @@ static int rxm_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
*/
peer = ofi_av_addr_context(&av->util_av, fi_addr[i]);
(*peer)->refcnt++;
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);

ofi_genlock_lock(&av->util_av.ep_list_lock);
dlist_foreach(&av->util_av.ep_list, item) {
Expand All @@ -261,7 +261,7 @@ static int rxm_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
}
ofi_genlock_unlock(&av->util_av.ep_list_lock);

ofi_mutex_lock(&av->util_av.lock);
ofi_genlock_lock(&av->util_av.lock);
util_deref_peer(*peer);
}

Expand All @@ -271,7 +271,7 @@ static int rxm_av_remove(struct fid_av *av_fid, fi_addr_t *fi_addr,
ofi_ibuf_free(av_entry);
}
}
ofi_mutex_unlock(&av->util_av.lock);
ofi_genlock_unlock(&av->util_av.lock);

return 0;
}
Expand Down
Loading

0 comments on commit 08d885d

Please sign in to comment.