Working state before pushing to cyu remote
This commit is contained in:
101
core/tiny_c6_inline_slots_ifl.c
Normal file
101
core/tiny_c6_inline_slots_ifl.c
Normal file
@ -0,0 +1,101 @@
|
||||
// tiny_c6_inline_slots_ifl.c - Phase 91: C6 Intrusive LIFO Inline Slots Implementation
|
||||
//
|
||||
// Goal: TLS variable definition, ENV refresh, overflow handler
|
||||
// Scope: Per-thread LIFO state, initialization, drain to unified_cache
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "box/tiny_c6_inline_slots_ifl_env_box.h"
|
||||
#include "box/tiny_c6_inline_slots_ifl_tls_box.h"
|
||||
#include "box/tiny_unified_lifo_box.h"
|
||||
|
||||
// ============================================================================
|
||||
// Global State (set by refresh function)
|
||||
// ============================================================================
|
||||
|
||||
uint8_t g_tiny_c6_inline_slots_ifl_enabled = 0;
|
||||
uint8_t g_tiny_c6_inline_slots_ifl_strict = 0;
|
||||
|
||||
// ============================================================================
|
||||
// TLS Variable Definition
|
||||
// ============================================================================
|
||||
|
||||
// TLS instance (one per thread)
|
||||
// Zero-initialized by default (head=NULL, count=0, enabled=0)
|
||||
__thread struct TinyC6InlineSlotsIFL g_tiny_c6_inline_slots_ifl = {
|
||||
.head = NULL,
|
||||
.count = 0,
|
||||
.enabled = 0,
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// ENV Refresh (called from bench_profile.h::refresh_all_env_caches)
|
||||
// ============================================================================
|
||||
|
||||
void tiny_c6_inline_slots_ifl_refresh_from_env(void) {
|
||||
// 1. Read master ENV gate
|
||||
const char* env_val = getenv("HAKMEM_TINY_C6_INLINE_SLOTS_IFL");
|
||||
int requested = (env_val && *env_val && *env_val != '0') ? 1 : 0;
|
||||
|
||||
if (!requested) {
|
||||
g_tiny_c6_inline_slots_ifl_enabled = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Fail-fast: LARSON_FIX incompatible
|
||||
// Intrusive LIFO uses next pointer in freed object header,
|
||||
// cannot coexist with owner_tid validation in header
|
||||
const char* larson_env = getenv("HAKMEM_TINY_LARSON_FIX");
|
||||
int larson_fix_enabled = (larson_env && *larson_env && *larson_env != '0') ? 1 : 0;
|
||||
|
||||
if (larson_fix_enabled) {
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
fprintf(stderr, "[C6-IFL] FAIL-FAST: HAKMEM_TINY_LARSON_FIX=1 incompatible with intrusive LIFO, disabling\n");
|
||||
fflush(stderr);
|
||||
#endif
|
||||
g_tiny_c6_inline_slots_ifl_enabled = 0;
|
||||
g_tiny_c6_inline_slots_ifl_strict = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Read strict mode (diagnostic, not enforced)
|
||||
const char* strict_env = getenv("HAKMEM_TINY_C6_IFL_STRICT");
|
||||
g_tiny_c6_inline_slots_ifl_strict = (strict_env && *strict_env && *strict_env != '0') ? 1 : 0;
|
||||
|
||||
// 4. Enable IFL for this thread
|
||||
g_tiny_c6_inline_slots_ifl_enabled = 1;
|
||||
g_tiny_c6_inline_slots_ifl.enabled = 1;
|
||||
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
fprintf(stderr, "[C6-IFL] Initialized: enabled=1, strict=%d\n",
|
||||
g_tiny_c6_inline_slots_ifl_strict);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Overflow Handler: Drain LIFO to Unified Cache
|
||||
// ============================================================================
|
||||
|
||||
void tiny_c6_inline_slots_ifl_drain_to_unified(void) {
|
||||
// Drain all entries from LIFO head to unified_cache
|
||||
// Called when count > 128 (overflow condition)
|
||||
|
||||
while (g_tiny_c6_inline_slots_ifl.count > 0) {
|
||||
void* ptr = tiny_c6_inline_slots_ifl_pop_fast();
|
||||
if (ptr == NULL) {
|
||||
break; // Should not happen if count tracking is correct
|
||||
}
|
||||
|
||||
// Push to unified_cache LIFO for C6
|
||||
int success = unified_cache_try_push_lifo(6, ptr);
|
||||
if (!success) {
|
||||
// Unified cache is full; this should be rare
|
||||
// For now, we leak the pointer (FIXME: proper fallback)
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
fprintf(stderr, "[C6-IFL-DRAIN] WARNING: unified_cache full, dropping pointer %p\n", ptr);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user