Line data Source code
1 : #ifndef HEADER_fd_src_groove_fd_groove_meta_h 2 : #define HEADER_fd_src_groove_fd_groove_meta_h 3 : 4 : #include "fd_groove_base.h" /* includes ../util/fd_util.h */ 5 : 6 : /* fd_groove_meta_bits API ********************************************/ 7 : 8 : /* The groove key metadata contains a 64-bit wide bitfield used to hold 9 : irregularly sized key metadata compactly. 10 : 11 : bits[ 0: 0] 1 -> used (map slot contains a key-meta pair) 12 : bits[ 1: 1] 1 -> cold (val for key present in cold store) 13 : bits[ 2: 2] 1 -> hot (val for key present in hot store) 14 : bits[ 3:15] 13 -> - (available for additional use) 15 : bits[16:39] 24 -> val_sz (num bytes for key's val) 16 : bits[40:63] 24 -> val_max (max bytes for key's val, 0<=val_sz<=val_max) 17 : 18 : fd_groove_meta_bits pack the components used, cold, hot, val_sz and 19 : val_max into this bitfield. used, cold and hot treat 0/non-zero as 20 : 0/1. val_sz and val_max are assumed in [0,2^24). 21 : 22 : fd_grove_meta_bits_{used,cold,hot,val_sz,val_max} unpack this field 23 : from the bitfield. used, cold and hot return a value in [0,1]. 24 : val_sz and val_max will be in [0,2^24). */ 25 : 26 : FD_PROTOTYPES_BEGIN 27 : 28 : FD_FN_CONST static inline ulong 29 : fd_groove_meta_bits( int used, 30 : int cold, 31 : int hot, 32 : ulong val_sz, 33 300000000 : ulong val_max ) { 34 300000000 : return ((ulong)!!used) | (((ulong)!!cold)<<1) | (((ulong)!!hot)<<2) | (val_sz<<16) | (val_max<<40); 35 300000000 : } 36 : 37 639546780 : FD_FN_CONST static inline int fd_groove_meta_bits_used ( ulong bits ) { return (int)( bits & 1UL); } 38 600000000 : FD_FN_CONST static inline int fd_groove_meta_bits_cold ( ulong bits ) { return (int)((bits>> 1) & 1UL); } 39 600000000 : FD_FN_CONST static inline int fd_groove_meta_bits_hot ( ulong bits ) { return (int)((bits>> 2) & 1UL); } 40 600000000 : FD_FN_CONST static inline ulong fd_groove_meta_bits_val_sz ( ulong bits ) { return (bits>>16) & 16777215UL; } 41 600000000 : FD_FN_CONST static inline ulong fd_groove_meta_bits_val_max( ulong bits ) { return bits>>40; } 42 : 43 : FD_PROTOTYPES_END 44 : 45 : /* fd_groove_meta API *************************************************/ 46 : 47 : /* FIXME: consider if memoizing is worth speed / footprint tradeoff */ 48 : 49 : struct fd_groove_meta { 50 : fd_groove_key_t key; 51 : ulong bits; /* groove metadata bit field */ 52 : ulong val_off; /* if key's val is in the cold store, cold store bytes [val_off,val_off+val_sz) 53 : hold the current val and bytes [val_off,val_off+val_max) are reserved for key's val. 54 : Thus: 0 <= val_off <= val_off+val_sz <= val_off+val_max <= cold store addr space sz. 55 : Further val's reserved bytes will all reside within a single cold store volume. */ 56 : }; 57 : 58 : typedef struct fd_groove_meta fd_groove_meta_t; 59 : 60 : #define MAP_NAME fd_groove_meta_map 61 : #define MAP_ELE_T fd_groove_meta_t 62 : #define MAP_KEY_T fd_groove_key_t 63 9596079 : #define MAP_KEY_EQ fd_groove_key_eq 64 34946271 : #define MAP_KEY_HASH fd_groove_key_hash 65 26440899 : #define MAP_ELE_IS_FREE(ctx,ele) (!fd_groove_meta_bits_used( (ele)->bits )) 66 1875204 : #define MAP_ELE_FREE(ctx,ele) do (ele)->bits = fd_groove_meta_bits( 0,0,0, 0UL, 0UL ); while(0) 67 170796 : #define MAP_ELE_MOVE(ctx,dst,src) do { \ 68 170796 : fd_groove_meta_t * _src = (src); \ 69 170796 : *(dst) = *_src; \ 70 170796 : _src->bits = fd_groove_meta_bits( 0,0,0, 0UL, 0UL ); \ 71 170796 : } while(0) 72 44502711 : #define MAP_VERSION_T ushort 73 9 : #define MAP_LOCK_MAX (8192) 74 : #define MAP_MAGIC (0xfd67007e3e7a3a90UL) /* fd groove meta map version 0 */ 75 : #define MAP_IMPL_STYLE 1 76 : #include "../util/tmpl/fd_map_slot_para.c" 77 : 78 : #endif /* HEADER_fd_src_groove_fd_groove_meta_h */