Skip to content

Commit 0294958

Browse files
committed
bank: support use_consumed_cus flag
1 parent b566eac commit 0294958

File tree

2 files changed

+73
-44
lines changed

2 files changed

+73
-44
lines changed

src/app/firedancer/topology.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ fd_topo_initialize( config_t * config ) {
341341
fd_topob_wksp( topo, "pack_poh" );
342342
fd_topob_wksp( topo, "pack_bank" );
343343
fd_topob_wksp( topo, "resolv_repla" );
344-
fd_topob_wksp( topo, "bank_pack" );
344+
if( FD_LIKELY( config->tiles.pack.use_consumed_cus ) ) {
345+
fd_topob_wksp( topo, "bank_pack" );
346+
}
345347
fd_topob_wksp( topo, "bank_poh" );
346348
fd_topob_wksp( topo, "bank_busy" );
347349
fd_topob_wksp( topo, "poh_shred" );
@@ -459,14 +461,16 @@ fd_topo_initialize( config_t * config ) {
459461
FOR(resolv_tile_cnt) fd_topob_link( topo, "resolv_pack", "resolv_pack", 65536UL, FD_TPU_RESOLVED_MTU, 1UL );
460462
/**/ fd_topob_link( topo, "replay_stake", "replay_stake", 128UL, FD_STAKE_OUT_MTU, 1UL ); /* TODO: This should be 2 but requires fixing STEM_BURST */
461463
/**/ fd_topob_link( topo, "replay_out", "replay_out", 8192UL, sizeof(fd_replay_message_t), 1UL );
462-
/**/ fd_topob_link( topo, "pack_poh", "pack_poh", 128UL, sizeof(fd_done_packing_t), 1UL );
464+
/**/ fd_topob_link( topo, "pack_poh", "pack_poh", 4UL*65536UL, sizeof(fd_done_packing_t), 1UL );
463465
/* pack_bank is shared across all banks, so if one bank stalls due to complex transactions, the buffer neeeds to be large so that
464466
other banks can keep proceeding. */
465467
/**/ fd_topob_link( topo, "pack_bank", "pack_bank", 65536UL, USHORT_MAX, 1UL );
466468
FOR(bank_tile_cnt) fd_topob_link( topo, "bank_poh", "bank_poh", 16384UL, USHORT_MAX, 1UL );
467-
FOR(bank_tile_cnt) fd_topob_link( topo, "bank_pack", "bank_pack", 16384UL, USHORT_MAX, 1UL );
469+
if( FD_LIKELY( config->tiles.pack.use_consumed_cus ) ) {
470+
FOR(bank_tile_cnt) fd_topob_link( topo, "bank_pack", "bank_pack", 16384UL, USHORT_MAX, 1UL );
471+
}
468472
/**/ fd_topob_link( topo, "poh_shred", "poh_shred", 16384UL, USHORT_MAX, 1UL );
469-
/**/ fd_topob_link( topo, "poh_replay", "poh_replay", 128UL, sizeof(fd_poh_leader_slot_ended_t), 1UL ); /* TODO: Depth probably doesn't need to be 128 */
473+
/**/ fd_topob_link( topo, "poh_replay", "poh_replay", 16384UL, sizeof(fd_poh_leader_slot_ended_t), 1UL ); /* TODO: Depth probably doesn't need to be 128 */
470474
FOR(resolv_tile_cnt) fd_topob_link( topo, "resolv_repla", "resolv_repla", 128UL, sizeof(fd_resolv_slot_exchanged_t), 1UL );
471475
/**/ fd_topob_link( topo, "executed_txn", "executed_txn", 16384UL, 64UL, 1UL ); /* TODO: Rename this ... */
472476

@@ -703,14 +707,16 @@ fd_topo_initialize( config_t * config ) {
703707
/**/ fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "executed_txn", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
704708
fd_topob_tile_out( topo, "pack", 0UL, "pack_bank", 0UL );
705709
fd_topob_tile_out( topo, "pack", 0UL, "pack_poh" , 0UL );
706-
FOR(bank_tile_cnt) fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "bank_pack", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
710+
if( FD_LIKELY( config->tiles.pack.use_consumed_cus ) ) {
711+
FOR(bank_tile_cnt) fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "bank_pack", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
712+
}
707713
FOR(bank_tile_cnt) fd_topob_tile_in( topo, "bank", i, "metric_in", "pack_bank", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
708714
FOR(bank_tile_cnt) fd_topob_tile_out( topo, "bank", i, "bank_poh", i );
709-
FOR(bank_tile_cnt) fd_topob_tile_out( topo, "bank", i, "bank_pack", i );
710-
FOR(bank_tile_cnt) fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "bank_poh", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
711715
if( FD_LIKELY( config->tiles.pack.use_consumed_cus ) ) {
712-
/**/ fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "pack_poh", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
716+
FOR(bank_tile_cnt) fd_topob_tile_out( topo, "bank", i, "bank_pack", i );
713717
}
718+
FOR(bank_tile_cnt) fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "bank_poh", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
719+
/**/ fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "pack_poh", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
714720
/**/ fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "replay_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
715721
/**/ fd_topob_tile_out( topo, "poh", 0UL, "poh_shred", 0UL );
716722
/**/ fd_topob_tile_out( topo, "poh", 0UL, "poh_replay", 0UL );

src/discof/bank/fd_bank_tile.c

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
#include "../../flamenco/runtime/fd_bank.h"
1616
#include "../../flamenco/runtime/fd_exec_stack.h"
1717

18+
struct fd_bank_out {
19+
ulong idx;
20+
fd_wksp_t * mem;
21+
ulong chunk0;
22+
ulong wmark;
23+
ulong chunk;
24+
};
25+
26+
typedef struct fd_bank_out fd_bank_out_t;
27+
1828
typedef struct {
1929
ulong kind_id;
2030

@@ -32,16 +42,11 @@ typedef struct {
3242
ulong pack_in_chunk0;
3343
ulong pack_in_wmark;
3444

35-
fd_wksp_t * out_mem;
36-
ulong out_chunk0;
37-
ulong out_wmark;
38-
ulong out_chunk;
45+
fd_bank_out_t out_poh[1];
46+
fd_bank_out_t out_pack[1];
3947

40-
fd_wksp_t * rebate_mem;
41-
ulong rebate_chunk0;
42-
ulong rebate_wmark;
43-
ulong rebate_chunk;
44-
ulong rebates_for_slot;
48+
ulong rebates_for_slot;
49+
int enable_rebates;
4550
fd_pack_rebate_sum_t rebater[ 1 ];
4651

4752
fd_banks_t * banks;
@@ -112,9 +117,8 @@ during_frag( fd_bank_ctx_t * ctx,
112117
ulong chunk,
113118
ulong sz,
114119
ulong ctl FD_PARAM_UNUSED ) {
115-
116120
uchar * src = (uchar *)fd_chunk_to_laddr( ctx->pack_in_mem, chunk );
117-
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
121+
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_poh->mem, ctx->out_poh->chunk );
118122

119123
if( FD_UNLIKELY( chunk<ctx->pack_in_chunk0 || chunk>ctx->pack_in_wmark || sz>USHORT_MAX ) )
120124
FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->pack_in_chunk0, ctx->pack_in_wmark ));
@@ -155,7 +159,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
155159
ulong sz,
156160
ulong begin_tspub,
157161
fd_stem_context_t * stem ) {
158-
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
162+
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_poh->mem, ctx->out_poh->chunk );
159163

160164
ulong slot = fd_disco_poh_sig_slot( sig );
161165
ulong txn_cnt = (sz-sizeof(fd_microblock_bank_trailer_t))/sizeof(fd_txn_p_t);
@@ -198,7 +202,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
198202

199203
if( FD_UNLIKELY( !txn_ctx->err.is_committable ) ) {
200204
FD_TEST( !txn_ctx->err.is_fees_only );
201-
fd_pack_rebate_sum_add_txn( ctx->rebater, txn, NULL, 1UL );
205+
if( FD_LIKELY( ctx->enable_rebates ) ) fd_pack_rebate_sum_add_txn( ctx->rebater, txn, NULL, 1UL );
202206
ctx->metrics.txn_landed[ FD_METRICS_ENUM_TRANSACTION_LANDED_V_UNLANDED_IDX ]++;
203207
ctx->metrics.txn_result[ fd_bank_err_from_runtime_err( txn_ctx->err.exec_err ) ]++;
204208
continue;
@@ -269,7 +273,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
269273
alt accounts, and finally the read-only alt accounts. */
270274
fd_txn_t * txn_descriptor = TXN( &txn_ctx->txn );
271275
fd_acct_addr_t const * writable_alt = fd_type_pun_const( txn_ctx->accounts.account_keys+txn_descriptor->acct_addr_cnt );
272-
fd_pack_rebate_sum_add_txn( ctx->rebater, txn, &writable_alt, 1UL );
276+
if( FD_LIKELY( ctx->enable_rebates ) ) fd_pack_rebate_sum_add_txn( ctx->rebater, txn, &writable_alt, 1UL );
273277

274278
/* The VM will stop executing and fail an instruction immediately if
275279
it exceeds its requested CUs. A transaction which requests less
@@ -329,8 +333,8 @@ handle_microblock( fd_bank_ctx_t * ctx,
329333
transactions so the PoH tile can keep an accurate count of microblocks
330334
it has seen. */
331335
ulong new_sz = txn_cnt*sizeof(fd_txn_p_t) + sizeof(fd_microblock_trailer_t);
332-
fd_stem_publish( stem, 0UL, bank_sig, ctx->out_chunk, new_sz, 0UL, (ulong)fd_frag_meta_ts_comp( microblock_start_ticks ), (ulong)fd_frag_meta_ts_comp( tickcount ) );
333-
ctx->out_chunk = fd_dcache_compact_next( ctx->out_chunk, new_sz, ctx->out_chunk0, ctx->out_wmark );
336+
fd_stem_publish( stem, ctx->out_poh->idx, bank_sig, ctx->out_poh->chunk, new_sz, 0UL, (ulong)fd_frag_meta_ts_comp( microblock_start_ticks ), (ulong)fd_frag_meta_ts_comp( tickcount ) );
337+
ctx->out_poh->chunk = fd_dcache_compact_next( ctx->out_poh->chunk, new_sz, ctx->out_poh->chunk0, ctx->out_poh->wmark );
334338
}
335339

336340
static inline void
@@ -341,7 +345,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
341345
ulong begin_tspub,
342346
fd_stem_context_t * stem ) {
343347

344-
fd_txn_p_t * txns = (fd_txn_p_t *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
348+
fd_txn_p_t * txns = (fd_txn_p_t *)fd_chunk_to_laddr( ctx->out_poh->mem, ctx->out_poh->chunk );
345349

346350
ulong slot = fd_disco_poh_sig_slot( sig );
347351
ulong txn_cnt = (sz-sizeof(fd_microblock_bank_trailer_t))/sizeof(fd_txn_p_t);
@@ -432,7 +436,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
432436
}
433437
}
434438

435-
fd_pack_rebate_sum_add_txn( ctx->rebater, txns, writable_alt, txn_cnt );
439+
if( FD_LIKELY( ctx->enable_rebates ) ) fd_pack_rebate_sum_add_txn( ctx->rebater, txns, writable_alt, txn_cnt );
436440

437441
/* Indicate to pack tile we are done processing the transactions so
438442
it can pack new microblocks using these accounts. */
@@ -447,7 +451,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
447451
}
448452

449453
for( ulong i=0UL; i<txn_cnt; i++ ) {
450-
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
454+
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_poh->mem, ctx->out_poh->chunk );
451455
fd_memcpy( dst, bundle_txn_temp+i, sizeof(fd_txn_p_t) );
452456

453457
fd_microblock_trailer_t * trailer = (fd_microblock_trailer_t *)( dst+sizeof(fd_txn_p_t) );
@@ -472,8 +476,8 @@ handle_bundle( fd_bank_ctx_t * ctx,
472476
trailer->txn_preload_end_pct = (uchar)(((double)(tx_preload_end_ticks - microblock_start_ticks) * (double)UCHAR_MAX) / (double)microblock_duration_ticks);
473477

474478
ulong new_sz = sizeof(fd_txn_p_t) + sizeof(fd_microblock_trailer_t);
475-
fd_stem_publish( stem, 0UL, bank_sig, ctx->out_chunk, new_sz, 0UL, (ulong)fd_frag_meta_ts_comp( microblock_start_ticks ), (ulong)fd_frag_meta_ts_comp( tickcount ) );
476-
ctx->out_chunk = fd_dcache_compact_next( ctx->out_chunk, new_sz, ctx->out_chunk0, ctx->out_wmark );
479+
fd_stem_publish( stem, ctx->out_poh->idx, bank_sig, ctx->out_poh->chunk, new_sz, 0UL, (ulong)fd_frag_meta_ts_comp( microblock_start_ticks ), (ulong)fd_frag_meta_ts_comp( tickcount ) );
480+
ctx->out_poh->chunk = fd_dcache_compact_next( ctx->out_poh->chunk, new_sz, ctx->out_poh->chunk0, ctx->out_poh->wmark );
477481
}
478482

479483
metrics_write( ctx );
@@ -494,7 +498,7 @@ after_frag( fd_bank_ctx_t * ctx,
494498
if( FD_UNLIKELY( slot!=ctx->rebates_for_slot ) ) {
495499
/* If pack has already moved on to a new slot, the rebates are no
496500
longer useful. */
497-
fd_pack_rebate_sum_clear( ctx->rebater );
501+
if( FD_LIKELY( ctx->enable_rebates ) ) fd_pack_rebate_sum_clear( ctx->rebater );
498502
ctx->rebates_for_slot = slot;
499503
}
500504

@@ -503,14 +507,39 @@ after_frag( fd_bank_ctx_t * ctx,
503507

504508
/* TODO: Use fancier logic to coalesce rebates e.g. and move this to
505509
after_credit */
506-
ulong written_sz = 0UL;
507-
while( 0UL!=(written_sz=fd_pack_rebate_sum_report( ctx->rebater, fd_chunk_to_laddr( ctx->rebate_mem, ctx->rebate_chunk ) )) ) {
508-
ulong tspub = (ulong)fd_frag_meta_ts_comp( fd_tickcount() );
509-
fd_stem_publish( stem, 1UL, slot, ctx->rebate_chunk, written_sz, 0UL, tsorig, tspub );
510-
ctx->rebate_chunk = fd_dcache_compact_next( ctx->rebate_chunk, written_sz, ctx->rebate_chunk0, ctx->rebate_wmark );
510+
if( FD_LIKELY( ctx->enable_rebates ) ) {
511+
ulong written_sz = 0UL;
512+
while( 0UL!=(written_sz=fd_pack_rebate_sum_report( ctx->rebater, fd_chunk_to_laddr( ctx->out_pack->mem, ctx->out_pack->chunk ) )) ) {
513+
ulong tspub = (ulong)fd_frag_meta_ts_comp( fd_tickcount() );
514+
fd_stem_publish( stem, ctx->out_pack->idx, slot, ctx->out_pack->chunk, written_sz, 0UL, tsorig, tspub );
515+
ctx->out_pack->chunk = fd_dcache_compact_next( ctx->out_pack->chunk, written_sz, ctx->out_pack->chunk0, ctx->out_pack->wmark );
516+
}
511517
}
512518
}
513519

520+
static inline fd_bank_out_t
521+
out1( fd_topo_t const * topo,
522+
fd_topo_tile_t const * tile,
523+
char const * name ) {
524+
ulong idx = ULONG_MAX;
525+
526+
for( ulong i=0UL; i<tile->out_cnt; i++ ) {
527+
fd_topo_link_t const * link = &topo->links[ tile->out_link_id[ i ] ];
528+
if( !strcmp( link->name, name ) ) {
529+
if( FD_UNLIKELY( idx!=ULONG_MAX ) ) FD_LOG_ERR(( "tile %s:%lu had multiple output links named %s but expected one", tile->name, tile->kind_id, name ));
530+
idx = i;
531+
}
532+
}
533+
534+
if( FD_UNLIKELY( idx==ULONG_MAX ) ) return (fd_bank_out_t){ .idx = ULONG_MAX, .mem = NULL, .chunk0 = 0, .wmark = 0, .chunk = 0 };
535+
536+
void * mem = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ idx ] ].dcache_obj_id ].wksp_id ].wksp;
537+
ulong chunk0 = fd_dcache_compact_chunk0( mem, topo->links[ tile->out_link_id[ idx ] ].dcache );
538+
ulong wmark = fd_dcache_compact_wmark ( mem, topo->links[ tile->out_link_id[ idx ] ].dcache, topo->links[ tile->out_link_id[ idx ] ].mtu );
539+
540+
return (fd_bank_out_t){ .idx = idx, .mem = mem, .chunk0 = chunk0, .wmark = wmark, .chunk = chunk0 };
541+
}
542+
514543
static void
515544
unprivileged_init( fd_topo_t * topo,
516545
fd_topo_tile_t * tile ) {
@@ -580,16 +609,10 @@ unprivileged_init( fd_topo_t * topo,
580609
ctx->pack_in_chunk0 = fd_dcache_compact_chunk0( ctx->pack_in_mem, topo->links[ tile->in_link_id[ 0UL ] ].dcache );
581610
ctx->pack_in_wmark = fd_dcache_compact_wmark ( ctx->pack_in_mem, topo->links[ tile->in_link_id[ 0UL ] ].dcache, topo->links[ tile->in_link_id[ 0UL ] ].mtu );
582611

583-
ctx->out_mem = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ 0 ] ].dcache_obj_id ].wksp_id ].wksp;
584-
ctx->out_chunk0 = fd_dcache_compact_chunk0( ctx->out_mem, topo->links[ tile->out_link_id[ 0 ] ].dcache );
585-
ctx->out_wmark = fd_dcache_compact_wmark ( ctx->out_mem, topo->links[ tile->out_link_id[ 0 ] ].dcache, topo->links[ tile->out_link_id[ 0 ] ].mtu );
586-
ctx->out_chunk = ctx->out_chunk0;
587-
612+
*ctx->out_poh = out1( topo, tile, "bank_poh" ); FD_TEST( ctx->out_poh->idx!=ULONG_MAX );
613+
*ctx->out_pack = out1( topo, tile, "bank_pack" );
588614

589-
ctx->rebate_mem = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ 1 ] ].dcache_obj_id ].wksp_id ].wksp;
590-
ctx->rebate_chunk0 = fd_dcache_compact_chunk0( ctx->rebate_mem, topo->links[ tile->out_link_id[ 1 ] ].dcache );
591-
ctx->rebate_wmark = fd_dcache_compact_wmark ( ctx->rebate_mem, topo->links[ tile->out_link_id[ 1 ] ].dcache, topo->links[ tile->out_link_id[ 1 ] ].mtu );
592-
ctx->rebate_chunk = ctx->rebate_chunk0;
615+
ctx->enable_rebates = ctx->out_pack->idx!=ULONG_MAX;
593616
}
594617

595618
static ulong

0 commit comments

Comments
 (0)