25typedef enum : uint32_t {
31 "tdefl overlay must fit the semantic cache backing");
32static_assert(
alignof(max_align_t) >=
alignof(tdefl_compressor),
33 "composition cache alignment must satisfy tdefl");
56 struct timespec ts = {};
57 (void)clock_gettime(CLOCK_MONOTONIC, &ts);
58 return ((uint64_t)ts.tv_sec * (uint64_t)
k_cbs_ns_per_s) + (uint64_t)ts.tv_nsec;
65 if ((meter ==
nullptr) || (meter->
inner ==
nullptr)) {
69 meter->
bytes += length;
103 if ((be ==
nullptr) || (payload_read ==
nullptr) || (payload_ctx ==
nullptr) ||
104 (blob_bytes == 0U)) {
107 be->read = payload_read;
108 be->read_ctx = payload_ctx;
109 be->backing_bytes = blob_bytes;
110 be->src_bytes =
nullptr;
131 be->read_ctx =
nullptr;
132 be->src_bytes =
nullptr;
155 size_t position = 0U;
156 memcpy(&output[position],
"RBKC",
sizeof(
"RBKC") - 1U);
157 position +=
sizeof(
"RBKC") - 1U;
158 memcpy(&output[position], &block_bytes,
sizeof(block_bytes));
159 position +=
sizeof(block_bytes);
160 memcpy(&output[position], &total,
sizeof(total));
161 position +=
sizeof(total);
162 memcpy(&output[position], &count,
sizeof(count));
163 position +=
sizeof(count);
164 const uint32_t reserved = 0U;
165 memcpy(&output[position], &reserved,
sizeof(reserved));
189 if ((sink ==
nullptr) || (data ==
nullptr) || (length < 0) || sink->
failed) {
198 sink->
offset += (uint64_t)length;
230 uint32_t input_capacity,
234 const mz_uint flags = tdefl_create_comp_flags_from_zip_params(MZ_BEST_COMPRESSION,
236 MZ_DEFAULT_STRATEGY);
240 uint32_t complete = 0U;
241 while (complete < length) {
242 uint32_t span = length - complete;
243 if (span > input_capacity) {
244 span = input_capacity;
246 if (payload_read(payload_ctx, (uint64_t)offset + complete, input, span) !=
k_ra8_ok ||
247 tdefl_compress_buffer(compressor, input, span, TDEFL_NO_FLUSH) < TDEFL_STATUS_OKAY) {
252 const tdefl_status status = tdefl_compress_buffer(compressor,
nullptr, 0U, TDEFL_FINISH);
253 return ((status == TDEFL_STATUS_DONE) && !sink->
failed) ? 0 : 1;
282 uint32_t block_bytes,
285 uint32_t input_capacity,
286 uint64_t* output_length)
289 (((uintptr_t)config->
cache_backing %
alignof(tdefl_compressor)) != 0U)) {
293 const uint32_t count = (blob_bytes + block_bytes - 1U) / block_bytes;
301 uint64_t relative = 0U;
308 tdefl_compressor* compressor = (tdefl_compressor*)config->
cache_backing;
310 for (uint32_t chunk = 0U; chunk < count; ++chunk) {
311 const uint32_t offset = chunk * block_bytes;
312 uint32_t length = blob_bytes - offset;
313 if (length > block_bytes) {
314 length = block_bytes;
326 relative = sink.
offset - payload_offset;
327 const uint64_t table_offset =
334 *output_length = sink.
offset;
362 const uint64_t table_offset =
399 uint32_t output_length)
402 uint64_t source = begin;
403 uint32_t produced = 0U;
404 tinfl_status status = TINFL_STATUS_NEEDS_MORE_INPUT;
405 while (status != TINFL_STATUS_DONE) {
406 uint32_t input_length = (uint32_t)(end - source);
417 size_t consumed = input_length;
418 size_t available = output_length - produced;
419 const mz_uint32 flags =
420 (mz_uint32)(TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF |
421 (((source + input_length) < end) ? TINFL_FLAG_HAS_MORE_INPUT : 0U));
422 status = tinfl_decompress(rb->
inflater,
430 produced += (uint32_t)available;
431 if ((status < TINFL_STATUS_DONE) || (consumed == 0U)) {
462 if ((rb ==
nullptr) || (buffer ==
nullptr)) {
468 const uint32_t chunk = (uint32_t)(offset / rb->
chunk_bytes);
469 uint32_t expected = (uint32_t)(rb->
total_bytes - offset);
473 if ((chunk >= rb->
chunk_count) || (length != expected)) {
501 const size_t alignment =
alignof(max_align_t);
502 const size_t span = (bytes + alignment - 1U) & ~(alignment - 1U);
539 uint32_t block_bytes,
542 if ((be ==
nullptr) || (payload_read ==
nullptr) || (config ==
nullptr) ||
543 (config->
scratch ==
nullptr) || (block_bytes == 0U)) {
547 uint64_t file_length = 0U;
555 &file_length) != 0)) {
560 tinfl_decompressor* inflater =
563 if ((rb ==
nullptr) || (inflater ==
nullptr) || (input ==
nullptr)) {
566 const uint32_t count = (blob_bytes + block_bytes - 1U) / block_bytes;
568 .inflater = inflater,
571 .chunk_bytes = block_bytes,
572 .chunk_count = count,
573 .total_bytes = blob_bytes,
578 be->backing_bytes = file_length;
591 if (out_count !=
nullptr) {
@ k_book_container_header_len
Fixed header bytes ahead of the chunk table.
@ k_book_container_entry_len
One chunk-table entry (uint64 LE offset).
Demand-paged chunk reader for the "RBKC" .rabook container.
cb_io_status_t
Status returned by tool-local injected I/O callbacks.
@ k_cb_io_ok
Operation completed.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#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.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
ra8_err_t(* ra8_vsource_read_fn)(void *ctx, uint64_t offset, uint8_t *buf, uint32_t len)
Read len bytes at offset from a paged object's backing.
Injected bounded random-access scratch transaction.
void * ctx
Caller-owned binding.
uint64_t size
Logical bytes written.
cb_scratch_io_fn write
Complete write-at callback.
cb_scratch_io_fn read
Complete read-at callback.
Caller-owned bindings for the block sweep.
size_t cache_capacity
Supplied cache bytes.
size_t workspace_floor
Persistent payload-index prefix.
size_t workspace_capacity
Supplied workspace bytes.
uint8_t * workspace
Small metadata/codec-input workspace.
cb_scratch_t * scratch
Host-composed streamed RBKC transaction.
size_t workspace_used
Current phase workspace usage.
uint8_t * cache_backing
Exactly the measured resident-cache budget.
size_t workspace_required
Exact latest requirement.
One byte-addressed backing store the sweep reads through – the backend DIP seam the #208 hardware leg...
Counting shim around an ra8_vsource_read_fn.
uint64_t bytes
Bytes served through the shim.
uint64_t calls
Read calls forwarded so far.
void * inner_ctx
Context for inner.
ra8_vsource_read_fn inner
Wrapped reader.
cb_scratch_t * scratch
Destination transaction.
uint64_t offset
Next destination byte.
bool failed
Sticky publication failure.
uint64_t total_bytes
Logical payload extent.
cb_scratch_t * scratch
Container source transaction.
uint32_t chunk_count
Container chunk count.
uint32_t chunk_bytes
Logical bytes per chunk.
tinfl_decompressor * inflater
Caller-owned inflate state.
uint8_t * input
Compressed-input staging.
uint64_t payload_offset
First compressed payload byte.
uint64_t source_bytes
Complete container extent.
uint32_t input_capacity
Input staging extent.
RA8_PRIV uint64_t priv_now_ns(void)
Monotonic wall-clock in nanoseconds.
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.
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 mz_bool internal_pack_write(const void *data, int length, void *user)
Append one compressor fragment to the injected scratch transaction.
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 cbs_backend_t s_cbs_backends[]
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 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 void internal_backend_teardown(cbs_backend_t *be)
Clear the borrowed runtime bindings of one backend.
@ k_cbs_codec_window_bits
Zlib window size as log2(bytes).
@ k_cbs_codec_input_bytes
Streamed codec transfer grain.
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.
RA8_PRIV cbs_backend_t * priv_backends(uint32_t *out_count)
Expose the registered sweep backends (the seam the HW leg extends).
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 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 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_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.
Module-private seams shared by the #208 sweep translation units.
@ k_cbs_cache_bytes
1 MiB resident cache budget (constant).
@ k_cbs_ns_per_s
Nanoseconds per second.