## 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>
47 lines
1.9 KiB
C
47 lines
1.9 KiB
C
// Inline helpers for Background Refill Bin (lock-free SLL)
|
|
// This header is textually included from hakmem_tiny.c after the following
|
|
// symbols are defined:
|
|
// - g_bg_bin_enable, g_bg_bin_head[]
|
|
|
|
#include "box/tiny_next_ptr_box.h" // Phase E1-CORRECT: Box API for next pointer
|
|
|
|
static inline void* bgbin_pop(int class_idx) {
|
|
if (!g_bg_bin_enable) return NULL;
|
|
uintptr_t h = atomic_load_explicit(&g_bg_bin_head[class_idx], memory_order_acquire);
|
|
while (h != 0) {
|
|
void* p = (void*)h;
|
|
// Phase E1-CORRECT: Use Box API for next pointer read
|
|
uintptr_t next = (uintptr_t)tiny_next_read(class_idx, p);
|
|
if (atomic_compare_exchange_weak_explicit(&g_bg_bin_head[class_idx], &h, next,
|
|
memory_order_acq_rel, memory_order_acquire)) {
|
|
#if HAKMEM_DEBUG_COUNTERS
|
|
g_bgbin_pops[class_idx]++;
|
|
#endif
|
|
return p;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static inline void bgbin_push_chain(int class_idx, void* chain_head, void* chain_tail) {
|
|
if (!chain_head) return;
|
|
uintptr_t h = atomic_load_explicit(&g_bg_bin_head[class_idx], memory_order_acquire);
|
|
// Phase E1-CORRECT: Use Box API for next pointer write
|
|
do { tiny_next_write(class_idx, chain_tail, (void*)h); }
|
|
while (!atomic_compare_exchange_weak_explicit(&g_bg_bin_head[class_idx], &h,
|
|
(uintptr_t)chain_head,
|
|
memory_order_acq_rel, memory_order_acquire));
|
|
}
|
|
|
|
static inline int bgbin_length_approx(int class_idx, int cap) {
|
|
uintptr_t h = atomic_load_explicit(&g_bg_bin_head[class_idx], memory_order_acquire);
|
|
int n = 0;
|
|
while (h && n < cap) {
|
|
void* p = (void*)h;
|
|
// Phase E1-CORRECT: Use Box API for next pointer read
|
|
h = (uintptr_t)tiny_next_read(class_idx, p);
|
|
n++;
|
|
}
|
|
return n;
|
|
}
|