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
21 changes: 11 additions & 10 deletions src/ucs/datastruct/mpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,10 @@ ucs_mpool_create(const char *name, size_t elem_size, size_t align_offset,
return UCS_OK;
}

static void __mpool_destroy(ucs_mpool_h mp, unsigned check_inuse)
static void __mpool_destroy(ucs_mpool_h mp)
{
ucs_mpool_chunk_t *chunk;

/* Sanity check - all elements should be put back to the mpool */
if (check_inuse) {
ucs_assertv(mp->num_elems_inuse == 0,
"destroying memory pool %s with %u used elements", mp->name,
mp->num_elems_inuse);
}

while (!ucs_queue_is_empty(&mp->chunks)) {
chunk = ucs_queue_pull_elem_non_empty(&mp->chunks, ucs_mpool_chunk_t, queue);
mp->chunk_free_cb(mp->mp_context, chunk);
Expand All @@ -161,12 +154,20 @@ static void __mpool_destroy(ucs_mpool_h mp, unsigned check_inuse)

void ucs_mpool_destroy(ucs_mpool_h mp)
{
__mpool_destroy(mp, 1);
ucs_mpool_check_empty(mp);
__mpool_destroy(mp);
}

void ucs_mpool_destroy_unchecked(ucs_mpool_h mp)
{
__mpool_destroy(mp, 0);
__mpool_destroy(mp);
}

void ucs_mpool_check_empty(ucs_mpool_h mp)
{
ucs_assertv(mp->num_elems_inuse == 0,
"destroying memory pool %s with %u used elements", mp->name,
mp->num_elems_inuse);
}

void *ucs_mpool_get(ucs_mpool_h mp)
Expand Down
5 changes: 5 additions & 0 deletions src/ucs/datastruct/mpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ ucs_mpool_create(const char *name, size_t elem_size, size_t align_offset,
void ucs_mpool_destroy(ucs_mpool_h mp);
void ucs_mpool_destroy_unchecked(ucs_mpool_h mp);

/**
* Check that memory pool is empty. Also called from ucs_mpool_destroy().
*/
void ucs_mpool_check_empty(ucs_mpool_h mp);

/**
* Get an element from the memory pool.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/uct/api/tl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef struct uct_iface_ops {

void (*iface_close)(uct_iface_h iface);

void (*iface_release_desc)(uct_iface_h iface, void *desc);

ucs_status_t (*ep_create)(uct_iface_h iface, uct_ep_h *ep_p);
void (*ep_destroy)(uct_ep_h ep);

Expand Down
5 changes: 5 additions & 0 deletions src/uct/api/uct.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ UCT_INLINE_API void uct_iface_close(uct_iface_h iface)
iface->ops.iface_close(iface);
}

UCT_INLINE_API void uct_iface_release_desc(uct_iface_h iface, void *desc)

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.

this is new public API that has to be documented (brief documentation)

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, the assumption here that the descriptor is not released automatically after the callback ? So we have to add the explicit call ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

re documentation - i have another commit in the queue which fixes it

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 there was a discussion to control the release through return code of the callback?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes - if the callback returns UCS_INPROGRESS , it will be owned by user

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.

so in order to release user has to cache both Iface and descriptor pair. Can we just use desc ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

then desc mighl have to cache iface..

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.

yeah….I'm not sure what is the right answer

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 spent some time thinking about it. I think, I prefer not to cache it on the descriptor.

{
iface->ops.iface_release_desc(iface, desc);
}

UCT_INLINE_API ucs_status_t uct_ep_create(uct_iface_h iface, uct_ep_h *ep_p)
{
return iface->ops.ep_create(iface, ep_p);
Expand Down
5 changes: 5 additions & 0 deletions src/uct/api/uct_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ typedef void (*uct_rkey_release_func_t)(uct_context_h context, uct_rkey_t rkey);
/**
* Callback to process incoming active message
*
* When the callback is called, `desc' does not necessarily contain the payload.
* In this case, `data' would not point inside `desc', and user may want copy the
* payload from `data' to `desc' before returning UCT_INPROGRESS (it's guaranteed
* `desc' has enough room to hold the payload).
*
* @param [in] arg User-defined argument.
* @param [in] data Points to the received data.
* @param [in] length Length of data.
Expand Down
15 changes: 12 additions & 3 deletions src/uct/ib/base/ib_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ ucs_status_t uct_ib_iface_recv_mpool_create(uct_ib_iface_t *iface,
mp_p);
}

void uct_ib_iface_release_desc(uct_iface_t *tl_iface, void *desc)
{
uct_ib_iface_t *iface = ucs_derived_of(tl_iface, uct_ib_iface_t);
void *ib_desc;

ib_desc = desc - iface->config.rx_headroom_offset;
ucs_mpool_put(ib_desc);
}

/**
* @param rx_headroom Headroom requested by the user.
* @param rx_priv_len Length of transport private data to reserve (0 if unused)
Expand Down Expand Up @@ -196,10 +205,10 @@ static UCS_CLASS_INIT_FUNC(uct_ib_iface_t, uct_iface_ops_t *ops,
self->gid_index = config->gid_index;
self->sl = config->sl;
self->path_bits_count = config->lid_path_bits.count;
self->config.rx_headroom = rx_headroom;
self->config.rx_payload_offset = sizeof(uct_ib_iface_recv_desc_t) +
ucs_max(rx_headroom, rx_priv_len + rx_hdr_len);
self->config.rx_hdr_offset = self->config.rx_payload_offset - rx_hdr_len;
self->config.rx_headroom_offset= self->config.rx_payload_offset - rx_headroom;
self->config.seg_size = config->super.max_bcopy;

if (self->path_bits_count == 0) {
Expand Down Expand Up @@ -254,8 +263,8 @@ static UCS_CLASS_INIT_FUNC(uct_ib_iface_t, uct_iface_ops_t *ops,
goto err_destroy_recv_cq;
}

ucs_debug("created uct_ib_iface_t rx_headroom %d payload_ofs %d hdr_ofs %d data_sz %d",
self->config.rx_headroom, self->config.rx_payload_offset,
ucs_debug("created uct_ib_iface_t headroom_ofs %d payload_ofs %d hdr_ofs %d data_sz %d",
self->config.rx_headroom_offset, self->config.rx_payload_offset,
self->config.rx_hdr_offset, self->config.seg_size);

return UCS_OK;
Expand Down
20 changes: 19 additions & 1 deletion src/uct/ib/base/ib_iface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ typedef struct uct_ib_iface {
/* TODO comp_channel */

struct {
unsigned rx_headroom; /* user-requested headroom */
unsigned rx_payload_offset; /* offset from desc to payload */
unsigned rx_hdr_offset; /* offset from desc to network header */
unsigned rx_headroom_offset; /* offset from desc to user headroom */
unsigned seg_size;
} config;

Expand Down Expand Up @@ -100,6 +100,9 @@ typedef struct uct_ib_iface_config {
*
* (1)
*
* <rx_headroom_offset>
* |
*
* am_callback
* |
* +------+----------+-----------+---------+
Expand Down Expand Up @@ -143,6 +146,8 @@ ucs_status_t uct_ib_iface_recv_mpool_create(uct_ib_iface_t *iface,
uct_ib_iface_config_t *config,
const char *name, ucs_mpool_h *mp_p);

void uct_ib_iface_release_desc(uct_iface_t *tl_iface, void *desc);

static inline uct_ib_device_t * uct_ib_iface_device(uct_ib_iface_t *iface)
{
return ucs_derived_of(iface->super.super.pd, uct_ib_device_t);
Expand Down Expand Up @@ -174,4 +179,17 @@ int uct_ib_iface_prepare_rx_wrs(uct_ib_iface_t *iface,
ucs_mpool_h rx_mp, uct_ib_recv_wr_t *wrs, unsigned n);


static inline void uct_ib_iface_desc_received(uct_ib_iface_t *iface,
uct_ib_iface_recv_desc_t *desc,
unsigned byte_len, int has_data)
{
if (has_data) {
/* Memory has valid data */
VALGRIND_MAKE_MEM_DEFINED((void*)desc + iface->config.rx_hdr_offset, byte_len);
} else {
/* Data is invalid, but memory is addressable */
VALGRIND_MAKE_MEM_UNDEFINED((void*)desc + iface->config.rx_hdr_offset, byte_len);
}
}

#endif
5 changes: 3 additions & 2 deletions src/uct/ib/rc/rc_iface.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ static UCS_F_ALWAYS_INLINE ucs_status_t
uct_rc_iface_invoke_am(uct_rc_iface_t *iface, uct_rc_hdr_t *hdr, unsigned length,
uct_ib_iface_recv_desc_t *desc)
{
return uct_iface_invoke_am(&iface->super.super, hdr->am_id, hdr + 1,
length - sizeof(*hdr), desc);
return uct_iface_invoke_am(&iface->super.super,
hdr->am_id, hdr + 1, length - sizeof(*hdr),
(void*)desc + iface->super.config.rx_headroom_offset);
}

#endif
21 changes: 18 additions & 3 deletions src/uct/ib/rc/rc_mlx5_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ static inline void uct_rc_mlx5_iface_poll_rx(uct_rc_mlx5_iface_t *iface)
desc = ucs_queue_pull_elem_non_empty(&iface->rx.desc_q, uct_rc_mlx5_recv_desc_t, queue);
byte_len = ntohl(cqe->byte_cnt);

uct_ib_iface_desc_received(&iface->super.super, &desc->super, byte_len,
!(cqe->op_own & (MLX5_INLINE_SCATTER_32|MLX5_INLINE_SCATTER_64)));

/* Get a pointer to AM header (after which comes the payload)
* Support cases of inline scatter by pointing directly to CQE.
Expand All @@ -165,10 +167,9 @@ static inline void uct_rc_mlx5_iface_poll_rx(uct_rc_mlx5_iface_t *iface)
UCS_STATS_UPDATE_COUNTER(iface->stats, UCT_RC_MLX5_IFACE_STAT_RX_INL_32, 1);
} else if (cqe->op_own & MLX5_INLINE_SCATTER_64) {
hdr = (uct_rc_hdr_t*)(cqe - 1);
UCS_STATS_UPDATE_COUNTER(iface->stats, UCT_RC_MLX5_IFACE_STAT_RX_INL_64, 1);
UCS_STATS_UPDATE_COUNTER(iface->stats, UCT_RC_MLX5_IFACE_STAT_RX_INL_64, 1)
} else {
hdr = uct_ib_iface_recv_desc_hdr(&iface->super.super, &desc->super);
VALGRIND_MAKE_MEM_DEFINED(hdr, byte_len);
}

uct_ib_mlx5_log_rx(IBV_QPT_RC, cqe, hdr, uct_rc_ep_am_packet_dump);
Expand All @@ -188,6 +189,18 @@ static inline void uct_rc_mlx5_iface_poll_rx(uct_rc_mlx5_iface_t *iface)
++iface->super.rx.available;
}

static void uct_rc_mlx5_iface_free_rx_descs(uct_rc_mlx5_iface_t *iface)
{
uct_rc_mlx5_recv_desc_t *desc;

while (!ucs_queue_is_empty(&iface->rx.desc_q)) {
desc = ucs_queue_pull_elem_non_empty(&iface->rx.desc_q,
uct_rc_mlx5_recv_desc_t, queue);
ucs_mpool_put(desc);
}
ucs_mpool_check_empty(iface->super.rx.mp);
}

static void uct_rc_mlx5_iface_progress(void *arg)
{
uct_rc_mlx5_iface_t *iface = arg;
Expand Down Expand Up @@ -334,6 +347,7 @@ static UCS_CLASS_CLEANUP_FUNC(uct_rc_mlx5_iface_t)
uct_context_h context = uct_ib_iface_device(&self->super.super)->super.context;

ucs_notifier_chain_remove(&context->progress_chain, uct_rc_mlx5_iface_progress, self);
uct_rc_mlx5_iface_free_rx_descs(self);
UCS_STATS_NODE_FREE(self->stats);
ucs_mpool_destroy(self->tx.atomic_desc_mp);
}
Expand All @@ -345,9 +359,10 @@ static UCS_CLASS_DEFINE_NEW_FUNC(uct_rc_mlx5_iface_t, uct_iface_t, uct_context_h
static UCS_CLASS_DEFINE_DELETE_FUNC(uct_rc_mlx5_iface_t, uct_iface_t);

uct_iface_ops_t uct_rc_mlx5_iface_ops = {
.iface_close = UCS_CLASS_DELETE_FUNC_NAME(uct_rc_mlx5_iface_t),
.iface_get_address = uct_rc_iface_get_address,
.iface_flush = uct_rc_iface_flush,
.iface_close = UCS_CLASS_DELETE_FUNC_NAME(uct_rc_mlx5_iface_t),
.iface_release_desc = uct_ib_iface_release_desc,
.ep_get_address = uct_rc_ep_get_address,
.ep_connect_to_iface = NULL,
.ep_connect_to_ep = uct_rc_ep_connect_to_ep,
Expand Down
9 changes: 5 additions & 4 deletions src/uct/ib/rc/rc_verbs_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ static inline ucs_status_t uct_rc_verbs_iface_poll_rx(uct_rc_verbs_iface_t *ifac
UCS_STATS_UPDATE_COUNTER(iface->super.stats, UCT_RC_IFACE_STAT_RX_COMPLETION, 1);

desc = (void*)wc[i].wr_id;
hdr = uct_ib_iface_recv_desc_hdr(&iface->super.super, desc);
VALGRIND_MAKE_MEM_DEFINED(hdr, wc[i].byte_len);
uct_ib_iface_desc_received(&iface->super.super, desc, wc[i].byte_len, 1);

hdr = uct_ib_iface_recv_desc_hdr(&iface->super.super, desc);
uct_ib_log_recv_completion(IBV_QPT_RC, &wc[i], hdr, uct_rc_ep_am_packet_dump);

status = uct_rc_iface_invoke_am(&iface->super, hdr, wc[i].byte_len, desc);
Expand Down Expand Up @@ -329,13 +329,14 @@ static UCS_CLASS_DEFINE_DELETE_FUNC(uct_rc_verbs_iface_t, uct_iface_t);


uct_iface_ops_t uct_rc_verbs_iface_ops = {
.iface_close = UCS_CLASS_DELETE_FUNC_NAME(uct_rc_verbs_iface_t),
.iface_query = uct_rc_verbs_iface_query,
.iface_get_address = uct_rc_iface_get_address,
.iface_flush = uct_rc_iface_flush,
.iface_close = UCS_CLASS_DELETE_FUNC_NAME(uct_rc_verbs_iface_t),
.iface_release_desc = uct_ib_iface_release_desc,
.ep_get_address = uct_rc_ep_get_address,
.ep_connect_to_iface = NULL,
.ep_connect_to_ep = uct_rc_ep_connect_to_ep,
.iface_query = uct_rc_verbs_iface_query,
.ep_am_short = uct_rc_verbs_ep_am_short,
.ep_am_bcopy = uct_rc_verbs_ep_am_bcopy,
.ep_am_zcopy = uct_rc_verbs_ep_am_zcopy,
Expand Down
2 changes: 1 addition & 1 deletion src/uct/tl/tl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct uct_tl_ops {
*/
typedef struct uct_am_handler {
uct_am_callback_t cb;
void *arg;
void *arg;
} uct_am_handler_t;


Expand Down
4 changes: 2 additions & 2 deletions test/gtest/uct/test_amo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ void uct_amo_test::init() {

srand48(rand());

entity *receiver = new entity(GetParam());
entity *receiver = new entity(GetParam(), 0);
m_entities.push_back(receiver);

for (unsigned i = 0; i < num_senders(); ++i) {
receiver->add_ep();
entity *sender = new entity(GetParam());
entity *sender = new entity(GetParam(), 0);
m_entities.push_back(sender);
sender->add_ep();
sender->connect(0, *receiver, i);
Expand Down
62 changes: 55 additions & 7 deletions test/gtest/uct/test_p2p_am.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ class uct_p2p_am_test : public uct_p2p_test {
static const uint8_t AM_ID = 11;
static const uint64_t SEED1 = 0xa1a1a1a1a1a1a1a1ul;
static const uint64_t SEED2 = 0xa2a2a2a2a2a2a2a2ul;

uct_p2p_am_test() : m_am_count(0) {
static const uint64_t MAGIC = 0xdeadbeef12345678ul;

typedef struct {
uint64_t magic;
unsigned length;
/* data follows */
} receive_desc_t;

uct_p2p_am_test() :
uct_p2p_test(sizeof(receive_desc_t)),
m_keep_data(false),
m_am_count(0) {
}

virtual void init() {
Expand All @@ -25,13 +35,33 @@ class uct_p2p_am_test : public uct_p2p_test {

static ucs_status_t am_handler(void *arg, void *data, size_t length, void *desc) {
uct_p2p_am_test *self = reinterpret_cast<uct_p2p_am_test*>(arg);
self->am_handler(data, length);
return UCS_OK; /* TODO test keeping data */
return self->am_handler(data, length, desc);
}

void am_handler(void *data, size_t length) {
mapped_buffer::pattern_check(data, length, SEED1);
ucs_status_t am_handler(void *data, size_t length, void *desc) {
++m_am_count;
if (m_keep_data) {
receive_desc_t *my_desc = (receive_desc_t *)desc;
my_desc->magic = MAGIC;
my_desc->length = length;
if (data != my_desc + 1) {
memcpy(my_desc + 1, data, length);
}
m_backlog.push_back(my_desc);
return UCS_INPROGRESS;
}
mapped_buffer::pattern_check(data, length, SEED1);
return UCS_OK;
}

void check_backlog() {
while (!m_backlog.empty()) {
receive_desc_t *my_desc = m_backlog.back();
m_backlog.pop_back();
EXPECT_EQ(uint64_t(MAGIC), my_desc->magic);
mapped_buffer::pattern_check(my_desc + 1, my_desc->length, SEED1);
uct_iface_release_desc(receiver().iface(), (void*)my_desc);
}
}

static void am_pack(void *dest, void *arg, size_t length) {
Expand Down Expand Up @@ -84,10 +114,18 @@ class uct_p2p_am_test : public uct_p2p_test {

status = uct_set_am_handler(receiver().iface(), AM_ID, NULL, NULL);
ASSERT_UCS_OK(status);

check_backlog();
}

void set_keep_data(bool keep) {
m_keep_data = keep;
}

private:
unsigned m_am_count;
bool m_keep_data;
unsigned m_am_count;
std::vector<receive_desc_t*> m_backlog;

};

Expand All @@ -107,6 +145,16 @@ UCS_TEST_P(uct_p2p_am_test, am_bcopy) {
DIRECTION_SEND_TO_RECV);
}

UCS_TEST_P(uct_p2p_am_test, am_bcopy_keep_data) {
check_caps(UCT_IFACE_FLAG_AM_BCOPY);
set_keep_data(true);
test_xfer_multi(static_cast<send_func_t>(&uct_p2p_am_test::am_bcopy),
0ul,
sender().iface_attr().cap.am.max_bcopy,
DIRECTION_SEND_TO_RECV);
}


UCS_TEST_P(uct_p2p_am_test, am_zcopy) {
check_caps(UCT_IFACE_FLAG_AM_ZCOPY);
test_xfer_multi(static_cast<send_func_t>(&uct_p2p_am_test::am_zcopy),
Expand Down
Loading