Files
hakmem/core/box/tiny_class_policy_box.h

62 lines
2.3 KiB
C
Raw Normal View History

// tiny_class_policy_box.h - Class-scoped policy box for Tiny front-end
//
// Purpose:
// - Centralize per-class feature toggles (Page Box / Warm Pool / caps).
// - Keep hot paths free from direct ENV parsing or scattered conditionals.
// - Defaults:
// legacy (デフォルト): Page Box は C5C7、Warm は C0C7 で cap は小さめ
// c5_7_only: Page/Warm とも C5C7 のみ
// tinyplus_all: 予備プロファイル(当面 legacy と同等)
// - ENV: HAKMEM_TINY_POLICY_PROFILE=legacy|c5_7_only|tinyplus_all
// - Learner が入るまでは固定ポリシーで運用し、Hot path は tiny_policy_get() を見るだけに保つ。
#ifndef TINY_CLASS_POLICY_BOX_H
#define TINY_CLASS_POLICY_BOX_H
#include <stdatomic.h>
#include <stdint.h>
#include <stdlib.h>
#include "../hakmem_tiny_config.h"
typedef struct TinyClassPolicy {
uint8_t page_box_enabled; // Enable Tiny Page Box for this class
uint8_t warm_enabled; // Enable Warm Pool for this class
uint8_t warm_cap; // Max warm SuperSlabs to keep (per-thread)
uint8_t tls_carve_enabled; // Enable Warm→TLS carve experiment for this class
} TinyClassPolicy;
extern TinyClassPolicy g_tiny_class_policy[TINY_NUM_CLASSES];
// ENV-gated policy logging (default ON; disable with HAKMEM_TINY_POLICY_LOG=0)
static inline int tiny_policy_log_enabled(void) {
static int g_policy_log = -1;
if (__builtin_expect(g_policy_log == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_POLICY_LOG");
g_policy_log = (e && *e && *e != '0') ? 1 : 0;
}
return g_policy_log;
}
// Initialize policy table once (idempotent).
void tiny_class_policy_init_once(void);
// Refresh auto profile based on learner output (no-op for non-auto profiles)
void tiny_class_policy_refresh_auto(void);
// True when active profile is "auto" (learner-managed)
int tiny_class_policy_is_auto(void);
// Debug helper: dump current policy (tag optional)
void tiny_class_policy_dump(const char* tag);
// Lightweight accessor for hot paths.
static inline const TinyClassPolicy* tiny_policy_get(int class_idx) {
if (class_idx < 0 || class_idx >= TINY_NUM_CLASSES) {
return NULL;
}
tiny_class_policy_init_once();
return &g_tiny_class_policy[class_idx];
}
#endif // TINY_CLASS_POLICY_BOX_H