2025-12-13 18:04:14 +09:00
|
|
|
// tiny_static_route_box.h - Static routing table for policy_snapshot bypass (Phase 3 C3)
|
|
|
|
|
// Eliminates per-malloc policy_snapshot + learner evaluation overhead
|
|
|
|
|
// ENV gate: HAKMEM_TINY_STATIC_ROUTE=0/1 (default 0)
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-12-13 18:46:11 +09:00
|
|
|
#include <stdatomic.h>
|
2025-12-13 18:04:14 +09:00
|
|
|
#include "smallobject_policy_v7_box.h"
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2025-12-13 18:46:11 +09:00
|
|
|
// 0: uninit/disabled, -1: initializing, 1: ready
|
|
|
|
|
atomic_int inited;
|
2025-12-13 18:04:14 +09:00
|
|
|
SmallRouteKind route_kind[8]; // C0-C7 static route (determined at init, no learner update)
|
|
|
|
|
} TinyStaticRoute;
|
|
|
|
|
|
|
|
|
|
extern TinyStaticRoute g_tiny_static_route;
|
|
|
|
|
|
2025-12-13 18:46:11 +09:00
|
|
|
// Hot-path helper: true when static route table is ready (enabled + initialized).
|
|
|
|
|
static inline int tiny_static_route_ready_fast(void) {
|
|
|
|
|
return atomic_load_explicit(&g_tiny_static_route.inited, memory_order_acquire) == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hot-path helper: fetch route kind when tiny_static_route_ready_fast()==true.
|
|
|
|
|
static inline SmallRouteKind tiny_static_route_get_kind_fast(int class_idx) {
|
|
|
|
|
return g_tiny_static_route.route_kind[(unsigned)class_idx & 7u];
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-13 18:04:14 +09:00
|
|
|
// Initialize static route table (called once, at library load time)
|
|
|
|
|
// Returns 1 if static routing is enabled and initialized, 0 otherwise
|
|
|
|
|
int tiny_static_route_init_once(void);
|
|
|
|
|
|
2025-12-13 18:46:11 +09:00
|
|
|
// Get static route for class_idx.
|
|
|
|
|
// Returns SMALL_ROUTE_LEGACY when disabled/uninitialized/invalid (safe fallback).
|
2025-12-13 18:04:14 +09:00
|
|
|
SmallRouteKind tiny_static_route_get_kind(int class_idx);
|
|
|
|
|
|
|
|
|
|
// Refresh from ENV (for bench_apply_profile() sync)
|
|
|
|
|
void tiny_static_route_refresh_from_env(void);
|
|
|
|
|
|
|
|
|
|
// Check if static routing is enabled (cached ENV value)
|
|
|
|
|
int tiny_static_route_enabled(void);
|