Line data Source code
1 : /* _GNU_SOURCE for recvmmsg and sendmmsg */
2 : #define _GNU_SOURCE
3 :
4 : #include "../../../../disco/metrics/fd_metrics.h"
5 : #include "../../../../disco/fd_clock_tile.h"
6 : #include "../../../../disco/topo/fd_topo.h"
7 : #include "../../../../waltz/quic/fd_quic.h"
8 : #include "../../../../waltz/quic/tests/fd_quic_test_helpers.h"
9 : #include "../../../../waltz/tls/test_tls_helper.h"
10 :
11 : #include <errno.h>
12 : #include <sys/types.h>
13 : #include <sys/socket.h>
14 : #include <netinet/in.h>
15 : #include <string.h>
16 : #include <unistd.h>
17 : #include <poll.h>
18 :
19 : #include <stdio.h>
20 : #include <stdlib.h>
21 : #include <time.h>
22 :
23 : /* max number of buffers batched for receive */
24 0 : #define IO_VEC_CNT 128
25 :
26 : static int
27 : quic_tx_aio_send( void * _ctx,
28 : fd_aio_pkt_info_t const * batch,
29 : ulong batch_cnt,
30 : ulong * opt_batch_idx,
31 : int flush );
32 :
33 : typedef struct {
34 : ulong round_robin_cnt;
35 : ulong round_robin_id;
36 :
37 : ulong packet_cnt;
38 :
39 : ulong conn_cnt;
40 : int conn_fd[ 128UL ];
41 : struct pollfd poll_fd[ 128UL ];
42 :
43 : fd_tls_test_sign_ctx_t test_signer[1];
44 : int no_quic;
45 : fd_quic_t * quic;
46 : uint quic_ip;
47 : ushort quic_port;
48 : fd_quic_conn_t * quic_conn;
49 : ulong no_stream;
50 : uint service_ratio_idx;
51 : fd_aio_t tx_aio;
52 :
53 : long now; /* current time in ns */
54 : fd_clock_tile_t clock[1];
55 :
56 : /* vector receive members */
57 : struct mmsghdr rx_msgs[IO_VEC_CNT];
58 : struct mmsghdr tx_msgs[IO_VEC_CNT];
59 : struct iovec rx_iovecs[IO_VEC_CNT];
60 : struct iovec tx_iovecs[IO_VEC_CNT];
61 : uchar rx_bufs[IO_VEC_CNT][2048];
62 : uchar tx_bufs[IO_VEC_CNT][2048];
63 :
64 : ulong tx_idx;
65 :
66 : fd_wksp_t * mem;
67 : } fd_benchs_ctx_t;
68 :
69 : static void
70 : service_quic( fd_benchs_ctx_t * ctx,
71 0 : long now ) {
72 :
73 0 : if( !ctx->no_quic ) {
74 : /* Publishes to mcache via callbacks */
75 :
76 : /* receive from socket, and pass to quic */
77 0 : int poll_rc = poll( ctx->poll_fd, ctx->conn_cnt, 0 );
78 0 : if( FD_LIKELY( poll_rc == 0 ) ) {
79 0 : return;
80 0 : } if( FD_UNLIKELY( poll_rc == -1 ) ) {
81 0 : if( FD_UNLIKELY( errno == EINTR ) ) return; /* will try later */
82 0 : FD_LOG_ERR(( "Error occurred during poll: %d %s", errno,
83 0 : strerror( errno ) ));
84 0 : }
85 :
86 0 : for( ulong j = 0; j < ctx->conn_cnt; ++j ) {
87 0 : int revents = ctx->poll_fd[j].revents;
88 0 : if( FD_LIKELY( revents & POLLIN ) ) {
89 : /* data available - receive up to IO_VEC_CNT buffers */
90 0 : struct timespec timeout = {0};
91 0 : int retval = recvmmsg( ctx->poll_fd[j].fd, ctx->rx_msgs, IO_VEC_CNT, 0, &timeout );
92 0 : if( FD_UNLIKELY( retval < 0 ) ) {
93 0 : FD_LOG_ERR(( "Error occurred on recvmmsg: %d %s", errno, strerror( errno ) ));
94 0 : }
95 : /* pass buffers to QUIC */
96 0 : for( ulong k = 0; k < (ulong)retval; k++ ) {
97 0 : uchar * buf = ctx->rx_bufs[k];
98 :
99 : /* set some required values */
100 0 : uint payload_len = ctx->rx_msgs[k].msg_len;
101 0 : uint udp_len = payload_len + 8;
102 0 : uint ip_len = udp_len + 20;
103 :
104 : /* set ver and len */
105 0 : buf[0] = 0x45;
106 :
107 : /* set protocol */
108 0 : buf[9] = 17;
109 :
110 : /* set udp length */
111 0 : buf[20 + 4] = (uchar)( udp_len >> 8 );
112 0 : buf[20 + 5] = (uchar)( udp_len );
113 :
114 : /* set ip length */
115 0 : buf[2] = (uchar)( ip_len >> 8 );
116 0 : buf[3] = (uchar)( ip_len );
117 :
118 : /* set src ip addr */
119 0 : buf[12] = (uchar)( ctx->quic_ip );
120 0 : buf[13] = (uchar)( ctx->quic_ip >> 8 );
121 0 : buf[14] = (uchar)( ctx->quic_ip >> 16 );
122 0 : buf[15] = (uchar)( ctx->quic_ip >> 24 );
123 :
124 0 : fd_quic_process_packet( ctx->quic, buf, ip_len, now );
125 0 : }
126 0 : } else if( FD_UNLIKELY( revents & POLLERR ) ) {
127 0 : int error = 0;
128 0 : socklen_t errlen = sizeof(error);
129 :
130 0 : if( getsockopt( ctx->poll_fd[j].fd, SOL_SOCKET, SO_ERROR, (void *)&error, &errlen ) == -1 ) {
131 0 : FD_LOG_ERR(( "Unknown error on socket" ));
132 0 : } else {
133 0 : FD_LOG_ERR(( "Error on socket: %d %s", error, strerror( error ) ));
134 0 : }
135 0 : }
136 0 : }
137 0 : }
138 0 : }
139 :
140 : /* quic_conn_new is invoked by the QUIC engine whenever a new connection
141 : is being established. */
142 : static void
143 : quic_conn_new( fd_quic_conn_t * conn,
144 0 : void * _ctx ) {
145 0 : (void)conn;
146 0 : (void)_ctx;
147 0 : }
148 :
149 :
150 : static void
151 : handshake_complete( fd_quic_conn_t * conn,
152 0 : void * _ctx ) {
153 0 : (void)conn;
154 0 : (void)_ctx;
155 0 : FD_LOG_NOTICE(( "client handshake complete" ));
156 0 : }
157 :
158 : static void
159 : conn_final( fd_quic_conn_t * conn,
160 0 : void * _ctx ) {
161 0 : (void)conn;
162 :
163 0 : fd_benchs_ctx_t * ctx = (fd_benchs_ctx_t *)_ctx;
164 :
165 0 : if( ctx ) {
166 0 : ctx->quic_conn = NULL;
167 0 : }
168 0 : }
169 :
170 : FD_FN_CONST static inline ulong
171 0 : scratch_align( void ) {
172 0 : return fd_ulong_max( fd_quic_align(), alignof( fd_benchs_ctx_t ) );
173 0 : }
174 :
175 : static void
176 0 : populate_quic_limits( fd_quic_limits_t * limits ) {
177 0 : limits->conn_cnt = 2;
178 0 : limits->handshake_cnt = limits->conn_cnt;
179 0 : limits->conn_id_cnt = 16;
180 0 : limits->inflight_frame_cnt = 1500;
181 0 : limits->tx_buf_sz = 1UL<<11;
182 0 : limits->stream_pool_cnt = 1UL<<16;
183 0 : limits->stream_id_cnt = 1UL<<16;
184 0 : }
185 :
186 : static void
187 0 : populate_quic_config( fd_quic_config_t * config ) {
188 0 : config->role = FD_QUIC_ROLE_CLIENT;
189 0 : config->retry = 0;
190 0 : config->initial_rx_max_stream_data = 0; /* we don't expect the server to initiate streams */
191 0 : config->net.dscp = 0;
192 0 : }
193 :
194 : static inline ulong
195 0 : scratch_footprint( fd_topo_tile_t const * tile ) {
196 0 : ulong l = FD_LAYOUT_INIT;
197 0 : l = FD_LAYOUT_APPEND( l, alignof( fd_benchs_ctx_t ), sizeof( fd_benchs_ctx_t ) );
198 0 : if( !tile->benchs.no_quic ) {
199 0 : fd_quic_limits_t quic_limits = {0};
200 0 : populate_quic_limits( &quic_limits );
201 0 : ulong quic_fp = fd_quic_footprint( &quic_limits );
202 0 : l = FD_LAYOUT_APPEND( l, fd_quic_align(), quic_fp );
203 0 : }
204 0 : return FD_LAYOUT_FINI( l, scratch_align() );
205 0 : }
206 :
207 : static inline void
208 0 : metrics_write( fd_benchs_ctx_t * ctx ) {
209 0 : FD_MCNT_SET( BENCHS, TRANSACTIONS_SENT, ctx->packet_cnt );
210 0 : }
211 :
212 : static inline int
213 : before_frag( fd_benchs_ctx_t * ctx,
214 : ulong in_idx,
215 : ulong seq,
216 0 : ulong sig ) {
217 0 : (void)in_idx;
218 0 : (void)sig;
219 :
220 0 : ctx->now = fd_clock_tile_now( ctx->clock );
221 :
222 0 : return (int)( (seq%ctx->round_robin_cnt)!=ctx->round_robin_id );
223 0 : }
224 :
225 : static inline void
226 : during_frag( fd_benchs_ctx_t * ctx,
227 : ulong in_idx FD_PARAM_UNUSED,
228 : ulong seq FD_PARAM_UNUSED,
229 : ulong sig FD_PARAM_UNUSED,
230 : ulong chunk,
231 : ulong sz,
232 0 : ulong ctl FD_PARAM_UNUSED ) {
233 0 : if( ctx->no_quic ) {
234 :
235 0 : if( FD_UNLIKELY( -1==send( ctx->conn_fd[ ctx->packet_cnt % ctx->conn_cnt ], fd_chunk_to_laddr( ctx->mem, chunk ), sz, 0 ) ) )
236 0 : FD_LOG_ERR(( "send() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
237 :
238 0 : ctx->packet_cnt++;
239 0 : } else {
240 : /* allows to accumulate multiple transactions before creating a UDP datagram */
241 : /* make this configurable */
242 0 : if( FD_UNLIKELY( ctx->service_ratio_idx++ == 8 ) ) {
243 0 : ctx->service_ratio_idx = 0;
244 0 : service_quic( ctx, ctx->now );
245 0 : fd_quic_service( ctx->quic, ctx->now );
246 0 : }
247 :
248 0 : if( FD_UNLIKELY( !ctx->quic_conn ) ) {
249 0 : ctx->no_stream = 0;
250 :
251 : /* try to connect */
252 0 : uint dest_ip = ctx->quic_ip;
253 0 : ushort dest_port = fd_ushort_bswap( ctx->quic_port );
254 :
255 0 : ctx->quic_conn = fd_quic_connect( ctx->quic, dest_ip, dest_port, 0U, 12000, ctx->now );
256 :
257 : /* failed? try later */
258 0 : if( FD_UNLIKELY( !ctx->quic_conn ) ) {
259 0 : service_quic( ctx, ctx->now );
260 0 : fd_quic_service( ctx->quic, ctx->now );
261 0 : return;
262 0 : }
263 :
264 0 : FD_LOG_NOTICE(( "connection created on port %d", (int)dest_port ));
265 :
266 : /* set the context to point to the location
267 : of the quic_conn pointer
268 : this allows the notification to NULL the value when
269 : a connection dies */
270 0 : fd_quic_conn_set_context( ctx->quic_conn, ctx );
271 :
272 0 : service_quic( ctx, ctx->now );
273 0 : fd_quic_service( ctx->quic, ctx->now );
274 :
275 : /* conn and streams may be invalidated by fd_quic_service */
276 :
277 0 : return;
278 0 : }
279 :
280 0 : fd_quic_stream_t * stream = fd_quic_conn_new_stream( ctx->quic_conn );
281 0 : if( FD_UNLIKELY( !stream ) ) {
282 0 : ctx->no_stream++;
283 0 : service_quic( ctx, ctx->now );
284 0 : fd_quic_service( ctx->quic, ctx->now );
285 :
286 : /* conn and streams may be invalidated by fd_quic_service */
287 :
288 0 : return;
289 0 : } else {
290 0 : int fin = 1;
291 0 : int rtn = fd_quic_stream_send( stream, fd_chunk_to_laddr( ctx->mem, chunk ), sz, fin );
292 0 : ctx->packet_cnt++;
293 :
294 0 : if( FD_UNLIKELY( rtn != FD_QUIC_SUCCESS ) ) {
295 : /* this can happen dring handshaking */
296 0 : if( rtn != FD_QUIC_SEND_ERR_INVAL_CONN ) {
297 0 : FD_LOG_ERR(( "fd_quic_stream_send failed with: %d", rtn ));
298 0 : }
299 0 : }
300 0 : }
301 0 : }
302 0 : }
303 :
304 : static void
305 : privileged_init( fd_topo_t * topo,
306 0 : fd_topo_tile_t * tile ) {
307 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
308 :
309 : /* call wallclock so glibc loads VDSO, which requires calling mmap while
310 : privileged */
311 0 : fd_log_wallclock();
312 :
313 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
314 0 : fd_benchs_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_benchs_ctx_t ), sizeof( fd_benchs_ctx_t ) );
315 0 : fd_memset( ctx, 0, sizeof(fd_benchs_ctx_t) );
316 :
317 0 : int no_quic = ctx->no_quic = tile->benchs.no_quic;
318 0 : ushort port = 12000;
319 :
320 0 : ctx->conn_cnt = tile->benchs.conn_cnt;
321 0 : if( !no_quic ) ctx->conn_cnt = 1;
322 0 : FD_TEST( ctx->conn_cnt <=sizeof(ctx->conn_fd)/sizeof(*ctx->conn_fd) );
323 0 : ctx->quic_ip = tile->benchs.send_to_ip_addr;
324 0 : ctx->quic_port = tile->benchs.send_to_port;
325 0 : for( ulong i=0UL; i<ctx->conn_cnt ; i++ ) {
326 0 : int conn_fd = socket( AF_INET, SOCK_DGRAM, 0 );
327 0 : if( FD_UNLIKELY( -1==conn_fd ) ) FD_LOG_ERR(( "socket() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
328 :
329 0 : int recvbuff = 8<<20;
330 :
331 : // Set the buffer size
332 0 : if( setsockopt( conn_fd, SOL_SOCKET, SO_RCVBUF, &recvbuff, sizeof(recvbuff) ) < 0 ) {
333 0 : FD_LOG_ERR(( "Error setting receive buffer size. Error: %d %s", errno, strerror( errno ) ));
334 0 : }
335 :
336 0 : int sendbuff = 8<<20;
337 0 : if( setsockopt( conn_fd, SOL_SOCKET, SO_SNDBUF, &sendbuff, sizeof(sendbuff) ) < 0 ) {
338 0 : FD_LOG_ERR(( "Error setting transmit buffer size. Error: %d %s", errno, strerror( errno ) ));
339 0 : }
340 :
341 0 : ushort found_port = 0;
342 0 : for( ulong j=0UL; j<10UL; j++ ) {
343 0 : struct sockaddr_in addr = {
344 0 : .sin_family = AF_INET,
345 0 : .sin_port = fd_ushort_bswap( port ),
346 0 : .sin_addr.s_addr = fd_uint_bswap( INADDR_ANY ),
347 0 : };
348 0 : if( FD_UNLIKELY( -1!=bind( conn_fd, fd_type_pun( &addr ), sizeof(addr) ) ) ) {
349 0 : found_port = port;
350 0 : break;
351 0 : }
352 0 : if( FD_UNLIKELY( EADDRINUSE!=errno ) ) FD_LOG_ERR(( "bind() failed (%i-%s)", errno, fd_io_strerror( errno ) ) );
353 0 : port = (ushort)(port + ctx->conn_cnt); /* Make sure it round robins to the same tile index */
354 0 : }
355 0 : if( FD_UNLIKELY( !found_port ) ) FD_LOG_ERR(( "bind() failed to find a src port" ));
356 :
357 0 : struct sockaddr_in addr = {
358 0 : .sin_family = AF_INET,
359 0 : .sin_port = fd_ushort_bswap( tile->benchs.send_to_port ),
360 0 : .sin_addr.s_addr = tile->benchs.send_to_ip_addr,
361 0 : };
362 0 : if( FD_UNLIKELY( -1==connect( conn_fd, fd_type_pun( &addr ), sizeof(addr) ) ) ) FD_LOG_ERR(( "connect() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
363 :
364 0 : ctx->conn_fd[ i ] = conn_fd;
365 0 : if( !no_quic ) {
366 0 : ctx->poll_fd[i].fd = conn_fd;
367 0 : ctx->poll_fd[i].events = POLLIN;
368 0 : }
369 0 : port++;
370 0 : }
371 0 : }
372 :
373 : static void
374 : unprivileged_init( fd_topo_t * topo,
375 0 : fd_topo_tile_t * tile ) {
376 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
377 :
378 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
379 0 : fd_benchs_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_benchs_ctx_t ), sizeof( fd_benchs_ctx_t ) );
380 :
381 0 : ctx->packet_cnt = 0UL;
382 :
383 0 : ctx->round_robin_id = tile->kind_id;
384 0 : ctx->round_robin_cnt = fd_topo_tile_name_cnt( topo, "benchs" );
385 :
386 0 : ctx->mem = topo->workspaces[ topo->objs[ topo->links[ tile->in_link_id[ 0UL ] ].dcache_obj_id ].wksp_id ].wksp;
387 :
388 0 : if( !ctx->no_quic ) {
389 0 : fd_quic_limits_t quic_limits = {0};
390 0 : populate_quic_limits( &quic_limits );
391 :
392 0 : ulong quic_fp = fd_quic_footprint( &quic_limits );
393 0 : if( FD_UNLIKELY( !quic_fp ) ) FD_LOG_ERR(( "invalid QUIC parameters" ));
394 0 : void * quic_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_quic_align(), quic_fp );
395 0 : fd_quic_t * quic = fd_quic_join( fd_quic_new( quic_mem, &quic_limits ) );
396 :
397 0 : populate_quic_config( &quic->config );
398 :
399 : /* FIXME this always results in the same private key */
400 0 : fd_rng_t _rng[1];
401 0 : fd_rng_t * rng = fd_rng_join( fd_rng_new( _rng, 4242424242, 0UL ) );
402 0 : fd_tls_test_sign_ctx( ctx->test_signer, rng );
403 0 : fd_quic_config_test_signer( quic, ctx->test_signer );
404 :
405 0 : ctx->quic = quic;
406 0 : ctx->tx_idx = 0UL;
407 :
408 0 : fd_aio_t * quic_tx_aio = fd_aio_join( fd_aio_new( &ctx->tx_aio, ctx, quic_tx_aio_send ) );
409 0 : if( FD_UNLIKELY( !quic_tx_aio ) ) FD_LOG_ERR(( "fd_aio_join failed" ));
410 :
411 0 : ulong quic_idle_timeout_millis = 10000; /* idle timeout in milliseconds */
412 0 : quic->config.role = FD_QUIC_ROLE_CLIENT;
413 0 : quic->config.idle_timeout = (long)( quic_idle_timeout_millis * 1000000L );
414 0 : quic->config.initial_rx_max_stream_data = 0;
415 0 : quic->config.retry = 0; /* unused on clients */
416 :
417 0 : quic->cb.conn_new = quic_conn_new;
418 0 : quic->cb.conn_hs_complete = handshake_complete;
419 0 : quic->cb.conn_final = conn_final;
420 0 : quic->cb.quic_ctx = ctx;
421 :
422 0 : fd_quic_set_aio_net_tx( quic, quic_tx_aio );
423 0 : if( FD_UNLIKELY( !fd_quic_init( quic ) ) ) FD_LOG_ERR(( "fd_quic_init failed" ));
424 :
425 0 : ulong hdr_sz = 20 + 8;
426 0 : for( ulong i = 0; i < IO_VEC_CNT; i++ ) {
427 : /* leave space for headers */
428 0 : ctx->rx_iovecs[i] = (struct iovec) {
429 0 : .iov_base = ctx->rx_bufs[i] + hdr_sz,
430 0 : .iov_len = sizeof(ctx->rx_bufs[i]) - hdr_sz
431 0 : };
432 0 : ctx->rx_msgs[i] = (struct mmsghdr) {
433 0 : .msg_hdr = {
434 0 : .msg_iov = &ctx->rx_iovecs[i],
435 0 : .msg_iovlen = 1
436 0 : }
437 0 : };
438 0 : }
439 0 : }
440 :
441 0 : ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, 1UL );
442 0 : if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
443 0 : FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
444 :
445 0 : fd_clock_tile_t * clock = ctx->clock;
446 0 : fd_clock_tile_init( clock );
447 0 : ctx->now = fd_clock_tile_now( clock );
448 0 : }
449 :
450 : static void
451 0 : quic_tx_aio_send_flush( fd_benchs_ctx_t * ctx ) {
452 0 : if( FD_LIKELY( ctx->tx_idx ) ) {
453 0 : int flags = 0;
454 0 : int rtn = sendmmsg( ctx->conn_fd[0], ctx->tx_msgs, (uint)ctx->tx_idx, flags );
455 0 : if( FD_UNLIKELY( rtn < 0 ) ) {
456 0 : FD_LOG_NOTICE(( "Error occurred in sendmmsg. Error: %d %s",
457 0 : errno, strerror( errno ) ));
458 0 : }
459 0 : ctx->tx_idx = 0;
460 0 : }
461 0 : }
462 :
463 : static int
464 : quic_tx_aio_send( void * _ctx,
465 : fd_aio_pkt_info_t const * batch,
466 : ulong batch_cnt,
467 : ulong * opt_batch_idx,
468 0 : int flush ) {
469 0 : fd_benchs_ctx_t * ctx = _ctx;
470 :
471 : /* quic adds ip and udp headers which we don't need */
472 : /* assume 20 + 8 for those */
473 0 : ulong hdr_sz = 20+8;
474 :
475 0 : if( FD_LIKELY( batch_cnt ) ) {
476 : /* do we have space? */
477 0 : ulong remain = IO_VEC_CNT - ctx->tx_idx;
478 0 : if( FD_UNLIKELY( remain > batch_cnt ) ) {
479 0 : quic_tx_aio_send_flush( ctx );
480 :
481 : /* tx_idx may have changed */
482 0 : remain = IO_VEC_CNT - ctx->tx_idx;
483 0 : }
484 :
485 0 : ulong cnt = fd_ulong_min( remain, batch_cnt );
486 0 : ulong tx_idx = ctx->tx_idx;
487 0 : for( ulong j = 0; j < cnt; ++j ) {
488 0 : if( FD_UNLIKELY( batch[j].buf_sz < hdr_sz ) ) continue;
489 :
490 0 : uchar * tx_buf = ctx->tx_bufs[tx_idx];
491 :
492 : /* copy, stripping the header */
493 0 : fd_memcpy( tx_buf, (uchar*)batch[j].buf + hdr_sz, batch[j].buf_sz - hdr_sz );
494 :
495 0 : ctx->tx_iovecs[tx_idx] = (struct iovec) {
496 0 : .iov_base = tx_buf,
497 0 : .iov_len = batch[j].buf_sz - hdr_sz
498 0 : };
499 0 : ctx->tx_msgs[tx_idx] = (struct mmsghdr) {
500 0 : .msg_hdr = {
501 0 : .msg_iov = &ctx->tx_iovecs[tx_idx],
502 0 : .msg_iovlen = 1,
503 0 : }
504 0 : };
505 :
506 0 : tx_idx++;
507 0 : }
508 :
509 : /* write back */
510 0 : ctx->tx_idx = tx_idx;
511 :
512 : // TODO count drops?
513 : // ctx->dropped += batch_cnt - remain;
514 0 : }
515 :
516 0 : if( FD_UNLIKELY( ctx->tx_idx == IO_VEC_CNT || flush ) ) {
517 0 : quic_tx_aio_send_flush( ctx );
518 0 : }
519 :
520 0 : if( FD_LIKELY( opt_batch_idx ) ) *opt_batch_idx = batch_cnt;
521 :
522 0 : return 0;
523 0 : }
524 :
525 : static void
526 0 : during_housekeeping( fd_benchs_ctx_t * ctx ) {
527 0 : if( FD_UNLIKELY( fd_clock_tile_recal_due( ctx->clock ) ) ) {
528 0 : fd_clock_tile_recal( ctx->clock );
529 0 : }
530 0 : }
531 :
532 0 : #define STEM_BURST (1UL)
533 :
534 0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_benchs_ctx_t
535 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_benchs_ctx_t)
536 :
537 0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
538 0 : #define STEM_CALLBACK_BEFORE_FRAG before_frag
539 0 : #define STEM_CALLBACK_DURING_FRAG during_frag
540 0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
541 :
542 : #include "../../../../disco/stem/fd_stem.c"
543 :
544 : fd_topo_run_tile_t fd_tile_benchs = {
545 : .name = "benchs",
546 : .scratch_align = scratch_align,
547 : .scratch_footprint = scratch_footprint,
548 : .privileged_init = privileged_init,
549 : .unprivileged_init = unprivileged_init,
550 : .run = stem_run,
551 : };
|