Line data Source code
1 : #define _GNU_SOURCE
2 : #include "fddev.h"
3 :
4 : #include "../fdctl/configure/configure.h"
5 : #include "../fdctl/run/run.h"
6 : #include "rpc_client/fd_rpc_client.h"
7 :
8 : #include "../../disco/topo/fd_topob.h"
9 : #include "../../disco/keyguard/fd_keyload.h"
10 : #include "../../util/net/fd_ip4.h"
11 : #include "../../util/shmem/fd_shmem_private.h"
12 :
13 : #include <unistd.h>
14 : #include <stdio.h>
15 : #include <sched.h>
16 : #include <fcntl.h>
17 : #include <pthread.h>
18 : #include <linux/capability.h>
19 : #include <linux/futex.h>
20 : #include <sys/syscall.h>
21 : #include <sys/wait.h>
22 : #include <sys/socket.h>
23 : #include <arpa/inet.h>
24 :
25 : #include "../../util/tile/fd_tile_private.h"
26 :
27 : void
28 : bench_cmd_perm( args_t * args,
29 : fd_caps_ctx_t * caps,
30 0 : config_t * const config ) {
31 0 : (void)args;
32 :
33 0 : args_t configure_args = {
34 0 : .configure.command = CONFIGURE_CMD_INIT,
35 0 : };
36 0 : for( ulong i=0; i<CONFIGURE_STAGE_COUNT; i++ )
37 0 : configure_args.configure.stages[ i ] = STAGES[ i ];
38 0 : configure_cmd_perm( &configure_args, caps, config );
39 :
40 0 : run_cmd_perm( NULL, caps, config );
41 0 : }
42 :
43 : void
44 : bench_cmd_args( int * pargc,
45 : char *** pargv,
46 0 : args_t * args ) {
47 0 : (void)pargc;
48 0 : (void)pargv;
49 0 : (void)args;
50 0 : args->load.no_quic = fd_env_strip_cmdline_contains( pargc, pargv, "--no-quic" );
51 0 : }
52 :
53 : static void *
54 0 : agave_thread_main( void * _args ) {
55 0 : config_t * config = _args;
56 0 : agave_boot( config );
57 :
58 : /* Agave will never exit, we never set exit flag to true */
59 0 : FD_LOG_ERR(( "agave_boot() exited" ));
60 0 : return NULL;
61 0 : }
62 :
63 : void
64 : add_bench_topo( fd_topo_t * topo,
65 : char const * affinity,
66 : ulong benchg_tile_cnt,
67 : ulong benchs_tile_cnt,
68 : ulong accounts_cnt,
69 : int transaction_mode,
70 : float contending_fraction,
71 : float cu_price_spread,
72 : ulong conn_cnt,
73 : ushort send_to_port,
74 : uint send_to_ip_addr,
75 : ushort rpc_port,
76 : uint rpc_ip_addr,
77 0 : int no_quic ) {
78 :
79 0 : fd_topob_wksp( topo, "bench" );
80 0 : fd_topob_link( topo, "bencho_out", "bench", 0, 128UL, 64UL, 1UL );
81 0 : for( ulong i=0UL; i<benchg_tile_cnt; i++ ) fd_topob_link( topo, "benchg_s", "bench", 0, 65536UL, FD_TXN_MTU, 1UL );
82 :
83 0 : int is_bench_auto_affinity = !strcmp( affinity, "auto" );
84 :
85 0 : ushort parsed_tile_to_cpu[ FD_TILE_MAX ];
86 0 : for( ulong i=0UL; i<FD_TILE_MAX; i++ ) parsed_tile_to_cpu[ i ] = USHORT_MAX;
87 :
88 0 : ulong affinity_tile_cnt = 0UL;
89 0 : if( FD_LIKELY( !is_bench_auto_affinity ) ) affinity_tile_cnt = fd_tile_private_cpus_parse( affinity, parsed_tile_to_cpu );
90 :
91 0 : ulong tile_to_cpu[ FD_TILE_MAX ] = {0};
92 0 : for( ulong i=0UL; i<affinity_tile_cnt; i++ ) {
93 0 : if( FD_UNLIKELY( parsed_tile_to_cpu[ i ]!=USHORT_MAX && parsed_tile_to_cpu[ i ]>=fd_numa_cpu_cnt() ) )
94 0 : FD_LOG_ERR(( "The CPU affinity string in the configuration file under [development.bench.affinity] specifies a CPU index of %hu, but the system "
95 0 : "only has %lu CPUs. You should either change the CPU allocations in the affinity string, or increase the number of CPUs "
96 0 : "in the system.",
97 0 : parsed_tile_to_cpu[ i ], fd_numa_cpu_cnt() ));
98 0 : tile_to_cpu[ i ] = fd_ulong_if( parsed_tile_to_cpu[ i ]==USHORT_MAX, ULONG_MAX, (ulong)parsed_tile_to_cpu[ i ] );
99 0 : }
100 0 : if( FD_LIKELY( !is_bench_auto_affinity ) ) {
101 0 : if( FD_UNLIKELY( affinity_tile_cnt<benchg_tile_cnt+1UL+benchs_tile_cnt ) )
102 0 : FD_LOG_ERR(( "The benchmark topology you are using has %lu bench tiles, but the CPU affinity specified "
103 0 : "in the [development.bench.affinity] only provides for %lu cores. ",
104 0 : benchg_tile_cnt+1UL+benchs_tile_cnt, affinity_tile_cnt ));
105 0 : else if( FD_UNLIKELY( affinity_tile_cnt>benchg_tile_cnt+1UL+benchs_tile_cnt ) )
106 0 : FD_LOG_WARNING(( "The benchmark topology you are using has %lu bench tiles, but the CPU affinity specified "
107 0 : "in the [development.bench.affinity] provides for %lu cores. The extra cores will be unused.",
108 0 : benchg_tile_cnt+1UL+benchs_tile_cnt, affinity_tile_cnt ));
109 0 : }
110 0 : fd_topo_tile_t * bencho = fd_topob_tile( topo, "bencho", "bench", "bench", tile_to_cpu[ 0 ], 0 );
111 0 : bencho->bencho.rpc_port = rpc_port;
112 0 : bencho->bencho.rpc_ip_addr = rpc_ip_addr;
113 0 : for( ulong i=0UL; i<benchg_tile_cnt; i++ ) {
114 0 : fd_topo_tile_t * benchg = fd_topob_tile( topo, "benchg", "bench", "bench", tile_to_cpu[ i+1UL ], 0 );
115 0 : benchg->benchg.accounts_cnt = accounts_cnt;
116 0 : benchg->benchg.mode = transaction_mode;
117 0 : benchg->benchg.contending_fraction = contending_fraction;
118 0 : benchg->benchg.cu_price_spread = cu_price_spread;
119 0 : }
120 0 : for( ulong i=0UL; i<benchs_tile_cnt; i++ ) {
121 0 : fd_topo_tile_t * benchs = fd_topob_tile( topo, "benchs", "bench", "bench", tile_to_cpu[ benchg_tile_cnt+1UL+i ], 0 );
122 0 : benchs->benchs.send_to_ip_addr = send_to_ip_addr;
123 0 : benchs->benchs.send_to_port = send_to_port;
124 0 : benchs->benchs.conn_cnt = conn_cnt;
125 0 : benchs->benchs.no_quic = no_quic;
126 0 : }
127 :
128 0 : fd_topob_tile_out( topo, "bencho", 0UL, "bencho_out", 0UL );
129 0 : for( ulong i=0UL; i<benchg_tile_cnt; i++ ) {
130 0 : fd_topob_tile_in( topo, "benchg", i, "bench", "bencho_out", 0, 1, 1 );
131 0 : fd_topob_tile_out( topo, "benchg", i, "benchg_s", i );
132 0 : }
133 0 : for( ulong i=0UL; i<benchg_tile_cnt; i++ ) {
134 0 : for( ulong j=0UL; j<benchs_tile_cnt; j++ ) {
135 0 : fd_topob_tile_in( topo, "benchs", j, "bench", "benchg_s", i, 1, 1 );
136 0 : }
137 0 : }
138 :
139 : /* This will blow away previous auto topology layouts and recompute an auto topology. */
140 0 : if( FD_UNLIKELY( is_bench_auto_affinity ) ) fd_topob_auto_layout( topo );
141 0 : fd_topob_finish( topo, fdctl_obj_align, fdctl_obj_footprint, fdctl_obj_loose );
142 0 : }
143 :
144 : extern int * fd_log_private_shared_lock;
145 :
146 : void
147 : bench_cmd_fn( args_t * args,
148 0 : config_t * const config ) {
149 0 : (void)args;
150 :
151 0 : ushort dest_port = fd_ushort_if( args->load.no_quic,
152 0 : config->tiles.quic.regular_transaction_listen_port,
153 0 : config->tiles.quic.quic_transaction_listen_port );
154 :
155 0 : config->rpc.port = fd_ushort_if( config->rpc.port, config->rpc.port, 8899 );
156 0 : config->rpc.full_api = 1;
157 :
158 0 : add_bench_topo( &config->topo,
159 0 : config->development.bench.affinity,
160 0 : config->development.bench.benchg_tile_count,
161 0 : config->development.bench.benchs_tile_count,
162 0 : config->development.genesis.fund_initial_accounts,
163 0 : 0, 0.0f, 0.0f,
164 0 : config->layout.quic_tile_count,
165 0 : dest_port,
166 0 : config->tiles.net.ip_addr,
167 0 : config->rpc.port,
168 0 : config->tiles.net.ip_addr,
169 0 : args->load.no_quic );
170 :
171 0 : if( FD_LIKELY( !args->dev.no_configure ) ) {
172 0 : args_t configure_args = {
173 0 : .configure.command = CONFIGURE_CMD_INIT,
174 0 : };
175 0 : for( ulong i=0; i<CONFIGURE_STAGE_COUNT; i++ )
176 0 : configure_args.configure.stages[ i ] = STAGES[ i ];
177 0 : configure_cmd_fn( &configure_args, config );
178 0 : }
179 :
180 0 : update_config_for_dev( config );
181 :
182 0 : run_firedancer_init( config, 1 );
183 :
184 0 : fd_xdp_fds_t fds = fd_topo_install_xdp( &config->topo );
185 0 : (void)fds;
186 :
187 0 : fd_log_private_shared_lock[ 1 ] = 0;
188 0 : fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE );
189 :
190 0 : fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run, NULL );
191 0 : pthread_t agave;
192 0 : pthread_create( &agave, NULL, agave_thread_main, config );
193 :
194 : /* Sleep parent thread forever, Ctrl+C will terminate. */
195 0 : for(;;) pause();
196 0 : }
|