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>
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
// tiny_front_stats_box.h - Front class distribution counters (ENV gated)
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdatomic.h>
|
|
#include "../hakmem_build_flags.h"
|
|
#include "../hakmem_tiny_config.h"
|
|
|
|
extern _Atomic uint64_t g_tiny_front_alloc_class[TINY_NUM_CLASSES];
|
|
extern _Atomic uint64_t g_tiny_front_free_class[TINY_NUM_CLASSES];
|
|
|
|
static inline int tiny_front_class_stats_enabled(void) {
|
|
#if !HAKMEM_DEBUG_COUNTERS
|
|
return 0;
|
|
#else
|
|
static int g = -1;
|
|
if (__builtin_expect(g == -1, 0)) {
|
|
const char* e = getenv("HAKMEM_TINY_FRONT_CLASS_STATS");
|
|
g = (e && *e && *e != '0') ? 1 : 0;
|
|
}
|
|
return g;
|
|
#endif
|
|
}
|
|
|
|
static inline int tiny_front_class_stats_dump_enabled(void) {
|
|
#if !HAKMEM_DEBUG_COUNTERS
|
|
return 0;
|
|
#else
|
|
static int g = -1;
|
|
if (__builtin_expect(g == -1, 0)) {
|
|
const char* e = getenv("HAKMEM_TINY_FRONT_CLASS_STATS_DUMP");
|
|
const char* e2 = getenv("HAKMEM_TINY_FRONT_CLASS_STATS");
|
|
g = ((e && *e && *e != '0') || (e2 && *e2 && *e2 != '0')) ? 1 : 0;
|
|
}
|
|
return g;
|
|
#endif
|
|
}
|
|
|
|
static inline void tiny_front_alloc_stat_inc(int class_idx) {
|
|
#if HAKMEM_DEBUG_COUNTERS
|
|
if (__builtin_expect(tiny_front_class_stats_enabled(), 0)) {
|
|
atomic_fetch_add_explicit(&g_tiny_front_alloc_class[class_idx], 1, memory_order_relaxed);
|
|
}
|
|
#else
|
|
(void)class_idx;
|
|
#endif
|
|
}
|
|
|
|
static inline void tiny_front_free_stat_inc(int class_idx) {
|
|
#if HAKMEM_DEBUG_COUNTERS
|
|
if (__builtin_expect(tiny_front_class_stats_enabled(), 0)) {
|
|
atomic_fetch_add_explicit(&g_tiny_front_free_class[class_idx], 1, memory_order_relaxed);
|
|
}
|
|
#else
|
|
(void)class_idx;
|
|
#endif
|
|
}
|