Skip to content

UCP/PROTO: Update EP config on SPEED_CHANGE events - #11056

Merged
brminich merged 15 commits into
openucx:masterfrom
iyastreb:ucp-dflow-lb-multi-proto-weights
Feb 3, 2026
Merged

brminich merged 15 commits into
openucx:masterfrom
iyastreb:ucp-dflow-lb-multi-proto-weights

Conversation

@iyastreb

@iyastreb iyastreb commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor

What?

UCP part of the Load Balancer based on PORT_SPEED IB events.
The central ideas of the load balancing:

  1. Measure actual iface bandwidth using perf_estimate, and quantize the actual/maximum BW into 4 bits value
  2. Lazily update EP config and rkey on the first post request after PORT_SPEED event happens
  3. port_speed is a part of EP config key, so new EP config and rkey config are created on PORT_SPEED change

Unit tests will be added in the subsequent PR

@iyastreb
iyastreb force-pushed the ucp-dflow-lb-multi-proto-weights branch from bd347ae to 46b2b15 Compare December 17, 2025 12:23
@iyastreb
iyastreb force-pushed the ucp-dflow-lb-multi-proto-weights branch 3 times, most recently from de34887 to de4ba58 Compare January 8, 2026 16:16
@iyastreb
iyastreb marked this pull request as ready for review January 8, 2026 16:23
@iyastreb iyastreb changed the title UCP/PROTO: Adapt multi-proto weights on SPEED_CHANGE events UCP/PROTO: Update EP config on SPEED_CHANGE events Jan 8, 2026
@iyastreb
iyastreb force-pushed the ucp-dflow-lb-multi-proto-weights branch from de4ba58 to 11a8850 Compare January 9, 2026 15:25
Comment thread src/ucp/core/ucp_ep.h Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/proto/proto_select.h Resolved
Comment thread src/ucp/proto/proto_select.inl Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
@iyastreb
iyastreb force-pushed the ucp-dflow-lb-multi-proto-weights branch from 2b5ddb9 to 86439b9 Compare January 13, 2026 08:43

@evgeny-leksikov evgeny-leksikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM besides couple minor comments

Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_worker.h Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_worker.c Outdated
wiface->flags |= UCP_WORKER_IFACE_FLAG_PENDING_UPDATE;
if (worker->dflow_cb_id == UCS_CALLBACKQ_ID_NULL) {
uct_worker_progress_register_safe(
worker->uct, ucp_worker_iface_handle_port_speed_progress, worker, 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we provide wiface as a parameter instead of a worker? You would not need to check every iface then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The comment above explains the rationale.
I intentionally want to handle all affected ifaces at once to avoid creating "intermediate ep configs/rkey configs". Otherwise we could just handle this event per iface right here, without calling async callback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

imo it is overkill. I'd handle just one iface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can do that.
There is just a small risk that we may create intermediate ep_config/rkey config that will be wasted

@iyastreb iyastreb Jan 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

redesigned to handle this event synchronously

Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_worker.h Resolved
Comment thread src/ucp/rma/rma_send.c Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_worker.c Resolved
Comment thread src/ucp/core/ucp_worker.c
Comment on lines +803 to +805
if (status != UCS_OK) {
return 0;
}

@shasson5 shasson5 Jan 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe return ucs_status to indicate error? or check if result is 0 after returning to caller context

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@evgeny-leksikov what will be the behavior if 0 is returned? Is it desired?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good question - AFAIU all lanes from this iface will be disqualified from protocol by perf, not by failure. And the only correct way to recover them later is new perf event on the iface. IMO better dont do this and allow lanes to fail if iface is not working. In this case, lanes will be marker as failed by failover flow and recoverable when iface is back to working state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so I keep it as is for now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok, could you pls add TODO summarized my comment above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure

Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_ep.c Resolved
Comment thread src/ucp/core/ucp_worker.h Resolved
Comment thread src/ucp/core/ucp_ep.h Resolved
Comment thread src/ucp/core/ucp_ep.c Outdated
cfg_key.lanes[lane].port_speed = wiface->port_speed;
}

if (ucp_ep_config_is_equal(&cfg_key, &ucp_ep_config(ep)->key)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we have some tests for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can add another test (in addition to #11109) to cover a use case when config remains the same after update (if that was your suggestion)

Comment thread src/ucp/core/ucp_worker.h
* Incremented after major connectivity changes (e.g. lane failure, port
* speed change). A matching epoch is stored in @ref ucp_proto_select_t.
* If epochs differ, the cached config is stale and must be updated. */
uint64_t epoch;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe put these 2 in a dedicated struct? Like in similar places above..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the epoch also will be used for FT... btw, I would avoid "dflow/DF/etc" usage in code, it's something too generic for handling of "speed change" event.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree, "DF" semantics is weird in this context..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so what's the final proposal on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed dflow_cb_id entirely

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess, without scheduling handler on async progress async block assertion will fail for UD since it has ASYNC_CB capability

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This shouldn't be the case, because we propagate PORT_SPEED event from the UCT level via progress queue, for any IB ifaces:

static void
uct_ib_device_async_event_schedule_callback(uct_ib_device_t *dev,
                                            uct_ib_async_event_wait_t *wait_ctx)
{
    ucs_assert(ucs_spinlock_is_held(&dev->async_event_lock));
    ucs_assert(wait_ctx->cb_id == UCS_CALLBACKQ_ID_NULL);
    wait_ctx->cb_id = ucs_callbackq_add_safe(wait_ctx->cbq, wait_ctx->cb,
                                             wait_ctx);
}

Comment thread src/ucp/core/ucp_worker.c Outdated
++progress_count;
}
wiface_iter = worker->ifaces[iface_id];
if (wiface_iter->rsc_index != wiface->rsc_index) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think the intent was to check dev_index, as rsc_index represents iface, so different ifaces created on the same device will have different rsc_idx

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, let me fix that

@brminich
brminich merged commit 7fb0b91 into openucx:master Feb 3, 2026
146 checks passed
@iyastreb
iyastreb deleted the ucp-dflow-lb-multi-proto-weights branch February 3, 2026 15:07
Comment thread src/ucp/core/ucp_ep.c
key->lanes[i].dst_sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN;
key->lanes[i].path_index = 0;
key->lanes[i].lane_types = 0;
key->lanes[i].port_speed = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

port_speed name is too HW-specific

Comment thread src/ucp/core/ucp_ep.c
}
}

static ucs_status_t ucp_rkey_update_config(ucp_rkey_h rkey, ucp_ep_h ep)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pls add doc to this function

Comment thread src/ucp/core/ucp_ep.c
}

/* Now rkey config is up to date with worker epoch */
rkey_cfg = ucp_rkey_config(worker, rkey);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe use new var - new_rkey_cfg

Comment thread src/ucp/core/ucp_ep.c

/* Now rkey config is up to date with worker epoch */
rkey_cfg = ucp_rkey_config(worker, rkey);
rkey_cfg->proto_select.worker_epoch = worker->epoch;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is worker->epoch is for ep configurations?
so rename it to worker->ep_config_epoch or worker->ep_config_sn

Comment thread src/ucp/core/ucp_ep.c
return status;
}

if (old_cfg_index != ep->cfg_index) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems better not have ucp_rkey_update_config as separate function and just put its code here
the names "ucp_rkey_update_config" and "ucp_ep_update_rkey_config" very similar and confusing

Comment thread src/ucp/core/ucp_worker.c
Comment on lines +810 to +813
ratio = perf_attr.bandwidth.shared / wiface->attr.bandwidth.shared;
ratio = ucs_min(ucs_max(ratio, 0.0), 0.99);
/* 4 bits range [0, 15] */
return (uint8_t)(ratio * 16.0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. need to document in the field declaration how BW is represented
  2. can simplify the calculation?
  3. why counting only "shared" and not "dedicated" ?

Comment thread src/ucp/core/ucp_worker.c
return (uint8_t)(ratio * 16.0);
}

static void ucp_worker_iface_handle_port_speed_event(ucp_worker_iface_t *wiface)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

port_speed is too hw specific

Comment thread src/ucp/core/ucp_worker.c
UCP_WIFACE_ARG(wiface_iter), wiface_iter->port_speed,
port_speed);
wiface_iter->port_speed = port_speed;
++progress_count;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rename progress_count -> bw_changed / is_changed

ucs_status_t status;

proto_select = &ucp_rkey_config(worker, rkey)->proto_select;
if (ucs_unlikely(proto_select->worker_epoch != worker->epoch)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. why only for RMA?
  2. can we do this from slow path of protocol selection - in the part that does hash lookup?

}

ucp_proto_select_cache_reset(proto_select);
proto_select->worker_epoch = epoch;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in all places rename "epoch" to "ep_config_epoch" / ep_config_sn or similar. to show the epoch / sn are of the ep configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants