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,71 @@
// tiny_ultra_heap.h - Phase UltraFront Heap (L0 heap skeleton)
//
// 目的:
// - per-thread Tiny/Mid heap を明示化する箱。
// - 当面は既存の Unified + Superslab 経路をそのまま使い、
// 「heap→page→block」構造への足場だけを用意する。
// - 将来的に PageLocal/page arena と統合していく起点。
//
// 注意:
// - HAKMEM_TINY_ULTRA_HEAP=1 のビルドライン専用(実験用)。
// - 既存経路を壊さないよう、当面は tiny_ultrafront_* を薄くラップするだけ。
#ifndef HAK_ULTRA_TINY_ULTRA_HEAP_H
#define HAK_ULTRA_TINY_ULTRA_HEAP_H
#include "../hakmem_build_flags.h"
#if HAKMEM_TINY_ULTRA_HEAP
#include "../hakmem_tiny.h" // tiny_get_max_size, hak_tiny_size_to_class, TINY_NUM_CLASSES
#include "../tiny_tls.h" // TinyTLSSlab (TLS view of current slab/page)
#include "../front/tiny_ultrafront.h" // 現行 UltraFront helperUnified+header 経路)
// L0: Per-class PageLocal view
// - Box 的には「UltraFront が見る Tiny の page ローカル状態」の顔となる。
// - 当面は TinyTLSSlab への薄いビューaliasに留め、既存実装をそのまま利用する。
// - 将来、独立した freelist / bump ポインタを持たせる場合もここを拡張するだけで済む。
typedef struct TinyUltraPageLocal {
TinyTLSSlab* tls; // 現行 TLS slab 構造体へのポインタg_tls_slabs[class] の alias
uint8_t cls; // size class (07)
} TinyUltraPageLocal;
// L0: UltraHeap 内部の per-class 小型キャッシュ
// - Box 的には「Unified Cache より手前の極小バッファ」として扱う。
// - 実験用: C2/C3 (128B/256B) などホットクラス専用に使う想定。
#define TINY_ULTRA_L0_CAP 64
typedef struct TinyUltraL0 {
void* slots[TINY_ULTRA_L0_CAP];
uint16_t count;
uint16_t _pad;
} TinyUltraL0;
typedef struct TinyUltraHeap {
int initialized;
TinyUltraPageLocal page[TINY_NUM_CLASSES]; // C0C7 の PageLocal ビュー
TinyUltraL0 l0[TINY_NUM_CLASSES]; // 任意クラス向け L0 キャッシュenv で ON/OFF
// 観察用: UltraHeap 経由 Tiny alloc の挙動をクラス別に記録
uint64_t alloc_unified_hit[TINY_NUM_CLASSES]; // Unified hit で返せた回数
uint64_t alloc_unified_refill[TINY_NUM_CLASSES]; // refill で Superslab から供給した回数
uint64_t alloc_fallback_ultrafront[TINY_NUM_CLASSES]; // UltraFront 経路にフォールバックした回数
} TinyUltraHeap;
extern __thread TinyUltraHeap g_tiny_ultra_heap;
// 初期化per-thread
void tiny_ultra_heap_init(void);
// UltraHeap 経由の Tiny alloc/free
void* tiny_ultra_heap_alloc(size_t size);
int tiny_ultra_heap_free(void* ptr);
// UltraHeap 統計のスナップショット取得(オプション)
// reset!=0 のとき、読み取り後に 0 にクリアする。
void tiny_ultra_heap_stats_snapshot(uint64_t hit[TINY_NUM_CLASSES],
uint64_t refill[TINY_NUM_CLASSES],
uint64_t fallback[TINY_NUM_CLASSES],
int reset);
#endif // HAKMEM_TINY_ULTRA_HEAP
#endif // HAK_ULTRA_TINY_ULTRA_HEAP_H