一:IBV_WR_ATOMIC_FETCH_AND_ADD
int post_send_faa(struct RemoteMR remote_mr, int size)
{
struct ibv_sge list = {
.addr = (uint64_t)ib_res.buf,
.length = size,//要大于等于8
.lkey = ib_res.mr->lkey
};
struct ibv_send_wr *bad_wr, wr = {
.wr_id = WRITE_WRID,
.sg_list = &list,
.num_sge = 1,
.opcode = IBV_WR_ATOMIC_FETCH_AND_ADD,
.opcode = IBV_WR_ATOMIC_CMP_AND_SWP,
.send_flags = IBV_SEND_SIGNALED,
.wr.atomic.remote_addr = remote_mr.remote_addr,
.wr.atomic.rkey = remote_mr.rkey,
.wr.atomic.compare_add = 7UL,
.next = NULL
};
return ibv_post_send(ib_res.qp, &wr, &bad_wr);
}
二:IBV_WR_ATOMIC_CMP_AND_SWP(CAS)
注:这里的remote端是下发cas的一段。
int post_send_cas(struct RemoteMR remote_mr, int size)
{
struct ibv_sge list = {
.addr = (uint64_t)ib_res.buf,
.length = size,//要大于等于8
.lkey = ib_res.mr->lkey
};
struct ibv_send_wr *bad_wr, wr = {
.wr_id = WRITE_WRID,
.sg_list = &list,
.num_sge = 1,
.opcode = IBV_WR_ATOMIC_CMP_AND_SWP,
.send_flags = IBV_SEND_SIGNALED,
.wr.atomic.remote_addr = remote_mr.remote_addr,
.wr.atomic.rkey = remote_mr.rkey,
.wr.atomic.swap = 10UL,
.wr.atomic.compare_add = 7UL,
.next = NULL
};
return ibv_post_send(ib_res.qp, &wr, &bad_wr);
}