Line data Source code
1 : #ifndef HEADER_fd_src_waltz_route_fd_fib4_private_h 2 : #define HEADER_fd_src_waltz_route_fd_fib4_private_h 3 : 4 : #include "fd_fib4.h" 5 : #include "../../util/fd_util.h" 6 : 7 : struct __attribute__((aligned(FD_FIB4_ALIGN))) fd_fib4_key { 8 : /* FIXME optimize this to 8 bytes? */ 9 : uint addr; /* prefix bits, little endian (low bits outside of mask are undefined) */ 10 : uint mask; /* bit pattern */ 11 : uint prio; /* lower is higher */ 12 : }; 13 : 14 : typedef struct fd_fib4_key fd_fib4_key_t; 15 : 16 : struct __attribute__((aligned(FD_FIB4_ALIGN))) fd_fib4 { 17 : ulong hmap_offset; 18 : ulong hmap_elem_offset; 19 : ulong hmap_cnt; 20 : ulong hmap_max; 21 : ulong generation; 22 : ulong cnt; 23 : ulong max; 24 : ulong hop_off; 25 : /* fd_fib4_key_t[] follows */ 26 : /* fd_fib4_hop_t[] follows */ 27 : /* hmap_mem follows */ 28 : /* hmap_elem_mem follows */ 29 : }; 30 : 31 : FD_FN_CONST static inline ulong 32 387 : fd_fib4_key_tbl_laddr( fd_fib4_t const * fib ) { 33 387 : return (ulong)fib + sizeof(fd_fib4_t); 34 387 : } 35 : 36 : FD_FN_PURE static inline ulong 37 387 : fd_fib4_hop_tbl_laddr( fd_fib4_t const * fib ) { 38 387 : return (ulong)fib + fib->hop_off; 39 387 : } 40 : 41 237 : FD_FN_CONST static inline fd_fib4_key_t const * fd_fib4_key_tbl_const( fd_fib4_t const * fib ) { return (fd_fib4_key_t const *)fd_fib4_key_tbl_laddr( fib ); } 42 150 : FD_FN_CONST static inline fd_fib4_key_t * fd_fib4_key_tbl ( fd_fib4_t * fib ) { return (fd_fib4_key_t *) fd_fib4_key_tbl_laddr( fib ); } 43 237 : FD_FN_CONST static inline fd_fib4_hop_t const * fd_fib4_hop_tbl_const( fd_fib4_t const * fib ) { return (fd_fib4_hop_t const *)fd_fib4_hop_tbl_laddr( fib ); } 44 150 : FD_FN_CONST static inline fd_fib4_hop_t * fd_fib4_hop_tbl ( fd_fib4_t * fib ) { return (fd_fib4_hop_t *) fd_fib4_hop_tbl_laddr( fib ); } 45 : 46 : 47 : /* Hashmap private APIs */ 48 : 49 : #define MAP_NAME fd_fib4_hmap 50 2232 : #define MAP_ELE_T fd_fib4_hmap_entry_t 51 : #define MAP_KEY_T uint 52 897 : #define MAP_KEY dst_addr 53 639 : #define MAP_KEY_HASH(key,seed) fd_uint_hash( (*(key)) ^ ((uint)seed) ) 54 : 55 : struct __attribute__((aligned(16))) fd_fib4_hmap_entry { 56 : uint dst_addr; /* Little endian. All 32-bits defined */ 57 : fd_fib4_hop_t next_hop; 58 : }; 59 : 60 : typedef struct fd_fib4_hmap_entry fd_fib4_hmap_entry_t; 61 : 62 : #define MAP_IMPL_STYLE 0 63 : #include "../../util/tmpl/fd_map_slot_para.c" 64 : 65 741 : static inline void * fd_fib4_hmap_mem ( fd_fib4_t * fib ) { return (void *)( (ulong)fib + fib->hmap_offset ); } 66 741 : static inline void * fd_fib4_hmap_ele_mem ( fd_fib4_t * fib ) { return (void *)( (ulong)fib + fib->hmap_elem_offset ); } 67 : 68 : /* Get the hashmap's total capacity (50% extra capacity beyond the requested size to optimize performance) */ 69 99 : static inline ulong fd_fib4_hmap_get_ele_max ( ulong max_cnt ) { return fd_ulong_pow2_up( max_cnt + ( max_cnt>>1 ) ); } 70 : /* Get the hashmap's probe limit (75% of total capacity). Higher than requested size to avoid probe failure */ 71 87 : static inline ulong fd_fib4_hmap_get_probe_max ( ulong elem_max ) { return elem_max - ( elem_max>>2 ); } 72 : /* Get the hashmap's lock count. Each lock roughly protects 1/16 elements in the hashmap */ 73 105 : static inline ulong fd_fib4_hmap_get_lock_cnt ( ulong elem_max ) { return ( elem_max<=32 ) ? 1 : ( elem_max>>4 ); } 74 : 75 : #endif /* HEADER_fd_src_waltz_route_fd_fib4_private_h */