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
2 changes: 1 addition & 1 deletion src/ucs/datastruct/mpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ucs_mpool_create(const char *name, size_t elem_size, size_t align_offset,

VALGRIND_CREATE_MEMPOOL(mp, 0, 0);

ucs_debug("mpool %s: align %lu, maxelems %u, elemsize %lu, padding %lu",
ucs_debug("mpool %s: align %lu, maxelems %d, elemsize %lu, padding %lu",
mp->name, mp->alignment, mp->max_elems, mp->elem_size, mp->elem_padding);
*mpp = mp;
return UCS_OK;
Expand Down
8 changes: 4 additions & 4 deletions src/ucs/debug/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void ucs_log_default_handler(const char *file, unsigned line, const char *functi
char *buf;
char *valg_buf;

if (level > ucs_log_level) {
if (!ucs_log_enabled(level)) {
return;
}

Expand All @@ -153,17 +153,17 @@ void ucs_log_default_handler(const char *file, unsigned line, const char *functi
if (RUNNING_ON_VALGRIND) {
valg_buf = alloca(buffer_size + 1);
snprintf(valg_buf, buffer_size,
"[%lu.%06lu] %13s:%-4u %-4s %-5s %s\n", tv.tv_sec, tv.tv_usec,
"[%lu.%06lu] %16s:%-4u %-4s %-5s %s\n", tv.tv_sec, tv.tv_usec,
short_file, line, "UCX", ucs_log_level_names[level], buf);
VALGRIND_PRINTF("%s", valg_buf);
} else if (ucs_log_initialized) {
fprintf(ucs_log_file,
"[%lu.%06lu] [%s:%-5d:%d] %13s:%-4u %-4s %-5s %s\n",
"[%lu.%06lu] [%s:%-5d:%d] %16s:%-4u %-4s %-5s %s\n",
tv.tv_sec, tv.tv_usec, ucs_log_hostname, ucs_log_pid, get_thread_num(),
short_file, line, "UCX", ucs_log_level_names[level], buf);
} else {
fprintf(stdout,
"[%lu.%06lu] %13s:%-4u %-4s %-5s %s\n",
"[%lu.%06lu] %16s:%-4u %-4s %-5s %s\n",
tv.tv_sec, tv.tv_usec, short_file, line,
"UCX", ucs_log_level_names[level], buf);
}
Expand Down
5 changes: 3 additions & 2 deletions src/ucs/debug/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#include <stdint.h>


#define ucs_log_level (ucs_global_opts.log_level)
#define ucs_log_enabled(_level) \
ucs_unlikely(((_level) <= UCS_MAX_LOG_LEVEL) && ((_level) <= (ucs_global_opts.log_level)))

#define ucs_log(_level, _message, ...) \
do { \
if (ucs_unlikely(((_level) <= UCS_MAX_LOG_LEVEL) && ((_level) <= ucs_log_level))) { \
if (ucs_log_enabled(_level)) { \
__ucs_log(__FILE__, __LINE__, __FUNCTION__, (_level), \
_message, ## __VA_ARGS__); \
} \
Expand Down
9 changes: 7 additions & 2 deletions src/uct/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ nobase_dist_libuct_la_HEADERS = \

noinst_HEADERS = \
tl/context.h \
tl/tl_base.h
tl/tl_base.h \
tl/tl_log.h

libuct_la_SOURCES = \
tl/context.c \
Expand All @@ -35,18 +36,22 @@ noinst_HEADERS += \
ib/base/ib_context.h \
ib/base/ib_device.h \
ib/base/ib_iface.h \
ib/base/ib_log.h \
ib/base/ib_verbs.h

libuct_la_SOURCES += \
ib/base/ib_context.c \
ib/base/ib_device.c \
ib/base/ib_iface.c
ib/base/ib_iface.c \
ib/base/ib_log.c

if HAVE_MLX5_HW
libuct_la_SOURCES += \
ib/mlx5/ib_mlx5_log.c \
ib/mlx5/ib_mlx5.c

noinst_HEADERS += \
ib/mlx5/ib_mlx5_log.h \
ib/mlx5/ib_mlx5.h
endif

Expand Down
5 changes: 2 additions & 3 deletions src/uct/ib/base/ib_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ ucs_status_t uct_ib_init(uct_context_h context)
}
}

/* If we don't have any IB devices, fail the component */
if (ibctx->num_devices > 0) {
ucs_debug("initialized IB component with %u devices", ibctx->num_devices);
if (ibctx->num_devices == 0) {
ucs_debug("no infiniband devices found");
}
status = UCS_OK;

Expand Down
8 changes: 4 additions & 4 deletions src/uct/ib/base/ib_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ static UCS_CLASS_INIT_FUNC(uct_ib_iface_t, uct_iface_ops_t *ops,
self->config.rx_hdr_offset = self->config.rx_payload_offset - rx_hdr_len;
self->config.seg_size = config->super.max_bcopy;

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

/* TODO comp_channel */
/* TODO inline scatter for send SQ */
self->send_cq = ibv_create_cq(dev->ibv_context, tx_cq_len, NULL, NULL, 0);
Expand Down Expand Up @@ -214,6 +210,10 @@ 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,
self->config.rx_hdr_offset, self->config.seg_size);

return UCS_OK;

err_destroy_recv_cq:
Expand Down
274 changes: 274 additions & 0 deletions src/uct/ib/base/ib_log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2015. ALL RIGHTS RESERVED.
*
* $COPYRIGHT$
* $HEADER$
*/

#include "ib_log.h"

#include <ucs/sys/sys.h>


void uct_ib_log_dump_opcode(uint32_t qp_num, uct_ib_opcode_t *op, int signal,
int fence, int se, char *buf, size_t max)
{
snprintf(buf, max, "%s qp 0x%x %c%c%c", op->name, qp_num,
signal ? 's' : '-', fence ? 'f' : '-', se ? 'e' : '-');
}

void uct_ib_log_dump_sg_list(struct ibv_sge *sg_list, int num_sge, uint64_t inline_bitmap,
uct_log_data_dump_func_t data_dump, char *buf, size_t max)
{
char data[256];
size_t total_len = 0;
size_t total_valid_len = 0;;
char *s = buf;
char *ends = buf + max;
void *pd = data;
size_t len;
int i;

for (i = 0; i < num_sge; ++i) {
if (inline_bitmap & UCS_BIT(i)) {
snprintf(s, ends - s, " [inl len %d]", sg_list[i].length);
} else {
snprintf(s, ends - s, " [va 0x%"PRIx64" len %d lkey 0x%x]",
sg_list[i].addr, sg_list[i].length, sg_list[i].lkey);
}

len = ucs_min(sg_list[i].length, (void*)data + sizeof(data) - pd);
memcpy(pd, (void*)sg_list[i].addr, len);

s += strlen(s);
pd += len;
total_len += len;
total_valid_len += sg_list[i].length;
}

if (data_dump != NULL) {
data_dump(data, total_len, total_valid_len, s, ends - s);
}
}

void uct_ib_log_dump_remote_addr(uint64_t remote_addr, uint32_t rkey,
char *buf, size_t max)
{
snprintf(buf, max, " [rva 0x%"PRIx64" rkey 0x%x]", remote_addr, rkey);
}

void uct_ib_log_dump_atomic_fadd(uint64_t add, char *buf, size_t max)
{
snprintf(buf, max, " [add %ld]", add);
}

void uct_ib_log_dump_atomic_cswap(uint64_t compare, uint64_t swap, char *buf, size_t max)
{
snprintf(buf, max, " [cmp %ld swap %ld]", compare, swap);
}

void uct_ib_log_dump_atomic_masked_fadd(int argsize, uint64_t add, uint64_t boundary,
char *buf, size_t max)
{
snprintf(buf, max, " [%dbit add %"PRIi64"/0x%"PRIx64"]", argsize * 8, add, boundary);
}

void uct_ib_log_dump_atomic_masked_cswap(int argsize, uint64_t compare, uint64_t compare_mask,
uint64_t swap, uint64_t swap_mask,
char *buf, size_t max)
{
snprintf(buf, max, " [%d bit cmp %"PRIi64"/0x%"PRIx64" swap %"PRIi64"/0x%"PRIx64"]",
argsize * 8, compare, compare_mask, swap, swap_mask);
}

void uct_ib_log_dump_recv_completion(enum ibv_qp_type qp_type,
uint32_t local_qp, uint32_t sender_qp,
uint16_t sender_lid, void *data, size_t length,
uct_log_data_dump_func_t data_dump,
char *buf, size_t max)
{
char *s = buf;
char *ends = buf + max;

snprintf(s, ends - s, "RECV qp 0x%x", local_qp);
s += strlen(s);

if (qp_type == IBV_QPT_UD) {
snprintf(s, ends - s, " [slid %d sqp 0x%x]", sender_lid, sender_qp);
s += strlen(s);
}

snprintf(s, ends - s, " [va %p len %zu]", data, length);
s += strlen(s);

if (data_dump != NULL) {
data_dump(data, length, length, s, ends - s);
}
}

static void uct_ib_dump_wr_opcode(struct ibv_qp *qp, uct_ib_opcode_t *op,
int send_flags, char *buf, size_t max)
{
uct_ib_log_dump_opcode(qp->qp_num, op,
send_flags & IBV_SEND_SIGNALED,
send_flags & IBV_SEND_FENCE,
send_flags & IBV_SEND_SOLICITED,
buf, max);
}

static void uct_ib_dump_wr(struct ibv_qp *qp, uct_ib_opcode_t *op,
struct ibv_send_wr *wr, char *buf, size_t max)
{
char *s = buf;
char *ends = buf + max;

if (op->flags & UCT_IB_OPCODE_FLAG_HAS_RADDR) {
uct_ib_log_dump_remote_addr(wr->wr.rdma.remote_addr, wr->wr.rdma.rkey, s, ends - s);
s += strlen(s);
}

if (op->flags & UCT_IB_OPCODE_FLAG_HAS_ATOMIC) {
uct_ib_log_dump_remote_addr(wr->wr.atomic.remote_addr, wr->wr.atomic.rkey, s, ends - s);
s += strlen(s);

if (wr->opcode == IBV_WR_ATOMIC_FETCH_AND_ADD) {
uct_ib_log_dump_atomic_fadd(wr->wr.atomic.compare_add, s, ends - s);
} else if (wr->opcode == IBV_WR_ATOMIC_CMP_AND_SWP) {
uct_ib_log_dump_atomic_cswap(wr->wr.atomic.compare_add,
wr->wr.atomic.swap, s, ends - s);
}
s += strlen(s);
}
}

static void uct_ib_dump_send_wr(struct ibv_qp *qp, struct ibv_send_wr *wr,
uct_log_data_dump_func_t data_dump,
char *buf, size_t max)
{
static uct_ib_opcode_t opcodes[] = {
[IBV_WR_RDMA_WRITE] = { "RDMA_WRITE", UCT_IB_OPCODE_FLAG_HAS_RADDR },
[IBV_WR_RDMA_READ] = { "RDMA_READ", UCT_IB_OPCODE_FLAG_HAS_RADDR },
[IBV_WR_SEND] = { "SEND", 0 },
[IBV_WR_ATOMIC_CMP_AND_SWP] = { "CS", UCT_IB_OPCODE_FLAG_HAS_ATOMIC },
[IBV_WR_ATOMIC_FETCH_AND_ADD] = { "FA", UCT_IB_OPCODE_FLAG_HAS_ATOMIC },
};

char *s = buf;
char *ends = buf + max;
uct_ib_opcode_t *op = &opcodes[wr->opcode];

uct_ib_dump_wr_opcode(qp, op, wr->send_flags, s, ends - s);
s += strlen(s);

uct_ib_dump_wr(qp, op, wr, s, ends - s);
s += strlen(s);

uct_ib_log_dump_sg_list(wr->sg_list, wr->num_sge,
(wr->send_flags & IBV_SEND_INLINE) ? -1 : 0,
data_dump, s, ends - s);
}

void __uct_ib_log_post_send(const char *file, int line, const char *function,
struct ibv_qp *qp, struct ibv_send_wr *wr,
uct_log_data_dump_func_t data_dump_cb)
{
char buf[256] = {0};
while (wr != NULL) {
uct_ib_dump_send_wr(qp, wr, data_dump_cb, buf, sizeof(buf) - 1);
uct_log_data(file, line, function, buf);
wr = wr->next;
}
}

void __uct_ib_log_recv_completion(const char *file, int line, const char *function,
enum ibv_qp_type qp_type, struct ibv_wc *wc, void *data,
uct_log_data_dump_func_t packet_dump_cb)
{
char buf[256] = {0};
uct_ib_log_dump_recv_completion(qp_type, wc->qp_num, wc->src_qp, wc->slid,
data, wc->byte_len, packet_dump_cb,
buf, sizeof(buf) - 1);
uct_log_data(file, line, function, buf);
}

#if HAVE_DECL_IBV_EXP_POST_SEND
static void uct_ib_dump_exp_send_wr(struct ibv_qp *qp, struct ibv_exp_send_wr *wr,
uct_log_data_dump_func_t data_dump_cb,
char *buf, size_t max)
{
static uct_ib_opcode_t exp_opcodes[] = {
[IBV_EXP_WR_NOP] = { "NOP", 0},
[IBV_EXP_WR_RDMA_WRITE] = { "RDMA_WRITE", UCT_IB_OPCODE_FLAG_HAS_RADDR },
[IBV_EXP_WR_RDMA_READ] = { "RDMA_READ", UCT_IB_OPCODE_FLAG_HAS_RADDR },
[IBV_EXP_WR_SEND] = { "SEND", 0 },
[IBV_EXP_WR_ATOMIC_CMP_AND_SWP] = { "CS", UCT_IB_OPCODE_FLAG_HAS_ATOMIC },
[IBV_EXP_WR_ATOMIC_FETCH_AND_ADD] = { "FA", UCT_IB_OPCODE_FLAG_HAS_ATOMIC },
[IBV_EXP_WR_EXT_MASKED_ATOMIC_CMP_AND_SWP] = { "MASKED_CS", UCT_IB_OPCODE_FLAG_HAS_EXT_ATOMIC },
[IBV_EXP_WR_EXT_MASKED_ATOMIC_FETCH_AND_ADD] = { "MASKED_FA", UCT_IB_OPCODE_FLAG_HAS_EXT_ATOMIC },

};

char *s = buf;
char *ends = buf + max;
uct_ib_opcode_t *op = &exp_opcodes[wr->exp_opcode];

/* opcode in legacy mode */
UCS_STATIC_ASSERT((int)IBV_SEND_SIGNALED == (int)IBV_EXP_SEND_SIGNALED);
UCS_STATIC_ASSERT((int)IBV_SEND_FENCE == (int)IBV_EXP_SEND_FENCE);
UCS_STATIC_ASSERT((int)IBV_SEND_SOLICITED == (int)IBV_EXP_SEND_SOLICITED);
uct_ib_dump_wr_opcode(qp, op, wr->exp_send_flags, s, ends - s);
s += strlen(s);

/* TODO DC address handle */

/* WR data in legacy mode */
UCS_STATIC_ASSERT((int)IBV_WR_ATOMIC_FETCH_AND_ADD == (int)IBV_EXP_WR_ATOMIC_FETCH_AND_ADD);
UCS_STATIC_ASSERT((int)IBV_WR_ATOMIC_CMP_AND_SWP == (int)IBV_EXP_WR_ATOMIC_CMP_AND_SWP);
UCS_STATIC_ASSERT(ucs_offsetof(struct ibv_send_wr, opcode) ==
ucs_offsetof(struct ibv_exp_send_wr, exp_opcode));
UCS_STATIC_ASSERT(ucs_offsetof(struct ibv_send_wr, wr) ==
ucs_offsetof(struct ibv_exp_send_wr, wr));
uct_ib_dump_wr(qp, op, (struct ibv_send_wr*)wr, s, ends - s);
s += strlen(s);

/* Extended atomics */
if (op->flags & UCT_IB_OPCODE_FLAG_HAS_EXT_ATOMIC) {
uct_ib_log_dump_remote_addr(wr->ext_op.masked_atomics.remote_addr,
wr->ext_op.masked_atomics.rkey,
s, ends - s);
s += strlen(s);

if (wr->exp_opcode == IBV_EXP_WR_EXT_MASKED_ATOMIC_FETCH_AND_ADD) {
uct_ib_log_dump_atomic_masked_fadd(wr->ext_op.masked_atomics.log_arg_sz,
wr->ext_op.masked_atomics.wr_data.inline_data.op.fetch_add.add_val,
wr->ext_op.masked_atomics.wr_data.inline_data.op.fetch_add.field_boundary,
s, ends - s);
} else if (wr->exp_opcode == IBV_EXP_WR_EXT_MASKED_ATOMIC_CMP_AND_SWP) {
uct_ib_log_dump_atomic_masked_cswap(wr->ext_op.masked_atomics.log_arg_sz,
wr->ext_op.masked_atomics.wr_data.inline_data.op.cmp_swap.compare_val,
wr->ext_op.masked_atomics.wr_data.inline_data.op.cmp_swap.compare_mask,
wr->ext_op.masked_atomics.wr_data.inline_data.op.cmp_swap.swap_val,
wr->ext_op.masked_atomics.wr_data.inline_data.op.cmp_swap.swap_mask,
s, ends - s);
}
s += strlen(s);
}

uct_ib_log_dump_sg_list(wr->sg_list, wr->num_sge,
(wr->exp_send_flags & IBV_EXP_SEND_INLINE) ? -1 : 0,
data_dump_cb, s, ends - s);
}

void __uct_ib_log_exp_post_send(const char *file, int line, const char *function,
struct ibv_qp *qp, struct ibv_exp_send_wr *wr,
uct_log_data_dump_func_t packet_dump_cb)
{
char buf[256] = {0};
while (wr != NULL) {
uct_ib_dump_exp_send_wr(qp, wr, packet_dump_cb, buf, sizeof(buf) - 1);
uct_log_data(file, line, function, buf);
wr = wr->next;
}
}

#endif
Loading