29typedef enum : uint32_t {
47typedef enum : uint32_t {
60typedef enum : uint64_t {
65typedef enum : uint64_t {
147 uint64_t value = *state;
172 return (span == 0U) ? 0U : (uint32_t)(
internal_rng(state) % (uint64_t)span);
197 if (book ==
nullptr || buffer ==
nullptr) {
200 if (offset > book->
bytes || (uint64_t)length > (book->
bytes - offset)) {
203 for (uint32_t i = 0U; i < length; ++i) {
204 const uint64_t absolute = offset + i;
224 for (uint32_t chapter = 0U; chapter < (uint32_t)
k_rv_chapters; ++chapter) {
225 const uint32_t count =
249 void* page =
nullptr;
301 for (uint32_t chapter = 0U; chapter < (uint32_t)
k_rv_chapters; ++chapter) {
303 for (uint32_t index = 0U; index < extent.
count; ++index) {
304 const uint32_t frame = extent.
first + index;
309 if (glance && index > 0U) {
329 for (uint32_t round = 0U; round < (uint32_t)
k_rv_toc_rounds; ++round) {
353 for (uint32_t round = 0U; round < (uint32_t)
k_rv_sr_rounds; ++round) {
385 if (text ==
nullptr || text[0] ==
'\0') {
389 for (
size_t i = 0U; text[i] !=
'\0'; ++i) {
390 if (text[i] <
'0' || text[i] >
'9') {
393 const uint32_t digit = (uint32_t)(text[i] -
'0');
402 *budget = (uint32_t)value;
430 .frame_count = budget,
431 .meta = workspace->
meta,
432 .keys = workspace->
keys,
436 .loader_ctx = sources};
454 uint64_t scaled = 0U;
455 if (accesses != 0U) {
456 scaled = (((uint64_t)hits * (uint64_t)
k_rv_rate_scale) + (accesses / 2U)) / accesses;
487 const char* trace_path,
568 priv_rv_diag(
"reader_vmem: invalid workspace requirement\n");
583 priv_rv_diag(
"reader_vmem: cache workspace/source setup failed\n");
634 driver.
trace = &trace;
639 uint32_t misses = 0U;
640 uint32_t evictions = 0U;
642 const bool run_ok = !driver.
failed && stats_ok;
648 internal_report(&driver, &book, budget, trace_path, hits, misses, evictions);
664 priv_rv_diag(
"usage: reader_vmem [TRACE [FRAME_BUDGET]]\n");
672 if (argc > 3 || (argc > 1 &&
strcmp(argv[1],
"--help") == 0)) {
674 return (argc > 3) ? 2 : 0;
676 const char* trace_path = (argc > 1) ? argv[1] :
"reader_vmem.trace";
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
Lightweight Logging Interface for ra8-firmware.
Byte-range page cache with SLRU eviction (Layer 2, #147).
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_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_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_keycache_cell_t ra8_vmem_frame_t
Per-frame cache metadata (one caller-owned array entry per frame).
Virtual-memory object sources – the page-cache storage seam (Layer 1, #147).
ra8_err_t ra8_vsource_loader(void *ctx, uint32_t object_id, uint64_t offset, uint8_t *frame, uint32_t frame_bytes)
Fill a page frame from an object – the ra8_vmem_loader_fn adapter.
ra8_err_t ra8_vsource_add_paged(ra8_vsource_t *vs, ra8_vsource_read_fn read, void *ctx, uint64_t base, uint64_t size, uint32_t *out_id)
Register a storage-paged object; returns its object_id.
ra8_err_t ra8_vsource_init(ra8_vsource_t *vs, ra8_vsource_obj_t *objs, uint32_t cap)
Initialise an empty source registry over a caller-owned object array.
static uint64_t internal_rng(uint64_t *state)
Advance the driver's fixed-seed xorshift generator.
static void internal_report_rate(uint32_t hits, uint64_t accesses)
Print an integer percentage rounded to two fractional digits.
static void internal_report(const rv_driver_t *driver, const rv_book_t *book, uint32_t budget, const char *trace_path, uint32_t hits, uint32_t misses, uint32_t evictions)
Report the firmware cache counters in the legacy CLI format.
int main(int argc, char **argv)
rv_dimension_t
Book and workload model dimensions.
@ k_rv_toc_rounds
TOC jump rounds.
@ k_rv_pct_base
Percentage denominator.
@ k_rv_chap_span_fr
Random chapter-size span.
@ k_rv_chapters
Synthetic chapter count.
@ k_rv_chap_min_fr
Minimum frames per chapter.
@ k_rv_header_frames
Persistent header frames.
@ k_rv_def_budget
Default cache-frame budget.
@ k_rv_backglance_pct
Prior-page glance percent.
@ k_rv_max_objs
Source registry capacity.
@ k_rv_sr_hot_pass
Hot-set passes per round.
@ k_rv_sr_hot_fr
Hot-set frame count.
@ k_rv_sr_scan_fr
Scan frames per round.
@ k_rv_sr_rounds
Scan-resistance rounds.
@ k_rv_toc_read_fr
Frames read after a TOC jump.
static void internal_phase_scan(rv_driver_t *driver)
Run hot-set rereads interleaved with one-shot scan floods.
static bool internal_parse_budget(const char *text, uint32_t *budget)
Parse one strict non-zero decimal frame budget.
static rv_workspace_storage_t s_reader_workspace
Composition-root BSS cache memory, never used by reusable libraries.
static ra8_err_t internal_book_read(void *context, uint64_t offset, uint8_t *buffer, uint32_t length)
Generate exact synthetic source bytes directly at the read seam.
rv_constant_t
Deterministic generation and decimal constants.
@ k_rv_xs_shift_c
Third xorshift distance.
@ k_rv_rate_scale
Hundredths-percent scale.
@ k_rv_decimal_base
Decimal radix.
@ k_rv_workspace_pads
Maximum region padding count.
@ k_rv_xs_shift_a
First xorshift distance.
@ k_rv_fill_shift
Synthetic-byte shift.
@ k_rv_xs_shift_b
Second xorshift distance.
@ k_rv_fill_mul
Synthetic-byte multiplier.
@ k_rv_rate_digits
Printed fractional digits.
static bool internal_vmem_setup(ra8_vmem_t *vm, const rv_workspace_t *workspace, uint32_t budget, ra8_vsource_t *sources)
Initialise production vmem over already bound workspace views.
void ra8_log_emit_error(const char *tag, const char *message)
Emit an ERROR-level log line with only a tag and a message.
static bool internal_execute(const char *trace_path, uint32_t budget)
Execute one complete cache run and atomic trace transaction.
static bool internal_prepare(uint32_t budget, const rv_book_t *book, rv_workspace_t *workspace, ra8_vsource_t *sources, ra8_vsource_obj_t objects[k_rv_max_objs], uint32_t *object_id, rv_workspace_need_t *need)
Bind the workspace and register the generated book source.
static void internal_phase_linear(rv_driver_t *driver)
Run linear page-turns with hot furniture and back-glances.
static void internal_phase_toc(rv_driver_t *driver)
Run TOC-driven chapter jumps.
static void internal_layout_book(rv_driver_t *driver)
Lay out deterministic variable-size chapters.
static void internal_usage(void)
Print CLI usage and the explicit compiled cache ceiling.
void ra8_log_emit_error_val(const char *tag, const char *message, uint32_t value)
Emit an ERROR log line with a uint32_t companion value.
static void internal_touch(rv_driver_t *driver, uint32_t frame)
Access one production cache frame and append its trace record.
static uint32_t internal_below(uint64_t *state, uint32_t span)
Draw one deterministic value below a non-negative span.
rv_seed_t
Fixed deterministic RNG seed.
@ k_rv_rng_seed
Reproducible xorshift seed.
static void internal_touch_header(rv_driver_t *driver)
Re-reference the hot header and TOC region.
static void internal_report_workspace(uint32_t budget, const rv_workspace_need_t *need)
Report an exact compiled-workspace capacity failure.
rv_storage_size_t
Compile-time bytes reserved by the standalone composition root.
@ k_rv_workspace_storage_bytes
BSS bytes.
Private host sink and caller-owned workspace contracts for reader_vmem.
bool priv_rv_workspace_require(uint32_t budget, rv_workspace_need_t *need)
Query exact split-region requirements for one frame budget.
bool priv_rv_trace_reference(rv_trace_t *trace, uint32_t object_id, uint32_t frame)
Append one exact object/frame reference to a trace transaction.
void priv_rv_diag_u64(uint64_t value)
Write one unsigned decimal diagnostic without stdio.
void priv_rv_diag(const char *text)
Write one best-effort diagnostic fragment to standard error.
#define READER_VMEM_MAX_BUDGET
Maximum frames reserved by the standalone composition root.
bool priv_rv_trace_begin(const char *path, rv_trace_t *trace)
Begin one unpublished same-directory trace transaction.
@ k_rv_frame_bytes
Bytes per cache frame.
@ k_rv_bucket_count
Cache hash-bucket count.
void priv_rv_trace_abort(rv_trace_t *trace)
Close and unlink an unpublished trace.
bool priv_rv_trace_commit(rv_trace_t *trace)
Durably and atomically publish a complete trace.
bool priv_rv_workspace_bind(void *backing, size_t backing_bytes, const rv_workspace_need_t *need, rv_workspace_t *workspace)
Bind typed cache views into an aligned caller-owned backing.
Caller-supplied storage + loader for ra8_vmem_init.
The (object_id, frame-aligned offset) key the page cache hashes on.
Page-cache state (caller-owned; treat as private).
One registered object's backing (paged or XIP).
Object-source registry (caller-owned; treat as private).
Statelessly generated book extent.
uint64_t bytes
Total addressable synthetic bytes.
Per-chapter frame extent.
uint32_t first
First frame.
uint32_t count
Frame count.
Workload state shared by all navigation phases.
rv_chapter_t chapters[k_rv_chapters]
Deterministic chapter extents.
rv_trace_t * trace
Atomic raw-fd trace sink.
uint64_t rng
Xorshift state.
ra8_vmem_t * vm
Production cache instance.
uint32_t object_id
Registered book object.
uint32_t total_frames
Total synthetic book frames.
uint64_t accesses
References attempted.
bool failed
Sticky cache/trace failure.
Caller-owned atomic trace-publication state.
Exact byte regions required for one cache budget.
size_t total_bytes
Exact workspace high-water.
Explicit aligned storage owned only by this single-process CLI.
uint8_t bytes[k_rv_workspace_storage_bytes]
Cache workspace backing.
Typed views carved from a caller's workspace.
ra8_vmem_key_t * keys
Per-frame key storage.
ra8_vmem_frame_t * meta
Per-frame metadata.
uint8_t * frame_mem
Page-frame pool.
int32_t * buckets
Hash-bucket index heads.