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