Infrastructure and build updates

- Update build configuration and flags
- Add missing header files and dependencies
- Update TLS list implementation with proper scoping
- Fix various compilation warnings and issues
- Update debug ring and tiny allocation infrastructure
- Update benchmark results documentation

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
Moe Charm (CI)
2025-11-11 21:49:05 +09:00
parent 79c74e72da
commit 862e8ea7db
34 changed files with 541 additions and 214 deletions

View File

@ -9,14 +9,15 @@
#include <stdio.h> // For debug output (getenv, fprintf, stderr)
#include <stdlib.h> // For getenv
#include "hakmem_tiny.h"
#include "tiny_nextptr.h"
// ============================================================================
// Box 5-NEW: Super Front Cache - Global Config
// ============================================================================
// Default capacities (can be overridden per-class)
#define SFC_DEFAULT_CAPACITY 128
#define SFC_DEFAULT_REFILL_COUNT 64
#define SFC_DEFAULT_CAPACITY 256
#define SFC_DEFAULT_REFILL_COUNT 128
#define SFC_DEFAULT_SPILL_THRESH 90 // Spill when >90% full
// Per-class capacity limits
@ -78,13 +79,8 @@ static inline void* sfc_alloc(int cls) {
void* base = g_sfc_head[cls];
if (__builtin_expect(base != NULL, 1)) {
#if HAKMEM_TINY_HEADER_CLASSIDX
const size_t next_offset = (cls == 7) ? 0 : 1;
#else
const size_t next_offset = 0;
#endif
// Pop: header-aware next
g_sfc_head[cls] = *(void**)((uint8_t*)base + next_offset);
// Pop: safe header-aware next
g_sfc_head[cls] = tiny_next_load(base, cls);
g_sfc_count[cls]--; // count--
#if HAKMEM_DEBUG_COUNTERS
@ -109,23 +105,22 @@ static inline int sfc_free_push(int cls, void* ptr) {
uint32_t cap = g_sfc_capacity[cls];
uint32_t cnt = g_sfc_count[cls];
// Debug: Always log sfc_free_push calls when SFC_DEBUG is set
static __thread int free_debug_count = 0;
if (getenv("HAKMEM_SFC_DEBUG") && free_debug_count < 20) {
free_debug_count++;
extern int g_sfc_enabled;
fprintf(stderr, "[SFC_FREE_PUSH] cls=%d, ptr=%p, cnt=%u, cap=%u, will_succeed=%d, enabled=%d\n",
cls, ptr, cnt, cap, (cnt < cap), g_sfc_enabled);
}
#if !HAKMEM_BUILD_RELEASE && defined(HAKMEM_SFC_DEBUG_LOG)
// Debug logging (compile-time gated; zero cost in release)
do {
static __thread int free_debug_count = 0;
if (getenv("HAKMEM_SFC_DEBUG") && free_debug_count < 20) {
free_debug_count++;
extern int g_sfc_enabled;
fprintf(stderr, "[SFC_FREE_PUSH] cls=%d, ptr=%p, cnt=%u, cap=%u, will_succeed=%d, enabled=%d\n",
cls, ptr, cnt, cap, (cnt < cap), g_sfc_enabled);
}
} while(0);
#endif
if (__builtin_expect(cnt < cap, 1)) {
#if HAKMEM_TINY_HEADER_CLASSIDX
const size_t next_offset = (cls == 7) ? 0 : 1;
#else
const size_t next_offset = 0;
#endif
// Push: header-aware next placement
*(void**)((uint8_t*)ptr + next_offset) = g_sfc_head[cls];
// Push: safe header-aware next placement
tiny_next_store(ptr, cls, g_sfc_head[cls]);
g_sfc_head[cls] = ptr; // head = base
g_sfc_count[cls] = cnt + 1; // count++
@ -149,6 +144,7 @@ static inline int sfc_free_push(int cls, void* ptr) {
// Initialize SFC (called once at startup)
void sfc_init(void);
void sfc_cascade_from_tls_initial(void);
// Shutdown SFC (called at exit, optional)
void sfc_shutdown(void);