LCOV - code coverage report
Current view: top level - vinyl - fd_vinyl.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 55 0.0 %
Date: 2026-01-21 05:06:28 Functions: 0 399 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_vinyl_fd_vinyl_h
       2             : #define HEADER_fd_src_vinyl_fd_vinyl_h
       3             : 
       4             : //#include "fd_vinyl_base.h"            /* includes ../tango/fd_tango.h, ../util/tmpl/fd_map.h */
       5             : //#include "bstream/fd_vinyl_bstream.h" /* includes fd_vinyl_base.h */
       6             : //#include "io/fd_vinyl_io.h"           /* includes bstream/fd_vinyl_bstream.h */
       7             : //#include "meta/fd_vinyl_meta.h"       /* includes bstream/fd_vinyl_bstream.h */
       8             : //#include "data/fd_vinyl_data.h"       /* includes io/fd_vinyl_io.h */
       9             : #include "line/fd_vinyl_line.h"         /* includes meta/fd_vinyl_meta.h data/fd_vinyl_data.h */
      10             : #include "rq/fd_vinyl_rq.h"             /* includes fd_vinyl_base.h */
      11             : #include "cq/fd_vinyl_cq.h"             /* includes fd_vinyl_base.h */
      12             : 
      13           0 : #define FD_VINYL_CNC_TYPE (0xFDC12C2CUL) /* FD VIN CNC */
      14             : 
      15           0 : #define FD_VINYL_CNC_SIGNAL_RUN          FD_CNC_SIGNAL_RUN
      16           0 : #define FD_VINYL_CNC_SIGNAL_BOOT         FD_CNC_SIGNAL_BOOT
      17           0 : #define FD_VINYL_CNC_SIGNAL_FAIL         FD_CNC_SIGNAL_FAIL
      18           0 : #define FD_VINYL_CNC_SIGNAL_HALT         FD_CNC_SIGNAL_HALT
      19           0 : #define FD_VINYL_CNC_SIGNAL_SYNC         (4UL) /* Signal that recovery should resume from the current bstream past */
      20           0 : #define FD_VINYL_CNC_SIGNAL_GET          (5UL) /* Get the value of the given option */
      21           0 : #define FD_VINYL_CNC_SIGNAL_SET          (6UL) /* Set the value of the given option */
      22           0 : #define FD_VINYL_CNC_SIGNAL_CLIENT_JOIN  (7UL) /* Have a client join the vinyl tile */
      23           0 : #define FD_VINYL_CNC_SIGNAL_CLIENT_LEAVE (8UL) /* Have a client leave the vinyl tile */
      24             : 
      25           0 : #define FD_VINYL_OPT_PART_THRESH (0)
      26           0 : #define FD_VINYL_OPT_GC_THRESH   (1)
      27           0 : #define FD_VINYL_OPT_GC_EAGER    (2)
      28           0 : #define FD_VINYL_OPT_STYLE       (3)
      29             : 
      30             : union fd_vinyl_cmd {
      31             :   struct {
      32             :     int   err;
      33             :     ulong link_id;
      34             :     ulong burst_max;
      35             :     ulong quota_max;
      36             :     char  rq  [ FD_WKSP_CSTR_MAX  ];
      37             :     char  cq  [ FD_WKSP_CSTR_MAX  ];
      38             :     char  wksp[ FD_SHMEM_NAME_MAX ];
      39             :   } join;
      40             :   struct {
      41             :     int   err;
      42             :     ulong link_id;
      43             :   } leave;
      44             :   struct {
      45             :     int   err;
      46             :     int   opt;
      47             :     ulong val;
      48             :   } get;
      49             :   struct {
      50             :     int   err;
      51             :     int   opt;
      52             :     ulong val;
      53             :   } set;
      54             : };
      55             : 
      56             : typedef union fd_vinyl_cmd fd_vinyl_cmd_t;
      57             : 
      58             : /* FIXME: ADD ADDITIONAL DIAGNOSTICS (LIKE DISK USAGE, PAIR_CNT, ETC) */
      59             : 
      60           0 : #define FD_VINYL_DIAG_DROP_LINK (0)
      61           0 : #define FD_VINYL_DIAG_DROP_COMP (1)
      62           0 : #define FD_VINYL_DIAG_CACHE_HIT (2)
      63           0 : #define FD_VINYL_DIAG_CNT (3UL)
      64             : 
      65           0 : #define FD_VINYL_CNC_APP_SZ (sizeof(fd_vinyl_cmd_t) + sizeof(ulong)*FD_VINYL_DIAG_CNT)
      66             : 
      67             : struct __attribute__((aligned(128))) fd_vinyl_private {
      68             : 
      69             :   /* Underlying shared objects */
      70             : 
      71             :   fd_cnc_t *        cnc;
      72             :   fd_vinyl_line_t * line; /* Indexed [0,line_cnt) */
      73             :   fd_vinyl_io_t *   io;
      74             : 
      75             :   /* Config */
      76             : 
      77             :   ulong line_cnt;  /* Max pairs data that can be cached, in [3,min(pair_max,FD_VINYL_LINE_MAX)] */
      78             :   ulong pair_max;  /* Max pairs that can be tracked globally, in [3,meta->ele_max) */
      79             :   ulong async_min; /* Min run loop iterations per async handling, positive */
      80             :   ulong async_max; /* Max run loop iterations per async handling, >=async_min */
      81             : 
      82             :   /* State */
      83             : 
      84             :   ulong part_thresh;  /* Insert partition blocks roughly every part_thresh bytes for parallel recovery */
      85             :   ulong gc_thresh;    /* Only compact if past_sz > gc_thresh */
      86             :   int   gc_eager;     /* Compact until <~ 2^-gc_eager fraction is garbage, in [-1,63], -1 disables */
      87             :   int   style;        /* Preferred bstream io encoding (i.e. is background compressed enabled) */
      88             :   uint  line_idx_lru; /* Index of the least recently used cache line, in [0,line_cnt] */
      89             :   ulong pair_cnt;     /* Num pair meta cached, in [0,pair_max] */
      90             :   ulong garbage_sz;   /* Num bytes garbage in the bstream's past */
      91             : 
      92             :   fd_vinyl_meta_t meta[1]; /* probe_max==ele_max, ele_max is a power 2 of at least 4, seed is meta_seed */
      93             :   fd_vinyl_data_t data[1]; /* data_laddr0 is local address of data cache gaddr0, obj contains data volumes */
      94             : 
      95             :   ulong cnc_footprint;
      96             :   ulong meta_footprint;
      97             :   ulong line_footprint;
      98             :   ulong ele_footprint;
      99             :   ulong obj_footprint;
     100             : 
     101             :   /* Padding to 128 byte aligned */
     102             : 
     103             : };
     104             : 
     105             : typedef struct fd_vinyl_private fd_vinyl_t;
     106             : 
     107             : FD_PROTOTYPES_BEGIN
     108             : 
     109             : FD_FN_CONST ulong fd_vinyl_align    ( void );
     110             : FD_FN_CONST ulong fd_vinyl_footprint( void );
     111             : 
     112             : /* fd_vinyl_init uses the the caller (typically tpool thread t0) and
     113             :    tpool threads (t0,t1) to init the vinyl structure (this structure can
     114             :    be extremely large ... hundreds of gigabytes to terabytes in memory
     115             :    for petabytes or more in persistent storage ... so it is worthwhile
     116             :    to parallelize the initialization).  The bstream's past will be used
     117             :    to recover the vinyl instance to the bstream's seq_present.  The
     118             :    recovery level is given by level (see fd_vinyl_recover below).
     119             :    Assumes tpool threads (t0,t1) are available for dispatch.  These
     120             :    threads will be avaialble for dispatch on return.  Retain no interest
     121             :    in tpool.  If tpool is NULL and/or the set [t0,t1) is empty/invalid,
     122             :    uses a serial algorithm for initialization. */
     123             : 
     124             : fd_vinyl_t *
     125             : fd_vinyl_init( fd_tpool_t * tpool, ulong t0, ulong t1, int level,
     126             :                void * lmem,                         /* memory region to hold the vinyl's state */
     127             :                void * shcnc,  ulong cnc_footprint,  /* memory region to use for the tile cnc */
     128             :                void * shmeta, ulong meta_footprint, /* memory region to use for the cached pair metadata state */
     129             :                void * shline, ulong line_footprint, /* memory region to use for the cached pair state */
     130             :                void * shele,  ulong ele_footprint,  /* memory region to use for the cached pair metadata */
     131             :                void * shobj,  ulong obj_footprint,  /* memory region to use for the cached pairs */
     132             :                fd_vinyl_io_t * io,                  /* interface to the underlying bstream */
     133             :                ulong  seed,
     134             :                void * obj_laddr0,
     135             :                ulong  async_min,
     136             :                ulong  async_max,
     137             :                ulong  part_thresh,
     138             :                ulong  gc_thresh,
     139             :                int    gc_eager,
     140             :                int    style );
     141             : 
     142             : void *
     143             : fd_vinyl_fini( fd_vinyl_t * vinyl );
     144             : 
     145             : /* Accessors */
     146             : 
     147             : /* fd_vinyl_* return the eponymous field.  Where applicable
     148             :    fd_vinyl_*_const are const correct versions.  These assume vinyl is
     149             :    valid.  fd_vinyl_pair_cnt returns the num live pairs in the vinyl
     150             :    instance (e.g. all pairs that exist at bstream's seq_present and all
     151             :    pairs in the process of being created).  Will be in [0,pair_max].
     152             :    Assumes vinyl is valid. */
     153             : 
     154             : FD_FN_PURE static inline void *
     155           0 : fd_vinyl_shcnc( fd_vinyl_t const * vinyl ) {
     156           0 :   return (void *)fd_cnc_shmem_const( vinyl->cnc );
     157           0 : }
     158             : 
     159             : FD_FN_PURE static inline void *
     160           0 : fd_vinyl_shmeta( fd_vinyl_t const * vinyl ) {
     161           0 :   return (void *)fd_vinyl_meta_shmap_const( vinyl->meta );
     162           0 : }
     163             : 
     164             : FD_FN_PURE static inline void *
     165           0 : fd_vinyl_shline( fd_vinyl_t const * vinyl ) {
     166           0 :   return (void *)vinyl->line;
     167           0 : }
     168             : 
     169             : FD_FN_PURE static inline void *
     170           0 : fd_vinyl_shele( fd_vinyl_t const * vinyl ) {
     171           0 :   return (void *)fd_vinyl_meta_shele_const( vinyl->meta );
     172           0 : }
     173             : 
     174             : FD_FN_PURE static inline void *
     175           0 : fd_vinyl_shobj( fd_vinyl_t const * vinyl ) {
     176           0 :   return fd_vinyl_data_shmem( vinyl->data );
     177           0 : }
     178             : 
     179           0 : FD_FN_PURE static inline ulong fd_vinyl_cnc_footprint  ( fd_vinyl_t const * vinyl ) { return vinyl->cnc_footprint;  }
     180           0 : FD_FN_PURE static inline ulong fd_vinyl_meta_footprint_( fd_vinyl_t const * vinyl ) { return vinyl->meta_footprint; } /* FIXME: sigh */
     181           0 : FD_FN_PURE static inline ulong fd_vinyl_line_footprint ( fd_vinyl_t const * vinyl ) { return vinyl->line_footprint; }
     182           0 : FD_FN_PURE static inline ulong fd_vinyl_ele_footprint  ( fd_vinyl_t const * vinyl ) { return vinyl->ele_footprint;  }
     183           0 : FD_FN_PURE static inline ulong fd_vinyl_obj_footprint  ( fd_vinyl_t const * vinyl ) { return vinyl->obj_footprint;  }
     184             : 
     185             : FD_FN_PURE static inline fd_vinyl_io_t *
     186           0 : fd_vinyl_io( fd_vinyl_t const * vinyl ) {
     187           0 :   return (fd_vinyl_io_t *)vinyl->io;
     188           0 : }
     189             : 
     190             : FD_FN_PURE static inline ulong
     191           0 : fd_vinyl_seed( fd_vinyl_t const * vinyl ) {
     192           0 :   return fd_vinyl_meta_seed( vinyl->meta );
     193           0 : }
     194             : 
     195             : FD_FN_PURE static inline void *
     196           0 : fd_vinyl_obj_laddr0( fd_vinyl_t const * vinyl ) {
     197           0 :   return fd_vinyl_data_laddr0( vinyl->data );
     198           0 : }
     199             : 
     200           0 : FD_FN_PURE static inline ulong fd_vinyl_async_min  ( fd_vinyl_t const * vinyl ) { return vinyl->async_min;   }
     201           0 : FD_FN_PURE static inline ulong fd_vinyl_async_max  ( fd_vinyl_t const * vinyl ) { return vinyl->async_max;   }
     202           0 : FD_FN_PURE static inline ulong fd_vinyl_part_thresh( fd_vinyl_t const * vinyl ) { return vinyl->part_thresh; }
     203           0 : FD_FN_PURE static inline ulong fd_vinyl_gc_thresh  ( fd_vinyl_t const * vinyl ) { return vinyl->gc_thresh;   }
     204           0 : FD_FN_PURE static inline int   fd_vinyl_gc_eager   ( fd_vinyl_t const * vinyl ) { return vinyl->gc_eager;    }
     205           0 : FD_FN_PURE static inline int   fd_vinyl_style      ( fd_vinyl_t const * vinyl ) { return vinyl->style;       }
     206             : 
     207             : /* fd_vinyl_compact does up to compact_max rounds of compaction to the
     208             :    bstream's past.  This cannot fail from the caller's perspective (will
     209             :    FD_LOG_CRIT if any corruption is detected). */
     210             : /* FIXME: PRIVATE */
     211             : 
     212             : void
     213             : fd_vinyl_compact( fd_vinyl_t * vinyl,
     214             :                   ulong        compact_max );
     215             : 
     216             : /* fd_vinyl_recover uses the caller (typically tpool thread t0) and
     217             :    tpool threads (t0,t1) to reset the vinyl meta cache, reset the vinyl
     218             :    data cache, reset vinyl cache line eviction priorities and repopulate
     219             :    the vinyl meta data cache from the current state of the bstream's
     220             :    past to the bstream's seq_present.  level zero/non-zero indicates to
     221             :    do a soft/hard reset.  In a soft reset, the data cache region is
     222             :    minimally cleared.  In a hard reset, it is fully cleared.  A hard
     223             :    reset is recommended for most usage but a soft reset can allow faster
     224             :    startup for rapid iteration during development.
     225             : 
     226             :    Returns the bstream sequence number of how far recovery got (if this
     227             :    is not seq_present, the recovery was partial and it is theoretically
     228             :    moves in the recovery were not processed atomically).  Logs details
     229             :    of any issues encoutered.
     230             : 
     231             :    Assumes the tpool threads (t0,t1) are available for dispatch.
     232             :    Retains no interest in tpool and threads (t0,t1) will be available
     233             :    for dispatch on return. */
     234             : /* FIXME: PRIVATE */
     235             : 
     236             : ulong
     237             : fd_vinyl_recover( fd_tpool_t * tpool, ulong t0, ulong t1, int level,
     238             :                   fd_vinyl_t * vinyl );
     239             : 
     240             : /* fd_vinyl_exec runs a vinyl tile on the caller. */
     241             : 
     242             : void
     243             : fd_vinyl_exec( fd_vinyl_t * vinyl );
     244             : 
     245             : int
     246             : fd_vinyl_halt( fd_cnc_t * cnc );
     247             : 
     248             : int
     249             : fd_vinyl_sync( fd_cnc_t * cnc );
     250             : 
     251             : int
     252             : fd_vinyl_get( fd_cnc_t * cnc,
     253             :               int        opt,
     254             :               ulong *    opt_val );
     255             : 
     256             : int
     257             : fd_vinyl_set( fd_cnc_t * cnc,
     258             :               int        opt,
     259             :               ulong      val,
     260             :               ulong *    opt_val );
     261             : 
     262             : int
     263             : fd_vinyl_client_join( fd_cnc_t *      cnc,
     264             :                       fd_vinyl_rq_t * rq,
     265             :                       fd_vinyl_cq_t * cq,
     266             :                       fd_wksp_t *     wksp,
     267             :                       ulong           link_id,
     268             :                       ulong           burst_max,
     269             :                       ulong           quota_max );
     270             : 
     271             : int
     272             : fd_vinyl_client_leave( fd_cnc_t * cnc,
     273             :                        ulong      link_id );
     274             : 
     275           0 : #define FD_VINYL_CNC_SIGNAL_CSTR_BUF_MAX (21UL)
     276             : 
     277             : char *
     278             : fd_vinyl_cnc_signal_cstr( ulong  signal,
     279             :                           char * buf );
     280             : 
     281             : FD_PROTOTYPES_END
     282             : 
     283             : #endif /* HEADER_fd_src_vinyl_fd_vinyl_h */

Generated by: LCOV version 1.14