Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_bpf_frames_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_bpf_frames_h 3 : 4 : /* fd_bpf_frames holds the BPF loader input serialization frames for the 5 : exec{rp,le} tiles. A BPF instruction serializes its input into a 6 : frame and holds it until it returns, and a CPI takes another frame 7 : while its caller keeps its own, so a tile holds up to one frame per 8 : instruction stack level. This object allows for shared and 9 : tile-local frames for both tiles. Each tile can keep some number of 10 : frames local to itself for performance reasons. The last shared 11 : frames are held back so the pool cannot deadlock. This is sized so 12 : that contending transactions cannot starve each other for bpf frames. 13 : 14 : Each join also owns one fd_bpf_deploy_scratch_t for program 15 : deployment. 16 : 17 : fd_bpf_frames_shmem_t is the pool and fd_bpf_frames_t is one user's 18 : local join to it. */ 19 : 20 : #include "fd_runtime_const.h" 21 : #include "../../ballet/sbpf/fd_sbpf_loader.h" 22 : 23 : /* FD_BPF_FRAMES_HELD_CNT is the number of shared frames held back when 24 : each join has local_cnt local frames, and so the fewest shared frames 25 : a pool can have. */ 26 : 27 75 : #define FD_BPF_FRAMES_HELD_CNT( local_cnt ) (2UL*(FD_MAX_INSTRUCTION_STACK_DEPTH-(local_cnt))) 28 0 : #define FD_BPF_FRAMES_CNT_MAX (1UL<<16) 29 : 30 : /* FD_BPF_FRAMES_ALIGN is the alignment of every frame. */ 31 : 32 : #define FD_BPF_FRAMES_ALIGN (4096UL) 33 : 34 : /* fd_bpf_deploy_scratch_t is the scratch memory used by 35 : fd_deploy_program to load and validate a program. */ 36 : 37 : struct fd_bpf_deploy_scratch { 38 : uchar rodata [ FD_RUNTIME_ACC_SZ_MAX ] __attribute__((aligned(FD_SBPF_PROG_RODATA_ALIGN))); 39 : uchar sbpf_footprint[ FD_SBPF_PROGRAM_FOOTPRINT ] __attribute__((aligned(alignof(fd_sbpf_program_t)))); 40 : uchar programdata [ FD_RUNTIME_ACC_SZ_MAX ] __attribute__((aligned(FD_ACCOUNT_REC_ALIGN))); 41 : }; 42 : typedef struct fd_bpf_deploy_scratch fd_bpf_deploy_scratch_t; 43 : 44 : struct fd_bpf_frames_shmem; 45 : typedef struct fd_bpf_frames_shmem fd_bpf_frames_shmem_t; 46 : 47 : struct fd_bpf_frames; 48 : typedef struct fd_bpf_frames fd_bpf_frames_t; 49 : 50 : FD_PROTOTYPES_BEGIN 51 : 52 : /* fd_bpf_frames_shmem_{align,footprint,new} size and format a pool of 53 : frame_cnt shared frames, plus local_cnt local frames and one deploy 54 : scratch reserved for each of up to joiner_cnt_max joins. footprint 55 : returns 0 if local_cnt is more than FD_MAX_INSTRUCTION_STACK_DEPTH, 56 : frame_cnt is less than FD_BPF_FRAMES_HELD_CNT( local_cnt ), or the 57 : pool would have more than FD_BPF_FRAMES_CNT_MAX frames. new returns 58 : shmem on success, NULL on failure (logs details). */ 59 : 60 : FD_FN_CONST ulong 61 : fd_bpf_frames_shmem_align( void ); 62 : 63 : FD_FN_CONST ulong 64 : fd_bpf_frames_shmem_footprint( ulong frame_cnt, 65 : ulong joiner_cnt_max, 66 : ulong local_cnt ); 67 : 68 : void * 69 : fd_bpf_frames_shmem_new( void * shmem, 70 : ulong frame_cnt, 71 : ulong joiner_cnt_max, 72 : ulong local_cnt ); 73 : 74 : /* fd_bpf_frames_{align,footprint,join} size and create a local join to 75 : the pool at shframes in the memory at ljoin, taking the next joiner's 76 : local frames and deploy scratch. Each user needs its own join. join 77 : returns NULL (logs details) if joiner_cnt_max users already joined. */ 78 : 79 : FD_FN_CONST ulong 80 : fd_bpf_frames_align( void ); 81 : 82 : FD_FN_CONST ulong 83 : fd_bpf_frames_footprint( void ); 84 : 85 : fd_bpf_frames_t * 86 : fd_bpf_frames_join( void * ljoin, 87 : void * shframes ); 88 : 89 : /* fd_bpf_frames_acquire takes a frame, spinning until one is 90 : available. priority is whether the caller is the priority caller. */ 91 : 92 : uchar * 93 : fd_bpf_frames_acquire( fd_bpf_frames_t * join, 94 : int priority ); 95 : 96 : /* fd_bpf_frames_release returns a frame acquired through join. A 97 : join's frames must be released in the reverse order they were 98 : acquired. */ 99 : 100 : void 101 : fd_bpf_frames_release( fd_bpf_frames_t * join, 102 : uchar * frame ); 103 : 104 : /* fd_bpf_frames_deploy_scratch returns the deploy scratch owned by 105 : join. */ 106 : 107 : fd_bpf_deploy_scratch_t * 108 : fd_bpf_frames_deploy_scratch( fd_bpf_frames_t * join ); 109 : 110 : FD_PROTOTYPES_END 111 : 112 : #endif /* HEADER_fd_src_flamenco_runtime_fd_bpf_frames_h */