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