2025-12-06 01:34:04 +09:00
|
|
|
|
// 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 は C5–C7、Warm は C0–C7 で cap は小さめ
|
|
|
|
|
|
// c5_7_only: Page/Warm とも C5–C7 のみ
|
|
|
|
|
|
// 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 "../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 reserved;
|
|
|
|
|
|
} TinyClassPolicy;
|
|
|
|
|
|
|
|
|
|
|
|
extern TinyClassPolicy g_tiny_class_policy[TINY_NUM_CLASSES];
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize policy table once (idempotent).
|
|
|
|
|
|
void tiny_class_policy_init_once(void);
|
|
|
|
|
|
|
2025-12-06 01:44:05 +09:00
|
|
|
|
// Refresh auto profile based on learner output (no-op for non-auto profiles)
|
|
|
|
|
|
void tiny_class_policy_refresh_auto(void);
|
|
|
|
|
|
|
|
|
|
|
|
// Debug helper: dump current policy (tag optional)
|
|
|
|
|
|
void tiny_class_policy_dump(const char* tag);
|
|
|
|
|
|
|
2025-12-06 01:34:04 +09:00
|
|
|
|
// 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
|