|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Reference eviction policies + the registry for the #147 benchmark. More...
Go to the source code of this file.
Data Structures | |
| struct | cb_lru_t |
| LRU recency list threaded through prev/next frame-index arrays. More... | |
Enumerations | |
| enum | cb_rand_seed_t : uint64_t { k_rand_seed = 0x123456789ABCDEF0ULL } |
| Initial PRNG seed for the Random eviction policy. More... | |
| enum | cb_rand_shift_t : uint8_t { k_rand_shift_a = 13U , k_rand_shift_b = 7U , k_rand_shift_c = 17U } |
| xorshift64 shift-amount triple used in the Random policy's PRNG step. More... | |
Functions | |
| static int | internal_fifo_init (cb_cache_t *c) |
| Bind FIFO state: a single round-robin hand over the frame ring. | |
| static void | internal_fifo_deinit (cb_cache_t *c) |
| Release FIFO state (the insertion hand). | |
| static uint32_t | internal_fifo_victim (cb_cache_t *c, uint32_t *scanned) |
| Choose the FIFO victim: the frame the hand currently points at. | |
| static int | internal_rand_init (cb_cache_t *c) |
| Bind Random-policy state: a deterministic xorshift64 seed. | |
| static void | internal_rand_deinit (cb_cache_t *c) |
| Release Random-policy state (the PRNG seed). | |
| static uint32_t | internal_rand_victim (cb_cache_t *c, uint32_t *scanned) |
| Choose a uniformly random victim frame. | |
| static int | internal_lru_init (cb_cache_t *c) |
| Bind true-LRU state: a doubly-linked recency list over frames. | |
| static void | internal_lru_deinit (cb_cache_t *c) |
| Release true-LRU state (control block + index arrays). | |
| static void | internal_lru_unlink (cb_lru_t *l, int32_t f) |
Unlink frame f from the recency list. | |
| static void | internal_lru_to_head (cb_lru_t *l, int32_t f) |
Splice frame f to the MRU (most-recently-used) head. | |
| static void | internal_lru_touch (cb_cache_t *c, uint32_t frame) |
LRU hit hook: move the just-accessed frame to the MRU head. | |
| static void | internal_lru_insert (cb_cache_t *c, uint32_t frame) |
LRU insert hook: place a freshly-loaded frame at the MRU head. | |
| static uint32_t | internal_lru_victim (cb_cache_t *c, uint32_t *scanned) |
| Choose the LRU victim: the frame at the list tail. | |
| static int | internal_clock_init (cb_cache_t *c) |
| Bind CLOCK state: one reference bit per frame + a sweep hand. | |
| static void | internal_clock_deinit (cb_cache_t *c) |
| Release CLOCK state (the sweep hand). | |
| static void | internal_clock_set (cb_cache_t *c, uint32_t frame) |
CLOCK reference hook: set frame's reference bit. | |
| static uint32_t | internal_clock_victim (cb_cache_t *c, uint32_t *scanned) |
| Choose the CLOCK victim by second-chance sweep. | |
Variables | |
| static const cache_policy_t | s_cb_policy_fifo |
| static const cache_policy_t | s_cb_policy_random |
| static const cache_policy_t | s_cb_policy_lru |
| static const cache_policy_t | s_cb_policy_clock |
| const cache_policy_t *const | g_cb_policies [] |
| The registered policy table (defined in src/policies.c). | |
| const uint32_t | g_cb_policy_count = (uint32_t)(sizeof(g_cb_policies) / sizeof(g_cb_policies[0])) |
| Number of entries in g_cb_policies. | |
Reference eviction policies + the registry for the #147 benchmark.
Baselines the scan-resistant candidates must beat: FIFO and Random (no recency), true LRU (good on locality, thrashes on linear scan), and CLOCK (the standard embedded second-chance LRU approximation). The scan-resistant policies (2Q / Segmented-LRU, CLOCK-Pro, CAR) live in their own TUs and are appended to g_cb_policies.
[Ring 7 / Tooling] {World: NS}
Definition in file policies.c.
| enum cb_rand_seed_t : uint64_t |
Initial PRNG seed for the Random eviction policy.
A fixed non-zero 64-bit value that initialises the xorshift64 state so benchmark runs are reproducible. Any non-zero odd value would work; this one is the splitmix64 gamma constant, chosen for good bit-distribution as a starting state.
| Enumerator | |
|---|---|
| k_rand_seed | Reproducible non-zero xorshift seed. |
Definition at line 124 of file policies.c.
| enum cb_rand_shift_t : uint8_t |
xorshift64 shift-amount triple used in the Random policy's PRNG step.
The triple (13, 7, 17) is one of the parameter sets listed in Marsaglia (2003) for a full-period 64-bit xorshift generator. Changing any value breaks the period guarantee.
| Enumerator | |
|---|---|
| k_rand_shift_a | First xorshift64 shift. |
| k_rand_shift_b | Second xorshift64 shift. |
| k_rand_shift_c | Third xorshift64 shift. |
Definition at line 136 of file policies.c.
|
static |
Release CLOCK state (the sweep hand).
Ends the CLOCK binding without releasing caller-owned storage.
| [in,out] | c | Cache whose CLOCK binding is ended. |
c is non-NULL. Definition at line 506 of file policies.c.
References cb_cache_t::policy_data.
|
static |
Bind CLOCK state: one reference bit per frame + a sweep hand.
Allocates one zeroed uint32_t sweep hand in c->policy_data; the reference bit lives in each frame's meta[0], set on access/insert and cleared as the hand gives a frame its second chance.
| [in,out] | c | Cache whose policy_data receives the hand pointer. |
| 0 | c->policy_data holds a zeroed hand. |
| 1 | Caller storage is absent; c->policy_data is NULL. |
c is non-NULL and its policy_data is unset. Definition at line 484 of file policies.c.
References cb_cache_t::policy_data, and cb_cache_t::policy_workspace.
|
static |
CLOCK reference hook: set frame's reference bit.
Writes 1 to frames[frame].meta[0], marking the frame as recently used so the sweep hand grants it one second chance before eviction. Bound as both on_access and on_insert.
| [in,out] | c | Cache whose frame reference bit is set. |
| [in] | frame | Frame just accessed or inserted. |
c is non-NULL and frame < capacity. frame is currently resident. Definition at line 529 of file policies.c.
References cb_cache_t::frames, and cb_frame_t::meta.
|
static |
Choose the CLOCK victim by second-chance sweep.
Advances the hand around the ring: a frame with its reference bit set is spared once (the bit is cleared) and skipped; the first frame found with a clear bit is evicted. Reports the number of frames examined, so a full ring of set bits costs one extra pass at most.
| [in,out] | c | Cache holding the sweep hand in policy_data. |
| [out] | scanned | Receives the frames examined this call (>= 1). |
| <capacity | The first frame reached with a clear reference bit. |
scanned is non-NULL. Definition at line 556 of file policies.c.
References cb_cache_t::capacity, cb_cache_t::frames, cb_frame_t::meta, and cb_cache_t::policy_data.
|
static |
Release FIFO state (the insertion hand).
Ends the FIFO binding without releasing caller-owned storage.
| [in,out] | c | Cache whose policy_data binding is ended. |
c is non-NULL. Definition at line 67 of file policies.c.
References cb_cache_t::policy_data.
|
static |
Bind FIFO state: a single round-robin hand over the frame ring.
Allocates one zeroed uint32_t insertion hand and stores it in c->policy_data; the hand advances modulo capacity on each victim pick, giving pure first-in-first-out order with no recency bits.
| [in,out] | c | Cache whose policy_data receives the hand pointer. |
| 0 | c->policy_data holds a zeroed hand. |
| 1 | Caller storage is absent; c->policy_data is NULL. |
c is non-NULL and its policy_data is unset. Definition at line 45 of file policies.c.
References cb_cache_t::policy_data, and cb_cache_t::policy_workspace.
|
static |
Choose the FIFO victim: the frame the hand currently points at.
Returns the frame under the round-robin hand, then advances the hand modulo capacity, so frames are evicted in insertion order. Reports a scan depth of exactly one (O(1), the ideal WCET).
| [in,out] | c | Cache holding the FIFO hand in policy_data. |
| [out] | scanned | Receives the frames examined (always 1). |
| <capacity | The frame the hand pointed at on entry. |
scanned is non-NULL and c->capacity > 0. Definition at line 93 of file policies.c.
References cb_cache_t::capacity, and cb_cache_t::policy_data.
|
static |
Release true-LRU state (control block + index arrays).
Frees the prev/next arrays and the cb_lru_t itself when present; a NULL policy_data (a failed init) is tolerated.
| [in,out] | c | Cache whose LRU binding is ended. |
c is non-NULL. Definition at line 302 of file policies.c.
References cb_cache_t::policy_data.
|
static |
Bind true-LRU state: a doubly-linked recency list over frames.
Allocates the cb_lru_t control block plus prev/next index arrays (one entry per frame) and marks the list empty (head/tail -1). The control block and arrays occupy one exact caller slab.
| [in,out] | c | Cache whose policy_data receives the list; capacity sizes the prev/next arrays. |
| 0 | c->policy_data holds an empty recency list. |
| 1 | Caller workspace does not meet the exact requirement. |
c is non-NULL with capacity > 0. Definition at line 271 of file policies.c.
References cb_cache_t::capacity, cb_lru_t::head, cb_lru_t::next, cb_cache_t::policy_data, cb_cache_t::policy_workspace, cb_cache_t::policy_workspace_bytes, cb_lru_t::prev, and cb_lru_t::tail.
|
static |
LRU insert hook: place a freshly-loaded frame at the MRU head.
Links the newly populated frame in at the head (it is not yet in the list), so it becomes the most-recently-used. Bound as the policy's on_insert.
| [in,out] | c | Cache holding the LRU list in policy_data. |
| [in] | frame | Frame that was just (re)populated. |
frame is detached (its old key was unlinked on eviction). frame is at the MRU head of the list. Definition at line 413 of file policies.c.
References internal_lru_to_head(), and cb_cache_t::policy_data.
|
static |
Splice frame f to the MRU (most-recently-used) head.
Makes f the new head, linking the former head behind it and setting the tail to f when the list was empty. f must already be detached (see internal_lru_unlink).
| [in,out] | l | The recency list to edit. |
| [in] | f | Frame index to place at the head. |
l is a valid list and f is currently detached. f is a valid frame index < capacity. f precedes the former head. f iff the list was previously empty.Definition at line 357 of file policies.c.
References cb_lru_t::head, cb_lru_t::next, cb_lru_t::prev, and cb_lru_t::tail.
Referenced by internal_lru_insert(), and internal_lru_touch().
|
static |
LRU hit hook: move the just-accessed frame to the MRU head.
Unlinks frame from its current position and re-inserts it at the head, so the least-recently-used frame stays at the tail (the next victim). Bound as the policy's on_access.
| [in,out] | c | Cache holding the LRU list in policy_data. |
| [in] | frame | Frame that was just hit. |
frame is currently resident and linked. frame is at the MRU head of the list. Definition at line 388 of file policies.c.
References internal_lru_to_head(), internal_lru_unlink(), and cb_cache_t::policy_data.
|
static |
Unlink frame f from the recency list.
Repairs its neighbours' prev/next links and, when f was the head or tail, advances that endpoint inward, leaving the list consistent with f detached.
| [in,out] | l | The recency list to edit. |
| [in] | f | Frame index to detach (must be a member). |
l is a valid list and f is currently linked in it. f is a valid frame index < capacity. f is absent from the list; neighbour links stay consistent. Definition at line 325 of file policies.c.
References cb_lru_t::head, cb_lru_t::next, cb_lru_t::prev, and cb_lru_t::tail.
Referenced by internal_lru_touch(), and internal_lru_victim().
|
static |
Choose the LRU victim: the frame at the list tail.
Returns the least-recently-used frame (the tail) and unlinks it so the caller can repopulate it. Reports a scan depth of one – true LRU finds its victim in O(1).
| [in,out] | c | Cache holding the LRU list in policy_data. |
| [out] | scanned | Receives the frames examined (always 1). |
| <capacity | The least-recently-used resident frame. |
scanned is non-NULL. Definition at line 440 of file policies.c.
References internal_lru_unlink(), cb_cache_t::policy_data, and cb_lru_t::tail.
|
static |
Release Random-policy state (the PRNG seed).
Ends the Random binding without releasing caller-owned storage.
| [in,out] | c | Cache whose seed binding is ended. |
c is non-NULL. Definition at line 189 of file policies.c.
References cb_cache_t::policy_data.
|
static |
Bind Random-policy state: a deterministic xorshift64 seed.
Allocates one uint64_t seeded with the fixed k_rand_seed so eviction choices are pseudo-random yet reproducible across runs and hosts. Stored in c->policy_data.
| [in,out] | c | Cache whose policy_data receives the seed pointer. |
| 0 | c->policy_data holds the seeded PRNG state. |
| 1 | Caller storage is absent; c->policy_data is NULL. |
c is non-NULL and its policy_data is unset. Definition at line 164 of file policies.c.
References k_rand_seed, cb_cache_t::policy_data, and cb_cache_t::policy_workspace.
|
static |
Choose a uniformly random victim frame.
Advances the xorshift64 state one step and returns x % capacity, so any resident frame is equally likely regardless of recency. Reports a scan depth of one (the choice is O(1)).
| [in,out] | c | Cache holding the PRNG seed in policy_data. |
| [out] | scanned | Receives the frames examined (always 1). |
| <capacity | A pseudo-random resident frame. |
scanned is non-NULL and c->capacity > 0. Definition at line 215 of file policies.c.
References cb_cache_t::capacity, k_rand_shift_a, k_rand_shift_b, k_rand_shift_c, and cb_cache_t::policy_data.
| const cache_policy_t* const g_cb_policies[] |
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().
| const uint32_t g_cb_policy_count = (uint32_t)(sizeof(g_cb_policies) / sizeof(g_cb_policies[0])) |
Number of entries in g_cb_policies.
Definition at line 594 of file policies.c.
Referenced by internal_report_summary(), and internal_report_trace().
|
static |
Definition at line 572 of file policies.c.
|
static |
Definition at line 101 of file policies.c.
|
static |
Definition at line 448 of file policies.c.
|
static |
Definition at line 226 of file policies.c.