Files
hakmem/core/box/tiny_route_box.c

57 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// tiny_route_box.c - Implementation of Tiny Front Routing Policy Box
#include "tiny_route_box.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
// Default: conservative profile (all classes TINY_FIRST).
// This keeps Tiny in the fast path but always allows Pool fallback.
uint8_t g_tiny_route[8] = {
ROUTE_TINY_FIRST, ROUTE_TINY_FIRST, ROUTE_TINY_FIRST, ROUTE_TINY_FIRST,
ROUTE_TINY_FIRST, ROUTE_TINY_FIRST, ROUTE_TINY_FIRST, ROUTE_TINY_FIRST
};
void tiny_route_init(void)
{
const char* profile = getenv("HAKMEM_TINY_PROFILE");
if (!profile || !*profile) {
profile = "conservative";
}
if (strcmp(profile, "hot") == 0) {
// Hot profile:
// - C0-C3: TINY_ONLY (小さいクラスは Tiny 専用で aggressive
// - C4-C6: TINY_FIRST (中間サイズは fallback あり)
// - C7 : POOL_ONLY 1KB headerless は Pool に任せる)
g_tiny_route[0] = g_tiny_route[1] = g_tiny_route[2] = g_tiny_route[3] = ROUTE_TINY_ONLY;
g_tiny_route[4] = g_tiny_route[5] = g_tiny_route[6] = ROUTE_TINY_FIRST;
g_tiny_route[7] = ROUTE_POOL_ONLY;
} else if (strcmp(profile, "full") == 0) {
// Full Tiny profile:
// - 全クラス TINY_ONLYmicrobench 用、Pool に逃がさない)
memset(g_tiny_route, ROUTE_TINY_ONLY, sizeof(g_tiny_route));
} else if (strcmp(profile, "off") == 0) {
// Tiny off profile:
// - 全クラス POOL_ONLYTiny front 完全無効化)
memset(g_tiny_route, ROUTE_POOL_ONLY, sizeof(g_tiny_route));
} else {
// "conservative" および未知の値:
// - 全クラス TINY_FIRSTTiny を使うが必ず Pool fallbackあり
memset(g_tiny_route, ROUTE_TINY_FIRST, sizeof(g_tiny_route));
}
#if HAKMEM_BUILD_RELEASE
static int rel_logged = 0;
if (!rel_logged) {
const char* mode =
(g_tiny_route[7] == ROUTE_TINY_ONLY) ? "TINY_ONLY" :
(g_tiny_route[7] == ROUTE_TINY_FIRST) ? "TINY_FIRST" :
(g_tiny_route[7] == ROUTE_POOL_ONLY) ? "POOL_ONLY" : "UNKNOWN";
fprintf(stderr, "[REL_C7_ROUTE] profile=%s route=%s\n", profile, mode);
rel_logged = 1;
}
#endif
}