Skip to content

Commit b353004

Browse files
committed
progcache: shared memory concurrency
1 parent 1d05b87 commit b353004

30 files changed

+1472
-1316
lines changed

src/app/firedancer-dev/commands/backtest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../../../discof/restore/utils/fd_ssmsg.h"
2626
#include "../../../discof/tower/fd_tower_tile.h"
2727
#include "../../../discof/replay/fd_exec.h" /* FD_RUNTIME_PUBLIC_ACCOUNT_UPDATE_MSG_MTU */
28+
#include "../../../flamenco/progcache/fd_progcache_admin.h"
2829

2930
#include "../main.h"
3031

src/app/firedancer/topology.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "../../discof/restore/utils/fd_ssmsg.h"
2121
#include "../../flamenco/gossip/fd_gossip.h"
2222
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
23+
#include "../../flamenco/progcache/fd_progcache_admin.h"
2324

2425
#include <sys/random.h>
2526
#include <sys/types.h>

src/discof/replay/fd_replay_tile.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "../../util/pod/fd_pod.h"
1818
#include "../../flamenco/rewards/fd_rewards.h"
1919
#include "../../flamenco/leaders/fd_multi_epoch_leaders.h"
20+
#include "../../flamenco/progcache/fd_progcache_admin.h"
2021
#include "../../disco/metrics/fd_metrics.h"
2122

2223
#include <errno.h>
@@ -127,7 +128,7 @@ struct fd_replay_tile {
127128
int tx_metadata_storage;
128129

129130
fd_funk_t funk[1];
130-
fd_progcache_t progcache[1];
131+
fd_progcache_admin_t progcache_admin[1];
131132

132133
fd_txncache_t * txncache;
133134
fd_store_t * store;
@@ -613,8 +614,8 @@ replay_block_start( fd_replay_tile_t * ctx,
613614

614615
fd_funk_txn_xid_t xid = { .ul = { slot, slot } };
615616
fd_funk_txn_xid_t parent_xid = { .ul = { parent_slot, parent_slot } };
616-
fd_funk_txn_prepare( ctx->funk, &parent_xid, &xid );
617-
fd_funk_txn_prepare( ctx->progcache->funk, &parent_xid, &xid );
617+
fd_funk_txn_prepare ( ctx->funk, &parent_xid, &xid );
618+
fd_progcache_txn_prepare( ctx->progcache_admin, &parent_xid, &xid );
618619

619620
/* Update any required runtime state and handle any potential epoch
620621
boundary change. */
@@ -823,8 +824,8 @@ prepare_leader_bank( fd_replay_tile_t * ctx,
823824
/* prepare the funk transaction for the leader bank */
824825
fd_funk_txn_xid_t xid = { .ul = { slot, slot } };
825826
fd_funk_txn_xid_t parent_xid = { .ul = { parent_slot, parent_slot } };
826-
fd_funk_txn_prepare( ctx->funk, &parent_xid, &xid );
827-
fd_funk_txn_prepare( ctx->progcache->funk, &parent_xid, &xid );
827+
fd_funk_txn_prepare ( ctx->funk, &parent_xid, &xid );
828+
fd_progcache_txn_prepare( ctx->progcache_admin, &parent_xid, &xid );
828829

829830
fd_bank_execution_fees_set( ctx->leader_bank, 0UL );
830831
fd_bank_priority_fees_set( ctx->leader_bank, 0UL );
@@ -977,12 +978,12 @@ init_funk( fd_replay_tile_t * ctx,
977978
/* The program cache tracks the account database's fork graph at all
978979
times. Perform initial synchronization: pivot from funk 'root' (a
979980
sentinel XID) to 'last publish' (the bootstrap root slot). */
980-
if( FD_UNLIKELY( !ctx->progcache->funk->shmem ) ) {
981+
if( FD_UNLIKELY( !ctx->progcache_admin->funk->shmem ) ) {
981982
FD_LOG_CRIT(( "failed to initialize account database: replay tile is not joined to program cache" ));
982983
}
983-
fd_progcache_clear( ctx->progcache );
984-
fd_funk_txn_prepare( ctx->progcache->funk, fd_funk_root( ctx->progcache->funk ), fd_funk_last_publish( ctx->funk ) );
985-
fd_funk_txn_publish( ctx->progcache->funk, fd_funk_last_publish( ctx->funk ) );
984+
fd_progcache_clear( ctx->progcache_admin );
985+
fd_progcache_txn_prepare( ctx->progcache_admin, fd_funk_root( ctx->progcache_admin->funk ), fd_funk_last_publish( ctx->funk ) );
986+
fd_progcache_txn_publish( ctx->progcache_admin, fd_funk_last_publish( ctx->funk ) );
986987
}
987988

988989
static void
@@ -1448,10 +1449,6 @@ replay( fd_replay_tile_t * ctx,
14481449
FD_LOG_CRIT(( "invariant violation: bank is NULL for bank index %lu", ready_txn->bank_idx ));
14491450
}
14501451

1451-
fd_funk_txn_xid_t xid = { .ul = { ready_txn->slot, ready_txn->slot } };
1452-
1453-
fd_runtime_update_program_cache( bank, ctx->progcache, ctx->funk, &xid, txn_p, ctx->runtime_spad );
1454-
14551452
/* At this point, we are going to send the txn down the execution
14561453
pipeline. Increment the refcnt so we don't prematurely prune a
14571454
bank that's needed by an in-flight txn. */
@@ -1602,8 +1599,8 @@ funk_publish( fd_replay_tile_t * ctx,
16021599
/* This is the standard case. Publish all transactions up to and
16031600
including the watermark. This will publish any in-prep ancestors
16041601
of root_txn as well. */
1605-
if( FD_UNLIKELY( !fd_funk_txn_publish( ctx->funk, &xid ) ) ) FD_LOG_CRIT(( "failed to root slot %lu: fd_funk_txn_publish(accdb) failed", slot ));
1606-
if( FD_UNLIKELY( !fd_funk_txn_publish( ctx->progcache->funk, &xid ) ) ) FD_LOG_CRIT(( "failed to root slot %lu: fd_funk_txn_publish(progcache) failed", slot ));
1602+
if( FD_UNLIKELY( !fd_funk_txn_publish( ctx->funk, &xid ) ) ) FD_LOG_CRIT(( "failed to root slot %lu: fd_funk_txn_publish(accdb) failed", slot ));
1603+
fd_progcache_txn_publish( ctx->progcache_admin, &xid );
16071604
}
16081605

16091606
static int
@@ -2052,7 +2049,9 @@ unprivileged_init( fd_topo_t * topo,
20522049
fd_features_enable_one_offs( features, one_off_features, (uint)tile->replay.enable_features_cnt, 0UL );
20532050

20542051
FD_TEST( fd_funk_join( ctx->funk, fd_topo_obj_laddr( topo, tile->replay.funk_obj_id ) ) );
2055-
FD_TEST( fd_progcache_join( ctx->progcache, fd_topo_obj_laddr( topo, tile->replay.progcache_obj_id ) ) );
2052+
FD_TEST( fd_progcache_admin_join(
2053+
ctx->progcache_admin,
2054+
fd_topo_obj_laddr( topo, tile->replay.progcache_obj_id ) ) );
20562055

20572056
void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->replay.txncache_obj_id );
20582057
fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );

src/flamenco/progcache/Local.mk

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
ifdef FD_HAS_INT128
2+
3+
# Public APIs
4+
25
$(call add-hdrs,fd_prog_load.h)
36
$(call add-objs,fd_prog_load,fd_flamenco)
4-
$(call add-hdrs,fd_progcache.h fd_progcache_rec.h)
5-
$(call add-objs,fd_progcache fd_progcache_rec fd_progcache_evict,fd_flamenco)
7+
8+
$(call add-hdrs,fd_progcache_admin.h)
9+
$(call add-objs,fd_progcache_admin,fd_flamenco)
10+
11+
$(call add-hdrs,fd_progcache_user.h)
12+
$(call add-objs,fd_progcache_user,fd_flamenco)
13+
614
$(call make-unit-test,test_progcache,test_progcache,fd_flamenco fd_funk fd_ballet fd_util)
715
$(call run-unit-test,test_progcache)
16+
17+
# Internals
18+
19+
$(call add-objs,fd_progcache_rec,fd_flamenco)
20+
821
endif

src/flamenco/progcache/fd_prog_load.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "fd_prog_load.h"
22
#include "../runtime/program/fd_bpf_loader_program.h"
33
#include "../runtime/program/fd_loader_v4_program.h"
4+
#include "../runtime/sysvar/fd_sysvar_epoch_schedule.h"
45

56
/* Similar to the below function, but gets the executable program content for the v4 loader.
67
Unlike the v3 loader, the programdata is stored in a single program account. The program must
@@ -167,3 +168,17 @@ fd_prog_versions( fd_features_t const * features,
167168
}
168169
return v;
169170
}
171+
172+
173+
fd_prog_load_env_t *
174+
fd_prog_load_env_from_bank( fd_prog_load_env_t * env,
175+
fd_bank_t const * bank ) {
176+
*env = (fd_prog_load_env_t) {
177+
.features = fd_bank_features_query( bank ),
178+
.slot = fd_bank_slot_get ( bank ),
179+
.epoch = fd_bank_epoch_get ( bank ),
180+
.epoch_slot0 = fd_epoch_slot0( fd_bank_epoch_schedule_query( bank ), fd_bank_epoch_get( bank ) ),
181+
.gen = 1UL,
182+
};
183+
return env;
184+
}

src/flamenco/progcache/fd_prog_load.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,24 @@ fd_prog_versions( fd_features_t const * features,
4242

4343
FD_PROTOTYPES_END
4444

45+
struct fd_prog_load_env {
46+
fd_features_t const * features;
47+
48+
ulong slot; /* current slot */
49+
ulong epoch; /* current epoch */
50+
ulong epoch_slot0; /* slot0 of current epoch */
51+
52+
ulong gen;
53+
};
54+
55+
typedef struct fd_prog_load_env fd_prog_load_env_t;
56+
57+
FD_PROTOTYPES_BEGIN
58+
59+
fd_prog_load_env_t *
60+
fd_prog_load_env_from_bank( fd_prog_load_env_t * env,
61+
fd_bank_t const * bank );
62+
63+
FD_PROTOTYPES_END
64+
4565
#endif /* HEADER_fd_src_flamenco_fd_progcache_fd_prog_load_h */

0 commit comments

Comments
 (0)