Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prov/efa: Split efa_rdm_ep.inject_size, add support for remaining EP size opts #10413

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions prov/efa/src/rdm/efa_rdm_ep.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ struct efa_rdm_ep {
struct fid_ep *shm_ep;

size_t mtu_size;
size_t inject_size;
size_t max_msg_size; /**< #FI_OPT_MAX_MSG_SIZE */
size_t max_tagged_size; /**< #FI_OPT_MAX_TAGGED_SIZE */
size_t max_rma_size; /**< #FI_OPT_MAX_RMA_SIZE */
size_t max_atomic_size; /**< #FI_OPT_MAX_ATOMIC_SIZE */
size_t inject_msg_size; /**< #FI_OPT_INJECT_MSG_SIZE */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering whether we can make it as an array with index as op code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a blocking comment though

size_t inject_tagged_size; /**< #FI_OPT_INJECT_TAGGED_SIZE */
size_t inject_rma_size; /**< #FI_OPT_INJECT_RMA_SIZE */
size_t inject_atomic_size; /**< #FI_OPT_INJECT_ATOMIC_SIZE */

/* Endpoint's capability to support zero-copy rx */
bool use_zcpy_rx;
Expand All @@ -73,11 +80,6 @@ struct efa_rdm_ep {
/* Resource management flag */
uint64_t rm_full;

/* Application's maximum msg size hint */
size_t max_msg_size;

/** Application's maximum RMA size */
size_t max_rma_size;

/* Applicaiton's message prefix size. */
size_t msg_prefix_size;
Expand Down
198 changes: 68 additions & 130 deletions prov/efa/src/rdm/efa_rdm_ep_fiops.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,18 @@ int efa_rdm_ep_open(struct fid_domain *domain, struct fi_info *info,
EFA_INFO(FI_LOG_EP_CTRL, "efa_rdm_ep->host_id: i-%017lx\n", efa_rdm_ep->host_id);
}

efa_rdm_ep->inject_size = info->tx_attr->inject_size;
efa_rdm_ep->max_msg_size = info->ep_attr->max_msg_size;
efa_rdm_ep->max_tagged_size = info->ep_attr->max_msg_size;
efa_rdm_ep->max_rma_size = info->ep_attr->max_msg_size;
efa_rdm_ep->max_atomic_size = info->ep_attr->max_msg_size;
efa_rdm_ep->inject_msg_size = info->tx_attr->inject_size;
efa_rdm_ep->inject_tagged_size = info->tx_attr->inject_size;
efa_rdm_ep->inject_rma_size = info->tx_attr->inject_size;
efa_rdm_ep->inject_atomic_size = info->tx_attr->inject_size;
efa_rdm_ep->efa_max_outstanding_tx_ops = efa_domain->device->rdm_info->tx_attr->size;
efa_rdm_ep->efa_max_outstanding_rx_ops = efa_domain->device->rdm_info->rx_attr->size;
efa_rdm_ep->use_device_rdma = efa_rdm_get_use_device_rdma(info->fabric_attr->api_version);
efa_rdm_ep->shm_permitted = true;
efa_rdm_ep->max_msg_size = info->ep_attr->max_msg_size;
efa_rdm_ep->max_rma_size = info->ep_attr->max_msg_size;
efa_rdm_ep->msg_prefix_size = info->ep_attr->msg_prefix_size;
efa_rdm_ep->mtu_size = efa_domain->device->rdm_info->ep_attr->max_msg_size;

Expand Down Expand Up @@ -1251,7 +1256,7 @@ static int efa_rdm_ep_ctrl(struct fid *fid, int command, void *arg)
* when supported
*/
if (ep->use_zcpy_rx)
ep->inject_size = MIN(ep->inject_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size);
ep->inject_rma_size = MIN(ep->inject_rma_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size);

ret = efa_rdm_ep_create_base_ep_ibv_qp(ep);
if (ret)
Expand Down Expand Up @@ -1440,110 +1445,6 @@ static int efa_rdm_ep_set_shared_memory_permitted(struct efa_rdm_ep *ep, bool sh
return 0;
}

/**
* @brief Conditionally set efa_rdm_ep#max_msg_size per user's request
*
* If the requested msg size exceeds the EFA provider's default value, the
* request is rejected.
*
* @param[in,out] ep EFA RDM endpoint
* @param[in] max_msg_size Requested maximum msg size
*
* @return 0 on success, -FI_EINVAL otherwise
*
* @sa #FI_OPT_MAX_MSG_SIZE
*/
static int efa_rdm_ep_set_max_msg_size(struct efa_rdm_ep *ep, size_t max_msg_size)
{
if (max_msg_size > ep->base_ep.info->ep_attr->max_msg_size) {
EFA_WARN(FI_LOG_EP_CTRL,
"Requested size of %zu for FI_OPT_MAX_MSG_SIZE "
"exceeds the maximum (%zu)\n",
max_msg_size, ep->base_ep.info->ep_attr->max_msg_size);
return -FI_EINVAL;
}
ep->max_msg_size = max_msg_size;
return 0;
}

/**
* @brief Conditionally set efa_rdm_ep#max_rma_size per user's request
*
* If the requested inject size exceeds the EFA provider's default value, the
* request is rejected.
*
* @param[in,out] ep EFA RDM endpoint
* @param[in] max_rma_size Requested max RMA size
*
* @return 0 on success, -FI_EINVAL otherwise
*
* @sa #FI_OPT_MAX_RMA_SIZE
*/
static int efa_rdm_ep_set_max_rma_size(struct efa_rdm_ep *ep, size_t max_rma_size)
{
if (max_rma_size > ep->base_ep.info->ep_attr->max_msg_size) {
EFA_WARN(FI_LOG_EP_CTRL,
"Requested size of %zu for FI_OPT_MAX_RMA_SIZE "
"exceeds the maximum (%zu)\n",
max_rma_size, ep->base_ep.info->ep_attr->max_msg_size);
return -FI_EINVAL;
}
ep->max_rma_size = max_rma_size;
return 0;
}

/**
* @brief Conditionally set efa_rdm_ep#inject_size per user's request
*
* If the requested inject size exceeds the EFA provider's default value, the
* request is rejected.
*
* @param[in,out] ep EFA RDM endpoint
* @param[in] inject_size Requested inject size
*
* @return 0 on success, -FI_EINVAL otherwise
*
* @sa #FI_OPT_INJECT_MSG_SIZE
*/
static int efa_rdm_ep_set_inject_msg_size(struct efa_rdm_ep *ep, size_t inject_msg_size)
{
if (inject_msg_size > ep->base_ep.info->tx_attr->inject_size) {
EFA_WARN(FI_LOG_EP_CTRL,
"Requested size of %zu for FI_OPT_INJECT_MSG_SIZE "
"exceeds the maximum (%zu)\n",
inject_msg_size, ep->base_ep.info->tx_attr->inject_size);
return -FI_EINVAL;
}
ep->inject_size = inject_msg_size;
return 0;
}

/**
* @brief Conditionally set efa_rdm_ep#inject_size per user's request
*
* If the requested inject size exceeds the EFA provider's default value, the
* request is rejected.
*
* @param[in,out] ep EFA RDM endpoint
* @param[in] inject_size Requested inject size
*
* @return 0 on success, -FI_EINVAL otherwise
*
* @sa #FI_OPT_INJECT_RMA_SIZE
*/
static int efa_rdm_ep_set_inject_rma_size(struct efa_rdm_ep *ep, size_t inject_rma_size)
{
if (inject_rma_size > ep->base_ep.info->tx_attr->inject_size) {
EFA_WARN(FI_LOG_EP_CTRL,
"Requested size of %zu for FI_OPT_INJECT_RMA_SIZE "
"exceeds the maximum (%zu)\n",
inject_rma_size, ep->base_ep.info->tx_attr->inject_size);
return -FI_EINVAL;
}
ep->inject_size = inject_rma_size;
return 0;
}

/**
* @brief set use_device_rdma flag in efa_rdm_ep.
*
Expand Down Expand Up @@ -1662,6 +1563,23 @@ int efa_rdm_ep_check_qp_in_order_aligned_128_bytes(struct efa_rdm_ep *ep,
return ret;
}

/**
* Convenience macro for setopt with an enforced threshold
*/
#define EFA_RDM_EP_SETOPT_THRESHOLD(opt, field, threshold) { \
size_t _val = *(size_t *) optval; \
if (optlen != sizeof field) \
return -FI_EINVAL; \
if (_val > threshold) { \
EFA_WARN(FI_LOG_EP_CTRL, \
"Requested size of %zu for FI_OPT_" #opt " " \
"exceeds the maximum (%zu)\n", \
_val, threshold); \
return -FI_EINVAL; \
} \
field = _val; \
}

/**
* @brief implement the fi_setopt() API for EFA RDM endpoint
* @param[in] fid fid to endpoint
Expand Down Expand Up @@ -1745,32 +1663,28 @@ static int efa_rdm_ep_setopt(fid_t fid, int level, int optname,
return ret;
break;
case FI_OPT_MAX_MSG_SIZE:
if (optlen != sizeof (size_t))
return -FI_EINVAL;
ret = efa_rdm_ep_set_max_msg_size(efa_rdm_ep, *(size_t *) optval);
if (ret)
return ret;
EFA_RDM_EP_SETOPT_THRESHOLD(MAX_MSG_SIZE, efa_rdm_ep->max_msg_size, efa_rdm_ep->base_ep.info->ep_attr->max_msg_size)
break;
case FI_OPT_MAX_TAGGED_SIZE:
EFA_RDM_EP_SETOPT_THRESHOLD(MAX_TAGGED_SIZE, efa_rdm_ep->max_tagged_size, efa_rdm_ep->base_ep.info->ep_attr->max_msg_size)
break;
case FI_OPT_MAX_RMA_SIZE:
if (optlen != sizeof (size_t))
return -FI_EINVAL;
ret = efa_rdm_ep_set_max_rma_size(efa_rdm_ep, *(size_t *) optval);
if (ret)
return ret;
EFA_RDM_EP_SETOPT_THRESHOLD(MAX_RMA_SIZE, efa_rdm_ep->max_rma_size, efa_rdm_ep->base_ep.info->ep_attr->max_msg_size)
break;
case FI_OPT_MAX_ATOMIC_SIZE:
EFA_RDM_EP_SETOPT_THRESHOLD(MAX_ATOMIC_SIZE, efa_rdm_ep->max_atomic_size, efa_rdm_ep->base_ep.info->ep_attr->max_msg_size)
break;
case FI_OPT_INJECT_MSG_SIZE:
if (optlen != sizeof (size_t))
return -FI_EINVAL;
ret = efa_rdm_ep_set_inject_msg_size(efa_rdm_ep, *(size_t *) optval);
if (ret)
return ret;
EFA_RDM_EP_SETOPT_THRESHOLD(INJECT_MSG_SIZE, efa_rdm_ep->inject_msg_size, efa_rdm_ep->base_ep.info->tx_attr->inject_size)
break;
case FI_OPT_INJECT_TAGGED_SIZE:
EFA_RDM_EP_SETOPT_THRESHOLD(INJECT_TAGGED_SIZE, efa_rdm_ep->inject_tagged_size, efa_rdm_ep->base_ep.info->tx_attr->inject_size)
break;
case FI_OPT_INJECT_RMA_SIZE:
if (optlen != sizeof (size_t))
return -FI_EINVAL;
ret = efa_rdm_ep_set_inject_rma_size(efa_rdm_ep, *(size_t *) optval);
if (ret)
return ret;
EFA_RDM_EP_SETOPT_THRESHOLD(INJECT_RMA_SIZE, efa_rdm_ep->inject_rma_size, efa_rdm_ep->base_ep.info->tx_attr->inject_size)
break;
case FI_OPT_INJECT_ATOMIC_SIZE:
EFA_RDM_EP_SETOPT_THRESHOLD(INJECT_ATOMIC_SIZE, efa_rdm_ep->inject_atomic_size, efa_rdm_ep->base_ep.info->tx_attr->inject_size)
break;
case FI_OPT_EFA_USE_DEVICE_RDMA:
if (optlen != sizeof(bool))
Expand Down Expand Up @@ -1854,22 +1768,46 @@ static int efa_rdm_ep_getopt(fid_t fid, int level, int optname, void *optval,
*(size_t *) optval = efa_rdm_ep->max_msg_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_MAX_TAGGED_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->max_tagged_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_MAX_RMA_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->max_rma_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_MAX_ATOMIC_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->max_atomic_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_INJECT_MSG_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->inject_size;
*(size_t *) optval = efa_rdm_ep->inject_msg_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_INJECT_TAGGED_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->inject_tagged_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_INJECT_RMA_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->inject_size;
*(size_t *) optval = efa_rdm_ep->inject_rma_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_INJECT_ATOMIC_SIZE:
if (*optlen < sizeof (size_t))
return -FI_ETOOSMALL;
*(size_t *) optval = efa_rdm_ep->inject_atomic_size;
*optlen = sizeof (size_t);
break;
case FI_OPT_EFA_EMULATED_READ:
Expand Down
8 changes: 4 additions & 4 deletions prov/efa/src/rdm/efa_rdm_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ ssize_t efa_rdm_msg_inject(struct fid_ep *ep, const void *buf, size_t len,
struct efa_rdm_peer *peer;

efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid);
assert(len <= efa_rdm_ep->inject_size);
assert(len <= efa_rdm_ep->inject_msg_size);

peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr);
assert(peer);
Expand Down Expand Up @@ -384,7 +384,7 @@ ssize_t efa_rdm_msg_injectdata(struct fid_ep *ep, const void *buf,
struct efa_rdm_peer *peer;

efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid);
assert(len <= efa_rdm_ep->inject_size);
assert(len <= efa_rdm_ep->inject_msg_size);

peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr);
assert(peer);
Expand Down Expand Up @@ -559,7 +559,7 @@ ssize_t efa_rdm_msg_tinject(struct fid_ep *ep_fid, const void *buf, size_t len,
struct efa_rdm_peer *peer;

efa_rdm_ep = container_of(ep_fid, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid);
assert(len <= efa_rdm_ep->inject_size);
assert(len <= efa_rdm_ep->inject_tagged_size);

peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr);
assert(peer);
Expand All @@ -586,7 +586,7 @@ ssize_t efa_rdm_msg_tinjectdata(struct fid_ep *ep_fid, const void *buf, size_t l
struct efa_rdm_peer *peer;

efa_rdm_ep = container_of(ep_fid, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid);
assert(len <= efa_rdm_ep->inject_size);
assert(len <= efa_rdm_ep->inject_tagged_size);

peer = efa_rdm_ep_get_peer(efa_rdm_ep, dest_addr);
assert(peer);
Expand Down
2 changes: 1 addition & 1 deletion prov/efa/src/rdm/efa_rdm_ope.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ int efa_rdm_ope_post_remote_write(struct efa_rdm_ope *ope)

if (ope->fi_flags & FI_INJECT) {
assert(ope->iov_count == 1);
assert(ope->total_len <= ep->inject_size);
assert(ope->total_len <= ep->inject_rma_size);
copied = efa_rdm_pke_copy_from_hmem_iov(
ope->desc[iov_idx], pkt_entry, ope,
sizeof(struct efa_rdm_rma_context_pkt), 0,
Expand Down
4 changes: 2 additions & 2 deletions prov/efa/src/rdm/efa_rdm_rma.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ ssize_t efa_rdm_rma_inject_write(struct fid_ep *ep, const void *buf, size_t len,
int err;

efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid);
assert(len <= efa_rdm_ep->inject_size);
assert(len <= efa_rdm_ep->inject_rma_size);
err = efa_rdm_ep_cap_check_rma(efa_rdm_ep);
if (err)
return err;
Expand Down Expand Up @@ -679,7 +679,7 @@ ssize_t efa_rdm_rma_inject_writedata(struct fid_ep *ep, const void *buf, size_t
int err;

efa_rdm_ep = container_of(ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid.fid);
assert(len <= efa_rdm_ep->inject_size);
assert(len <= efa_rdm_ep->inject_rma_size);
err = efa_rdm_ep_cap_check_rma(efa_rdm_ep);
if (err)
return err;
Expand Down
10 changes: 5 additions & 5 deletions prov/efa/test/efa_unit_test_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ static void test_efa_rdm_ep_use_zcpy_rx_impl(struct efa_resource *resource,
struct efa_domain *efa_domain;
struct efa_rdm_ep *ep;
size_t max_msg_size = 1000;
size_t inject_size = 0;
size_t inject_rma_size = 0;
bool shm_permitted = false;

efa_unit_test_resource_construct_with_hints(resource, FI_EP_RDM, FI_VERSION(1, 14),
Expand Down Expand Up @@ -967,12 +967,12 @@ static void test_efa_rdm_ep_use_zcpy_rx_impl(struct efa_resource *resource,

assert_true(ep->use_zcpy_rx == expected_use_zcpy_rx);
assert_int_equal(fi_getopt(&resource->ep->fid, FI_OPT_ENDPOINT, FI_OPT_INJECT_RMA_SIZE,
&inject_size, &(size_t){sizeof inject_size}), 0);
assert_int_equal(ep->inject_size, inject_size);
&inject_rma_size, &(size_t){sizeof inject_rma_size}), 0);
assert_int_equal(ep->inject_rma_size, inject_rma_size);
if (expected_use_zcpy_rx)
assert_int_equal(inject_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size);
assert_int_equal(inject_rma_size, efa_rdm_ep_domain(ep)->device->efa_attr.inline_buf_size);
else
assert_int_equal(inject_size, resource->info->tx_attr->inject_size);
assert_int_equal(inject_rma_size, resource->info->tx_attr->inject_size);
}

/**
Expand Down