41typedef enum : uint32_t {
51typedef enum : uint32_t {
56typedef enum : uint32_t {
96 "\n### %s (%llu accesses, footprint %u pages)\n\n",
98 (
unsigned long long)tr->
n,
103 for (uint32_t s = 0U; s < nsz; ++s) {
111 for (uint32_t s = 0U; s < nsz; ++s) {
149 for (uint32_t s = 0U; s < nsz; ++s) {
224 if (
cb_sink_format(sink,
"\n## Summary at %u frames (mean over all workloads)\n\n", mid_cap) !=
226 cb_sink_format(sink,
"| policy | mean hit %% | worst scan/evict | meta bytes/frame |\n") !=
228 cb_sink_format(sink,
"|--------|-----------:|-----------------:|-----------------:|\n") !=
233 double sum_hit = 0.0;
235 for (uint32_t t = 0U; t < ntr; ++t) {
247 "| %-14s | %10.2f | %16u | %16zu |\n",
249 sum_hit / (
double)ntr,
259typedef enum : uint8_t {
264typedef enum :
size_t {
271 alignas(max_align_t) uint8_t
bytes[1048576U];
275typedef enum : uint64_t {
304 uint32_t nloaded = 0U;
305 for (
int a = 1; (a < argc) && (nloaded < (uint32_t)
k_cb_max_loaded); ++a) {
306 const size_t name_length = strcspn(argv[a],
"=");
307 if ((argv[a][name_length] !=
'=') ||
316 }
else if (sources[nloaded].fd >= 0) {
344 for (
int i = 1; i < argc; ++i) {
381 .cache_capacity =
sizeof(s_cb_sweep_backing.
bytes),
416 for (uint32_t index = 0U; index < count; ++index) {
455 const bool banner_ok =
457 (
cb_sink_format(output,
"\nHit rate (%%) by cache size (frames). Higher is better.\n") ==
466 for (uint32_t t = 0U; (t < nloaded) && (result == 0); ++t) {
476 "cache_bench: run failed (workspace required=%zu supplied=%zu)\n",
491 (void)
cb_sink_format(&error,
"cache_bench: output open failed\n");
494 const int result = ((argc > 1) && (
strcmp(argv[1],
"--sweep-block") == 0))
Eviction-policy comparison harness for the #147 memory-hierarchy decision record: the DIP seam every ...
const cache_policy_t *const g_cb_policies[]
The registered policy table (defined in src/policies.c).
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.
struct cb_trace cb_trace_t
const uint32_t g_cb_policy_count
Number of entries in g_cb_policies.
POSIX raw-descriptor composition bindings for cache_bench.
cb_io_status_t cb_host_source_open(const char *path, cb_host_source_t *binding, cb_source_t *source)
Open a captured-trace path and publish its source seam.
cb_io_status_t cb_host_scratch_close(cb_host_scratch_t *binding)
Close the scratch transaction.
cb_io_status_t cb_host_scratch_open(cb_host_scratch_t *binding, cb_scratch_t *scratch)
Create an unlinked raw-descriptor scratch transaction.
void cb_host_output_abort(cb_host_output_t *binding)
Abandon a temporary sibling while preserving the destination.
void cb_host_standard_sinks(cb_sink_t *output, cb_sink_t *error)
Bind the process standard-output and standard-error descriptor sinks.
cb_io_status_t cb_host_output_open(const char *path, cb_host_output_t *binding, cb_sink_t *sink)
Open a sibling output transaction, or bind descriptor one for NULL.
cb_io_status_t cb_host_output_commit(cb_host_output_t *binding)
Flush and atomically publish a transactional output.
cb_io_status_t cb_host_source_close(cb_host_source_t *binding)
Close a source binding.
Bounded byte-source and text-sink seams for cache_bench.
cb_io_status_t cb_sink_format(cb_sink_t *sink, const char *format,...)
Format one bounded record and publish it atomically to the sink seam.
@ k_cb_io_ok
Operation completed.
static int internal_run_capacity(int argc, char **argv, cb_sink_t *output, cb_sink_t *error)
Execute the capacity report over synthetic and captured traces.
@ k_cb_composition_workspace_bytes
Maximum exact metadata budget.
int main(int argc, char **argv)
static int internal_run_sweep(cb_sink_t *output, cb_sink_t *error)
Compose scratch, cache, and workspace bindings and execute block mode.
static int internal_report_summary(const cb_trace_t *traces, uint32_t ntr, cb_workspace_t *workspace, cb_sink_t *sink)
Print the cross-workload summary (WCET + metadata + mean hit rate).
static int internal_report_trace_row(const cache_policy_t *policy, const cb_trace_t *tr, cb_workspace_t *workspace, cb_sink_t *sink, uint32_t nsz)
Write one policy's hit-rate row across every swept cache size.
@ k_cb_sweep_canary_after
Trailing guard value.
@ k_cb_sweep_canary_before
Leading guard value.
static uint32_t internal_load_argv_traces(int argc, char **argv, cb_trace_t *loaded, cb_host_source_t *sources)
Load the extra captured traces named on the command line.
static int internal_close_sources(cb_host_source_t *sources, uint32_t count)
Close every captured source, preserving any close failure.
cb_loaded_cap_t
Capacity of the extra captured-trace table filled from argv.
@ k_cb_max_loaded
Most <name>=<path> traces accepted per run.
@ k_cb_output_prefix_bytes
Bytes in the literal --output= prefix.
cb_bench_size_t
Swept cache capacities (in frames) used on the RAM-budget axis.
@ k_cb_size_64
Smallest evaluated capacity (frames).
@ k_cb_size_2048
Largest evaluated capacity (frames).
@ k_cb_size_512
512-frame sweep point.
@ k_cb_size_128
128-frame sweep point.
@ k_cb_size_1024
1 K-frame sweep point.
@ k_cb_size_256
Mid-budget representative sweep point.
cb_mid_cap_t
Representative mid-budget capacity used in the summary table.
@ k_cb_mid_cap
Mid-point capacity (frames) for the summary view.
static const uint32_t s_cb_sizes[]
Swept cache capacities (frames) – the RAM-budget axis.
cb_pct_scale_t
Full scale used when computing a hit-rate percentage (integer form).
@ k_cb_pct_scale
Divisor to convert a ratio to a percentage.
static const char * internal_output_path(int argc, char **argv)
Find the optional report destination in the argument vector.
static int internal_report_trace(const cb_trace_t *tr, cb_workspace_t *workspace, cb_sink_t *sink)
Print the per-trace hit-rate matrix (policies x cache sizes).
static uint8_t s_cb_composition_workspace[k_cb_composition_workspace_bytes]
static const double s_cb_pct_scale_f
Floating-point 100.0 scale factor for hit-rate percentage output.
static int internal_report_trace_header(const cb_trace_t *tr, cb_sink_t *sink, uint32_t nsz)
Write the per-trace table header: title line, column heads, rule row.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
The replacement-policy DIP seam (the eventual firmware Layer-2 seam).
const char * name
Policy name for the report table.
Output transaction or borrowed standard descriptor.
Unlinked raw-descriptor scratch binding.
Borrowed raw descriptor source binding.
int fd
Open read-only descriptor.
Per-(policy, trace, size) result row.
uint64_t hits
Resident-set hits.
uint32_t worst_scan
Max frames scanned in any eviction.
uint64_t accesses
Total accesses replayed.
Injected bounded random-access scratch transaction.
Immutable injected byte source with a snapshotted length.
uint64_t before
Detect setup underflow.
uint64_t after
Detect setup overflow.
uint8_t bytes[1048576U]
Semantic cache budget.
Caller-owned bindings for the block sweep.
const char * name
Stable display name.
uint32_t footprint
Reported working-set pages.
uint64_t n
Valid access count.
Caller-owned replay workspace and exact capacity diagnostics.
size_t required
Exact bytes required by the latest request.
size_t capacity
Supplied bytes.
#208 block/frame-size sweep: the byte-size axis the capacity sweep never touches, so the chunked ....
int cb_sweep_block(cb_sweep_config_t *config)
Run the #208 block/frame-size sweep and print the report.
Resettable, allocation-free access streams for cache_bench.
@ k_cb_synthetic_trace_count
Fixed corpus size.
cb_io_status_t cb_trace_bind(const cb_source_t *source, const char *name, size_t name_length, cb_trace_t *out)
Validate and bind one captured decimal <object> <page> source.
void cb_traces_synthetic(cb_trace_t out[k_cb_synthetic_trace_count])
Populate the fixed built-in corpus without acquiring storage.