|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Core of the #208 block/frame-size sweep (--sweep-block). More...
#include "sweep_block.h"#include <string.h>#include "miniz.h"#include "ra8_err.h"#include "ra8_vmem.h"#include "ra8_vsource.h"#include "sweep_block_internal.h"Go to the source code of this file.
Data Structures | |
| struct | cbs_cache_t |
| One ::ra8_vmem instance sized for a swept block size + its storage. More... | |
Enumerations | |
| enum | cbs_block_size_t : uint32_t { k_cbs_block_512b = 512U , k_cbs_block_1kib = 1024U , k_cbs_block_4kib = 4096U , k_cbs_block_16kib = 16384U , k_cbs_block_64kib = 65536U , k_cbs_block_256kib = 262144U } |
| The swept block / frame / chunk sizes, in bytes. More... | |
| enum | cbs_leg_t : uint8_t { k_cbs_leg_seq = 0U , k_cbs_leg_hot = 1U , k_cbs_leg_count = 2U } |
| Leg indices for internal_run_block's per-leg loop. More... | |
Functions | |
| void | ra8_log_emit_error (const char *tag, const char *message) |
| Log backend stub so ra8_check's RA8_CHECK_* macros link host-side. | |
| void | ra8_log_emit_error_val (const char *tag, const char *message, uint32_t value) |
| Valued log backend stub (present for the linker, as reader_vmem). | |
| static uint32_t | internal_pow2_ceil (uint32_t v) |
Round v up to a power of two (>= 1). | |
| static void | internal_cache_close (cbs_cache_t *c) |
| End a cbs_cache_t's borrowed workspace bindings (idempotent). | |
| static size_t | internal_align_size (size_t value) |
| Round a workspace span to maximum fundamental alignment. | |
| static void * | internal_workspace_take (cb_sweep_config_t *config, size_t *used, size_t bytes) |
| Take one aligned region from the caller-owned sweep workspace. | |
| static int | internal_cache_storage (cbs_cache_t *c, uint32_t block_bytes, cb_sweep_config_t *config, uint32_t *out_buckets) |
| Carve and clear exact cache metadata from caller-owned bindings. | |
| static int | internal_cache_open (cbs_cache_t *c, const cbs_backend_t *be, uint32_t blob_bytes, uint32_t block_bytes, cb_sweep_config_t *config) |
| Stand up a real ::ra8_vmem cache with frame_bytes == block_bytes. | |
| static int | internal_drive (cbs_cache_t *c, ra8_vsource_read_fn payload_read, void *payload_ctx, uint64_t n_reads, uint64_t wrap_bytes, cbs_row_t *row) |
Drive one timed leg: n_reads requests of k_cbs_req_bytes each, at offsets (i * req) % wrap_bytes, verifying every byte returned. | |
| static int | internal_run_block (cbs_backend_t *be, ra8_vsource_read_fn payload_read, void *payload_ctx, uint32_t block_bytes, cbs_row_t *rows, uint32_t *nrows, cb_sweep_config_t *config) |
| Run both legs of one (backend, block size) combination. | |
| static int | internal_execute (cb_sweep_config_t *config, cbs_payload_t *payload, cbs_backend_t *backends, uint32_t backend_count, cbs_row_t *rows, uint32_t *row_count) |
| Execute every backend and block-size pair and append its result rows. | |
| static int | internal_summary (cb_sweep_config_t *config, const cbs_backend_t *backends, uint32_t backend_count, const cbs_row_t *rows, uint32_t row_count) |
| Publish all human summary tables and the crossover verdict. | |
| int | cb_sweep_block (cb_sweep_config_t *config) |
| Run the #208 block/frame-size sweep and print the report. | |
Variables | |
| static const char *const | s_cbs_leg_names [k_cbs_leg_count] = {"seq", "hot"} |
| Report names for the two workload legs, indexed by cbs_leg_t. | |
| static const uint32_t | s_cbs_blocks [] |
| The swept block sizes, ascending (drives loops + knee search). | |
Core of the #208 block/frame-size sweep (--sweep-block).
Drives the REAL ::ra8_vmem SLRU page cache (not a re-modelled policy) with frame_bytes swept from 512 B to 256 KiB under a constant byte budget, over the backends published by priv_backends() (the cbs_backend_t seam; implementations live in src/sweep_block_backends.c). Leg (a) scans the whole object sequentially; leg (b) re-reads one block. Every byte handed back by the cache is verified against the source blob. Row printing and the summary report live in src/sweep_block_report.c.
[Ring 7 / Tooling] {World: NS}
Definition in file sweep_block.c.
| enum cbs_block_size_t : uint32_t |
The swept block / frame / chunk sizes, in bytes.
Powers of two from one SD sector up to a quarter MiB, bracketing the 64 KiB .rabook chunk default (#204) by two octaves on each side so the knee is visible whichever way it falls.
Definition at line 39 of file sweep_block.c.
| enum cbs_leg_t : uint8_t |
Leg indices for internal_run_block's per-leg loop.
| Enumerator | |
|---|---|
| k_cbs_leg_seq | Sequential whole-object scan. |
| k_cbs_leg_hot | Same-block re-read loop. |
| k_cbs_leg_count | Number of legs. |
Definition at line 398 of file sweep_block.c.
| int cb_sweep_block | ( | cb_sweep_config_t * | config | ) |
Run the #208 block/frame-size sweep and print the report.
For every registered backend and every swept block size (512 B .. 256 KiB), builds the backing, stands up a real ::ra8_vmem cache with frame_bytes equal to the swept size under a constant byte budget, and drives legs (a) sequential whole-object scan and (b) same-block re-read. Prints one machine-parseable sweep-block ... line per row, then a human summary with the measured knee and a chunk-size recommendation versus the current 64 KiB .rabook default (#204). Every returned byte is verified against the source blob, so a lying backend fails the run instead of skewing it.
| [in,out] | config | Caller-owned cache, workspace, scratch, and sinks. |
| 0 | Sweep completed; every row verified byte-identical. |
| 1 | Capacity, backend setup, I/O, or data-verification failure. |
config supplies exactly 1 MiB of aligned cache backing, bounded metadata workspace, a scratch transaction, and output/error sinks. Definition at line 608 of file sweep_block.c.
References cb_sweep_config_t::cache_capacity, cb_sweep_config_t::cache_required, cb_sink_format(), cb_sweep_config_t::error, internal_align_size(), internal_execute(), internal_summary(), k_cb_io_ok, k_cbs_blob_bytes, k_cbs_cache_bytes, k_cbs_hot_reads, k_cbs_max_rows, k_cbs_req_bytes, k_cbs_seq_passes, cb_sweep_config_t::output, priv_backends(), priv_payload_init(), priv_payload_workspace_required(), cb_sweep_config_t::scratch, cb_sweep_config_t::workspace, cb_sweep_config_t::workspace_capacity, cb_sweep_config_t::workspace_floor, cb_sweep_config_t::workspace_required, and cb_sweep_config_t::workspace_used.
Referenced by internal_run_sweep().
|
static |
Round a workspace span to maximum fundamental alignment.
Applies the power-of-two alignment mask used by every metadata partition in this bounded sweep composition.
| [in] | value | Unaligned byte count. |
value. | other | Aligned span used for workspace partitioning. |
value plus the alignment bias fits in size_t by sweep geometry. Definition at line 160 of file sweep_block.c.
Referenced by cb_sweep_block(), and internal_workspace_take().
|
static |
End a cbs_cache_t's borrowed workspace bindings (idempotent).
Frees the frame storage, per-frame metadata, key-storage, and bucket arrays, then zeroes the bundle so a repeat call is a safe no-op. Called on every leg exit and on any partial internal_cache_open failure.
| [in,out] | c | Cache bundle to release (NULL tolerated as a no-op). |
c is NULL, or its buffers came from internal_cache_open. c is all-zero; caller-owned backing remains reusable. Definition at line 137 of file sweep_block.c.
Referenced by internal_cache_open(), and internal_run_block().
|
static |
Stand up a real ::ra8_vmem cache with frame_bytes == block_bytes.
The byte budget k_cbs_cache_bytes is constant across sizes, so the frame count is budget / block (min 1) and the bucket count is the next power of two above twice the frames (min k_cbs_bucket_min). The backend is wired in through the vsource-seam meter so meter.calls counts storage commands.
| [out] | c | Cache bundle to populate. |
| [in] | be | Backend with a live read (post-setup). |
| [in] | blob_bytes | Object length in bytes. |
| [in] | block_bytes | Swept frame size in bytes. |
| [in,out] | config | Caller cache/workspace bindings and diagnostics. |
| 0 | c is cold and ready for ra8_vmem_get. |
| 1 | A NULL/zero argument, exact capacity, or init step failed. |
c is writable. Definition at line 275 of file sweep_block.c.
References cbs_cache_t::buckets, cb_sweep_config_t::cache_backing, cb_sweep_config_t::cache_capacity, cbs_cache_t::frame_mem, cbs_cache_t::frames, internal_cache_close(), internal_cache_storage(), k_cbs_cache_bytes, k_ra8_ok, cbs_cache_t::keys, cbs_cache_t::meta, cbs_cache_t::meter, cbs_cache_t::object_id, cbs_cache_t::objs, priv_meter_read(), ra8_vmem_init(), ra8_vsource_add_paged(), ra8_vsource_init(), ra8_vsource_loader(), cbs_cache_t::vm, and cbs_cache_t::vs.
Referenced by internal_run_block().
|
static |
Carve and clear exact cache metadata from caller-owned bindings.
Derives frame and bucket counts for block_bytes, binds the fixed cache backing, and partitions metadata from the small workspace.
| [out] | c | Cache bundle receiving all borrowed regions. |
| [in] | block_bytes | Swept cache-frame size. |
| [in,out] | config | Caller bindings and exact-capacity diagnostics. |
| [out] | out_buckets | Receives the hash-bucket count. |
| 0 | Cache storage is bound and cleared. |
| 1 | Caller workspace is too small. |
block_bytes is one of the non-zero swept sizes. Definition at line 213 of file sweep_block.c.
References cbs_cache_t::buckets, cb_sweep_config_t::cache_backing, cb_sweep_config_t::cache_capacity, cbs_cache_t::frame_mem, cbs_cache_t::frames, internal_pow2_ceil(), internal_workspace_take(), k_cbs_bucket_min, k_cbs_cache_bytes, cbs_cache_t::keys, memset(), cbs_cache_t::meta, cb_sweep_config_t::workspace_required, and cb_sweep_config_t::workspace_used.
Referenced by internal_cache_open().
|
static |
Drive one timed leg: n_reads requests of k_cbs_req_bytes each, at offsets (i * req) % wrap_bytes, verifying every byte returned.
wrap_bytes == blob_bytes yields sequential whole-object passes (leg a); wrap_bytes == block_bytes pins the loop inside block 0 (leg b, the pure hit path after one cold fill). The wall clock brackets only this loop – backend setup and container packing are never timed.
| [in,out] | c | An open, cold cbs_cache_t. |
| [in] | payload_read | Ground-truth byte-source callback. |
| [in] | payload_ctx | Ground-truth callback context. |
| [in] | n_reads | Requests to issue. |
| [in] | wrap_bytes | Offset wrap span (see details). |
| [out] | row | Row receiving reads / stats / wall time. |
| 0 | Every request hit correct bytes; row is fully filled. |
| 1 | A NULL argument, a get/put error, or a byte mismatch occurred. |
c was opened by internal_cache_open and is unused (cold). wrap_bytes is a non-zero multiple of k_cbs_req_bytes. Definition at line 349 of file sweep_block.c.
References ra8_vmem_t::cfg, cbs_row_t::evictions, ra8_vmem_cfg_t::frame_bytes, cbs_row_t::hits, k_cbs_req_bytes, k_ra8_ok, memcmp(), cbs_row_t::misses, cbs_cache_t::object_id, priv_now_ns(), ra8_vmem_get(), ra8_vmem_put(), ra8_vmem_stats(), cbs_row_t::reads, cbs_cache_t::vm, and cbs_row_t::wall_ns.
Referenced by internal_run_block().
|
static |
Execute every backend and block-size pair and append its result rows.
Traverses the bounded backend-by-size matrix in stable order and stops at the first failed setup, drive, verification, or report.
| [in,out] | config | Bound sweep composition. |
| [in,out] | payload | Deterministic payload source. |
| [in,out] | backends | Backend table. |
| [in] | backend_count | Number of backend entries. |
| [out] | rows | Fixed result-row array. |
| [in,out] | row_count | Number of valid rows appended. |
| 0 | Every matrix point produced both workload rows. |
| 1 | One matrix point failed. |
backend_count and the static size count fit that row capacity. row_count equals the full matrix row count. row_count remain complete and ordered. Definition at line 534 of file sweep_block.c.
References internal_run_block(), priv_payload_read(), and s_cbs_blocks.
Referenced by cb_sweep_block().
|
static |
Round v up to a power of two (>= 1).
Starts at 1 and left-shifts until the running value reaches or exceeds v, yielding the smallest power of two not less than v. Used to size the ::ra8_vmem hash-bucket table for a swept frame count.
| [in] | v | Target to round up; both 0 and 1 map to 1. |
v (never 0). | 1 | v was 0 or 1. |
| other | The next power of two at or above v. |
v <= 2^31 so the next power of two fits in 32 bits. v and >= 1; no shared state is touched.v with no shared state. Definition at line 86 of file sweep_block.c.
Referenced by internal_cache_storage().
|
static |
Run both legs of one (backend, block size) combination.
Sets the backend up once for the size, then runs each leg on a fresh cold cache; per-leg backend counters are taken as deltas so open-time header/table reads never pollute a leg's traffic numbers. Each finished row is appended and printed immediately.
| [in,out] | be | Backend to exercise. |
| [in] | payload_read | Ground-truth byte-source callback. |
| [in] | payload_ctx | Ground-truth callback context. |
| [in] | block_bytes | Swept block size. |
| [in,out] | rows | Row array (capacity k_cbs_max_rows). |
| [in,out] | nrows | Row count; incremented per finished leg. |
| [in,out] | config | Caller workspace, scratch, and report sinks. |
| 0 | Both legs ran; k_cbs_leg_count rows were appended and printed. |
| 1 | A NULL argument, a backend setup, an open, or a drive failed. |
rows has space for k_cbs_leg_count more rows. be has setup and teardown bound. Definition at line 442 of file sweep_block.c.
References cbs_row_t::be_bytes, cbs_row_t::be_calls, cbs_meter_t::bytes, cbs_meter_t::calls, cbs_cache_t::frames, internal_cache_close(), internal_cache_open(), internal_drive(), k_cbs_blob_bytes, k_cbs_hot_reads, k_cbs_leg_count, k_cbs_leg_seq, k_cbs_req_bytes, k_cbs_seq_passes, cbs_cache_t::meter, cb_sweep_config_t::output, priv_print_row(), s_cbs_leg_names, cbs_row_t::src_bytes, cb_sweep_config_t::workspace_floor, and cb_sweep_config_t::workspace_used.
Referenced by internal_execute().
|
static |
Publish all human summary tables and the crossover verdict.
Emits the fixed report heading, both workload tables for each backend, and the measured chunk-size crossover conclusion.
| [in,out] | config | Bound output composition. |
| [in] | backends | Completed backend table. |
| [in] | backend_count | Number of backend entries. |
| [in] | rows | Completed result rows. |
| [in] | row_count | Number of valid rows. |
| 0 | Every summary fragment was accepted by the sink. |
| 1 | A table or verdict publication failed. |
config and backends are non-NULL. rows contains row_count complete matrix rows. Definition at line 577 of file sweep_block.c.
References cb_sink_format(), k_cb_io_ok, k_cbs_req_bytes, cb_sweep_config_t::output, priv_print_crossover(), priv_print_hot_table(), priv_print_seq_table(), and s_cbs_blocks.
Referenced by cb_sweep_block().
|
static |
Take one aligned region from the caller-owned sweep workspace.
Advances used only when the aligned request fits completely.
| [in,out] | config | Sweep configuration carrying workspace storage. |
| [in,out] | used | Current cursor, advanced on success. |
| [in] | bytes | Requested region size before alignment. |
| NULL | The aligned request does not fit. |
| other | Pointer to the start of the reserved region. |
config and used are non-NULL. used advances by the aligned span. used and workspace bytes are unchanged. Definition at line 183 of file sweep_block.c.
References internal_align_size(), cb_sweep_config_t::workspace, and cb_sweep_config_t::workspace_capacity.
Referenced by internal_cache_storage().
| void ra8_log_emit_error | ( | const char * | tag, |
| const char * | message ) |
Log backend stub so ra8_check's RA8_CHECK_* macros link host-side.
Emit an ERROR-level log line with only a tag and a message.
Definition at line 49 of file sweep_block.c.
| void ra8_log_emit_error_val | ( | const char * | tag, |
| const char * | message, | ||
| uint32_t | value ) |
Valued log backend stub (present for the linker, as reader_vmem).
Emit an ERROR log line with a uint32_t companion value.
Definition at line 56 of file sweep_block.c.
|
static |
The swept block sizes, ascending (drives loops + knee search).
Values come from cbs_block_size_t.
Definition at line 504 of file sweep_block.c.
Referenced by internal_execute(), and internal_summary().
|
static |
Report names for the two workload legs, indexed by cbs_leg_t.
Read-only.
Definition at line 411 of file sweep_block.c.
Referenced by internal_run_block().