Files
hakmem/core/hakmem_ace_stats.c
Moe Charm (CI) 52386401b3 Debug Counters Implementation - Clean History
Major Features:
- Debug counter infrastructure for Refill Stage tracking
- Free Pipeline counters (ss_local, ss_remote, tls_sll)
- Diagnostic counters for early return analysis
- Unified larson.sh benchmark runner with profiles
- Phase 6-3 regression analysis documentation

Bug Fixes:
- Fix SuperSlab disabled by default (HAKMEM_TINY_USE_SUPERSLAB)
- Fix profile variable naming consistency
- Add .gitignore patterns for large files

Performance:
- Phase 6-3: 4.79 M ops/s (has OOM risk)
- With SuperSlab: 3.13 M ops/s (+19% improvement)

This is a clean repository without large log files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-05 12:31:14 +09:00

83 lines
2.4 KiB
C

#include "hakmem_ace_stats.h"
#include <stdlib.h>
static _Atomic uint64_t g_mid_hit = 0;
static _Atomic uint64_t g_mid_miss = 0;
static _Atomic uint64_t g_large_hit = 0;
static _Atomic uint64_t g_large_miss = 0;
static _Atomic uint64_t g_l1_fallback = 0;
static _Atomic uint64_t g_mid_free = 0;
static _Atomic uint64_t g_large_free = 0;
static _Atomic uint32_t g_sample_mask = 0; // 0=off
static _Atomic uint64_t g_seq = 0;
void hkm_ace_stats_init(void) {
const char* env = getenv("HAKMEM_ACE_SAMPLE");
if (env) {
int n = atoi(env);
if (n > 0 && n < 31) {
uint32_t mask = (1u << n) - 1u; // sample every 2^n calls
atomic_store(&g_sample_mask, mask);
}
}
}
void hkm_ace_set_sample_mask(uint32_t mask) {
atomic_store(&g_sample_mask, mask);
}
static inline int should_sample(void) {
uint32_t mask = atomic_load(&g_sample_mask);
if (mask == 0) return 0;
uint64_t x = atomic_fetch_add(&g_seq, 1);
return ((x & mask) == 0);
}
void hkm_ace_stat_mid_attempt(int hit) {
if (!should_sample()) return;
if (hit) atomic_fetch_add(&g_mid_hit, 1);
else atomic_fetch_add(&g_mid_miss, 1);
}
void hkm_ace_stat_large_attempt(int hit) {
if (!should_sample()) return;
if (hit) atomic_fetch_add(&g_large_hit, 1);
else atomic_fetch_add(&g_large_miss, 1);
}
void hkm_ace_stat_l1_fallback(void) {
if (!should_sample()) return;
atomic_fetch_add(&g_l1_fallback, 1);
}
void hkm_ace_stat_mid_free(void) {
if (!should_sample()) return;
atomic_fetch_add(&g_mid_free, 1);
}
void hkm_ace_stat_large_free(void) {
if (!should_sample()) return;
atomic_fetch_add(&g_large_free, 1);
}
void hkm_ace_stats_snapshot(hkm_ace_stats_snapshot_t* out, int reset) {
if (!out) return;
out->mid_hit = atomic_load(&g_mid_hit);
out->mid_miss = atomic_load(&g_mid_miss);
out->large_hit = atomic_load(&g_large_hit);
out->large_miss = atomic_load(&g_large_miss);
out->l1_fallback = atomic_load(&g_l1_fallback);
out->mid_free = atomic_load(&g_mid_free);
out->large_free = atomic_load(&g_large_free);
if (reset) {
atomic_store(&g_mid_hit, 0);
atomic_store(&g_mid_miss, 0);
atomic_store(&g_large_hit, 0);
atomic_store(&g_large_miss, 0);
atomic_store(&g_l1_fallback, 0);
atomic_store(&g_mid_free, 0);
atomic_store(&g_large_free, 0);
}
}