|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Drive the real virtual-memory cache with a deterministic reader trace. More...
#include <stddef.h>#include <stdint.h>#include <string.h>#include "ra8_err.h"#include "ra8_log.h"#include "ra8_vmem.h"#include "ra8_vsource.h"#include "reader_vmem_internal.h"Go to the source code of this file.
Data Structures | |
| struct | rv_workspace_storage_t |
| Explicit aligned storage owned only by this single-process CLI. More... | |
| struct | rv_chapter_t |
| Per-chapter frame extent. More... | |
| struct | rv_book_t |
| Statelessly generated book extent. More... | |
| struct | rv_driver_t |
| Workload state shared by all navigation phases. More... | |
Enumerations | |
| enum | rv_dimension_t : uint32_t { k_rv_header_frames = 4U , k_rv_chapters = 24U , k_rv_chap_min_fr = 8U , k_rv_chap_span_fr = 160U , k_rv_backglance_pct = 12U , k_rv_toc_rounds = 600U , k_rv_toc_read_fr = 6U , k_rv_sr_rounds = 40U , k_rv_sr_hot_pass = 3U , k_rv_sr_hot_fr = 200U , k_rv_sr_scan_fr = 1200U , k_rv_pct_base = 100U , k_rv_def_budget = 256U , k_rv_max_objs = 2U } |
| Book and workload model dimensions. More... | |
| enum | rv_constant_t : uint32_t { k_rv_xs_shift_a = 13U , k_rv_xs_shift_b = 7U , k_rv_xs_shift_c = 17U , k_rv_fill_mul = 2654435761U , k_rv_fill_shift = 24U , k_rv_decimal_base = 10U , k_rv_rate_scale = 10000U , k_rv_rate_digits = 2U , k_rv_workspace_pads = 3U } |
| Deterministic generation and decimal constants. More... | |
| enum | rv_seed_t : uint64_t { k_rv_rng_seed = 0x9E3779B97F4A7C15ULL } |
| Fixed deterministic RNG seed. More... | |
| enum | rv_storage_size_t : uint64_t { k_rv_workspace_storage_bytes } |
| Compile-time bytes reserved by the standalone composition root. More... | |
Functions | |
| void | ra8_log_emit_error (const char *tag, const char *message) |
| Emit an ERROR-level log line with only a tag and a message. | |
| 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 uint64_t | internal_rng (uint64_t *state) |
| Advance the driver's fixed-seed xorshift generator. | |
| static uint32_t | internal_below (uint64_t *state, uint32_t span) |
| Draw one deterministic value below a non-negative span. | |
| 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. | |
| static void | internal_layout_book (rv_driver_t *driver) |
| Lay out deterministic variable-size chapters. | |
| static void | internal_touch (rv_driver_t *driver, uint32_t frame) |
| Access one production cache frame and append its trace record. | |
| static void | internal_touch_header (rv_driver_t *driver) |
| Re-reference the hot header and TOC region. | |
| 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_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 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. | |
| 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. | |
| static void | internal_report_workspace (uint32_t budget, const rv_workspace_need_t *need) |
| Report an exact compiled-workspace capacity failure. | |
| 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 bool | internal_execute (const char *trace_path, uint32_t budget) |
| Execute one complete cache run and atomic trace transaction. | |
| static void | internal_usage (void) |
| Print CLI usage and the explicit compiled cache ceiling. | |
| int | main (int argc, char **argv) |
Variables | |
| static rv_workspace_storage_t | s_reader_workspace |
| Composition-root BSS cache memory, never used by reusable libraries. | |
Drive the real virtual-memory cache with a deterministic reader trace.
This host decision-record tool registers a synthetic book through the real ra8_vsource callback seam, drives the production ra8_vmem SLRU cache, and emits one cache_bench-compatible <object> <frame> reference per access. Synthetic source bytes are generated at the requested offset, so the source exercises the complete miss/load path without allocating an 8 MiB replica. Cache RAM is carved from the explicit composition-root workspace below.
Definition in file reader_vmem.c.
| enum rv_constant_t : uint32_t |
Deterministic generation and decimal constants.
Definition at line 47 of file reader_vmem.c.
| enum rv_dimension_t : uint32_t |
Book and workload model dimensions.
Definition at line 29 of file reader_vmem.c.
| enum rv_seed_t : uint64_t |
Fixed deterministic RNG seed.
| Enumerator | |
|---|---|
| k_rv_rng_seed | Reproducible xorshift seed. |
Definition at line 60 of file reader_vmem.c.
| enum rv_storage_size_t : uint64_t |
Compile-time bytes reserved by the standalone composition root.
| Enumerator | |
|---|---|
| k_rv_workspace_storage_bytes | BSS bytes. |
Definition at line 65 of file reader_vmem.c.
|
static |
Draw one deterministic value below a non-negative span.
Advances the generator for non-zero spans and maps by unsigned modulo.
| [in,out] | state | Deterministic generator state. |
| [in] | span | Exclusive upper bound; zero selects deterministic zero. |
span is zero. | 0 | The zero-span result or a valid sampled zero. |
| sampled | A value strictly below non-zero span. |
state is non-null and writable. span may be any uint32_t value. Definition at line 170 of file reader_vmem.c.
References internal_rng(), and RA8_INTERNAL.
Referenced by internal_layout_book(), internal_phase_linear(), and internal_phase_toc().
|
static |
Generate exact synthetic source bytes directly at the read seam.
Computes each byte from its absolute offset, avoiding a synthetic-book allocation.
| [in] | context | Bound rv_book_t extent. |
| [in] | offset | First requested byte offset. |
| [out] | buffer | Destination spanning length bytes. |
| [in] | length | Exact requested byte count. |
| k_ra8_ok | The complete range was generated. |
| k_ra8_err_null_ptr | Context or destination was null. |
| k_ra8_err_out_of_range | Request exceeds the synthetic book. |
context and buffer are null or valid for their declared extents. length destination bytes. Definition at line 194 of file reader_vmem.c.
References rv_book_t::bytes, k_ra8_err_null_ptr, k_ra8_err_out_of_range, k_ra8_ok, k_rv_fill_mul, and k_rv_fill_shift.
Referenced by internal_prepare().
|
static |
Execute one complete cache run and atomic trace transaction.
Composes workspace/source/cache state, drives every workload phase, validates production statistics, and publishes only a complete synced trace. The driver, the cache and the trace are all owned by this one frame, so the cache and trace pointers the driver carries can never outlive their objects.
| [in] | trace_path | Final trace destination. |
| [in] | budget | Requested frame budget. |
| true | Run, statistics, sync, and publication succeeded. |
| false | Setup, cache, trace, or publication failed. |
trace_path is non-null and NUL-terminated. budget is non-zero and subject to the compiled maximum check. Definition at line 607 of file reader_vmem.c.
References rv_driver_t::failed, internal_layout_book(), internal_phase_linear(), internal_phase_scan(), internal_phase_toc(), internal_prepare(), internal_report(), internal_vmem_setup(), k_ra8_ok, k_rv_frame_bytes, k_rv_max_objs, k_rv_rng_seed, rv_driver_t::object_id, priv_rv_diag(), priv_rv_trace_abort(), priv_rv_trace_begin(), priv_rv_trace_commit(), RA8_INTERNAL, ra8_vmem_stats(), rv_driver_t::total_frames, rv_driver_t::trace, and rv_driver_t::vm.
Referenced by main().
|
static |
Lay out deterministic variable-size chapters.
Consumes one bounded random draw per chapter after the fixed header extent.
| [in,out] | driver | Workload driver owning RNG and chapter table. |
driver is non-null and its RNG was initialized. driver. Definition at line 221 of file reader_vmem.c.
References rv_driver_t::chapters, internal_below(), k_rv_chap_min_fr, k_rv_chap_span_fr, k_rv_chapters, k_rv_header_frames, RA8_INTERNAL, rv_driver_t::rng, and rv_driver_t::total_frames.
Referenced by internal_execute().
|
static |
Parse one strict non-zero decimal frame budget.
Accepts ASCII digits only and checks every base-ten accumulation for overflow.
| [in] | text | NUL-terminated budget spelling. |
| [out] | budget | Receives the parsed non-zero frame count. |
| true | A non-zero uint32_t value was stored. |
| false | Input is null, empty, non-decimal, zero, or overflowing. |
text is null or NUL-terminated. budget is non-null and writable. budget exactly once. budget unchanged. Definition at line 383 of file reader_vmem.c.
References k_rv_decimal_base, and RA8_INTERNAL.
Referenced by main().
|
static |
Run linear page-turns with hot furniture and back-glances.
Visits every chapter page, refreshing header frames each turn and adding deterministic prior-page glances according to the fixed percentage.
| [in,out] | driver | Prepared and laid-out workload driver. |
driver owns live cache, trace, chapter, and RNG state. Definition at line 299 of file reader_vmem.c.
References rv_driver_t::chapters, rv_chapter_t::count, rv_chapter_t::first, internal_below(), internal_touch(), internal_touch_header(), k_rv_backglance_pct, k_rv_chapters, k_rv_pct_base, RA8_INTERNAL, and rv_driver_t::rng.
Referenced by internal_execute().
|
static |
Run hot-set rereads interleaved with one-shot scan floods.
Alternates repeated hot prefixes with modular scans to exercise SLRU pollution resistance.
| [in,out] | driver | Prepared and laid-out workload driver. |
driver owns live cache and trace state. driver. Definition at line 350 of file reader_vmem.c.
References internal_touch(), k_rv_header_frames, k_rv_sr_hot_fr, k_rv_sr_hot_pass, k_rv_sr_rounds, k_rv_sr_scan_fr, RA8_INTERNAL, and rv_driver_t::total_frames.
Referenced by internal_execute().
|
static |
Run TOC-driven chapter jumps.
Repeats header refresh, deterministic chapter selection, and a bounded prefix read.
| [in,out] | driver | Prepared and laid-out workload driver. |
driver owns live cache, trace, chapter, and RNG state. driver. Definition at line 327 of file reader_vmem.c.
References rv_driver_t::chapters, rv_chapter_t::count, rv_chapter_t::first, internal_below(), internal_touch(), internal_touch_header(), k_rv_chapters, k_rv_toc_read_fr, k_rv_toc_rounds, RA8_INTERNAL, and rv_driver_t::rng.
Referenced by internal_execute().
|
static |
Bind the workspace and register the generated book source.
Derives exact region requirements, enforces the compiled ceiling, binds typed views, and registers one stateless positioned-read source.
| [in] | budget | Requested cache frame count. |
| [in] | book | Synthetic book extent. |
| [out] | workspace | Receives typed cache storage views. |
| [out] | sources | Receives initialized source registry. |
| [out] | objects | Caller-owned registry-object array. |
| [out] | object_id | Receives the registered synthetic object identifier. |
| [out] | need | Receives exact workspace geometry. |
| true | Workspace and source are ready for cache initialization. |
| false | Requirement, capacity, binding, or registration failed. |
book has a non-zero bounded byte extent. Definition at line 559 of file reader_vmem.c.
References rv_book_t::bytes, internal_book_read(), internal_report_workspace(), k_ra8_ok, k_rv_max_objs, priv_rv_diag(), priv_rv_workspace_bind(), priv_rv_workspace_require(), RA8_INTERNAL, ra8_vsource_add_paged(), ra8_vsource_init(), READER_VMEM_MAX_BUDGET, s_reader_workspace, and rv_workspace_need_t::total_bytes.
Referenced by internal_execute().
|
static |
Report the firmware cache counters in the legacy CLI format.
Emits deterministic raw-descriptor fragments for golden-output parity.
| [in] | driver | Completed workload driver. |
| [in] | book | Synthetic source extent. |
| [in] | budget | Configured frame budget. |
| [in] | trace_path | Published trace path. |
| [in] | hits | Production cache hit count. |
| [in] | misses | Production cache miss count. |
| [in] | evictions | Production cache eviction count. |
Definition at line 484 of file reader_vmem.c.
References rv_driver_t::accesses, rv_book_t::bytes, internal_report_rate(), priv_rv_diag(), priv_rv_diag_u64(), RA8_INTERNAL, and rv_driver_t::total_frames.
Referenced by internal_execute().
|
static |
Print an integer percentage rounded to two fractional digits.
Uses scaled integer arithmetic and raw diagnostic fragments only.
| [in] | hits | Successful cache-hit count. |
| [in] | accesses | Total reference count. |
hits does not exceed the successful-access subset. Definition at line 452 of file reader_vmem.c.
References k_rv_decimal_base, k_rv_pct_base, k_rv_rate_scale, priv_rv_diag(), priv_rv_diag_u64(), and RA8_INTERNAL.
Referenced by internal_report().
|
static |
Report an exact compiled-workspace capacity failure.
Prints requested and compiled capacities using integer-only formatting.
| [in] | budget | Requested frame budget. |
| [in] | need | Exact workspace requirement computed for that budget. |
need is non-null and fully initialized. Definition at line 525 of file reader_vmem.c.
References priv_rv_diag(), priv_rv_diag_u64(), RA8_INTERNAL, READER_VMEM_MAX_BUDGET, s_reader_workspace, and rv_workspace_need_t::total_bytes.
Referenced by internal_prepare().
|
static |
Advance the driver's fixed-seed xorshift generator.
Applies the fixed three-shift recurrence used by every workload phase.
| [in,out] | state | Non-zero deterministic generator state. |
| value | Exact next state after one recurrence. |
state is non-null and writable. Definition at line 145 of file reader_vmem.c.
References k_rv_xs_shift_a, k_rv_xs_shift_b, k_rv_xs_shift_c, and RA8_INTERNAL.
Referenced by internal_below().
|
static |
Access one production cache frame and append its trace record.
Exercises get/put through production vmem, records the same reference, and makes any cache or trace failure sticky while preserving workload length.
| [in,out] | driver | Fully prepared workload driver. |
| [in] | frame | Synthetic book frame number to reference. |
driver owns live cache and trace contexts. frame is below driver->total_frames. Definition at line 246 of file reader_vmem.c.
References rv_driver_t::accesses, rv_driver_t::failed, k_ra8_ok, k_rv_frame_bytes, rv_driver_t::object_id, priv_rv_diag(), priv_rv_diag_u64(), priv_rv_trace_reference(), RA8_INTERNAL, ra8_vmem_get(), ra8_vmem_put(), rv_driver_t::trace, and rv_driver_t::vm.
Referenced by internal_phase_linear(), internal_phase_scan(), internal_phase_toc(), and internal_touch_header().
|
static |
Re-reference the hot header and TOC region.
Touches the fixed leading frame range in ascending order.
| [in,out] | driver | Prepared workload driver. |
driver owns live cache and trace contexts. driver. Definition at line 280 of file reader_vmem.c.
References internal_touch(), k_rv_header_frames, and RA8_INTERNAL.
Referenced by internal_phase_linear(), and internal_phase_toc().
|
static |
Print CLI usage and the explicit compiled cache ceiling.
Uses bounded raw diagnostic fragments and integer formatting.
Definition at line 662 of file reader_vmem.c.
References priv_rv_diag(), priv_rv_diag_u64(), RA8_INTERNAL, and READER_VMEM_MAX_BUDGET.
Referenced by main().
|
static |
Initialise production vmem over already bound workspace views.
Binds explicit cache regions and the virtual-source loader into one configuration.
| [out] | vm | Caller-owned cache object. |
| [in] | workspace | Bound non-overlapping cache regions. |
| [in] | budget | Number of frames represented by the regions. |
| [in,out] | sources | Initialized virtual-source registry. |
| true | Cache is ready for get/put operations. |
| false | Production configuration validation failed. |
budget. sources remains alive for the cache lifetime. vm without acquiring storage. vm or sources. Definition at line 423 of file reader_vmem.c.
References rv_workspace_t::buckets, rv_workspace_t::frame_mem, k_ra8_ok, k_rv_bucket_count, k_rv_frame_bytes, rv_workspace_t::keys, rv_workspace_t::meta, RA8_INTERNAL, ra8_vmem_init(), and ra8_vsource_loader().
Referenced by internal_execute().
| int main | ( | int | argc, |
| char ** | argv ) |
Definition at line 670 of file reader_vmem.c.
References internal_execute(), internal_parse_budget(), internal_usage(), k_rv_def_budget, and strcmp().
| void ra8_log_emit_error | ( | const char * | tag, |
| const char * | message ) |
Emit an ERROR-level log line with only a tag and a message.
Backend entry point for the ra8_log_error() macro.
| [in] | tag | Short component tag; must not be NULL. |
| [in] | message | Free-form ASCII message; must not be NULL. |
Emit an ERROR-level log line with only a tag and a message.
Definition at line 112 of file reader_vmem.c.
References internal_emit_line(), and priv_rv_diag().
| 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.
Adds =<decimal> to the line emitted by ra8_log_emit_error.
| [in] | tag | Short component tag; must not be NULL. |
| [in] | message | Free-form ASCII message; must not be NULL. |
| [in] | value | Unsigned numeric companion appended to the line. |
Emit an ERROR log line with a uint32_t companion value.
Weak default backend. Forwards to internal_emit_line_u with the fixed level string "ERROR".
| [in] | tag | NUL-terminated module tag (e.g. "ra8_log"). |
| [in] | message | NUL-terminated short event description. |
| [in] | value | uint32 datum appended as "=NNN" to the line. |
Emit an ERROR log line with a uint32_t companion value.
Definition at line 121 of file reader_vmem.c.
References internal_emit_line_u(), priv_rv_diag(), and priv_rv_diag_u64().
|
static |
Composition-root BSS cache memory, never used by reusable libraries.
The workspace planner accepts arbitrary caller backings; this one named instance is the standalone tool's explicit RAM budget.
Definition at line 87 of file reader_vmem.c.
Referenced by internal_prepare(), and internal_report_workspace().