diff --git a/core/hakmem_elo.c b/core/hakmem_elo.c index f34ad7f6..3f65cd15 100644 --- a/core/hakmem_elo.c +++ b/core/hakmem_elo.c @@ -22,6 +22,12 @@ static uint64_t g_total_selections = 0; // This replaces the previous local is_quiet() implementation #define is_quiet() hak_is_quiet() +// Score normalization constants (used in hak_elo_compute_score) +// These define the "maximum" values for metric normalization (0-1 range) +static const double ELO_MAX_CPU_NS = 100000.0; // 100 microseconds +static const double ELO_MAX_PAGE_FAULTS = 1000.0; // 1000 page faults +static const double ELO_MAX_BYTES_LIVE = 100000000.0; // 100 MB + // Strategy threshold presets (geometric progression from 512KB to 8MB) static const size_t STRATEGY_THRESHOLDS[] = { 524288, // 512KB @@ -150,14 +156,10 @@ void hak_elo_record_alloc(int strategy_id, size_t size, uint64_t duration_ns) { // Compute composite score (normalized 0-1) double hak_elo_compute_score(const EloAllocStats* stats) { // Normalize each metric (lower is better, so invert) - // For now, use simple heuristics - const double MAX_CPU_NS = 100000.0; // 100 microseconds - const double MAX_PAGE_FAULTS = 1000.0; - const double MAX_BYTES_LIVE = 100000000.0; // 100MB - - double cpu_score = 1.0 - fmin(stats->cpu_ns / MAX_CPU_NS, 1.0); - double pf_score = 1.0 - fmin(stats->page_faults / MAX_PAGE_FAULTS, 1.0); - double mem_score = 1.0 - fmin(stats->bytes_live / MAX_BYTES_LIVE, 1.0); + // Using constants defined at file scope for maintainability + double cpu_score = 1.0 - fmin(stats->cpu_ns / ELO_MAX_CPU_NS, 1.0); + double pf_score = 1.0 - fmin(stats->page_faults / ELO_MAX_PAGE_FAULTS, 1.0); + double mem_score = 1.0 - fmin(stats->bytes_live / ELO_MAX_BYTES_LIVE, 1.0); // Weighted combination: 40% CPU, 30% PageFaults, 30% Memory return 0.4 * cpu_score + 0.3 * pf_score + 0.3 * mem_score;