Skip to content
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
4 changes: 2 additions & 2 deletions src/ucp/core/ucp_rkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,8 @@ void ucp_rkey_proto_select_dump(ucp_worker_h worker,
ucp_worker_cfg_index_t rkey_cfg_index,
ucs_string_buffer_t *strb)
{
const ucp_rkey_config_t *rkey_config = &ucs_array_elem(&worker->rkey_config,
rkey_cfg_index);
const ucp_rkey_config_t *rkey_config =
ucp_worker_rkey_config(worker, rkey_cfg_index);

ucp_proto_select_dump_short(&rkey_config->put_short, "put_short", strb);
ucp_proto_select_info(worker, rkey_config->key.ep_cfg_index, rkey_cfg_index,
Expand Down
14 changes: 12 additions & 2 deletions src/ucp/core/ucp_rkey.inl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ ucp_rkey_config_is_equal(ucp_rkey_config_key_t rkey_config_key1,
rkey_config_key2.unreachable_md_map);
}

/**
* @return remote key configuration by configuration index
*/
static inline ucp_rkey_config_t *

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls use UCS_F_ALWAYS_INLINE, since ucp_rkey_config() is on the RMA short path (ucp_put_send_short, amo_send).

Suggested change
static inline ucp_rkey_config_t *
static UCS_F_ALWAYS_INLINE ucp_rkey_config_t *
ucp_worker_rkey_config(ucp_worker_h worker, ucp_worker_cfg_index_t cfg_index)

ucp_worker_rkey_config(ucp_worker_h worker,
ucp_worker_cfg_index_t cfg_index)
{
ucs_assert(cfg_index != UCP_WORKER_CFG_INDEX_NULL);
return ucs_array_elem(&worker->rkey_config, cfg_index);
}

static UCS_F_ALWAYS_INLINE ucp_rkey_config_t *
ucp_rkey_config(ucp_worker_h worker, ucp_rkey_h rkey)
{
ucs_assert(rkey->cfg_index != UCP_WORKER_CFG_INDEX_NULL);
return &ucs_array_elem(&worker->rkey_config, rkey->cfg_index);
return ucp_worker_rkey_config(worker, rkey->cfg_index);
}

static UCS_F_ALWAYS_INLINE uct_rkey_t
Expand Down
49 changes: 29 additions & 20 deletions src/ucp/core/ucp_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -2291,9 +2291,8 @@ ucs_status_t ucp_worker_get_ep_config(ucp_worker_h worker,
return UCS_OK;
}

static void
ucp_worker_dump_rkey_config_key(ucs_string_buffer_t *log_strb,
ucp_rkey_config_key_t *key)
static void ucp_worker_dump_rkey_config_key(ucs_string_buffer_t *log_strb,
const ucp_rkey_config_key_t *key)
{
ucs_string_buffer_appendf(
log_strb,
Expand All @@ -2312,6 +2311,8 @@ ucp_worker_add_rkey_config(ucp_worker_h worker,
const ucp_ep_config_t *ep_config = &ucs_array_elem(&worker->ep_config,
key->ep_cfg_index);
ucp_worker_cfg_index_t rkey_cfg_index;
ucp_rkey_config_t **rkey_config_p;
unsigned dump_idx;
ucp_rkey_config_t *rkey_config;
ucp_lane_index_t lane;
ucs_status_t status;
Expand All @@ -2330,15 +2331,14 @@ ucp_worker_add_rkey_config(ucp_worker_h worker,
/* Dump all rkey config keys */
ucs_string_buffer_init(&log_strb);

ucs_array_for_each(rkey_config, &worker->rkey_config) {
ucs_string_buffer_appendf(
&log_strb, "rkey [%ld]: ",
rkey_config - ucs_array_begin(&worker->rkey_config));
ucp_worker_dump_rkey_config_key(&log_strb, &rkey_config->key);
ucs_array_for_each_index(rkey_config_p, dump_idx,
&worker->rkey_config) {
ucs_string_buffer_appendf(&log_strb, "rkey [%u]: ", dump_idx);
ucp_worker_dump_rkey_config_key(&log_strb, &(*rkey_config_p)->key);
}

ucs_string_buffer_appendf(&log_strb, "rkey key new: ");
ucp_worker_dump_rkey_config_key(&log_strb, &rkey_config->key);
ucp_worker_dump_rkey_config_key(&log_strb, key);

ucs_debug("%s", ucs_string_buffer_cstr(&log_strb));
ucs_string_buffer_cleanup(&log_strb);
Expand All @@ -2351,11 +2351,12 @@ ucp_worker_add_rkey_config(ucp_worker_h worker,
(lanes_distance != NULL));

/* Initialize rkey configuration */
rkey_cfg_index = ucs_array_length(&worker->rkey_config);
rkey_config = ucp_worker_config_array_append(
worker, &worker->rkey_config,
status = UCS_ERR_NO_MEMORY;
goto err;);
rkey_cfg_index = ucs_array_length(&worker->rkey_config);
rkey_config = ucs_malloc(sizeof(*rkey_config), "rkey_config");
if (rkey_config == NULL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls log the allocation failure, like the other allocations in this file (ucs_error("failed to allocate worker ifaces") etc.); previously ucs_array_grow() printed it for us.

Suggested change
if (rkey_config == NULL) {
rkey_config = ucs_malloc(sizeof(*rkey_config), "rkey_config");
if (rkey_config == NULL) {
ucs_error("failed to allocate rkey configuration");
status = UCS_ERR_NO_MEMORY;
goto err;
}

status = UCS_ERR_NO_MEMORY;
goto err;
}

rkey_config->key = *key;

Expand All @@ -2371,6 +2372,11 @@ ucp_worker_add_rkey_config(ucp_worker_h worker,
sizeof(buf)));
}

rkey_config_p = ucp_worker_config_array_append(worker, &worker->rkey_config,
status = UCS_ERR_NO_MEMORY;
goto err_free_rkey_config;);
*rkey_config_p = rkey_config;

/* Save key-to-index lookup */
khiter = kh_put(ucp_worker_rkey_config, &worker->rkey_config_hash, *key,
&khret);
Expand Down Expand Up @@ -2407,6 +2413,8 @@ ucp_worker_add_rkey_config(ucp_worker_h worker,
kh_del(ucp_worker_rkey_config, &worker->rkey_config_hash, khiter);
err_pop_rkey_config:
ucs_array_pop_back(&worker->rkey_config);
err_free_rkey_config:
ucs_free(rkey_config);
err:
return status;
}
Expand All @@ -2425,29 +2433,30 @@ static void ucp_worker_keepalive_reset(ucp_worker_h worker)
static void ucp_worker_trace_configs(ucp_worker_h worker)
{
ucp_ep_config_t *ep_config;
ucp_rkey_config_t *rkey_config;
ucp_rkey_config_t **rkey_config_p;

ucs_array_for_each(ep_config, &worker->ep_config) {
ucp_proto_select_trace(worker, &ep_config->proto_select);
}

ucs_array_for_each(rkey_config, &worker->rkey_config) {
ucp_proto_select_trace(worker, &rkey_config->proto_select);
ucs_array_for_each(rkey_config_p, &worker->rkey_config) {
ucp_proto_select_trace(worker, &(*rkey_config_p)->proto_select);
}
}

static void ucp_worker_destroy_configs(ucp_worker_h worker)
{
ucp_ep_config_t *ep_config;
ucp_rkey_config_t *rkey_config;
ucp_rkey_config_t **rkey_config_p;

ucs_array_for_each(ep_config, &worker->ep_config) {
ucp_ep_config_cleanup(worker, ep_config);
}
ucs_array_cleanup_dynamic(&worker->ep_config);

ucs_array_for_each(rkey_config, &worker->rkey_config) {
ucp_proto_select_cleanup(&rkey_config->proto_select);
ucs_array_for_each(rkey_config_p, &worker->rkey_config) {
ucp_proto_select_cleanup(&(*rkey_config_p)->proto_select);
ucs_free(*rkey_config_p);
}
ucs_array_cleanup_dynamic(&worker->rkey_config);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ucp/core/ucp_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ UCS_PTR_MAP_TYPE(ep, 1);
UCS_PTR_MAP_TYPE(request, 0);

/* rkey configuration storage */
UCS_ARRAY_DECLARE_TYPE(ucp_rkey_config_arr_t, unsigned, ucp_rkey_config_t);
UCS_ARRAY_DECLARE_TYPE(ucp_rkey_config_arr_t, unsigned, ucp_rkey_config_t*);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this adds an extra pointer dereference to ucp_rkey_config() in the put_short/amo fast path; did you check there is no message-rate impact?



/**
Expand Down
4 changes: 2 additions & 2 deletions src/ucp/proto/proto_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ ucp_proto_common_get_lane_perf(const ucp_proto_common_init_params_t *params,

/* For remote memory access, consider remote system topology distance */
if (params->flags & UCP_PROTO_COMMON_INIT_FLAG_REMOTE_ACCESS) {
rkey_config = &ucs_array_elem(&worker->rkey_config,
params->super.rkey_cfg_index);
rkey_config = ucp_worker_rkey_config(worker,
params->super.rkey_cfg_index);
distance = rkey_config->lanes_distance[lane];
ucp_proto_common_update_lane_perf_by_distance(
tl_perf, &distance, "remote system", "sys-dev %d %s",
Expand Down
4 changes: 2 additions & 2 deletions src/ucp/proto/proto_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "proto_select.inl"

#include <ucp/am/ucp_am.inl>
#include <ucp/core/ucp_rkey.inl>
#include <ucp/rndv/proto_rndv.h>
#include <ucs/arch/atomic.h>
#include <ucs/debug/table.h>
Expand Down Expand Up @@ -486,8 +487,7 @@ void ucp_proto_select_info_str(ucp_worker_h worker,
}

ucp_rkey_config_dump_brief(
&ucs_array_elem(&worker->rkey_config, rkey_cfg_index).key,
strb);
&ucp_worker_rkey_config(worker, rkey_cfg_index)->key, strb);
}

if (ucp_proto_select_is_atomic_op(select_param)) {
Expand Down
8 changes: 3 additions & 5 deletions src/ucp/proto/proto_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ ucp_proto_select_init_protocols(ucp_worker_h worker,
init_params.rkey_config_key = NULL;
} else {
init_params.rkey_config_key =
&ucs_array_elem(&worker->rkey_config, rkey_cfg_index).key;
&ucp_worker_rkey_config(worker, rkey_cfg_index)->key;

/* rkey configuration must be for the same ep */
ucs_assertv_always(
Expand Down Expand Up @@ -937,8 +937,7 @@ ucp_proto_select_get(ucp_worker_h worker, ucp_worker_cfg_index_t ep_cfg_index,
*new_rkey_cfg_index = UCP_WORKER_CFG_INDEX_NULL;
return &ucs_array_elem(&worker->ep_config, ep_cfg_index).proto_select;
} else {
rkey_config_key =
ucs_array_elem(&worker->rkey_config, rkey_cfg_index).key;
rkey_config_key = ucp_worker_rkey_config(worker, rkey_cfg_index)->key;

rkey_config_key.ep_cfg_index = ep_cfg_index;
status = ucp_worker_rkey_config_get(worker, &rkey_config_key, NULL,
Expand All @@ -948,8 +947,7 @@ ucp_proto_select_get(ucp_worker_h worker, ucp_worker_cfg_index_t ep_cfg_index,
return NULL;
}

return &ucs_array_elem(&worker->rkey_config, *new_rkey_cfg_index)
.proto_select;
return &ucp_worker_rkey_config(worker, *new_rkey_cfg_index)->proto_select;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/ucp/proto/proto_select.inl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ ucp_proto_select_lookup(ucp_worker_h worker, ucp_proto_select_t *proto_select,
}
}

/* FIXME proto_select could get invalidated by adding rkey config */
proto_select->cache.key = key.u64;
proto_select->cache.value = select_elem;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ucp/rndv/proto_rndv.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static ucs_status_t ucp_proto_rndv_ctrl_select_remote_proto(
ucs_trace("rndv select remote protocols rkey_config->md_map=0x%" PRIx64,
rkey_config_key.md_map);

rkey_config = &ucs_array_elem(&worker->rkey_config, rkey_cfg_index);
rkey_config = ucp_worker_rkey_config(worker, rkey_cfg_index);
*remote_proto = ucp_proto_select_lookup_slow(worker,
&rkey_config->proto_select, 1,
ep_cfg_index, rkey_cfg_index,
Expand Down
7 changes: 4 additions & 3 deletions test/gtest/ucp/test_ucp_peer_failure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,13 +784,14 @@ class test_ucp_peer_failure_rndv_abort : public test_ucp_peer_failure {
static void setup_progress_mock(ucp_worker_h worker, ucs::mock &mock)
{
ucp_ep_config_t *ep_config;
ucp_rkey_config_t **rkey_config_p;

ucs_array_for_each(ep_config, &worker->ep_config) {
setup_progress_mock(ep_config->proto_select, mock);
}

ucp_rkey_config_t *rkey_config;
ucs_array_for_each(rkey_config, &worker->rkey_config) {
setup_progress_mock(rkey_config->proto_select, mock);
ucs_array_for_each(rkey_config_p, &worker->rkey_config) {
setup_progress_mock((*rkey_config_p)->proto_select, mock);
}
}

Expand Down
42 changes: 33 additions & 9 deletions test/gtest/ucp/test_ucp_proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class test_ucp_proto : public ucp_test {
static size_t count_rkey_configs_with_flag(ucp_worker_h worker,
uint8_t flag)
{
ucp_rkey_config_t **rkey_config_p;
size_t count = 0;
ucp_rkey_config_t *rkey_config;

ucs_array_for_each(rkey_config, &worker->rkey_config) {
count += !!(rkey_config->key.flags & flag);
ucs_array_for_each(rkey_config_p, &worker->rkey_config) {
count += !!((*rkey_config_p)->key.flags & flag);
}

return count;
Expand Down Expand Up @@ -176,7 +176,7 @@ class test_ucp_proto : public ucp_test {
return nullptr;
}
auto proto_select =
&ucs_array_elem(&worker()->rkey_config, rkey_cfg_index).proto_select;
&ucp_worker_rkey_config(worker(), rkey_cfg_index)->proto_select;

ucp_proto_select_param_init(
&select_param, UCP_OP_ID_RNDV_RECV, 0,
Expand Down Expand Up @@ -244,8 +244,8 @@ class test_ucp_proto : public ucp_test {
return nullptr;
}

proto_select = &ucs_array_elem(&worker()->rkey_config,
rkey_cfg_index).proto_select;
proto_select =
&ucp_worker_rkey_config(worker(), rkey_cfg_index)->proto_select;
ucp_proto_select_param_init(&select_param, UCP_OP_ID_RNDV_SEND, 0,
rndv_op_flag, UCP_DATATYPE_CONTIG,
&mem_info, 1);
Expand Down Expand Up @@ -343,7 +343,7 @@ class test_ucp_proto_rma_rndv : public test_ucp_proto {
return nullptr;
}
proto_select =
&ucs_array_elem(&worker()->rkey_config, rkey_cfg_index).proto_select;
&ucp_worker_rkey_config(worker(), rkey_cfg_index)->proto_select;
ucp_proto_select_param_init(&select_param, op_id, 0, 0,
UCP_DATATYPE_CONTIG, &mem_info, 1);
select_elem = ucp_proto_select_lookup_slow(
Expand Down Expand Up @@ -386,8 +386,9 @@ class test_ucp_proto_rma_rndv : public test_ucp_proto {
}

key.param = remote_proto_config->select_param;
proto_select = &ucs_array_elem(&worker()->rkey_config,
remote_proto_config->rkey_cfg_index).proto_select;
proto_select = &ucp_worker_rkey_config(
worker(), remote_proto_config->rkey_cfg_index)
->proto_select;
EXPECT_NE(kh_end(proto_select->hash),
kh_get(ucp_proto_select_hash, proto_select->hash, key.u64));
}
Expand Down Expand Up @@ -526,6 +527,29 @@ test_ucp_proto::create_rkey_config_key(ucp_md_map_t md_map)
return rkey_config_key;
}

UCS_TEST_P(test_ucp_proto, rkey_config_stable_after_growth)
{
ucp_rkey_config_key_t key = create_rkey_config_key(0);
ucp_worker_cfg_index_t first_index, cfg_index;
ucp_rkey_config_t **old_buffer;
ucp_rkey_config_t *first_config;

key.ep_cfg_index = sender().ep()->cfg_index;
ASSERT_UCS_OK(
ucp_worker_rkey_config_get(worker(), &key, NULL, &first_index));
first_config = ucp_worker_rkey_config(worker(), first_index);
old_buffer = ucs_array_begin(&worker()->rkey_config);

/* Grow past the initial reserve using the production path only */
for (key.md_map = 1; key.md_map <= 64; ++key.md_map) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the bound 64 silently depends on the ucs_array_reserve(&worker->rkey_config, 32) in ucp_worker_create(); can we derive it from the initial ucs_array_capacity(&worker()->rkey_config) so ASSERT_NE(old_buffer, ...) does not become a no-op if the reserve changes?

ASSERT_UCS_OK(
ucp_worker_rkey_config_get(worker(), &key, NULL, &cfg_index));
}

ASSERT_NE(old_buffer, ucs_array_begin(&worker()->rkey_config));
EXPECT_EQ(first_config, ucp_worker_rkey_config(worker(), first_index));
}

UCS_TEST_P(test_ucp_proto, dump_protocols) {
ucp_proto_select_param_t select_param;
ucs_string_buffer_t strb;
Expand Down
12 changes: 6 additions & 6 deletions test/gtest/ucp/test_ucp_proto_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ class test_ucp_proto_mock : public ucp_test, public mock_iface {
ucp_proto_select_key_t key,
ucp_worker_cfg_index_t rkey_cfg_index)
{
ucp_rkey_config_t *config = &ucs_array_elem(&e.worker()->rkey_config,
rkey_cfg_index);
ucp_rkey_config_t *config = ucp_worker_rkey_config(e.worker(),
rkey_cfg_index);
check_proto_select(e, config->proto_select, data_vec, key,
rkey_cfg_index);
}
Expand Down Expand Up @@ -1686,8 +1686,8 @@ class test_ucp_proto_mock_mtype_sys_dev : public test_ucp_proto_mock {
auto rkey_packed = rkey_pack(receiver(), memh);
auto rkey = rkey_unpack(sender().ep(), rkey_packed);
ucp_worker_cfg_index_t ep_cfg_index = ep_config_index(sender());
ucp_rkey_config_t *rkey_config = &ucs_array_elem(&worker->rkey_config,
rkey->cfg_index);
ucp_rkey_config_t *rkey_config =
ucp_worker_rkey_config(worker, rkey->cfg_index);
ucp_memory_info_t mem_info;
ucp_proto_select_param_t select_param;
const ucp_proto_select_elem_t *select_elem;
Expand Down Expand Up @@ -1840,7 +1840,7 @@ UCS_TEST_P(test_ucp_proto_mock_mtype_sys_dev,

ucp_worker_cfg_index_t ep_cfg_index = ep_config_index(sender());
const ucp_rkey_config_t *base_rkey_config =
&ucs_array_elem(&worker->rkey_config, rkey->cfg_index);
ucp_worker_rkey_config(worker, rkey->cfg_index);
const ucp_ep_config_t *ep_config = ucp_worker_ep_config(worker,
ep_cfg_index);
ucp_rkey_config_key_t rkey_config_key = base_rkey_config->key;
Expand All @@ -1867,7 +1867,7 @@ UCS_TEST_P(test_ucp_proto_mock_mtype_sys_dev,
ucp_proto_select_param_init(&select_param, UCP_OP_ID_RNDV_RECV, 0, 0,
UCP_DATATYPE_CONTIG, &mem_info, 1);

rkey_config = &ucs_array_elem(&worker->rkey_config, rkey_cfg_index);
rkey_config = ucp_worker_rkey_config(worker, rkey_cfg_index);
select_elem = ucp_proto_select_lookup_slow(worker,
&rkey_config->proto_select, 1,
ep_cfg_index, rkey_cfg_index,
Expand Down
Loading