35static const char*
const s_tag =
"ra8_vmem";
43typedef enum : uint32_t {
54typedef enum : uint8_t {
89 const uint32_t lo = (uint32_t)k->
offset;
135 (void)
memset(vm, 0,
sizeof(*vm));
169 k.
offset = offset - (offset % (uint64_t)fb);
189 void* page =
nullptr;
201 uint32_t* out_misses,
202 uint32_t* out_evictions)
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
The one reusable hash + pin + evict cache engine (#147, #345).
ra8_err_t ra8_keycache_get(ra8_keycache_t *kc, const void *key, ra8_keycache_view_t *out_view)
Get (and pin) the cell for key, rendering it on a miss.
ra8_err_t ra8_keycache_stats(const ra8_keycache_t *kc, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_err_t ra8_keycache_init(ra8_keycache_t *kc, const ra8_keycache_cfg_t *cfg)
Initialise a cache engine over caller-supplied storage.
ra8_err_t ra8_keycache_put(ra8_keycache_t *kc, const uint8_t *data)
Release one pin on a cell previously returned by ra8_keycache_get.
@ k_ra8_keycache_evict_slru
Segmented LRU / 2Q (scan-resistant).
ra8_err_t ra8_vmem_put(ra8_vmem_t *vm, void *page)
Release one pin on a frame previously returned by ra8_vmem_get.
ra8_vmem_hash_const_t
Multiplicative constants mixing the two halves of the page key.
@ k_vmem_hash_mul_page
Odd multiplier mixing the offset.
@ k_vmem_hash_mul_obj
Knuth multiplicative hash (object id).
ra8_err_t ra8_vmem_get(ra8_vmem_t *vm, uint32_t object_id, uint64_t offset, void **out_page)
Get (and pin) the frame holding object object_id at offset.
ra8_vmem_shift_const_t
Bit shift splitting a 64-bit offset into two 32-bit halves.
@ k_vmem_off_shift
Shift for the high 32 bits of the offset.
static uint32_t internal_vmem_hash(const void *key, uint32_t key_bytes, void *ctx)
Injected key hash: fold the (object_id, offset) page key (division-free).
static ra8_err_t internal_vmem_fill(void *ctx, const void *key, uint8_t *cell, uint32_t cell_bytes, void *user)
Fill trampoline: adapt ra8_vmem_loader_fn to the keycache seam.
ra8_err_t ra8_vmem_init(ra8_vmem_t *vm, const ra8_vmem_cfg_t *cfg)
Initialise a page cache over caller-supplied storage.
ra8_err_t ra8_vmem_stats(const ra8_vmem_t *vm, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_err_t ra8_vmem_prefetch(ra8_vmem_t *vm, uint32_t object_id, uint64_t offset)
Warm the frame holding object object_id at offset into the cache without holding a pin (single-thread...
Byte-range page cache with SLRU eviction (Layer 2, #147).
Caller-supplied storage + policy + renderer for ra8_keycache_init.
void * hash_ctx
Opaque context passed to hash.
uint32_t bucket_count
Number of hash buckets (>= 1).
uint32_t user_bytes
Bytes per user descriptor (may be 0).
uint8_t * cell_mem
cell_count * cell_bytes of cell storage.
uint8_t protected_pct
SLRU protected share 1..100; 0 => 75%.
uint32_t cell_bytes
Bytes per cell (the rendered payload).
uint8_t * key_mem
cell_count * key_bytes of key storage.
int32_t * buckets
bucket_count hash-bucket heads.
ra8_keycache_evict_t evict
Eviction policy (0 => LRU; SLRU opt-in).
uint32_t key_bytes
Bytes per key (>= 1).
ra8_keycache_cell_t * meta
cell_count link-metadata entries.
uint32_t cell_count
Number of cells.
void * render_ctx
Opaque context passed to render.
ra8_keycache_render_fn render
Render-on-miss callback.
uint8_t * user_mem
cell_count * user_bytes, or NULL if none.
ra8_keycache_hash_fn hash
Key hash; NULL selects built-in FNV-1a.
uint32_t protected_cap
Protected-segment capacity (0 = LRU).
A pinned view of a cached cell returned by ra8_keycache_get.
Caller-supplied storage + loader for ra8_vmem_init.
uint32_t bucket_count
Number of hash buckets (>= 1).
uint32_t frame_bytes
Bytes per frame (page size, e.g.
ra8_vmem_frame_t * meta
frame_count metadata entries.
int32_t * buckets
bucket_count hash-bucket heads.
uint32_t frame_count
Number of frames.
uint8_t protected_pct
SLRU protected-segment share, 1..100; 0 selects the 75% default.
uint8_t * frame_mem
frame_count * frame_bytes of page storage.
void * loader_ctx
Opaque context passed to loader.
ra8_vmem_key_t * keys
frame_count key-storage entries.
ra8_vmem_loader_fn loader
Page-fill callback (the storage DIP seam).
The (object_id, frame-aligned offset) key the page cache hashes on.
uint64_t offset
Frame-aligned byte offset of the cached page.
uint32_t object_id
Cached object id.
Page-cache state (caller-owned; treat as private).
ra8_vmem_cfg_t cfg
The configuration (copied at init).
ra8_keycache_t kc
The underlying SLRU cache engine.
uint32_t protected_cap
Resolved SLRU protected-segment capacity.