Skip to content
Open
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
186 changes: 185 additions & 1 deletion src/ucp/core/ucp_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ __KHASH_IMPL(ucp_ep_peer_mem_hash, kh_inline, uint64_t,
ucp_ep_peer_mem_data_t, 1,
kh_int64_hash_func, kh_int64_hash_equal);

#define UCP_EP_FENCE_PROGRESS_BATCH 16

typedef struct {
double reg_growth;
double reg_overhead;
Expand Down Expand Up @@ -278,8 +280,12 @@ static ucp_ep_h ucp_ep_allocate(ucp_worker_h worker, const char *peer_name)
ep->ext->unflushed_lanes = 0;
ep->ext->lane_generation = 0;
ep->ext->fence_seq = 0;
ep->ext->fence_inflight_req = NULL;
ep->ext->fence_status = UCS_OK;
ep->ext->fence_pending_scheduled = 0;
ep->ext->uct_eps = NULL;
ep->ext->flush_sys_dev_map = 0;
ucs_queue_head_init(&ep->ext->fence_pending_q);

UCS_STATIC_ASSERT(sizeof(ep->ext->ep_match) >=
sizeof(ep->ext->flush_state));
Expand Down Expand Up @@ -522,13 +528,188 @@ static int ucp_ep_wireup_eps_progress_filter(const ucs_callbackq_elem_t *elem,
return (elem->cb == ucp_wireup_eps_progress) && (elem->arg == arg);
}

static UCS_F_ALWAYS_INLINE ucs_queue_elem_t*
ucp_ep_fence_req_elem(uct_pending_req_t *uct_req)
{
ucp_request_t *req = ucs_container_of(uct_req, ucp_request_t, send.uct);

return &req->send.fence_pending_elem;
}

static unsigned ucp_ep_fence_pending_progress(void *arg);

static int
ucp_ep_fence_pending_progress_filter(const ucs_callbackq_elem_t *elem,
void *arg)
{
return (elem->cb == ucp_ep_fence_pending_progress) && (elem->arg == arg);
}

static UCS_F_ALWAYS_INLINE void ucp_ep_fence_pending_schedule(ucp_ep_h ep)
{
if (ep->ext->fence_pending_scheduled) {
return;
}

ep->ext->fence_pending_scheduled = 1;
ucs_callbackq_add_oneshot(&ep->worker->uct->progress_q, ep,
ucp_ep_fence_pending_progress, ep);
ucp_worker_signal_internal(ep->worker);
}

void ucp_ep_fence_pending_resume(ucp_ep_h ep)
{
if (!ucs_queue_is_empty(&ep->ext->fence_pending_q)) {
ucp_ep_fence_pending_schedule(ep);
}
}

void ucp_ep_fence_pending_add(ucp_ep_h ep, uct_pending_req_t *uct_req)
{
ucs_queue_head_t *queue = &ep->ext->fence_pending_q;
ucp_request_t *new_req =
ucs_container_of(uct_req, ucp_request_t, send.uct);
ucs_queue_elem_t *elem = ucp_ep_fence_req_elem(uct_req);
ucs_queue_iter_t iter;
ucp_request_t *queued_req;

for (iter = ucs_queue_iter_begin(queue);
!ucs_queue_iter_end(queue, iter);
iter = ucs_queue_iter_next(iter)) {
queued_req = ucs_container_of(*iter, ucp_request_t,
send.fence_pending_elem);
if (queued_req->send.fence_seq > new_req->send.fence_seq) {
elem->next = *iter;
*iter = elem;
ucp_ep_fence_pending_schedule(ep);
return;
}
}

ucs_queue_push(queue, elem);
ucp_ep_fence_pending_schedule(ep);
}

void ucp_ep_fence_pending_purge(ucp_ep_h ep, ucs_status_t status)
{
ucp_request_t *req;

ucs_queue_for_each_extract(req, &ep->ext->fence_pending_q,
send.fence_pending_elem, 1) {
req->flags &= ~UCP_REQUEST_FLAG_FENCE_BLOCKED;
if (req->flags & UCP_REQUEST_FLAG_PROTO_SEND) {
ucp_proto_request_abort(req, status);
} else {
ucp_request_send_state_ff(req, status);
}
}
}

static UCS_F_ALWAYS_INLINE int
ucp_ep_fence_try_advance_epoch(ucp_ep_h ep, uint64_t fence_seq)
{
ucs_status_t status;

status = ucp_ep_fence_strong_nb(ep, fence_seq);
if (ucs_unlikely(status != UCS_OK)) {
ucp_ep_fence_pending_purge(ep, status);
return 0;
}

if (ucs_unlikely(ep->ext->fence_inflight_req == NULL)) {
return ep->ext->fence_status == UCS_OK;
}

return 0;
}

static int ucp_ep_fence_dispatch_request(ucp_ep_h ep)
{
ucp_ep_ext_t *ep_ext = ep->ext;
ucp_request_t *req;
ucs_status_t status;
int is_proto;
int batch;

req = ucs_queue_pull_elem_non_empty(&ep_ext->fence_pending_q,
ucp_request_t,
send.fence_pending_elem);

is_proto = req->flags & UCP_REQUEST_FLAG_PROTO_SEND;
req->flags &= ~UCP_REQUEST_FLAG_FENCE_BLOCKED;

for (batch = 0; batch < UCP_EP_FENCE_PROGRESS_BATCH; ++batch) {
/* coverity[address_free] */
status = req->send.uct.func(&req->send.uct);
if (status != UCS_INPROGRESS) {
break;
}
}

if ((status == UCS_INPROGRESS) ||
(status == UCS_ERR_NO_RESOURCE) ||
(status == UCP_STATUS_FENCE_DEFER)) {
req->flags |= UCP_REQUEST_FLAG_FENCE_BLOCKED;
ucs_queue_push_head(&ep_ext->fence_pending_q,
&req->send.fence_pending_elem);
if (ep_ext->fence_inflight_req == NULL) {
ucp_ep_fence_pending_schedule(ep);
}
return 0;
}

if (ucs_unlikely((status != UCS_OK) && UCS_STATUS_IS_ERR(status))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: (status != UCS_OK) && UCS_STATUS_IS_ERR(status) is redundant since UCS_OK == 0 can never satisfy UCS_STATUS_IS_ERR(). Suggestion:

Suggested change
if (ucs_unlikely((status != UCS_OK) && UCS_STATUS_IS_ERR(status))) {
if (ucs_unlikely(UCS_STATUS_IS_ERR(status))) {

if (is_proto) {
ucp_proto_request_abort(req, status);
} else {
ucp_request_send_state_ff(req, status);
}
} else {
ucs_assert(status == UCS_OK);
}

return 1;
}

static unsigned ucp_ep_fence_pending_progress(void *arg)
{
ucp_ep_h ep = arg;
ucp_ep_ext_t *ep_ext = ep->ext;
ucp_request_t *req;

ep_ext->fence_pending_scheduled = 0;

while (!ucs_queue_is_empty(&ep_ext->fence_pending_q)) {
if (ucs_unlikely(ep_ext->fence_inflight_req != NULL)) {
break;
}

req = ucs_queue_head_elem_non_empty(&ep_ext->fence_pending_q,
ucp_request_t,
send.fence_pending_elem);
if (ucs_unlikely(req->send.fence_seq > ep_ext->fence_seq)) {
if (!ucp_ep_fence_try_advance_epoch(ep,
req->send.fence_seq)) {
break;
}
}

if (!ucp_ep_fence_dispatch_request(ep)) {
break;
}
}

return 0;
}

static int ucp_ep_remove_filter(const ucs_callbackq_elem_t *elem, void *arg)
{
if (ucp_wireup_msg_ack_cb_pred(elem, arg) ||
ucp_listener_accept_cb_remove_filter(elem, arg) ||
ucp_ep_local_disconnect_progress_remove_filter(elem, arg) ||
ucp_ep_set_failed_remove_filter(elem, arg) ||
ucp_ep_wireup_eps_progress_filter(elem, arg)) {
ucp_ep_wireup_eps_progress_filter(elem, arg) ||
ucp_ep_fence_pending_progress_filter(elem, arg)) {
return 1;
}

Expand All @@ -546,6 +727,7 @@ void ucp_ep_destroy_base(ucp_ep_h ep)
ucp_ep_refcount_assert(ep, discard, ==, 0);
ucp_ep_refcount_assert(ep, probe, ==, 0);
ucs_assert(ucs_hlist_is_empty(&ep->ext->proto_reqs));
ucs_assert(ucs_queue_is_empty(&ep->ext->fence_pending_q));

if (!(ep->flags & UCP_EP_FLAG_INTERNAL)) {
ucs_assert(worker->num_all_eps > 0);
Expand Down Expand Up @@ -5251,6 +5433,8 @@ void ucp_ep_reqs_purge(ucp_ep_h ucp_ep, ucs_status_t status)
ucp_ep_flush_state_t *flush_state;
ucp_request_t *req;

ucp_ep_fence_pending_purge(ucp_ep, status);

while (!ucs_hlist_is_empty(proto_reqs)) {
req = ucs_hlist_head_elem(proto_reqs, ucp_request_t, send.list);
if (ucp_ep->worker->context->config.ext.proto_enable) {
Expand Down
8 changes: 8 additions & 0 deletions src/ucp/core/ucp_ep.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ typedef struct ucp_ep_ext {
uint64_t fence_seq; /* Sequence number for fence
detection */

ucs_queue_head_t fence_pending_q; /* Fence-blocked requests */
ucp_request_t *fence_inflight_req; /* Active fence flush */
ucs_status_t fence_status; /* Current/last flush status */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: fence_status looks redundant (effectively write-only) - its only read (fence_status == UCS_OK in ucp_ep_fence_try_advance_epoch()) is reachable only right after a synchronous completion where it is always UCS_OK; dropping it would also shrink ucp_ep_ext_t.

uint8_t fence_pending_scheduled; /* Progress armed */

/**
* UCT endpoints for every slow-path lane that has no room in the base endpoint
* structure. TODO allocate this array dynamically.
Expand Down Expand Up @@ -1012,6 +1017,9 @@ void ucp_ep_req_purge(ucp_ep_h ucp_ep, ucp_request_t *req,
*/
void ucp_ep_reqs_purge(ucp_ep_h ucp_ep, ucs_status_t status);

void ucp_ep_fence_pending_add(ucp_ep_h ep, uct_pending_req_t *req);
void ucp_ep_fence_pending_purge(ucp_ep_h ep, ucs_status_t status);
void ucp_ep_fence_pending_resume(ucp_ep_h ep);

/**
* @brief Query local and/or remote socket address of endpoint @a ucp_ep.
Expand Down
55 changes: 38 additions & 17 deletions src/ucp/core/ucp_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#define ucp_trace_req(_sreq, _message, ...) \
ucs_trace_req("req %p: " _message, (_sreq), ## __VA_ARGS__)

#define UCP_STATUS_FENCE_DEFER ((ucs_status_t)(UCS_ERR_LAST + 1))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

UCP_STATUS_FENCE_DEFER (UCS_ERR_LAST + 1 = -99) is inside the ucs_status_t error range, so UCS_STATUS_IS_ERR() treats it as a real error and ucs_status_string() cannot name it; if a deferring progress function is reached from ucp_request_try_send() (the regular RMA/AMO send path) or from a UCT pending callback we get ucs_fatal("unexpected error"). Can we use a request flag or an explicit out-param instead of a fake status?

#ifdef __cplusplus
static_assert((UCP_STATUS_FENCE_DEFER < UCS_OK) &&
(UCP_STATUS_FENCE_DEFER >= UCS_ERR_LAST),
"fence defer status must be an error pointer");
#else
_Static_assert((UCP_STATUS_FENCE_DEFER < UCS_OK) &&
(UCP_STATUS_FENCE_DEFER >= UCS_ERR_LAST),
"fence defer status must be an error pointer");
#endif

/**
* Request flags
Expand Down Expand Up @@ -69,7 +79,8 @@ enum {
UCP_REQUEST_FLAG_RNDV_SEND_INTERNAL = UCS_BIT(26),
UCP_REQUEST_FLAG_RNDV_GET_REQ = UCS_BIT(27),
UCP_REQUEST_FLAG_RNDV_FLUSH = UCS_BIT(28),
UCP_REQUEST_FLAG_RNDV_START_FLUSH = UCS_BIT(29)
UCP_REQUEST_FLAG_RNDV_START_FLUSH = UCS_BIT(29),
UCP_REQUEST_FLAG_FENCE_BLOCKED = UCS_BIT(30)
};


Expand Down Expand Up @@ -250,14 +261,31 @@ struct ucp_request {
} msg_proto;

struct {
uint64_t remote_addr; /* Remote address */
ucp_rkey_h rkey; /* Remote memory key */
/* Fence state shared by RMA and atomic send requests. */
uint64_t fence_seq;
ucs_queue_elem_t fence_pending_elem;

union {
struct {
uint64_t remote_addr; /* Remote address */
ucp_rkey_h rkey; /* Remote memory key */

struct {
const uint64_t *remote_addrs;
ucp_rkey_h const *rkeys;
} sgl;
} rma;

struct {
const uint64_t *remote_addrs;
ucp_rkey_h const *rkeys;
} sgl;
} rma;
struct {
uint64_t remote_addr; /* Remote address */
ucp_rkey_h rkey; /* Remote memory key */
uint64_t value; /* Atomic argument */
uint64_t result; /* Atomic result */
void *reply_buffer;
uct_atomic_op_t uct_op; /* Requested UCT AMO */
} amo;
};
};

struct {
/* Remote request ID received from a peer */
Expand Down Expand Up @@ -367,6 +395,8 @@ struct ucp_request {
} rkey_ptr;

struct {
/* Fence epoch advanced by this flush */
uint64_t fence_seq;
/* Snapshot of live lanes on the endpoint */
ucp_lane_map_t all_lanes;
/* Which lanes flush has been started on */
Expand Down Expand Up @@ -411,15 +441,6 @@ struct ucp_request {
ucp_rsc_index_t rsc_index;
} discard_uct_ep;

struct {
uint64_t remote_addr; /* Remote address */
ucp_rkey_h rkey; /* Remote memory key */
uint64_t value; /* Atomic argument */
uint64_t result; /* Atomic result */
void *reply_buffer;
uct_atomic_op_t uct_op; /* Requested UCT AMO */
} amo;

struct {
ucs_queue_elem_t queue; /* Elem in outgoing ssend reqs queue */
ucp_tag_t ssend_tag; /* Tag in offload sync send */
Expand Down
Loading
Loading