TAS
TCP Acceleration as an OS Service
tas_ll.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 University of Washington, Max Planck Institute for
3  * Software Systems, and The University of Texas at Austin
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef TAS_LL_H_
26 #define TAS_LL_H_
27 
36 #include <stddef.h>
37 #include <stdint.h>
38 #include <sys/types.h>
39 
40 #define FLEXTCP_MAX_CONTEXTS 32
41 #define FLEXTCP_MAX_FTCPCORES 16
42 
50  /* incoming queue from the kernel */
51  void *kin_base;
52  uint32_t kin_len;
53  uint32_t kin_head;
54 
55  /* outgoing queue to the kernel */
56  void *kout_base;
57  uint32_t kout_len;
58  uint32_t kout_head;
59 
60  /* queues from NIC cores */
61  uint32_t rxq_len;
62  uint32_t txq_len;
63  struct {
64  void *txq_base;
65  void *rxq_base;
66  uint32_t rxq_head;
67  uint32_t txq_tail;
68  uint32_t txq_avail;
69  uint32_t _pad;
70  uint64_t last_ts;
71  } queues[FLEXTCP_MAX_FTCPCORES];
72 
73  /* list of connections with pending updates for NIC */
74  struct flextcp_connection *bump_pending_first;
75  struct flextcp_connection *bump_pending_last;
76 
77  /* other */
78  uint32_t flags;
79  uint16_t db_id;
80  uint16_t ctx_id;
81 
82  uint16_t num_queues;
83  uint16_t next_queue;
84 
85  /* waiting */
86  uint64_t last_inev_ts;
87  int evfd;
88 };
89 
92  struct flextcp_connection *conns;
93 
94  uint16_t local_port;
95  uint8_t status;
96 };
97 
100  /* rx buffer */
101  uint8_t *rxb_base;
102  uint32_t rxb_len;
104  uint32_t rxb_head;
106  uint32_t rxb_used;
108  uint32_t rxb_bump;
109 
110  /* tx buffer */
111  uint8_t *txb_base;
112  uint32_t txb_len;
114  uint32_t txb_head;
116  uint32_t txb_sent;
118  uint32_t txb_allocated;
120  uint32_t txb_bump;
121 
122  uint32_t local_ip;
123  uint32_t remote_ip;
124  uint16_t local_port;
125  uint16_t remote_port;
126 
127  uint32_t seq_rx;
128  uint32_t seq_tx;
129 
130  uint32_t flow_id;
131  uint32_t bump_seq;
132 
133  struct flextcp_connection *bump_next;
134  struct flextcp_connection *bump_prev;
135  uint16_t fn_core;
136 
137  uint8_t bump_pending;
138  uint8_t status;
139  uint8_t flags;
140  /* TODO: kill rx closed and merge into flags */
141  uint8_t rx_closed;
142 };
143 
152 
167 };
168 
171  uint8_t event_type;
172  union {
174  struct {
175  int16_t status;
176  struct flextcp_listener *listener;
177  } listen_open;
179  struct {
180  uint16_t remote_port;
181  uint32_t remote_ip;
182  struct flextcp_listener *listener;
183  } listen_newconn;
185  struct {
186  int16_t status;
187  struct flextcp_connection *conn;
188  } listen_accept;
189 
191  struct {
192  int16_t status;
193  struct flextcp_connection *conn;
194  } conn_open;
196  struct {
197  void *buf;
198  size_t len;
199  struct flextcp_connection *conn;
200  } conn_received;
202  struct {
203  struct flextcp_connection *conn;
204  } conn_sendbuf;
206  struct {
207  struct flextcp_connection *conn;
208  } conn_rxclosed;
210  struct {
211  struct flextcp_connection *conn;
212  } conn_txclosed;
214  struct {
215  int16_t status;
216  struct flextcp_connection *conn;
217  } conn_moved;
219  struct {
220  int16_t status;
221  struct flextcp_connection *conn;
222  } conn_closed;
223  } ev;
224 };
225 
226 #define FLEXTCP_LISTEN_REUSEPORT 0x1
227 
232 int flextcp_init(void);
233 
237 int flextcp_context_create(struct flextcp_context *ctx);
238 
242 int flextcp_context_poll(struct flextcp_context *ctx, int num,
243  struct flextcp_event *events);
244 
253 int flextcp_context_waitfd(struct flextcp_context *ctx);
254 
262 
270 
277 int flextcp_context_wait(struct flextcp_context *ctx, int timeout_ms);
278 
279 /*****************************************************************************/
280 /* Regular TCP connection management */
281 
283 int flextcp_listen_open(struct flextcp_context *ctx,
284  struct flextcp_listener *lst, uint16_t port, uint32_t backlog,
285  uint32_t flags);
286 
289 int flextcp_listen_accept(struct flextcp_context *ctx,
290  struct flextcp_listener *lst, struct flextcp_connection *conn);
291 
292 
295  struct flextcp_connection *conn, uint32_t dst_ip, uint16_t dst_port);
296 
299  struct flextcp_connection *conn);
300 
302 int flextcp_connection_rx_done(struct flextcp_context *ctx, struct flextcp_connection *conn, size_t len);
303 
309 ssize_t flextcp_connection_tx_alloc(struct flextcp_connection *conn, size_t len,
310  void **buf);
311 
314 ssize_t flextcp_connection_tx_alloc2(struct flextcp_connection *conn, size_t len,
315  void **buf_1, size_t *len_1, void **buf_2);
316 
319  struct flextcp_connection *conn, size_t len);
320 
323  struct flextcp_connection *conn);
324 
330  struct flextcp_connection *conn);
331 
334  struct flextcp_connection *conn);
335 
338 #endif /* ndef TAS_LL_H_ */
int flextcp_connection_tx_send(struct flextcp_context *ctx, struct flextcp_connection *conn, size_t len)
Definition: conn.c:314
int flextcp_context_wait(struct flextcp_context *ctx, int timeout_ms)
Definition: init.c:995
int flextcp_context_waitfd(struct flextcp_context *ctx)
Definition: init.c:925
uint32_t rxb_bump
Definition: tas_ll.h:108
int flextcp_context_poll(struct flextcp_context *ctx, int num, struct flextcp_event *events)
Definition: init.c:454
int flextcp_context_create(struct flextcp_context *ctx)
Definition: init.c:90
flextcp_event_type
Definition: tas_ll.h:145
int flextcp_listen_open(struct flextcp_context *ctx, struct flextcp_listener *lst, uint16_t port, uint32_t backlog, uint32_t flags)
Definition: conn.c:41
int flextcp_connection_rx_done(struct flextcp_context *ctx, struct flextcp_connection *conn, size_t len)
Definition: conn.c:223
int flextcp_init(void)
Definition: init.c:75
int flextcp_connection_tx_close(struct flextcp_context *ctx, struct flextcp_connection *conn)
Definition: conn.c:337
uint32_t rxb_used
Definition: tas_ll.h:106
int flextcp_connection_close(struct flextcp_context *ctx, struct flextcp_connection *conn)
Definition: conn.c:161
int flextcp_connection_move(struct flextcp_context *ctx, struct flextcp_connection *conn)
Definition: conn.c:397
uint32_t rxb_head
Definition: tas_ll.h:104
uint32_t txb_sent
Definition: tas_ll.h:116
int flextcp_context_canwait(struct flextcp_context *ctx)
Definition: init.c:930
ssize_t flextcp_connection_tx_alloc2(struct flextcp_connection *conn, size_t len, void **buf_1, size_t *len_1, void **buf_2)
Definition: conn.c:277
int flextcp_connection_tx_possible(struct flextcp_context *ctx, struct flextcp_connection *conn)
Definition: conn.c:386
uint32_t txb_allocated
Definition: tas_ll.h:118
int flextcp_connection_open(struct flextcp_context *ctx, struct flextcp_connection *conn, uint32_t dst_ip, uint16_t dst_port)
Definition: conn.c:123
ssize_t flextcp_connection_tx_alloc(struct flextcp_connection *conn, size_t len, void **buf)
Definition: conn.c:242
void flextcp_context_waitclear(struct flextcp_context *ctx)
Definition: init.c:979
int flextcp_listen_accept(struct flextcp_context *ctx, struct flextcp_listener *lst, struct flextcp_connection *conn)
Definition: conn.c:89
uint32_t txb_bump
Definition: tas_ll.h:120
uint32_t txb_head
Definition: tas_ll.h:114