LCOV - code coverage report
Current view: top level - app/shared_dev/commands/bench - bench.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 113 0.0 %
Date: 2025-07-01 05:00:49 Functions: 0 3 0.0 %

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

Generated by: LCOV version 1.14