Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

rpma: Atomic write with IBV_SEND_FENCE flag #603

Merged
merged 1 commit into from
Dec 4, 2020
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/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ rpma_write(struct rpma_conn *conn,
return rpma_mr_write(conn->id->qp,
dst, dst_offset,
src, src_offset,
len, flags, op_context);
len, flags, op_context, false);
}

/*
Expand All @@ -343,7 +343,7 @@ rpma_write_atomic(struct rpma_conn *conn,
return rpma_mr_write(conn->id->qp,
dst, dst_offset,
src, src_offset,
RPMA_ATOMIC_WRITE_ALIGNMENT, flags, op_context);
RPMA_ATOMIC_WRITE_ALIGNMENT, flags, op_context, true);
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int
rpma_mr_write(struct ibv_qp *qp,
struct rpma_mr_remote *dst, size_t dst_offset,
const struct rpma_mr_local *src, size_t src_offset,
size_t len, int flags, const void *op_context)
size_t len, int flags, const void *op_context, bool fence)
{
struct ibv_send_wr wr;
struct ibv_sge sge;
Expand All @@ -168,6 +168,7 @@ rpma_mr_write(struct ibv_qp *qp,
wr.opcode = IBV_WR_RDMA_WRITE;
wr.send_flags = (flags & RPMA_F_COMPLETION_ON_SUCCESS) ?
IBV_SEND_SIGNALED : 0;
wr.send_flags |= fence ? IBV_SEND_FENCE : 0;

struct ibv_send_wr *bad_wr;
int ret = ibv_post_send(qp, &wr, &bad_wr);
Expand Down
2 changes: 1 addition & 1 deletion src/mr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int rpma_mr_read(struct ibv_qp *qp,
int rpma_mr_write(struct ibv_qp *qp,
struct rpma_mr_remote *dst, size_t dst_offset,
const struct rpma_mr_local *src, size_t src_offset,
size_t len, int flags, const void *op_context);
size_t len, int flags, const void *op_context, bool fence);

/*
* ASSUMPTIONS
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/common/mocks-rpma-mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int
rpma_mr_write(struct ibv_qp *qp,
struct rpma_mr_remote *dst, size_t dst_offset,
const struct rpma_mr_local *src, size_t src_offset,
size_t len, int flags, const void *op_context)
size_t len, int flags, const void *op_context, bool fence)
{
assert_non_null(qp);
assert_non_null(dst);
Expand All @@ -60,6 +60,7 @@ rpma_mr_write(struct ibv_qp *qp,
check_expected(len);
check_expected(flags);
check_expected_ptr(op_context);
check_expected(fence);

return mock_type(int);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/common/test-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#define MOCK_LEN (size_t)0xC415
#define MOCK_FLAGS (int)0xC416
#define MOCK_OP_CONTEXT (void *)0xC417
#define MOCK_NOFENCE false
#define MOCK_FENCE true

#define MOCK_OK 0
#define MOCK_ERRNO 123456
Expand Down
1 change: 1 addition & 0 deletions tests/unit/conn/conn-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ write__success(void **cstate_ptr)
expect_value(rpma_mr_write, len, MOCK_LEN);
expect_value(rpma_mr_write, flags, MOCK_FLAGS);
expect_value(rpma_mr_write, op_context, MOCK_OP_CONTEXT);
expect_value(rpma_mr_write, fence, MOCK_NOFENCE);
will_return(rpma_mr_write, MOCK_OK);

/* run test */
Expand Down
1 change: 1 addition & 0 deletions tests/unit/conn/conn-write_atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ write_atomic__success(void **cstate_ptr)
expect_value(rpma_mr_write, len, RPMA_ATOMIC_WRITE_ALIGNMENT);
expect_value(rpma_mr_write, flags, MOCK_FLAGS);
expect_value(rpma_mr_write, op_context, MOCK_OP_CONTEXT);
expect_value(rpma_mr_write, fence, MOCK_FENCE);
will_return(rpma_mr_write, MOCK_OK);

/* run test */
Expand Down
104 changes: 101 additions & 3 deletions tests/unit/mr/mr-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,37 @@ write__COMPL_ALWAYS_failed_E_PROVIDER(void **mrs_ptr)
int ret = rpma_mr_write(MOCK_QP, mrs->remote, MOCK_DST_OFFSET,
mrs->local, MOCK_SRC_OFFSET,
MOCK_LEN, RPMA_F_COMPLETION_ALWAYS,
MOCK_OP_CONTEXT);
MOCK_OP_CONTEXT, MOCK_NOFENCE);

/* verify the results */
assert_int_equal(ret, RPMA_E_PROVIDER);
}

/*
* write__COMPL_ALWAYS_FENCE_failed_E_PROVIDER - rpma_mr_write failed
* with RPMA_E_PROVIDER when send_flags == RPMA_F_COMPLETION_ON_SUCCESS
* and fence == true
*/
static void
write__COMPL_ALWAYS_FENCE_failed_E_PROVIDER(void **mrs_ptr)
{
struct mrs *mrs = (struct mrs *)*mrs_ptr;

/* configure mocks */
struct ibv_post_send_mock_args args;
args.qp = MOCK_QP;
args.opcode = IBV_WR_RDMA_WRITE;
/* for RPMA_F_COMPLETION_ALWAYS and fence is true */
args.send_flags = IBV_SEND_SIGNALED | IBV_SEND_FENCE;
args.wr_id = (uint64_t)MOCK_OP_CONTEXT;
args.ret = MOCK_ERRNO;
will_return(ibv_post_send_mock, &args);

/* run test */
int ret = rpma_mr_write(MOCK_QP, mrs->remote, MOCK_DST_OFFSET,
mrs->local, MOCK_SRC_OFFSET,
MOCK_LEN, RPMA_F_COMPLETION_ALWAYS,
MOCK_OP_CONTEXT, MOCK_FENCE);

/* verify the results */
assert_int_equal(ret, RPMA_E_PROVIDER);
Expand Down Expand Up @@ -66,7 +96,36 @@ write__COMPL_ON_ERROR_failed_E_PROVIDER(void **mrs_ptr)
int ret = rpma_mr_write(MOCK_QP, mrs->remote, MOCK_DST_OFFSET,
mrs->local, MOCK_SRC_OFFSET,
MOCK_LEN, RPMA_F_COMPLETION_ON_ERROR,
MOCK_OP_CONTEXT);
MOCK_OP_CONTEXT, MOCK_NOFENCE);

/* verify the results */
assert_int_equal(ret, RPMA_E_PROVIDER);
}

/*
* write__COMPL_ON_ERROR_failed_E_PROVIDER - rpma_mr_write failed
* with RPMA_E_PROVIDER when send_flags == 0 for RPMA_F_COMPLETION_ON_ERROR
* and fence == true
*/
static void
write__COMPL_ON_ERROR_FENCE_failed_E_PROVIDER(void **mrs_ptr)
{
struct mrs *mrs = (struct mrs *)*mrs_ptr;

/* configure mocks */
struct ibv_post_send_mock_args args;
args.qp = MOCK_QP;
args.opcode = IBV_WR_RDMA_WRITE;
args.send_flags = IBV_SEND_FENCE; /* for fence is true */
args.wr_id = (uint64_t)MOCK_OP_CONTEXT;
args.ret = MOCK_ERRNO;
will_return(ibv_post_send_mock, &args);

/* run test */
int ret = rpma_mr_write(MOCK_QP, mrs->remote, MOCK_DST_OFFSET,
mrs->local, MOCK_SRC_OFFSET,
MOCK_LEN, RPMA_F_COMPLETION_ON_ERROR,
MOCK_OP_CONTEXT, MOCK_FENCE);

/* verify the results */
assert_int_equal(ret, RPMA_E_PROVIDER);
Expand All @@ -93,7 +152,35 @@ write__success(void **mrs_ptr)
int ret = rpma_mr_write(MOCK_QP, mrs->remote, MOCK_DST_OFFSET,
mrs->local, MOCK_SRC_OFFSET,
MOCK_LEN, RPMA_F_COMPLETION_ALWAYS,
MOCK_OP_CONTEXT);
MOCK_OP_CONTEXT, MOCK_NOFENCE);

/* verify the results */
assert_int_equal(ret, MOCK_OK);
}

/*
* write__FENCE_success - happy day scenario
*/
static void
write__FENCE_success(void **mrs_ptr)
{
struct mrs *mrs = (struct mrs *)*mrs_ptr;

/* configure mocks */
struct ibv_post_send_mock_args args;
args.qp = MOCK_QP;
args.opcode = IBV_WR_RDMA_WRITE;
/* for RPMA_F_COMPLETION_ALWAYS and fence is true */
args.send_flags = IBV_SEND_SIGNALED | IBV_SEND_FENCE;
args.wr_id = (uint64_t)MOCK_OP_CONTEXT;
args.ret = MOCK_OK;
will_return(ibv_post_send_mock, &args);

/* run test */
int ret = rpma_mr_write(MOCK_QP, mrs->remote, MOCK_DST_OFFSET,
mrs->local, MOCK_SRC_OFFSET,
MOCK_LEN, RPMA_F_COMPLETION_ALWAYS,
MOCK_OP_CONTEXT, MOCK_FENCE);

/* verify the results */
assert_int_equal(ret, MOCK_OK);
Expand Down Expand Up @@ -129,13 +216,24 @@ static const struct CMUnitTest tests_mr_write[] = {
write__COMPL_ALWAYS_failed_E_PROVIDER,
setup__mr_local_and_remote,
teardown__mr_local_and_remote),
cmocka_unit_test_setup_teardown(
write__COMPL_ALWAYS_FENCE_failed_E_PROVIDER,
setup__mr_local_and_remote,
teardown__mr_local_and_remote),
cmocka_unit_test_setup_teardown(
write__COMPL_ON_ERROR_failed_E_PROVIDER,
setup__mr_local_and_remote,
teardown__mr_local_and_remote),
cmocka_unit_test_setup_teardown(
write__COMPL_ON_ERROR_FENCE_failed_E_PROVIDER,
setup__mr_local_and_remote,
teardown__mr_local_and_remote),
cmocka_unit_test_setup_teardown(write__success,
setup__mr_local_and_remote,
teardown__mr_local_and_remote),
cmocka_unit_test_setup_teardown(write__FENCE_success,
setup__mr_local_and_remote,
teardown__mr_local_and_remote),
cmocka_unit_test(NULL)
};

Expand Down