Tuvie commented on code in PR #1836:
URL: https://github.com/apache/incubator-brpc/pull/1836#discussion_r939473980


##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -0,0 +1,1468 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#if BRPC_WITH_RDMA
+
+#include <gflags/gflags.h>
+#include "butil/fd_utility.h"
+#include "butil/logging.h"                   // CHECK, LOG
+#include "butil/sys_byteorder.h"             // HostToNet,NetToHost
+#include "bthread/bthread.h"
+#include "brpc/errno.pb.h"
+#include "brpc/event_dispatcher.h"
+#include "brpc/input_messenger.h"
+#include "brpc/socket.h"
+#include "brpc/reloadable_flags.h"
+#include "brpc/rdma/block_pool.h"
+#include "brpc/rdma/rdma_helper.h"
+#include "brpc/rdma/rdma_endpoint.h"
+
+
+namespace brpc {
+namespace rdma {
+
+extern ibv_cq* (*IbvCreateCq)(ibv_context*, int, void*, ibv_comp_channel*, 
int);
+extern int (*IbvDestroyCq)(ibv_cq*);
+extern ibv_comp_channel* (*IbvCreateCompChannel)(ibv_context*);
+extern int (*IbvDestroyCompChannel)(ibv_comp_channel*);
+extern int (*IbvGetCqEvent)(ibv_comp_channel*, ibv_cq**, void**);
+extern void (*IbvAckCqEvents)(ibv_cq*, unsigned int);
+extern ibv_qp* (*IbvCreateQp)(ibv_pd*, ibv_qp_init_attr*);
+extern int (*IbvModifyQp)(ibv_qp*, ibv_qp_attr*, ibv_qp_attr_mask);
+extern int (*IbvQueryQp)(ibv_qp*, ibv_qp_attr*, ibv_qp_attr_mask, 
ibv_qp_init_attr*);
+extern int (*IbvDestroyQp)(ibv_qp*);
+extern bool g_skip_rdma_init;
+
+DEFINE_int32(rdma_sq_size, 128, "SQ size for RDMA");
+DEFINE_int32(rdma_rq_size, 128, "RQ size for RDMA");
+DEFINE_bool(rdma_recv_zerocopy, true, "Enable zerocopy for receive side");
+DEFINE_int32(rdma_zerocopy_min_size, 512, "The minimal size for receive 
zerocopy");
+DEFINE_string(rdma_recv_block_type, "default", "Default size type for recv WR: 
"
+              "default(8KB - 32B)/large(64KB - 32B)/huge(2MB - 32B)");
+DEFINE_int32(rdma_cqe_poll_once, 32, "The maximum of cqe number polled once.");
+DEFINE_int32(rdma_prepared_qp_size, 128, "SQ and RQ size for prepared QP.");
+DEFINE_int32(rdma_prepared_qp_cnt, 1024, "Initial count of prepared QP.");
+DEFINE_bool(rdma_trace_verbose, false, "Print log message verbosely");
+BRPC_VALIDATE_GFLAG(rdma_trace_verbose, brpc::PassValidate);
+
+static const size_t IOBUF_BLOCK_HEADER_LEN = 32; // implementation-dependent
+static const size_t IOBUF_BLOCK_DEFAULT_PAYLOAD =
+        butil::IOBuf::DEFAULT_BLOCK_SIZE - IOBUF_BLOCK_HEADER_LEN;
+
+// DO NOT change this value unless you know the safe value!!!
+// This is the number of reserved WRs in SQ/RQ for pure ACK.
+static const size_t RESERVED_WR_NUM = 3;
+
+// magic string RDMA (4B)
+// message length (2B)
+// hello version (2B)
+// impl version (2B): 0 means should use tcp
+// block size (2B)
+// sq size (2B)
+// rq size (2B)
+// GID (16B)
+// QP number (4B)
+static const char* MAGIC_STR = "RDMA";
+static const size_t MAGIC_STR_LEN = 4;
+static const size_t HELLO_MSG_LEN_MIN = 38;
+static const size_t HELLO_MSG_LEN_MAX = 4096;
+static const size_t ACK_MSG_LEN = 4;
+static uint16_t g_rdma_hello_msg_len = 38;  // In Byte
+static uint16_t g_rdma_hello_version = 1;
+static uint16_t g_rdma_impl_version = 1;
+static uint16_t g_rdma_recv_block_size = 0;
+
+static const uint32_t MAX_INLINE_DATA = 64;
+static const uint8_t MAX_HOP_LIMIT = 16;
+static const uint8_t TIMEOUT = 14;
+static const uint8_t RETRY_CNT = 7;
+static const uint16_t MIN_QP_SIZE = 16;
+static const uint16_t MIN_BLOCK_SIZE = 1024;
+static const uint32_t ACK_MSG_RDMA_OK = 0x1;
+
+static butil::Mutex* g_rdma_resource_mutex = NULL;
+static RdmaResource* g_rdma_resource_list = NULL;
+
+struct HelloMessage {

Review Comment:
   这个是握手协议,发送的第一个信息命名为Hello



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to