65 lines
2.4 KiB
C
65 lines
2.4 KiB
C
// tiny_route_box.h - Box: Tiny Front Routing Policy
|
||
//
|
||
// Purpose:
|
||
// Decide, per Tiny class, whether allocation should go through Tiny front
|
||
// or directly to the Pool/backend. This keeps routing policy in a single,
|
||
// cheap table lookup, without getenv() or complex logic in the hot path.
|
||
//
|
||
// Box Theory:
|
||
// - Single Responsibility:
|
||
// Only decides "Tiny vs Pool vs Tiny+Fallback" per class.
|
||
// - Clear Boundary:
|
||
// Front Gate / Alloc Gatekeeper calls tiny_route_get(class_idx) once.
|
||
// Tiny Fast Path and Pool backend remain unchanged.
|
||
// - Reversible / A/B:
|
||
// Profiles are selected via HAKMEM_TINY_PROFILE ENV at init time.
|
||
// Hot path is stable; routing can be tuned without touching fast code.
|
||
|
||
#ifndef TINY_ROUTE_BOX_H
|
||
#define TINY_ROUTE_BOX_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdio.h>
|
||
|
||
// Routing policy per Tiny class.
|
||
typedef enum {
|
||
ROUTE_TINY_ONLY = 0, // Tiny front only (no fallback; failure bubbles up)
|
||
ROUTE_TINY_FIRST = 1, // Try Tiny front, then fallback to Pool backend
|
||
ROUTE_POOL_ONLY = 2, // Skip Tiny entirely, use Pool/backend only
|
||
} TinyRoutePolicy;
|
||
|
||
// Global routing table for Tiny classes (0..7).
|
||
// Initialized once from ENV: HAKMEM_TINY_PROFILE.
|
||
extern uint8_t g_tiny_route[8];
|
||
|
||
// Initialize routing table from ENV profile.
|
||
// Profiles:
|
||
// "hot" C0-C3=TINY_ONLY, C4-C6=TINY_FIRST, C7=POOL_ONLY
|
||
// "conservative" 全クラス TINY_FIRST(デフォルト)
|
||
// "off" 全クラス POOL_ONLY(Tiny 無効)
|
||
// "full" 全クラス TINY_ONLY(microbench 用)
|
||
void tiny_route_init(void);
|
||
|
||
// Hot path helper: return routing policy for a given class.
|
||
// Uses simple array lookup; class_idx is masked to [0,7] defensively.
|
||
static inline TinyRoutePolicy tiny_route_get(int class_idx)
|
||
{
|
||
TinyRoutePolicy p = (TinyRoutePolicy)g_tiny_route[class_idx & 7];
|
||
#if HAKMEM_BUILD_RELEASE
|
||
if ((class_idx & 7) == 7) {
|
||
static int rel_route_logged = 0;
|
||
if (!rel_route_logged) {
|
||
const char* mode =
|
||
(p == ROUTE_TINY_ONLY) ? "TINY_ONLY" :
|
||
(p == ROUTE_TINY_FIRST) ? "TINY_FIRST" :
|
||
(p == ROUTE_POOL_ONLY) ? "POOL_ONLY" : "UNKNOWN";
|
||
fprintf(stderr, "[REL_C7_ROUTE] via tiny_route_get route=%s\n", mode);
|
||
rel_route_logged = 1;
|
||
}
|
||
}
|
||
#endif
|
||
return p;
|
||
}
|
||
|
||
#endif // TINY_ROUTE_BOX_H
|