-
Notifications
You must be signed in to change notification settings - Fork 4.1k
add pending signaled wrs checking #3137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -71,6 +71,8 @@ static const size_t IOBUF_BLOCK_HEADER_LEN = 32; // implementation-dependent | |||||
| // This is the number of reserved WRs in SQ/RQ for pure ACK. | ||||||
| static const size_t RESERVED_WR_NUM = 3; | ||||||
|
|
||||||
| static const uint64_t FIXED_ACK_WR_ID = 1; | ||||||
|
|
||||||
| // magic string RDMA (4B) | ||||||
| // message length (2B) | ||||||
| // hello version (2B) | ||||||
|
|
@@ -191,6 +193,8 @@ RdmaEndpoint::RdmaEndpoint(Socket* s) | |||||
| , _remote_window_capacity(0) | ||||||
| , _window_size(0) | ||||||
| , _new_rq_wrs(0) | ||||||
| , _pending_signaled_wrs(0) | ||||||
| , _pending_acks(0) | ||||||
| { | ||||||
| if (_sq_size < MIN_QP_SIZE) { | ||||||
| _sq_size = MIN_QP_SIZE; | ||||||
|
|
@@ -869,12 +873,14 @@ ssize_t RdmaEndpoint::CutFromIOBufList(butil::IOBuf** from, size_t ndata) { | |||||
| } | ||||||
|
|
||||||
| // Avoid too much send completion event to reduce the CPU overhead | ||||||
| bool signaled = false; | ||||||
| ++_sq_unsignaled; | ||||||
| if (_sq_unsignaled >= _local_window_capacity / 4) { | ||||||
| // Refer to: | ||||||
| // http::www.rdmamojo.com/2014/06/30/working-unsignaled-completions/ | ||||||
| wr.send_flags |= IBV_SEND_SIGNALED; | ||||||
| _sq_unsignaled = 0; | ||||||
| signaled = true; | ||||||
| } | ||||||
|
|
||||||
| ibv_send_wr* bad = NULL; | ||||||
|
|
@@ -889,6 +895,10 @@ ssize_t RdmaEndpoint::CutFromIOBufList(butil::IOBuf** from, size_t ndata) { | |||||
| return -1; | ||||||
| } | ||||||
|
|
||||||
| if (signaled) { | ||||||
| _pending_signaled_wrs.fetch_add(1, butil::memory_order_relaxed); | ||||||
| } | ||||||
|
|
||||||
| ++_sq_current; | ||||||
| if (_sq_current == _sq_size - RESERVED_WR_NUM) { | ||||||
| _sq_current = 0; | ||||||
|
|
@@ -918,6 +928,7 @@ int RdmaEndpoint::SendImm(uint32_t imm) { | |||||
|
|
||||||
| ibv_send_wr wr; | ||||||
| memset(&wr, 0, sizeof(wr)); | ||||||
| wr.wr_id = FIXED_ACK_WR_ID; | ||||||
| wr.opcode = IBV_WR_SEND_WITH_IMM; | ||||||
| wr.imm_data = butil::HostToNet32(imm); | ||||||
| wr.send_flags |= IBV_SEND_SOLICITED; | ||||||
|
|
@@ -936,9 +947,13 @@ int RdmaEndpoint::SendImm(uint32_t imm) { | |||||
|
|
||||||
| ssize_t RdmaEndpoint::HandleCompletion(ibv_wc& wc) { | ||||||
| bool zerocopy = FLAGS_rdma_recv_zerocopy; | ||||||
| uint16_t pending_signaled_wrs = _pending_signaled_wrs.load(butil::memory_order_relaxed); | ||||||
| switch (wc.opcode) { | ||||||
| case IBV_WC_SEND: { // send completion | ||||||
| // Do nothing | ||||||
| if (wc.wr_id == 0) { | ||||||
|
||||||
| if (wc.wr_id == 0) { | |
| if (wc.wr_id != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that _window_size may still be larger than the actual sq size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you give an example to describe it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the client sends _local_window_capacity / 4 + 1 requests, it receives an ACK and a send CQE from the server. At this point, _window_size increases by _local_window_capacity / 4 + 1, and sq size increases by _local_window_capacity / 4.
The issue of inconsistency between _window_size and sq size still exists.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -261,6 +261,10 @@ friend class brpc::Socket; | |||||
| butil::atomic<uint16_t> _window_size; | ||||||
| // The number of new WRs posted in the local Recv Queue | ||||||
| butil::atomic<uint16_t> _new_rq_wrs; | ||||||
| // The number of pending signaled send WRs | ||||||
| butil::atomic<uint16_t> _pending_signaled_wrs; | ||||||
| // The number of pending acks | ||||||
| uint16_t _pending_acks; | ||||||
|
||||||
| uint16_t _pending_acks; | |
| butil::atomic<uint16_t> _pending_acks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line, I'm not sure if send cqe can generate energy after this atomic operation.