Phase 3d-B: TLS Cache Merge - Unified g_tls_sll[] structure (+12-18% expected)

Merge separate g_tls_sll_head[] and g_tls_sll_count[] arrays into unified
TinyTLSSLL struct to improve L1D cache locality. Expected performance gain:
+12-18% from reducing cache line splits (2 loads → 1 load per operation).

Changes:
- core/hakmem_tiny.h: Add TinyTLSSLL type (16B aligned, head+count+pad)
- core/hakmem_tiny.c: Replace separate arrays with g_tls_sll[8]
- core/box/tls_sll_box.h: Update Box API (13 sites) for unified access
- Updated 32+ files: All g_tls_sll_head[i] → g_tls_sll[i].head
- Updated 32+ files: All g_tls_sll_count[i] → g_tls_sll[i].count
- core/hakmem_tiny_integrity.h: Unified canary guards
- core/box/integrity_box.c: Simplified canary validation
- Makefile: Added core/box/tiny_sizeclass_hist_box.o to link

Build:  PASS (10K ops sanity test)
Warnings: Only pre-existing LTO type mismatches (unrelated)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-20 07:32:30 +09:00
parent 38552c3f39
commit 9b0d746407
83 changed files with 7509 additions and 259 deletions

View File

@ -0,0 +1,41 @@
// tiny_ultra_page_arena.h - UltraHeap backend (heap→page) telemetry box
//
// 目的:
// - UltraFront Heap (L0) から見た「page 層」の顔を 1 箇所に集約する。
// - 現段階では Superslab refill 回数などの観察用カウンタのみを提供し、
// 既存の shared pool / superslab 実装には手を入れない。
// - 将来的に PageArena / LRU / prewarm のポリシーをここに集約する足場。
#ifndef HAK_ULTRA_TINY_ULTRA_PAGE_ARENA_H
#define HAK_ULTRA_TINY_ULTRA_PAGE_ARENA_H
#include "../hakmem_tiny.h" // TINY_NUM_CLASSES
#include "../hakmem_tiny_superslab.h" // SuperSlab
// Ultra backend stats (per-thread, Tiny classes only)
typedef struct TinyUltraPageStats {
// Superslab refills per class (heap→page 境界が何回発火したか)
uint64_t superslab_refills[TINY_NUM_CLASSES];
} TinyUltraPageStats;
// Per-thread stats instance
extern __thread TinyUltraPageStats g_tiny_ultra_page_stats;
// heap→page 境界通知:
// - superslab_refill() が成功して TLS slab が新しい Superslab を掴んだタイミングで呼ぶ。
// - 現状は統計を増やすだけで挙動は変えないFail-Fastポリシーは今後追加
void tiny_ultra_page_on_refill(int class_idx, SuperSlab* ss);
// 統計スナップショット取得TinyUltraHeap からも参照可能)
// - reset!=0 のとき、読み取り後に 0 クリア。
void tiny_ultra_page_stats_snapshot(uint64_t refills[TINY_NUM_CLASSES],
int reset);
// Global Superslab refill stats (all threads aggregated)
// - 学習スレッドなど、TinyUltraHeap を直接触らないスレッドから利用するための箱。
// - per-thread カウンタとは別に、軽量な _Atomic 集計を持つ。
// reset!=0 のとき、読み取り後に 0 クリア。
void tiny_ultra_page_global_stats_snapshot(uint64_t refills[TINY_NUM_CLASSES],
int reset);
#endif // HAK_ULTRA_TINY_ULTRA_PAGE_ARENA_H