## Summary - ChatGPT により bench_profile.h の setenv segfault を修正(RTLD_NEXT 経由に切り替え) - core/box/pool_zero_mode_box.h 新設:ENV キャッシュ経由で ZERO_MODE を統一管理 - core/hakmem_pool.c で zero mode に応じた memset 制御(FULL/header/off) - A/B テスト結果:ZERO_MODE=header で +15.34% improvement(1M iterations, C6-heavy) ## Files Modified - core/box/pool_api.inc.h: pool_zero_mode_box.h include - core/bench_profile.h: glibc setenv → malloc+putenv(segfault 回避) - core/hakmem_pool.c: zero mode 参照・制御ロジック - core/box/pool_zero_mode_box.h (新設): enum/getter - CURRENT_TASK.md: Phase ML1 結果記載 ## Test Results | Iterations | ZERO_MODE=full | ZERO_MODE=header | Improvement | |-----------|----------------|-----------------|------------| | 10K | 3.06 M ops/s | 3.17 M ops/s | +3.65% | | 1M | 23.71 M ops/s | 27.34 M ops/s | **+15.34%** | 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
72 lines
1.7 KiB
C
72 lines
1.7 KiB
C
// init_diag_box.h — 初期化時の診断(SIGSEGV ハンドラ、ベースライン、ビルドバナー)
|
||
#ifndef INIT_DIAG_BOX_H
|
||
#define INIT_DIAG_BOX_H
|
||
|
||
#include <signal.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
|
||
// Debug-only SIGSEGV handler (gated by HAKMEM_DEBUG_SEGV)
|
||
static inline void box_diag_install_sigsegv_handler(void (*handler)(int)) {
|
||
const char* dbg = getenv("HAKMEM_DEBUG_SEGV");
|
||
if (!dbg || atoi(dbg) == 0) return;
|
||
|
||
struct sigaction sa;
|
||
memset(&sa, 0, sizeof(sa));
|
||
sa.sa_flags = SA_RESETHAND;
|
||
sa.sa_handler = handler;
|
||
sigaction(SIGSEGV, &sa, NULL);
|
||
}
|
||
|
||
static inline void box_diag_record_baseline(void) {
|
||
#ifdef __linux__
|
||
memset(g_latency_histogram, 0, sizeof(g_latency_histogram));
|
||
g_latency_samples = 0;
|
||
|
||
get_page_faults(&g_baseline_soft_pf, &g_baseline_hard_pf);
|
||
g_baseline_rss_kb = get_rss_kb();
|
||
|
||
HAKMEM_LOG("Baseline: soft_pf=%lu, hard_pf=%lu, rss=%lu KB\n",
|
||
(unsigned long)g_baseline_soft_pf,
|
||
(unsigned long)g_baseline_hard_pf,
|
||
(unsigned long)g_baseline_rss_kb);
|
||
#endif
|
||
}
|
||
|
||
static inline void box_diag_print_banner(void) {
|
||
const char* bf = "UNKNOWN";
|
||
#ifdef HAKMEM_BUILD_RELEASE
|
||
bf = "RELEASE";
|
||
#elif defined(HAKMEM_BUILD_DEBUG)
|
||
bf = "DEBUG";
|
||
#endif
|
||
(void)bf;
|
||
HAKMEM_LOG(
|
||
"[Build] Flavor=%s Flags: HEADER_CLASSIDX=%d, AGGRESSIVE_INLINE=%d, "
|
||
"POOL_TLS_PHASE1=%d, POOL_TLS_PREWARM=%d\n",
|
||
bf,
|
||
#if HAKMEM_TINY_HEADER_CLASSIDX
|
||
1,
|
||
#else
|
||
0,
|
||
#endif
|
||
#ifdef HAKMEM_TINY_AGGRESSIVE_INLINE
|
||
1,
|
||
#else
|
||
0,
|
||
#endif
|
||
#ifdef HAKMEM_POOL_TLS_PHASE1
|
||
1,
|
||
#else
|
||
0,
|
||
#endif
|
||
#ifdef HAKMEM_POOL_TLS_PREWARM
|
||
1
|
||
#else
|
||
0
|
||
#endif
|
||
);
|
||
}
|
||
|
||
#endif // INIT_DIAG_BOX_H
|