Debian Codegraph @

librdmacm/docs/rsocket

raw
1 .. Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md
2 rsocket Protocol and Design Guide 11/11/2012
3
4 Data Streaming (TCP) Overview
5 -----------------------------
6 Rsockets is a protocol over RDMA that supports a socket-level API
7 for applications. For details on the current state of the
8 implementation, readers should refer to the rsocket man page. This
9 document describes the rsocket protocol, general design, and
10 some implementation details.
11
12 Rsockets exchanges data by performing RDMA write operations into
13 exposed data buffers. In addition to RDMA write data, rsockets uses
14 small, 32-bit messages for internal communication. RDMA writes
15 are used to transfer application data into remote data buffers
16 and to notify the peer when new target data buffers are available.
17 The following figure highlights the operation.
18
19 host A host B
20 remote SGL
21 target SGL <------------- [ ]
22 [ ] ------
23 [ ] -- ------ receive buffer(s)
24 -- -----> +--+
25 -- | |
26 -- | |
27 -- | |
28 -- +--+
29 --
30 ---> +--+
31 | |
32 | |
33 +--+
34
35 The remote SGL contains the address, size, and rkey of the target SGL. As
36 receive buffers become available on host B, rsockets will issue an RDMA
37 write against one of the entries in the target SGL on host A. The
38 updated entry will reference an available receive buffer. Immediate data
39 included with the RDMA write will indicate to host A that a target SGE
40 has been updated.
41
42 When host A has data to send, it will check its target SGL. The current
43 target SGE will contain the address, size, and rkey of the next receive
44 buffer on host B. If the data transfer is smaller than the size of the
45 remote receive buffer, host A will update its target SGE to reflect the
46 remaining size of the receive buffer. That is, once a receive buffer has
47 been published to a remote peer, it will be fully consumed before a second
48 buffer is used.
49
50 Rsockets relies on immediate data to notify the remote peer when data has
51 been transferred or when a target SGL has been updated. Because immediate
52 data requires that the remote QP have a posted receive, rsockets also uses
53 a credit based flow control mechanism. The number of credits is based on
54 the size of the receive queue, with initial credits exchanged during
55 connection setup. In order to transfer data, rsockets requires both
56 available receive buffers (published via the target SGL) and data credits.
57
58 Since immediate data is limited to 32-bits, messages may either indicate
59 the arrival of application data or may be an internal message, but not both.
60 To avoid credit deadlock, rsockets reserves a small number of available
61 credits for control messages only, with the protocol relying on RNR NAKs
62 and retries to make forward progress.
63
64
65 Connection Establishment
66 ------------------------
67 rsockets uses the RDMA CM for connection establishment. Struct rs_conn_data
68 is exchanged during the connection exchange as private data in the request
69 and reply messages.
70
71 struct rs_sge {
72 uint64_t addr;
73 uint32_t key;
74 uint32_t length;
75 };
76
77 #define RS_CONN_FLAG_NET 1
78
79 struct rs_conn_data {
80 uint8_t version;
81 uint8_t flags;
82 uint16_t credits;
83 uint32_t reserved2;
84 struct rs_sge target_sgl;
85 struct rs_sge data_buf;
86 };
87
88 Version - current version is 1
89 Flags
90 RS_CONN_FLAG_NET - Set to 1 if host is big Endian.
91 Determines byte ordering for RDMA write messages
92 Credits - number of initial receive credits
93 Reserved2 - set to 0
94 Target SGL - Address, size (# entries), and rkey of target SGL.
95 Remote side will copy this into their remote SGL.
96 Data Buffer - Initial receive buffer address, size (in bytes), and rkey.
97 Remote side will copy this into their first target SGE.
98
99
100 Message Format
101 --------------
102 Rsocket uses RDMA writes with immediate data for all message exchanges.
103 RDMA writes of 0 length are used if no additional data beyond the message
104 needs to be exchanged. Immediate data is limited to 32-bits. Rsockets
105 defines the following format for messages.
106
107 The upper 3 bits are used to define the type of message being exchanged,
108 with the meaning of the lower 29 bits determined by the upper bits.
109
110 Bits Message Meaning of
111 31:29 Type Bits 28:0
112 000 Data Transfer bytes transferred
113 001 reserved
114 010 reserved - used internally, available for future use
115 011 reserved
116 100 Credit Update received credits granted
117 101 reserved
118 110 Iomap Updated index of updated entry
119 111 Control control message type
120
121 Data Transfer
122 Indicates that application data has been written into the next available
123 receive buffer. The size of the transfer, in bytes, is carried in the lower
124 bits of the message.
125
126 Credit Update
127 Used to indicate that additional receive buffers and credits are available.
128 The number of available credits is carried in the lower bits of the message.
129 A credit update message is also used to indicate that a target SGE has been
130 updated, in which case the number of additional credits may be 0. The
131 receiver of a credit update message must check for updates to the target SGL
132 by inspecting the contents of the SGL. The rsocket implementation must take
133 care not to modify a remote target SGL while it may be in use. This is done
134 by tracking when a receive buffer referenced by a remote target SGL has been
135 filled.
136
137 Iomap Updated
138 Used to indicate that a remote iomap entry was updated. The updated entry
139 contains the offset value associated with an address, length, and rkey. Once
140 an iomap has been updated, the local application can issue directed IO
141 transfers against the corresponding remote buffer.
142
143 Control Message - DISCONNECT
144 Indicates that the rsocket connection has been fully disconnected and will no
145 longer send or receive data. Data received before the disconnect message was
146 processed may still be available for reading.
147
148 Control Message - SHUTDOWN
149 Indicates that the remote rsocket has shutdown the send side of its
150 connection. The recipient of a shutdown message will no longer accept
151 incoming data, but may still transfer outbound data.
152
153
154 Iomapped Buffers
155 ----------------
156 Rsockets allows for zero-copy transfers using what it refers to as iomapped
157 buffers. Iomapping and direct data placement (zero-copy) transfers are done
158 using rsocket specific extensions. The general operation is similar to
159 that used for normal data transfers described above.
160
161 host A host B
162 remote iomap
163 target iomap <----------- [ ]
164 [ ] ------
165 [ ] -- ------ iomapped buffer(s)
166 -- -----> +--+
167 -- | |
168 -- | |
169 -- | |
170 -- +--+
171 --
172 ---> +--+
173 | |
174 | |
175 +--+
176
177 The remote iomap contains the address, size, and rkey of the target iomap. As
178 the applicaton maps buffers host B to a given rsocket, rsockets will issue an RDMA
179 write against one of the entries in the target iomap on host A. The
180 updated entry will reference an available iomapped buffer. Immediate data
181 included with the RDMA write will indicate to host A that a target iomap
182 has been updated.
183
184 When host A wishes to transfer directly into an iomapped buffer, it will check
185 its target iomap for an offset corresponding to a remotely mapped buffer. A
186 matching iomap entry will contain the address, size, and rkey of the target
187 buffer on host B. Host A will then issue an RDMA operation against the
188 registered remote data buffer.
189
190 From host A's perspective, the transfer appears as a normal send/write
191 operation, with the data stream redirected directly into the receiving
192 application's buffer.
193
194
195
196 Datagram Overview
197 -----------------
198 The rsocket API supports datagram sockets. Datagram support is handled through an
199 entirely different protocol and internal implementation. Unlike connected rsockets,
200 datagram rsockets are not necessarily bound to a network (IP) address. A datagram
201 socket may use any number of network (IP) addresses, including those which map to
202 different RDMA devices. As a result, a single datagram rsocket must support
203 using multiple RDMA devices and ports, and a datagram rsocket references a single
204 UDP socket, plus zero or more UD QPs.
205
206 Rsockets uses headers inserted before user data sent over UDP sockets to resolve
207 remote UD QP numbers. When a user first attempts to send a datagram to a remote
208 address (IP and UDP port), rsockets will take the following steps:
209
210 1. Store the destination address into a lookup table.
211 2. Resolve which local network address should be used when sending
212 to the specified destination.
213 3. Allocate a UD QP on the RDMA device associated with the local address.
214 4. Send the user's datagram to the remote UDP socket.
215
216 A header is inserted before the user's datagram. The header specifies the
217 UD QP number associated with the local network address (IP and UDP port) of
218 the send.
219
220 A service thread is used to process messages received on the UDP socket. This
221 thread updates the rsocket lookup tables with the remote QPN and path record
222 data. The service thread forwards data received on the UDP socket to an
223 rsocket QP. After the remote QPN and path records have been resolved, datagram
224 communication between two nodes are done over the UD QP.
225
226 UDP Message Format
227 ------------------
228 Rsockets uses messages exchanged over UDP sockets to resolve remote QP numbers.
229 If a user sends a datagram to a remote service and the local rsocket is not
230 yet configured to send directly to a remote UD QP, the user data is sent over
231 a UDP socket with the following header inserted before the user data.
232
233 struct ds_udp_header {
234 uint32_t tag;
235 uint8_t version;
236 uint8_t op;
237 uint8_t length;
238 uint8_t reserved;
239 uint32_t qpn; /* lower 8-bits reserved */
240 union {
241 uint32_t ipv4;
242 uint8_t ipv6[16];
243 } addr;
244 };
245
246 Tag - Marker used to help identify that the UDP header is present.
247 #define DS_UDP_TAG 0x55555555
248
249 Version - IP address version, either 4 or 6
250 Op - Indicates message type, used to control the receiver's operation.
251 Valid operations are RS_OP_DATA and RS_OP_CTRL. Data messages
252 carry user data, while control messages are used to reply with the
253 local QP number.
254 Length - Size of the UDP header.
255 QPN - UD QP number associated with sender's IP address and port.
256 The sender's address and port is extracted from the received UDP
257 datagram.
258 Addr - Target IP address of the sent datagram.
259
260 Once the remote QP information has been resolved, data is sent directly
261 between UD QPs. The following header is inserted before any user data that
262 is transferred over a UD QP.
263
264 struct ds_header {
265 uint8_t version;
266 uint8_t length;
267 uint16_t port;
268 union {
269 uint32_t ipv4;
270 struct {
271 uint32_t flowinfo;
272 uint8_t addr[16];
273 } ipv6;
274 } addr;
275 };
276
277 Verion - IP address version
278 Length - Size of the header
279 Port - Associated source address UDP port
280 Addr - Associated source IP address