ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_keycache.h
Go to the documentation of this file.
1
70
71#pragma once
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77#include <stdint.h>
78
79#include "ra8_err.h"
80
99
119typedef uint32_t (*ra8_keycache_hash_fn)(const void* key, uint32_t key_bytes, void* ctx);
120
144 const void* key,
145 uint8_t* cell,
146 uint32_t cell_bytes,
147 void* user);
148
161typedef struct {
162 int32_t prev;
163 int32_t next;
164 int32_t hash_next;
165 uint16_t pin_count;
166 uint8_t seg;
167 uint8_t valid;
169
202
217typedef struct {
219 int32_t pb_head;
220 int32_t pb_tail;
221 int32_t pt_head;
222 int32_t pt_tail;
224 uint32_t protected_cap;
225 uint32_t hits;
226 uint32_t misses;
227 uint32_t evictions;
229
243typedef struct {
244 uint8_t* data;
245 void* user;
247
272[[nodiscard]] ra8_err_t ra8_keycache_init(ra8_keycache_t* kc, const ra8_keycache_cfg_t* cfg);
273
303[[nodiscard]] ra8_err_t
304ra8_keycache_get(ra8_keycache_t* kc, const void* key, ra8_keycache_view_t* out_view);
305
340[[nodiscard]] ra8_err_t ra8_keycache_prefetch(ra8_keycache_t* kc, const void* key);
341
363[[nodiscard]] ra8_err_t ra8_keycache_put(ra8_keycache_t* kc, const uint8_t* data);
364
387[[nodiscard]] ra8_err_t ra8_keycache_stats(const ra8_keycache_t* kc,
388 uint32_t* out_hits,
389 uint32_t* out_misses,
390 uint32_t* out_evictions);
391
392#ifdef __cplusplus
393}
394#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
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.
uint32_t(* ra8_keycache_hash_fn)(const void *key, uint32_t key_bytes, void *ctx)
Hash a key blob to a raw 32-bit value (the engine folds to a bucket).
ra8_err_t(* ra8_keycache_render_fn)(void *ctx, const void *key, uint8_t *cell, uint32_t cell_bytes, void *user)
Fill a cell with the rendered bytes for key (render-on-miss seam).
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.
ra8_keycache_evict_t
Eviction policy selected in ra8_keycache_cfg_t::evict.
@ k_ra8_keycache_evict_lru
Single-list LRU (the default when 0).
@ k_ra8_keycache_evict_slru
Segmented LRU / 2Q (scan-resistant).
ra8_err_t ra8_keycache_prefetch(ra8_keycache_t *kc, const void *key)
Warm the cell for key into the cache without holding a pin.
Per-cell link metadata (one caller-owned array entry per cell).
int32_t next
Recency link toward LRU within the segment, or -1.
uint16_t pin_count
Outstanding pins (0 => evictable).
int32_t prev
Recency link toward MRU within the segment, or -1.
uint8_t valid
1 => this cell holds an entry.
uint8_t seg
SLRU segment tag (probationary / protected).
int32_t hash_next
Hash bucket chain link, or -1.
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.
Cache engine state (caller-owned; treat as private).
uint32_t protected_count
Cells in the protected segment.
int32_t pt_tail
Protected LRU cell, or -1 (SLRU only).
uint32_t protected_cap
Protected-segment capacity (0 = LRU).
int32_t pt_head
Protected MRU cell, or -1 (SLRU only).
uint32_t hits
Get hits so far.
uint32_t misses
Get misses so far.
ra8_keycache_cfg_t cfg
Configuration (copied at init).
uint32_t evictions
Entries evicted so far.
int32_t pb_tail
Probationary LRU cell, or -1.
int32_t pb_head
Probationary MRU cell, or -1.
A pinned view of a cached cell returned by ra8_keycache_get.
uint8_t * data
Cell payload (cell_bytes wide).
void * user
Per-cell user descriptor, or NULL.