Files
hakmem/core/box/free_path_stats_box.h
Moe Charm (CI) d54893ea1d Phase 3 C3: Static Routing A/B Test ADOPT (+2.20% Mixed gain)
Step 2 & 3 Complete:
- A/B test (Mixed 10-run): STATIC_ROUTE=0 (38.91M) → =1 (39.77M) = +2.20% avg
  - Median gain: +1.98%
  - Result:  GO (exceeds +1.0% threshold)

- Decision:  ADOPT into MIXED_TINYV3_C7_SAFE preset
  - bench_profile.h line 77: HAKMEM_TINY_STATIC_ROUTE=1 default
  - Learner auto-disables static route when HAKMEM_SMALL_LEARNER_V7_ENABLED=1

Implementation Summary:
- core/box/tiny_static_route_box.{h,c}: Research box (Step 1A)
- core/front/malloc_tiny_fast.h: Route lookup integration (Step 1B, lines 249-256)
- core/bench_profile.h: Bench sync + preset adoption

Cumulative Phase 2-3 Gains:
- B3 (Routing shape): +2.89%
- B4 (Wrapper split): +1.47%
- C3 (Static routing): +2.20%
- Total: ~6.8% (35.2M → ~39.8M ops/s)

Next: Phase 3 C1 (TLS Prefetch, expected +2-4%)

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-13 18:46:11 +09:00

78 lines
2.5 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>
#include "../hakmem_build_flags.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 内訳
// Phase POLICY-FAST-PATH-V2: Fast-path policy skip
uint64_t policy_fast_v2_skip; // Phase POLICY-FAST-PATH-V2 fast-path skips
} FreePathStats;
// ENV gate
static inline bool free_path_stats_enabled(void) {
#if !HAKMEM_DEBUG_COUNTERS
return false;
#else
static int g_enabled = -1; // -1: unknown, 0: off, 1: on
static int g_probe_left = 64; // tolerate early getenv() instability (bench_profile putenv)
if (__builtin_expect(g_enabled == 1, 1)) return true;
if (__builtin_expect(g_enabled == 0, 1)) return false;
const char* e = getenv("HAKMEM_FREE_PATH_STATS");
if (e && *e) {
g_enabled = (*e != '0') ? 1 : 0;
return g_enabled == 1;
}
if (g_probe_left-- > 0) {
return false; // keep g_enabled==-1, retry later
}
g_enabled = 0;
return false;
#endif
}
// Global stats instance
extern FreePathStats g_free_path_stats;
// Increment macros (with unlikely guard)
#if HAKMEM_DEBUG_COUNTERS
#define FREE_PATH_STAT_INC(field) \
do { if (__builtin_expect(free_path_stats_enabled(), 0)) { \
g_free_path_stats.field++; \
} } while(0)
#else
#define FREE_PATH_STAT_INC(field) ((void)0)
#endif
#endif // HAKMEM_FREE_PATH_STATS_BOX_H