|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Streamed pseudo-memory and RBKC-z9 block-sweep backends. More...
#include <string.h>#include <time.h>#include "book_chunked.h"#include "miniz.h"#include "ra8_err.h"#include "sweep_block_internal.h"Go to the source code of this file.
Data Structures | |
| struct | cbs_pack_sink_t |
| struct | cbs_rbkc_t |
Enumerations | |
| enum | cbs_codec_limit_t : uint32_t { k_cbs_codec_input_bytes = 4096U , k_cbs_codec_window_bits = 15U } |
Functions | |
| RA8_PRIV uint64_t | priv_now_ns (void) |
| Monotonic wall-clock in nanoseconds. | |
| RA8_PRIV ra8_err_t | priv_meter_read (void *ctx, uint64_t offset, uint8_t *buffer, uint32_t length) |
| ra8_vsource_read_fn forwarding through a cbs_meter_t. | |
| static RA8_INTERNAL int | internal_mem_setup (cbs_backend_t *be, ra8_vsource_read_fn payload_read, void *payload_ctx, uint32_t blob_bytes, uint32_t block_bytes, cb_sweep_config_t *config) |
| Bind the deterministic payload directly as an uncompressed backend. | |
| static RA8_INTERNAL void | internal_backend_teardown (cbs_backend_t *be) |
| Clear the borrowed runtime bindings of one backend. | |
| static RA8_INTERNAL void | internal_rbkc_header (uint8_t *output, uint32_t block_bytes, uint64_t total, uint32_t count) |
| Encode the fixed RBKC container header into caller storage. | |
| static RA8_INTERNAL mz_bool | internal_pack_write (const void *data, int length, void *user) |
| Append one compressor fragment to the injected scratch transaction. | |
| static RA8_INTERNAL int | internal_rbkc_pack_chunk (tdefl_compressor *compressor, cbs_pack_sink_t *sink, ra8_vsource_read_fn payload_read, void *payload_ctx, uint8_t *input, uint32_t input_capacity, uint32_t offset, uint32_t length) |
| Compress one logical payload chunk into the scratch stream. | |
| static RA8_INTERNAL int | internal_rbkc_pack (ra8_vsource_read_fn payload_read, void *payload_ctx, uint32_t blob_bytes, uint32_t block_bytes, cb_sweep_config_t *config, uint8_t *input, uint32_t input_capacity, uint64_t *output_length) |
| Stream an RBKC container into the injected scratch transaction. | |
| static RA8_INTERNAL ra8_err_t | internal_rbkc_offsets (cbs_rbkc_t *rb, uint32_t chunk, uint64_t *begin, uint64_t *end) |
| Read and validate one compressed chunk's relative offset pair. | |
| static RA8_INTERNAL ra8_err_t | internal_rbkc_inflate (cbs_rbkc_t *rb, uint64_t begin, uint64_t end, uint8_t *output, uint32_t output_length) |
| Inflate one exact RBKC chunk from scratch into caller storage. | |
| static RA8_INTERNAL ra8_err_t | internal_rbkc_read (void *ctx, uint64_t offset, uint8_t *buffer, uint32_t length) |
| Serve one aligned logical chunk through the RBKC backend seam. | |
| static RA8_INTERNAL void * | internal_setup_take (cb_sweep_config_t *config, size_t bytes) |
| Take one aligned setup region from the shared small workspace. | |
| static RA8_INTERNAL int | internal_rbkc_setup (cbs_backend_t *be, ra8_vsource_read_fn payload_read, void *payload_ctx, uint32_t blob_bytes, uint32_t block_bytes, cb_sweep_config_t *config) |
| Construct and bind the streamed RBKC-z9 benchmark backend. | |
| RA8_PRIV cbs_backend_t * | priv_backends (uint32_t *out_count) |
| Expose the registered sweep backends (the seam the HW leg extends). | |
Variables | |
| static cbs_backend_t | s_cbs_backends [] |
Streamed pseudo-memory and RBKC-z9 block-sweep backends.
RBKC construction writes directly to an injected scratch transaction. Compression state temporarily overlays the 1 MiB cache backing before the measured cache exists; the region is zeroed before it is rebound as frame storage. Chunk offsets and compressed input are read on demand, so no container, table, or max-chunk staging array is resident.
[Ring 7 / Tooling] {World: NS}
Definition in file sweep_block_backends.c.
| enum cbs_codec_limit_t : uint32_t |
| Enumerator | |
|---|---|
| k_cbs_codec_input_bytes | Streamed codec transfer grain. |
| k_cbs_codec_window_bits | Zlib window size as log2(bytes). |
Definition at line 25 of file sweep_block_backends.c.
|
static |
Clear the borrowed runtime bindings of one backend.
Makes teardown idempotent by nulling the read, context, and source counter pointers while leaving static identity fields unchanged.
| [in,out] | be | Backend to unbind; NULL is accepted. |
be is NULL or points to an initialized backend record. be. Definition at line 127 of file sweep_block_backends.c.
|
static |
Bind the deterministic payload directly as an uncompressed backend.
Publishes the injected read callback and logical blob size without allocating, copying, or using the scratch transaction.
| [in,out] | be | Backend record to bind. |
| [in] | payload_read | Deterministic payload reader. |
| [in] | payload_ctx | Payload reader context. |
| [in] | blob_bytes | Logical source length. |
| [in] | block_bytes | Swept block size, unused by direct memory. |
| [in,out] | config | Sweep composition, unused by direct memory. |
| 0 | be publishes the injected source. |
| 1 | A required binding is absent or the blob is empty. |
be is writable. payload_read and payload_ctx remain valid through teardown. Definition at line 94 of file sweep_block_backends.c.
|
static |
Append one compressor fragment to the injected scratch transaction.
Implements miniz's output callback and advances the absolute scratch offset only after a complete injected write.
| [in] | data | Compressor output bytes. |
| [in] | length | Fragment length from miniz. |
| [in,out] | user | Bound cbs_pack_sink_t. |
| MZ_TRUE | The fragment was appended. |
| MZ_FALSE | An argument, prior failure, or scratch write failed. |
user identifies a live scratch transaction. data is readable for non-negative length bytes. length. Definition at line 186 of file sweep_block_backends.c.
References cb_scratch_t::ctx, cbs_pack_sink_t::failed, k_cb_io_ok, cbs_pack_sink_t::offset, cbs_pack_sink_t::scratch, and cb_scratch_t::write.
Referenced by internal_rbkc_pack_chunk().
|
static |
Encode the fixed RBKC container header into caller storage.
Writes magic, block geometry, total length, chunk count, and the reserved zero field in the reader's native container layout.
| [out] | output | Header buffer of k_book_container_header_len bytes. |
| [in] | block_bytes | Chunk size encoded in the header. |
| [in] | total | Logical uncompressed byte length. |
| [in] | count | Number of chunks. |
output is non-NULL and large enough for the fixed header. block_bytes and count describe total consistently. Definition at line 153 of file sweep_block_backends.c.
References memcpy().
Referenced by internal_rbkc_pack().
|
static |
Inflate one exact RBKC chunk from scratch into caller storage.
Pulls bounded compressed grains, drives tinfl in non-wrapping mode, and rejects stalled, truncated, extra-input, or wrong-size streams.
| [in,out] | rb | Bound RBKC reader and traffic counter. |
| [in] | begin | Relative compressed start. |
| [in] | end | Relative compressed end. |
| [out] | output | Destination buffer. |
| [in] | output_length | Exact expected uncompressed length. |
| k_ra8_ok | Exactly one stream produced the requested bytes. |
| k_ra8_err_invalid_size | Scratch I/O or stream geometry failed. |
rb and output are non-NULL and begin < end. output is writable for output_length bytes. Definition at line 395 of file sweep_block_backends.c.
References cb_scratch_t::ctx, cbs_rbkc_t::inflater, cbs_rbkc_t::input, cbs_rbkc_t::input_capacity, k_cb_io_ok, k_ra8_err_invalid_size, k_ra8_ok, cbs_rbkc_t::payload_offset, cb_scratch_t::read, cbs_rbkc_t::scratch, and cbs_rbkc_t::source_bytes.
Referenced by internal_rbkc_read().
|
static |
Read and validate one compressed chunk's relative offset pair.
Fetches adjacent table entries through the injected scratch seam and checks monotonicity plus the physical container bound.
| [in,out] | rb | Bound RBKC reader state. |
| [in] | chunk | Chunk-table index. |
| [out] | begin | Receives the relative compressed start. |
| [out] | end | Receives the relative compressed end. |
| k_ra8_ok | The offset pair is ordered and in range. |
| k_ra8_err_invalid_size | A read or geometry validation failed. |
rb, begin, and end are non-NULL. chunk is less than rb->chunk_count. Definition at line 360 of file sweep_block_backends.c.
References cb_scratch_t::ctx, k_book_container_entry_len, k_book_container_header_len, k_cb_io_ok, k_ra8_err_invalid_size, k_ra8_ok, cbs_rbkc_t::payload_offset, cb_scratch_t::read, cbs_rbkc_t::scratch, and cb_scratch_t::size.
Referenced by internal_rbkc_read().
|
static |
Stream an RBKC container into the injected scratch transaction.
Writes the fixed header and offset table incrementally, overlays tdefl state on the future cache backing, then erases that backing.
| [in] | payload_read | Deterministic payload reader. |
| [in] | payload_ctx | Payload reader context. |
| [in] | blob_bytes | Logical source length. |
| [in] | block_bytes | RBKC chunk size. |
| [in,out] | config | Scratch, cache overlay, and diagnostics. |
| [in,out] | input | Bounded codec input buffer. |
| [in] | input_capacity | Capacity of input. |
| [out] | output_length | Receives the container byte length. |
| 0 | Header, table, and all compressed chunks were written. |
| 1 | Alignment, capacity, read, compression, or scratch I/O failed. |
output_length match the container end. Definition at line 279 of file sweep_block_backends.c.
References cb_sweep_config_t::cache_backing, cb_sweep_config_t::cache_capacity, cb_scratch_t::ctx, internal_rbkc_header(), internal_rbkc_pack_chunk(), k_book_container_entry_len, k_book_container_header_len, k_cb_io_ok, memset(), cbs_pack_sink_t::offset, cb_sweep_config_t::scratch, cb_scratch_t::size, cb_sweep_config_t::workspace_required, and cb_scratch_t::write.
Referenced by internal_rbkc_setup().
|
static |
Compress one logical payload chunk into the scratch stream.
Reinitializes tdefl for an independent zlib stream, pulls the chunk in bounded input grains, and finishes through internal_pack_write.
| [in,out] | compressor | Caller-provided tdefl state. |
| [in,out] | sink | Scratch append binding. |
| [in] | payload_read | Payload read callback. |
| [in] | payload_ctx | Payload callback context. |
| [in,out] | input | Bounded codec input buffer. |
| [in] | input_capacity | Capacity of input. |
| [in] | offset | Payload start offset. |
| [in] | length | Uncompressed chunk length. |
| 0 | The chunk was fully compressed and appended. |
| 1 | Initialization, payload read, compression, or sink append failed. |
input_capacity is non-zero. sink points immediately after the chunk stream. Definition at line 225 of file sweep_block_backends.c.
References cbs_pack_sink_t::failed, internal_pack_write(), k_cbs_codec_window_bits, and k_ra8_ok.
Referenced by internal_rbkc_pack().
|
static |
Serve one aligned logical chunk through the RBKC backend seam.
Validates the vsource request geometry, fetches its table offsets, and inflates exactly the requested logical chunk.
| [in] | ctx | Bound cbs_rbkc_t. |
| [in] | offset | Chunk-aligned logical byte offset. |
| [out] | buffer | Destination buffer. |
| [in] | length | Exact logical chunk length. |
| k_ra8_ok | The chunk was decoded exactly. |
| k_ra8_err_null_ptr | A required binding is NULL. |
| k_ra8_err_out_of_range | The offset is outside or misaligned. |
| k_ra8_err_invalid_size | The length, table, or stream is invalid. |
buffer is writable for length bytes. ctx remains bound until backend teardown. buffer holds the requested payload bytes. Definition at line 459 of file sweep_block_backends.c.
References cbs_rbkc_t::chunk_bytes, cbs_rbkc_t::chunk_count, internal_rbkc_inflate(), internal_rbkc_offsets(), k_ra8_err_invalid_size, k_ra8_err_null_ptr, k_ra8_err_out_of_range, k_ra8_ok, and cbs_rbkc_t::total_bytes.
Referenced by internal_rbkc_setup().
|
static |
Construct and bind the streamed RBKC-z9 benchmark backend.
Temporarily reserves codec input, builds the scratch container, rolls back to the setup floor, then binds inflater reader state.
| [in,out] | be | Backend record to bind. |
| [in] | payload_read | Deterministic payload reader. |
| [in] | payload_ctx | Payload reader context. |
| [in] | blob_bytes | Logical source length. |
| [in] | block_bytes | Swept chunk size. |
| [in,out] | config | Scratch and workspace composition. |
| 0 | be publishes the RBKC read seam and traffic counter. |
| 1 | A binding, construction, or workspace check failed. |
block_bytes is non-zero. be remains valid until teardown or workspace reuse. Definition at line 535 of file sweep_block_backends.c.
References internal_rbkc_pack(), internal_rbkc_read(), internal_setup_take(), k_book_container_entry_len, k_book_container_header_len, k_cbs_codec_input_bytes, cb_sweep_config_t::scratch, cbs_rbkc_t::source_bytes, cb_sweep_config_t::workspace_floor, and cb_sweep_config_t::workspace_used.
|
static |
Take one aligned setup region from the shared small workspace.
Advances workspace_used on success and always updates the exact required-capacity diagnostic for the attempted partition.
| [in,out] | config | Sweep workspace state. |
| [in] | bytes | Requested byte count before alignment. |
| NULL | The aligned request does not fit. |
| other | Pointer to the reserved region. |
config and config->workspace are non-NULL. Definition at line 499 of file sweep_block_backends.c.
References cb_sweep_config_t::workspace, cb_sweep_config_t::workspace_capacity, cb_sweep_config_t::workspace_required, and cb_sweep_config_t::workspace_used.
Referenced by internal_rbkc_setup().
| RA8_PRIV cbs_backend_t * priv_backends | ( | uint32_t * | out_count | ) |
Expose the registered sweep backends (the seam the HW leg extends).
Returns the module's backend registry: mem first (the harness floor), then rbkc-z9. Entries are mutable because setup binds read/read_ctx/backing_bytes in place per (blob, size) pair.
| [out] | out_count | Receives the number of registered backends. |
out_count is non-NULL. Definition at line 589 of file sweep_block_backends.c.
References s_cbs_backends.
Referenced by cb_sweep_block().
ra8_vsource_read_fn forwarding through a cbs_meter_t.
Counts one call plus len bytes against the meter, then forwards to the wrapped reader. Registered at the vsource seam by the sweep core (counting storage commands == cache misses) and under the RBKC container file (counting raw compressed traffic).
| [in] | ctx | The cbs_meter_t to charge (as void*). |
| [in] | offset | Byte offset forwarded to the wrapped reader. |
| [out] | buf | Destination buffer forwarded to the wrapped reader. |
| [in] | len | Bytes requested. |
| k_ra8_err_null_ptr | ctx or its wrapped reader is NULL. |
ctx points at a cbs_meter_t with a live inner reader. buf covers len writable bytes for the wrapped reader. len. Definition at line 62 of file sweep_block_backends.c.
References cbs_meter_t::bytes, cbs_meter_t::calls, cbs_meter_t::inner, cbs_meter_t::inner_ctx, and k_ra8_err_null_ptr.
Referenced by internal_cache_open().
| RA8_PRIV uint64_t priv_now_ns | ( | void | ) |
Monotonic wall-clock in nanoseconds.
Reads CLOCK_MONOTONIC and folds seconds + nanoseconds into one 64-bit nanosecond count; the sweep core brackets each timed leg with two calls and reports the difference.
| other | The current CLOCK_MONOTONIC reading folded to nanoseconds. |
Definition at line 54 of file sweep_block_backends.c.
References k_cbs_ns_per_s.
Referenced by internal_drive().
|
static |
Definition at line 583 of file sweep_block_backends.c.
Referenced by priv_backends().