Files
hakmem/core/box/ss_stats_box.h
Moe Charm (CI) 9b0d746407 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>
2025-11-20 07:32:30 +09:00

73 lines
2.6 KiB
C

// ss_stats_box.h - SuperSlab Statistics Box
// Purpose: Global statistics tracking and reporting for SuperSlab allocations
// Box Theory: Centralized metrics collection with thread-safe updates
//
// Responsibilities:
// - Track global allocation/free counts
// - Track bytes allocated
// - Per-class allocation statistics
// - Statistics reporting (print functions)
//
// Dependencies: None (pure data collection)
//
// License: MIT
// Date: 2025-11-19
#ifndef HAKMEM_SS_STATS_BOX_H
#define HAKMEM_SS_STATS_BOX_H
#include <stdint.h>
#include <stddef.h>
#include <stdatomic.h>
#include "../superslab/superslab_types.h"
// ============================================================================
// Global Statistics (external visibility for tests/debugging)
// ============================================================================
extern uint64_t g_superslabs_allocated; // Total SuperSlabs allocated
extern uint64_t g_superslabs_freed; // Total SuperSlabs freed
extern uint64_t g_bytes_allocated; // Total bytes allocated
extern uint64_t g_ss_alloc_by_class[8]; // Per-class allocation counts
extern uint64_t g_ss_freed_by_class[8]; // Per-class free counts
extern uint64_t g_superslabs_reused; // Cache hit count
extern uint64_t g_superslabs_cached; // Cache store count
// Debug counters (free path instrumentation)
extern _Atomic uint64_t g_ss_active_dec_calls;
extern _Atomic uint64_t g_hak_tiny_free_calls;
extern _Atomic uint64_t g_ss_remote_push_calls;
extern _Atomic uint64_t g_free_ss_enter;
extern _Atomic uint64_t g_free_local_box_calls;
extern _Atomic uint64_t g_free_remote_box_calls;
// ============================================================================
// Statistics Update API
// ============================================================================
// Record OS allocation (new SuperSlab from mmap)
// Thread-safe: mutex protected
void ss_stats_os_alloc(uint8_t size_class, size_t ss_size);
// Record cache reuse (SuperSlab from LRU/prewarm cache)
// Thread-safe: mutex protected
void ss_stats_cache_reuse(void);
// Record cache store (SuperSlab stored in cache instead of munmap)
// Thread-safe: mutex protected
void ss_stats_cache_store(void);
// ============================================================================
// Statistics Reporting API
// ============================================================================
// Print per-SuperSlab statistics (for debugging)
void superslab_print_stats(SuperSlab* ss);
// Print global SuperSlab statistics
void superslab_print_global_stats(void);
#endif // HAKMEM_SS_STATS_BOX_H