Files
hakmem/core/hakmem_ace_controller.h

107 lines
3.4 KiB
C
Raw Normal View History

/* hakmem_ace_controller.h - ACE Learning Controller
*
* ACE (Adaptive Control Engine) :
* - Fast loop (0.5-1s): TLS capacity, drain threshold調整
* - Slow loop (30-60s): Fragmentation/RSS対策
* - UCB1学習で最適なブ値を選択
*/
#ifndef HAKMEM_ACE_CONTROLLER_H
#define HAKMEM_ACE_CONTROLLER_H
#include "hakmem_ace_metrics.h"
#include "hakmem_ace_ucb1.h"
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
/* ========== TLS Capacity候補値 ========== */
static const uint32_t TLS_CAP_CANDIDATES[] = {
16, 32, 64, 128, 256, 512
};
#define TLS_CAP_N_CANDIDATES (sizeof(TLS_CAP_CANDIDATES) / sizeof(TLS_CAP_CANDIDATES[0]))
/* ========== Drain Threshold候補値 ========== */
static const uint32_t DRAIN_THRESH_CANDIDATES[] = {
64, 128, 256, 512, 1024
};
#define DRAIN_THRESH_N_CANDIDATES (sizeof(DRAIN_THRESH_CANDIDATES) / sizeof(DRAIN_THRESH_CANDIDATES[0]))
/* ========== ACE Controller 構造体 ========== */
struct hkm_ace_controller {
/* 有効/無効フラグ */
bool enabled;
bool running; /* スレッド実行中フラグ */
/* メトリクス */
struct hkm_ace_metrics current;
struct hkm_ace_metrics prev;
/* UCB1 バンディット(クラス毎) */
struct hkm_ucb1_bandit tls_cap_bandit[8]; /* TLS capacity学習 */
struct hkm_ucb1_bandit drain_bandit[8]; /* Drain threshold学習 */
/* 現在のノブ値 */
uint32_t tls_capacity[8]; /* Per-class TLS magazine capacity */
uint32_t drain_threshold[8]; /* Per-class remote free drain threshold */
/* Fast loop設定 */
uint64_t fast_interval_ms; /* Fast loopインターバルデフォルト500ms */
uint64_t last_fast_tick_ms; /* 前回Fast loop実行時刻 */
/* Slow loop設定 */
uint64_t slow_interval_ms; /* Slow loopインターバルデフォルト30000ms */
uint64_t last_slow_tick_ms; /* 前回Slow loop実行時刻 */
/* ログレベル */
int log_level; /* 0=off, 1=info, 2=debug */
/* バックグラウンドスレッド */
pthread_t bg_thread;
bool stop_requested;
};
/* ========== API ========== */
/* 初期化(環境変数から設定読み込み) */
void hkm_ace_controller_init(struct hkm_ace_controller *ctrl);
/* 破棄(スレッド停止) */
void hkm_ace_controller_destroy(struct hkm_ace_controller *ctrl);
/* Tick処理fast/slow両方実行 */
void hkm_ace_controller_tick(struct hkm_ace_controller *ctrl);
/* Fast loop0.5-1s間隔 */
void hkm_ace_controller_fast_loop(struct hkm_ace_controller *ctrl);
/* Slow loop30-60s間隔 */
void hkm_ace_controller_slow_loop(struct hkm_ace_controller *ctrl);
/* バックグラウンドスレッド開始 */
void hkm_ace_controller_start(struct hkm_ace_controller *ctrl);
/* バックグラウンドスレッド停止 */
void hkm_ace_controller_stop(struct hkm_ace_controller *ctrl);
/* ========== Inline Helpers ========== */
/* コントローラーが有効か確認 */
static inline bool hkm_ace_is_enabled(const struct hkm_ace_controller *ctrl) {
return ctrl && ctrl->enabled;
}
/* ログ出力ヘルパー */
static inline bool hkm_ace_log_info_enabled(const struct hkm_ace_controller *ctrl) {
return ctrl && ctrl->log_level >= 1;
}
static inline bool hkm_ace_log_debug_enabled(const struct hkm_ace_controller *ctrl) {
return ctrl && ctrl->log_level >= 2;
}
#endif /* HAKMEM_ACE_CONTROLLER_H */