LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_public.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 81 0.0 %
Date: 2025-07-01 05:00:49 Functions: 0 1479 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_public_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_runtime_public_h
       3             : 
       4             : #include "../features/fd_features.h"
       5             : #include "../types/fd_types.h"
       6             : #include "../../disco/pack/fd_microblock.h"
       7             : #include "../../disco/fd_disco_base.h"
       8             : 
       9             : /* FIXME: Everything in this file should be migrated to fd_exec.h */
      10             : 
      11             : /* definition of the public/readable workspace */
      12           0 : #define FD_RUNTIME_PUBLIC_MAGIC (0xF17EDA2C9A7B1C21UL)
      13             : 
      14           0 : #define EXEC_NEW_TXN_SIG               (0x777777UL)
      15           0 : #define EXEC_HASH_ACCS_SIG             (0x888888UL)
      16           0 : #define EXEC_SNAP_HASH_ACCS_CNT_SIG    (0x191992UL)
      17           0 : #define EXEC_SNAP_HASH_ACCS_GATHER_SIG (0x193992UL)
      18             : 
      19           0 : #define FD_WRITER_BOOT_SIG             (0xAABB0011UL)
      20             : #define FD_WRITER_SLOT_SIG             (0xBBBB1122UL)
      21           0 : #define FD_WRITER_TXN_SIG              (0xBBCC2233UL)
      22             : 
      23           0 : #define FD_EXEC_STATE_NOT_BOOTED       (0xFFFFFFFFUL)
      24           0 : #define FD_EXEC_STATE_BOOTED           (1<<1UL      )
      25           0 : #define FD_EXEC_STATE_HASH_DONE        (1<<6UL      )
      26           0 : #define FD_EXEC_STATE_SNAP_CNT_DONE    (1<<8UL      )
      27           0 : #define FD_EXEC_STATE_SNAP_GATHER_DONE (1<<9UL      )
      28             : 
      29           0 : #define FD_WRITER_STATE_NOT_BOOTED     (0UL         )
      30           0 : #define FD_WRITER_STATE_READY          (1UL         )
      31           0 : #define FD_WRITER_STATE_TXN_DONE       (1UL<<1      )
      32             : 
      33           0 : #define FD_EXEC_ID_SENTINEL            (UINT_MAX    )
      34             : 
      35             : 
      36             : /* parallel execution apis ********************************************/
      37             : 
      38             : /* These are callbacks used to support different execution schemes.
      39             :    Namely, this is for tpool and to executing using the exec tiles. */
      40             : 
      41             : /* If you need more than the current amount of arguments/ways to exec,
      42             :    you need to update all uses of fd_exec_para_fn. */
      43             : 
      44             : #define FD_EXEC_PARA_TPOOL (0UL)
      45             : #define FD_EXEC_PARA_TILES (1UL)
      46             : 
      47             : typedef void (*fd_exec_para_cb_fn_t)( void * para_arg_1,
      48             :                                       void * para_arg_2,
      49             :                                       void * arg_1,
      50             :                                       void * arg_2,
      51             :                                       void * arg_3,
      52             :                                       void * arg_4 );
      53             : 
      54             : struct fd_exec_para_cb_ctx {
      55             :   uint                 num_args;
      56             :   fd_exec_para_cb_fn_t func;
      57             :   /* para_arg_{n} is used to pass arguments that are for the purpose of
      58             :     multithreaded execution. fn_arg_{n} are used to pass arguments used
      59             :     by the core business logic of the function. */
      60             :   void *            para_arg_1;
      61             :   void *            para_arg_2;
      62             :   void *            fn_arg_1;
      63             :   void *            fn_arg_2;
      64             :   void *            fn_arg_3;
      65             :   void *            fn_arg_4;
      66             : };
      67             : typedef struct fd_exec_para_cb_ctx fd_exec_para_cb_ctx_t;
      68             : 
      69             : static void FD_FN_UNUSED
      70           0 : fd_exec_para_call_func( fd_exec_para_cb_ctx_t * ctx ) {
      71           0 :   ctx->func( ctx->para_arg_1,
      72           0 :             ctx->para_arg_2,
      73           0 :             ctx->fn_arg_1,
      74           0 :             ctx->fn_arg_2,
      75           0 :             ctx->fn_arg_3,
      76           0 :             ctx->fn_arg_4 );
      77           0 : }
      78             : 
      79             : static int FD_FN_UNUSED
      80           0 : fd_exec_para_cb_is_single_threaded( fd_exec_para_cb_ctx_t * ctx ) {
      81           0 :   return ctx->para_arg_1==NULL && ctx->para_arg_2==NULL;
      82           0 : }
      83             : 
      84             : /**********************************************************************/
      85             : 
      86             : /* exec fseq management apis ******************************************/
      87             : 
      88             : static uint FD_FN_UNUSED
      89           0 : fd_exec_fseq_get_state( ulong fseq ) {
      90           0 :   return (uint)(fseq & 0xFFFFFFFFU);
      91           0 : }
      92             : 
      93             : static ulong FD_FN_UNUSED
      94           0 : fd_exec_fseq_set_booted( uint offset ) {
      95           0 :   ulong state = ((ulong)offset << 32UL);
      96           0 :   state      |= FD_EXEC_STATE_BOOTED;
      97           0 :   return state;
      98           0 : }
      99             : 
     100             : static uint FD_FN_UNUSED
     101           0 : fd_exec_fseq_get_booted_offset( ulong fseq ) {
     102           0 :   return (uint)(fseq >> 32UL);
     103           0 : }
     104             : 
     105             : static ulong FD_FN_UNUSED
     106           0 : fd_exec_fseq_set_hash_done( ulong slot ) {
     107           0 :   ulong state = ((ulong)slot << 32UL);
     108           0 :   state      |= FD_EXEC_STATE_HASH_DONE;
     109           0 :   return state;
     110           0 : }
     111             : 
     112             : static uint FD_FN_UNUSED
     113           0 : fd_exec_fseq_get_slot( ulong fseq ) {
     114           0 :   return (uint)(fseq >> 32UL);
     115           0 : }
     116             : 
     117             : static uint FD_FN_UNUSED
     118           0 : fd_exec_fseq_get_bpf_id( ulong fseq ) {
     119           0 :   return (uint)(fseq >> 32UL);
     120           0 : }
     121             : 
     122             : static ulong FD_FN_UNUSED
     123           0 : fd_exec_fseq_set_snap_hash_cnt_done( uint pairs_len ) {
     124           0 :   ulong state = ((ulong)pairs_len << 32UL);
     125           0 :   state      |= FD_EXEC_STATE_SNAP_CNT_DONE;
     126           0 :   return state;
     127           0 : }
     128             : 
     129             : static uint FD_FN_UNUSED
     130           0 : fd_exec_fseq_get_pairs_len( ulong fseq ) {
     131           0 :   return (uint)(fseq >> 32UL);
     132           0 : }
     133             : 
     134             : static ulong FD_FN_UNUSED
     135           0 : fd_exec_fseq_set_snap_hash_gather_done( void ) {
     136           0 :   return FD_EXEC_STATE_SNAP_GATHER_DONE;
     137           0 : }
     138             : 
     139             : static inline int
     140           0 : fd_exec_fseq_is_not_joined( ulong fseq ) {
     141           0 :   return fseq==ULONG_MAX;
     142           0 : }
     143             : 
     144             : /* Writer tile fseq management APIs ***********************************/
     145             : 
     146             : /*
     147             :    +----------------------------------+----------+----------------------+
     148             :    |         Transaction ID           | Exec Tile|         State        |
     149             :    |            (32 bits)             |   ID     |       (24 bits)      |
     150             :    |                                  | (8 bits) |                      |
     151             :    +----------------------------------+----------+----------------------+
     152             :  */
     153             : 
     154             : static inline uint
     155           0 : fd_writer_fseq_get_state( ulong fseq ) {
     156           0 :   return (uint)(fseq & 0x00FFFFFFU);
     157           0 : }
     158             : 
     159             : static inline ulong
     160           0 : fd_writer_fseq_set_txn_done( uint txn_id, uchar exec_tile_id ) {
     161           0 :   ulong state = (((ulong)txn_id) << 32);
     162           0 :   state      |= (((ulong)exec_tile_id) << 24);
     163           0 :   state      |= FD_WRITER_STATE_TXN_DONE;
     164           0 :   return state;
     165           0 : }
     166             : 
     167             : static inline uint
     168           0 : fd_writer_fseq_get_txn_id( ulong fseq ) {
     169           0 :   return (uint)(fseq >> 32);
     170           0 : }
     171             : 
     172             : static inline uchar
     173           0 : fd_writer_fseq_get_exec_tile_id( ulong fseq ) {
     174           0 :   return (uchar)((fseq >> 24) & 0xFFUL);
     175           0 : }
     176             : 
     177             : static inline int
     178           0 : fd_writer_fseq_is_not_joined( ulong fseq ) {
     179           0 :   return fseq==ULONG_MAX;
     180           0 : }
     181             : 
     182             : struct fd_runtime_public_txn_msg {
     183             :   ulong      slot;
     184             :   fd_txn_p_t txn;
     185             : };
     186             : typedef struct fd_runtime_public_txn_msg fd_runtime_public_txn_msg_t;
     187             : 
     188             : struct fd_runtime_public_hash_bank_msg {
     189             :   ulong task_infos_gaddr;
     190             :   ulong lthash_gaddr;
     191             :   ulong start_idx;
     192             :   ulong end_idx;
     193             :   ulong slot;
     194             : };
     195             : typedef struct fd_runtime_public_hash_bank_msg fd_runtime_public_hash_bank_msg_t;
     196             : 
     197             : struct fd_runtime_public_snap_hash_msg {
     198             :   ulong num_pairs_out_gaddr;
     199             :   ulong lt_hash_value_out_gaddr;
     200             :   ulong pairs_gaddr;
     201             : };
     202             : typedef struct fd_runtime_public_snap_hash_msg fd_runtime_public_snap_hash_msg_t;
     203             : 
     204             : struct fd_runtime_public_exec_writer_boot_msg {
     205             :   uint txn_ctx_offset;
     206             : };
     207             : typedef struct fd_runtime_public_exec_writer_boot_msg fd_runtime_public_exec_writer_boot_msg_t;
     208             : FD_STATIC_ASSERT( sizeof(fd_runtime_public_exec_writer_boot_msg_t)<=FD_EXEC_WRITER_MTU, exec_writer_msg_mtu );
     209             : 
     210             : struct fd_runtime_public_exec_writer_txn_msg {
     211             :   uint  txn_id;
     212             :   uchar exec_tile_id;
     213             : };
     214             : typedef struct fd_runtime_public_exec_writer_txn_msg fd_runtime_public_exec_writer_txn_msg_t;
     215             : FD_STATIC_ASSERT( sizeof(fd_runtime_public_exec_writer_txn_msg_t)<=FD_EXEC_WRITER_MTU, exec_writer_msg_mtu );
     216             : 
     217             : struct fd_runtime_public_replay_writer_slot_msg {
     218             :   ulong slot_ctx_gaddr;
     219             : };
     220             : typedef struct fd_runtime_public_replay_writer_slot_msg fd_runtime_public_replay_writer_slot_msg_t;
     221             : FD_STATIC_ASSERT( sizeof(fd_runtime_public_replay_writer_slot_msg_t)<=FD_REPLAY_WRITER_MTU, replay_writer_msg_mtu );
     222             : 
     223             : struct fd_runtime_public {
     224             :   /* FIXME:  This is a non-fork-aware copy of the currently active
     225             :      features.  Once the epoch_ctx and the slot_ctx get moved into
     226             :      this workspace AND we make the epoch_ctx properly fork aware at
     227             :      the epoch boundary, we can remove this copy of the features map
     228             :      and just use the epoch_ctx (or slot_ctx) copy directly. */
     229             : 
     230             :   /* TODO: Maybe it is better to split out the runtime_spad_gaddr into
     231             :      a different shared struct? I think it is okay because it is part of
     232             :      the runtime. */
     233             :   ulong         magic;
     234             :   fd_features_t features;
     235             :   ulong         runtime_spad_gaddr;
     236             : };
     237             : typedef struct fd_runtime_public fd_runtime_public_t;
     238             : 
     239             : FD_PROTOTYPES_BEGIN
     240             : 
     241             : FD_FN_CONST ulong
     242             : fd_runtime_public_align( void );
     243             : 
     244             : ulong
     245             : fd_runtime_public_footprint( ulong spad_mem_max );
     246             : 
     247             : void *
     248             : fd_runtime_public_new( void * shmem,
     249             :                        ulong  spad_mem_max );
     250             : 
     251             : fd_runtime_public_t *
     252             : fd_runtime_public_join( void * shmem );
     253             : 
     254             : /* Returns a local join of the runtime spad */
     255             : fd_spad_t *
     256             : fd_runtime_public_spad( fd_runtime_public_t const * runtime_public );
     257             : 
     258             : FD_PROTOTYPES_END
     259             : 
     260             : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_public_h */

Generated by: LCOV version 1.14