diff --git a/core/hakmem_env_cache.h b/core/hakmem_env_cache.h index ba9da1e0..4f228bd5 100644 --- a/core/hakmem_env_cache.h +++ b/core/hakmem_env_cache.h @@ -49,12 +49,16 @@ typedef struct { // ===== Warm Path: Lazy Init (1 variable) ===== int ss_map_trace; // HAKMEM_SS_MAP_TRACE (default: 0) - // ===== Warm Path: FastCache (5 variables) ===== + // ===== Warm Path: FastCache (9 variables) ===== int tiny_fast_debug; // HAKMEM_TINY_FAST_DEBUG (default: 0) int tiny_fast_debug_max; // HAKMEM_TINY_FAST_DEBUG_MAX (default: 0) int tiny_front_direct; // HAKMEM_TINY_FRONT_DIRECT (default: 0) int tiny_fast_stats; // HAKMEM_TINY_FAST_STATS (default: 0) int tiny_unified_cache; // HAKMEM_TINY_UNIFIED_CACHE (default: 1) + int sfc_debug; // HAKMEM_SFC_DEBUG (default: 0) + int sfc_enable; // HAKMEM_SFC_ENABLE (default: 1) + int sfc_capacity; // HAKMEM_SFC_CAPACITY (default: 128) + int sfc_refill_count; // HAKMEM_SFC_REFILL_COUNT (default: 16) // ===== Cold Path: Headers/Debug (12 variables) ===== int tiny_restore_header; // HAKMEM_TINY_RESTORE_HEADER (default: 0) @@ -171,6 +175,18 @@ static inline void hakmem_env_cache_init(void) { e = getenv("HAKMEM_TINY_UNIFIED_CACHE"); // Default: 1 (enabled), set HAKMEM_TINY_UNIFIED_CACHE=0 to disable g_hak_env_cache.tiny_unified_cache = (e && *e && *e == '0') ? 0 : 1; + + e = getenv("HAKMEM_SFC_DEBUG"); + g_hak_env_cache.sfc_debug = (e && *e && *e != '0') ? 1 : 0; + + e = getenv("HAKMEM_SFC_ENABLE"); + g_hak_env_cache.sfc_enable = (e && *e && *e != '0') ? 1 : 0; + + e = getenv("HAKMEM_SFC_CAPACITY"); + g_hak_env_cache.sfc_capacity = (e && *e) ? atoi(e) : 128; + + e = getenv("HAKMEM_SFC_REFILL_COUNT"); + g_hak_env_cache.sfc_refill_count = (e && *e) ? atoi(e) : 16; } // ===== Cold Path: Headers/Debug ===== @@ -217,7 +233,7 @@ static inline void hakmem_env_cache_init(void) { #if !HAKMEM_BUILD_RELEASE // Debug: Print cache summary (stderr only) if (!g_hak_env_cache.quiet) { - fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 37); + fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 41); fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n"); fflush(stderr); } @@ -251,6 +267,10 @@ static inline void hakmem_env_cache_init(void) { #define HAK_ENV_TINY_FRONT_DIRECT() (g_hak_env_cache.tiny_front_direct) #define HAK_ENV_TINY_FAST_STATS() (g_hak_env_cache.tiny_fast_stats) #define HAK_ENV_TINY_UNIFIED_CACHE() (g_hak_env_cache.tiny_unified_cache) +#define HAK_ENV_SFC_DEBUG() (g_hak_env_cache.sfc_debug) +#define HAK_ENV_SFC_ENABLE() (g_hak_env_cache.sfc_enable) +#define HAK_ENV_SFC_CAPACITY() (g_hak_env_cache.sfc_capacity) +#define HAK_ENV_SFC_REFILL_COUNT() (g_hak_env_cache.sfc_refill_count) // Cold path accessors #define HAK_ENV_TINY_RESTORE_HEADER() (g_hak_env_cache.tiny_restore_header) diff --git a/core/hakmem_tiny_sfc.c b/core/hakmem_tiny_sfc.c index 422b1681..82637c80 100644 --- a/core/hakmem_tiny_sfc.c +++ b/core/hakmem_tiny_sfc.c @@ -9,6 +9,7 @@ #include "hakmem_stats_master.h" // Phase 4d: Master stats control #include "tiny_tls.h" #include "box/tls_sll_box.h" // static inline tls_sll_pop/push API (Box TLS-SLL) +#include "hakmem_env_cache.h" // Priority-2: ENV cache (eliminate syscalls) #include #include #include @@ -49,37 +50,24 @@ static int g_sfc_refill_override[TINY_NUM_CLASSES] = {0}; // ============================================================================ void sfc_init(void) { - // Cache debug flag once (hot paths reuse g_sfc_debug) - const char* env_debug = getenv("HAKMEM_SFC_DEBUG"); - g_sfc_debug = (env_debug && *env_debug && *env_debug != '0') ? 1 : 0; - - // Parse ENV: HAKMEM_SFC_ENABLE - const char* env_enable = getenv("HAKMEM_SFC_ENABLE"); - if (env_enable && *env_enable && *env_enable != '0') { - g_sfc_enabled = 1; - } + // Priority-2: Use cached ENV (eliminate init syscall overhead) + g_sfc_debug = HAK_ENV_SFC_DEBUG(); + g_sfc_enabled = HAK_ENV_SFC_ENABLE(); if (!g_sfc_enabled) { // SFC disabled, skip initialization return; } - // Parse ENV: HAKMEM_SFC_CAPACITY (default capacity for all classes) - const char* env_cap = getenv("HAKMEM_SFC_CAPACITY"); - if (env_cap && *env_cap) { - int cap = atoi(env_cap); - if (cap >= SFC_MIN_CAPACITY && cap <= SFC_MAX_CAPACITY) { - g_sfc_default_capacity = cap; - } + // Priority-2: Use cached ENV (eliminate config syscall overhead) + int cap = HAK_ENV_SFC_CAPACITY(); + if (cap >= SFC_MIN_CAPACITY && cap <= SFC_MAX_CAPACITY) { + g_sfc_default_capacity = cap; } - // Parse ENV: HAKMEM_SFC_REFILL_COUNT (default refill for all classes) - const char* env_refill = getenv("HAKMEM_SFC_REFILL_COUNT"); - if (env_refill && *env_refill) { - int refill = atoi(env_refill); - if (refill >= 8 && refill <= 256) { - g_sfc_default_refill = refill; - } + int refill = HAK_ENV_SFC_REFILL_COUNT(); + if (refill >= 8 && refill <= 256) { + g_sfc_default_refill = refill; } // Parse ENV: HAKMEM_SFC_CAPACITY_CLASS{0..7} (per-class capacity override)