diff --git a/src/app/firedancer-dev/commands/backtest.c b/src/app/firedancer-dev/commands/backtest.c index 0390ff34db5..6457f2cb262 100644 --- a/src/app/firedancer-dev/commands/backtest.c +++ b/src/app/firedancer-dev/commands/backtest.c @@ -19,6 +19,7 @@ #include "../../shared/fd_config.h" /* config_t */ #include "../../shared/fd_config_json.h" #include "../../../disco/topo/fd_topob.h" +#include "../../../disco/topo/fd_cpu_topo.h" #include "../../../util/pod/fd_pod_format.h" #include "../../../disco/gui/fd_gui_config_parse.h" #include "../../../disco/diag/fd_diag_tile.h" @@ -73,24 +74,46 @@ backtest_topo( config_t * config ) { topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size ); topo->gigantic_page_threshold = config->hugetlbfs.gigantic_page_threshold_mib << 20; + ushort parsed_tile_to_cpu[ FD_TILE_MAX ]; + /* Unassigned tiles will be floating, unless auto topology is enabled. */ + for( ulong i=0UL; ilayout.affinity, "auto" ); + + fd_topo_cpus_t cpus[1]; + fd_topo_cpus_init( cpus ); + + ulong affinity_tile_cnt = 0UL; + if( FD_LIKELY( !is_auto_affinity ) ) affinity_tile_cnt = fd_topob_parse_affinity_cstr( config->layout.affinity, parsed_tile_to_cpu, 1, 1 ); + + ulong tile_to_cpu[ FD_TILE_MAX ] = {0}; + for( ulong i=0UL; i=cpus->cpu_cnt ) ) + FD_LOG_ERR(( "[layout.affinity] specifies CPU %hu but the system only has %lu CPUs", cpu, cpus->cpu_cnt )); + tile_to_cpu[ i ] = fd_ulong_if( parsed_tile_to_cpu[ i ]==USHORT_MAX, ULONG_MAX, (ulong)parsed_tile_to_cpu[ i ] ); + } + ulong cpu_idx = 1; +# define NEXT_CPU ( is_auto_affinity ? cpu_idx++ : tile_to_cpu[ topo->tile_cnt ] ) +# define FLOAT_CPU ( is_auto_affinity ? ULONG_MAX : tile_to_cpu[ topo->tile_cnt ] ) fd_topob_wksp( topo, "metric" ); fd_topob_wksp( topo, "metric_in" ); - fd_topob_tile( topo, "metric", "metric", "metric_in", ULONG_MAX, 0, 0, 0, 1 ); + fd_topob_tile( topo, "metric", "metric", "metric_in", FLOAT_CPU, 0, 0, 0, 1 ); fd_topob_wksp( topo, "backt" ); - fd_topo_tile_t * backt_tile = fd_topob_tile( topo, "backt", "backt", "metric_in", cpu_idx++, 0, 0, 0, 0 ); + fd_topo_tile_t * backt_tile = fd_topob_tile( topo, "backt", "backt", "metric_in", NEXT_CPU, 0, 0, 0, 0 ); fd_topob_wksp( topo, "replay" ); - fd_topo_tile_t * replay_tile = fd_topob_tile( topo, "replay", "replay", "metric_in", cpu_idx++, 0, 1, 0, 0 ); + fd_topo_tile_t * replay_tile = fd_topob_tile( topo, "replay", "replay", "metric_in", NEXT_CPU, 0, 1, 0, 0 ); fd_topo_obj_t * node_info_obj = fd_topob_obj( topo, "node_info", "replay" ); fd_topob_tile_uses( topo, replay_tile, node_info_obj, FD_SHMEM_JOIN_MODE_READ_WRITE ); FD_TEST( fd_pod_insertf_ulong( topo->props, node_info_obj->id, "node_info" ) ); fd_topob_wksp( topo, "accdb" )->core_dump_level = FD_TOPO_CORE_DUMP_LEVEL_FULL; - fd_topo_tile_t * accdb_tile = fd_topob_tile( topo, "accdb", "accdb", "metric_in", cpu_idx++, 0, 0, 0, 0 ); + fd_topo_tile_t * accdb_tile = fd_topob_tile( topo, "accdb", "accdb", "metric_in", NEXT_CPU, 0, 0, 0, 0 ); fd_topob_wksp( topo, "progcache" ); setup_topo_progcache( topo, "progcache", @@ -119,18 +142,18 @@ backtest_topo( config_t * config ) { /**********************************************************************/ fd_topob_wksp( topo, "execrp" ); #define FOR(cnt) for( ulong i=0UL; iallow_shutdown = 1; - snapin_tile = fd_topob_tile( topo, "snapin", "snapin", "metric_in", cpu_idx++, 0, 0, 0, 0 ); - fd_topo_tile_t * snapwr_tile = fd_topob_tile( topo, "snapwr", "snapwr", "metric_in", cpu_idx++, 0, 0, 0, 0 ); + fd_topo_tile_t * snapct_tile = fd_topob_tile( topo, "snapct", "snapct", "metric_in", NEXT_CPU, 0, 0, 0, 0 ); + fd_topo_tile_t * snapld_tile = fd_topob_tile( topo, "snapld", "snapld", "metric_in", NEXT_CPU, 0, 0, 0, 0 ); + FOR(snapdc_tile_cnt) fd_topob_tile( topo, "snapdc", "snapdc", "metric_in", NEXT_CPU, 0, 0, 0, 0 )->allow_shutdown = 1; + snapin_tile = fd_topob_tile( topo, "snapin", "snapin", "metric_in", NEXT_CPU, 0, 0, 0, 0 ); + fd_topo_tile_t * snapwr_tile = fd_topob_tile( topo, "snapwr", "snapwr", "metric_in", NEXT_CPU, 0, 0, 0, 0 ); snapct_tile->allow_shutdown = 1; snapld_tile->allow_shutdown = 1; @@ -155,7 +178,7 @@ backtest_topo( config_t * config ) { snapwr_tile->allow_shutdown = 1; } else { fd_topob_wksp( topo, "genesi" ); - fd_topob_tile( topo, "genesi", "genesi", "metric_in", cpu_idx++, 0, 0, 0, 0 )->allow_shutdown = 1; + fd_topob_tile( topo, "genesi", "genesi", "metric_in", NEXT_CPU, 0, 0, 0, 0 )->allow_shutdown = 1; } /**********************************************************************/ @@ -167,8 +190,8 @@ backtest_topo( config_t * config ) { fd_topob_wksp( topo, "event_sign" ); fd_topob_wksp( topo, "sign_event" ); - fd_topob_tile( topo, "sign", "sign", "metric_in", cpu_idx++, 0, 1, 1, 0 ); - fd_topo_tile_t * event_tile = fd_topob_tile( topo, "event", "event", "metric_in", cpu_idx++, 0, 1, 0, 1 ); + fd_topob_tile( topo, "sign", "sign", "metric_in", NEXT_CPU, 0, 1, 1, 0 ); + fd_topo_tile_t * event_tile = fd_topob_tile( topo, "event", "event", "metric_in", NEXT_CPU, 0, 1, 0, 1 ); ushort shred_version = 0; uchar genesis_hash[ 32 ] = {0}; @@ -333,7 +356,7 @@ backtest_topo( config_t * config ) { requires the snapshot tiles. */ if( FD_UNLIKELY( config->tiles.gui.enabled && !disable_snap_loader ) ) { fd_topob_wksp( topo, "gui" ); - fd_topo_tile_t * gui_tile = fd_topob_tile( topo, "gui", "gui", "metric_in", cpu_idx++, 0, 1, 0, 1 ); + fd_topo_tile_t * gui_tile = fd_topob_tile( topo, "gui", "gui", "metric_in", NEXT_CPU, 0, 1, 0, 1 ); fd_topob_wksp( topo, "diag_gui" ); fd_topob_link( topo, "diag_gui", "diag_gui", 4UL, sizeof(fd_diag_system_resources_t), 1UL ); @@ -432,7 +455,15 @@ backtest_topo( config_t * config ) { if( FD_LIKELY( telemetry_enabled ) ) wire_event_links( topo ); // fd_topob_auto_layout( topo, 0 ); + if( FD_UNLIKELY( !is_auto_affinity ) ) { + if( FD_UNLIKELY( affinity_tile_cnttile_cnt ) ) + FD_LOG_ERR(( "topology has %lu tiles but [layout.affinity] only provides %lu entries", topo->tile_cnt, affinity_tile_cnt )); + if( FD_UNLIKELY( affinity_tile_cnt>topo->tile_cnt ) ) + FD_LOG_WARNING(( "topology has %lu tiles but [layout.affinity] provides %lu entries, extra entries will be unused", topo->tile_cnt, affinity_tile_cnt )); + } + fd_topob_waker( topo ); + fd_topob_finish( topo, CALLBACKS ); }