ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
cache_bench.h File Reference

Eviction-policy comparison harness for the #147 memory-hierarchy decision record: the DIP seam every replacement policy implements, the fixed-frame cache it drives, and the per-run metrics it reports. More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for cache_bench.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cb_key_t
 A cache key: one (object, page) the reader's vm_get touches. More...
struct  cb_frame_t
 One frame slot in the fixed page cache. More...
struct  cb_cache_t
 The fixed-capacity frame cache a policy manages. More...
struct  cb_workspace_t
 Caller-owned replay workspace and exact capacity diagnostics. More...
struct  cache_policy_t
 The replacement-policy DIP seam (the eventual firmware Layer-2 seam). More...
struct  cb_result_t
 Per-(policy, trace, size) result row. More...

Typedefs

typedef struct cb_trace cb_trace_t

Functions

int cb_replay (const cache_policy_t *pol, const cb_trace_t *trace, uint32_t capacity, cb_workspace_t *workspace, cb_result_t *out)
 Replay an access trace through one policy at a fixed capacity.
size_t cb_replay_workspace_required (const cache_policy_t *pol, uint32_t capacity)
 Return the exact caller workspace required by one replay.

Variables

const cache_policy_t g_cb_policy_slru
 Segmented-LRU: the scan-resistant candidate (src/policy_scanresist.c).
const cache_policy_t g_cb_policy_srrip
 SRRIP: the 2-bit re-reference-interval candidate (src/policy_scanresist.c).
const cache_policy_t *const g_cb_policies []
 The registered policy table (defined in src/policies.c).
const uint32_t g_cb_policy_count
 Number of entries in g_cb_policies.

Detailed Description

Eviction-policy comparison harness for the #147 memory-hierarchy decision record: the DIP seam every replacement policy implements, the fixed-frame cache it drives, and the per-run metrics it reports.

This is a HOST tool (not firmware): it replays reader access traces through each candidate Layer-2 page-cache eviction policy at swept cache sizes and reports hit rate, per-eviction worst-case frames scanned (a WCET proxy), and per-frame metadata cost, so #147 can pick the knee of the hit-rate-vs-RAM curve that also clears the WCET / MC/DC bars. Policies plug in behind cache_policy_t exactly as the eventual firmware Layer 2 will (NASA Rule 9 allows the function-pointer vtable for this DIP seam).

[Ring 7 / Tooling] {World: NS}

Since
0.1.0

Definition in file cache_bench.h.

Typedef Documentation

◆ cb_trace_t

typedef struct cb_trace cb_trace_t

Definition at line 28 of file cache_bench.h.

Function Documentation

◆ cb_replay()

int cb_replay ( const cache_policy_t * pol,
const cb_trace_t * trace,
uint32_t capacity,
cb_workspace_t * workspace,
cb_result_t * out )

Replay an access trace through one policy at a fixed capacity.

Drives trace through an exact resident-set hash while delegating only eviction ordering to pol: hits update recency/frequency via the policy callbacks, misses evict the policy's victim and load the new key into that frame. Fills out with hit/miss and worst-case scan accounting for one (policy, trace, capacity) sweep point.

Parameters
[in]polPolicy to exercise.
[in]traceResettable access stream.
[in]capacityFrame count (the swept RAM budget).
[in,out]workspaceCaller-provided exact replay storage.
[out]outReceives the metrics for this run.
Returns
int 0 on success, non-zero on capacity, source, or argument failure.
Return values
0The replay completed and out holds the metrics.
1A NULL/zero argument, policy bind, source, or workspace check failed.
Precondition
pol has pick_victim bound and trace is resettable.
out is non-NULL and writable.
Postcondition
On success, out->accesses == trace->n and hits do not exceed accesses.
No storage ownership changes; exact demand is recorded in workspace.
Note
Independent calls are safe when their traces and workspaces are distinct.
Since
0.1.0

Definition at line 523 of file cache_bench.c.

References cache_policy_t::deinit, cache_policy_t::init, internal_replay_close(), internal_replay_open(), internal_replay_stream(), cache_policy_t::state_base_bytes, and cache_policy_t::state_frame_bytes.

Referenced by internal_report_summary(), and internal_report_trace_row().

◆ cb_replay_workspace_required()

size_t cb_replay_workspace_required ( const cache_policy_t * pol,
uint32_t capacity )

Return the exact caller workspace required by one replay.

Sums aligned frame, resident-index, link, and policy-state regions with overflow guards, without touching caller storage.

Parameters
[in]polPolicy whose private state is included.
[in]capacityFrame count.
Returns
Exact bytes, or zero for invalid/overflowing input.
Return values
0A policy/capacity check or size calculation failed.
otherExact aligned workspace bytes required by cb_replay.
Precondition
pol is NULL or points to readable policy geometry.
capacity is an intended fixed cache-frame count.
Postcondition
A non-zero result covers every replay workspace region.
No policy or caller storage is modified.
Note
Thread-safe: this function reads immutable policy geometry only.
Since
0.1.0

Definition at line 333 of file cache_bench.c.

References internal_align_size(), internal_pow2_ceil(), internal_size_multiply(), k_cb_max_hash_capacity, cache_policy_t::state_base_bytes, and cache_policy_t::state_frame_bytes.

Referenced by internal_replay_open().

Variable Documentation

◆ g_cb_policies

const cache_policy_t* const g_cb_policies[]
extern

The registered policy table (defined in src/policies.c).

Definition at line 586 of file policies.c.

Referenced by internal_report_summary(), and internal_report_trace().

◆ g_cb_policy_count

const uint32_t g_cb_policy_count
extern

Number of entries in g_cb_policies.

Definition at line 594 of file policies.c.

Referenced by internal_report_summary(), and internal_report_trace().

◆ g_cb_policy_slru

const cache_policy_t g_cb_policy_slru
extern

Segmented-LRU: the scan-resistant candidate (src/policy_scanresist.c).

A probationary + protected LRU pair; one-time scans churn only the probationary segment, so the re-referenced hot set survives.

Note
Read-only after load; registered in g_cb_policies.
Since
0.1.0

Definition at line 312 of file policy_scanresist.c.

◆ g_cb_policy_srrip

const cache_policy_t g_cb_policy_srrip
extern

SRRIP: the 2-bit re-reference-interval candidate (src/policy_scanresist.c).

Inserts predict a distant re-reference so scanned-once pages are evicted before re-referenced ones; a hit predicts immediate reuse.

Note
Read-only after load; registered in g_cb_policies.
Since
0.1.0

Definition at line 470 of file policy_scanresist.c.