Files
hakmem/core/box/free_path_stats_box.h
Moe Charm (CI) 1a8652a91a Phase TLS-UNIFY-3: C6 intrusive freelist implementation (完成)
Implement C6 ULTRA intrusive LIFO freelist with ENV gating:
- Single-linked LIFO using next pointer at USER+1 offset
- tiny_next_store/tiny_next_load for pointer access (single source of truth)
- Segment learning via ss_fast_lookup (per-class seg_base/seg_end)
- ENV gate: HAKMEM_TINY_C6_ULTRA_INTRUSIVE_FL (default OFF)
- Counters: c6_ifl_push/pop/fallback in FREE_PATH_STATS

Files:
- core/box/tiny_ultra_tls_box.h: Added c6_head field for intrusive LIFO
- core/box/tiny_ultra_tls_box.c: Pop/push with intrusive branching (case 6)
- core/box/tiny_c6_ultra_intrusive_env_box.h: ENV gate (new)
- core/box/tiny_c6_intrusive_freelist_box.h: L1 pure LIFO (new)
- core/tiny_debug_ring.h: C6_IFL events
- core/box/free_path_stats_box.h/c: c6_ifl_* counters

A/B Test Results (1M iterations, ws=200, 257-512B):
- ENV_OFF (array): 56.6 Mop/s avg
- ENV_ON (intrusive): 57.6 Mop/s avg (+1.8%, within noise)
- Counters verified: c6_ifl_push=265890, c6_ifl_pop=265815, fallback=0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-12 16:26:42 +09:00

54 lines
1.8 KiB
C

#ifndef HAKMEM_FREE_PATH_STATS_BOX_H
#define HAKMEM_FREE_PATH_STATS_BOX_H
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct FreePathStats {
uint64_t total_calls;
uint64_t c7_ultra_fast;
uint64_t c6_ultra_free_fast; // Phase 4-2: C6 ULTRA-free
uint64_t c6_ultra_alloc_hit; // Phase 4-4: C6 ULTRA-alloc (TLS pop)
uint64_t c6_ifl_push; // Phase TLS-UNIFY-3: C6 intrusive push
uint64_t c6_ifl_pop; // Phase TLS-UNIFY-3: C6 intrusive pop
uint64_t c6_ifl_fallback; // Phase TLS-UNIFY-3: C6 intrusive fallback (slow)
uint64_t c5_ultra_free_fast; // Phase 5-1: C5 ULTRA-free
uint64_t c5_ultra_alloc_hit; // Phase 5-2: C5 ULTRA-alloc (TLS pop)
uint64_t c4_ultra_free_fast; // Phase 6: C4 ULTRA-free (cap=64)
uint64_t c4_ultra_alloc_hit; // Phase 6: C4 ULTRA-alloc (TLS pop)
uint64_t smallheap_v3_fast;
uint64_t smallheap_v6_fast;
uint64_t smallheap_v7_fast; // Phase v7-2: SmallHeap v7 fast free
uint64_t tiny_heap_v1_fast;
uint64_t pool_v1_fast;
uint64_t remote_free;
uint64_t super_lookup_called;
uint64_t legacy_fallback;
// Phase 4-1: Legacy per-class breakdown
uint64_t legacy_by_class[8]; // C0-C7 の Legacy fallback 内訳
} FreePathStats;
// ENV gate
static inline bool free_path_stats_enabled(void) {
static int g_enabled = -1;
if (__builtin_expect(g_enabled == -1, 0)) {
const char* e = getenv("HAKMEM_FREE_PATH_STATS");
g_enabled = (e && *e && *e != '0') ? 1 : 0;
}
return g_enabled;
}
// Global stats instance
extern FreePathStats g_free_path_stats;
// Increment macros (with unlikely guard)
#define FREE_PATH_STAT_INC(field) \
do { if (__builtin_expect(free_path_stats_enabled(), 0)) { \
g_free_path_stats.field++; \
} } while(0)
#endif // HAKMEM_FREE_PATH_STATS_BOX_H