Add OBSERVE stats and auto tiny policy profile

This commit is contained in:
Moe Charm (CI)
2025-12-06 01:44:05 +09:00
parent 03538055ae
commit 18faa6a1c4
8 changed files with 182 additions and 144 deletions

View File

@ -11,6 +11,7 @@
#include "hakmem_env_cache.h" // Priority-2: ENV cache
#include "front/tiny_warm_pool.h" // Warm Pool: Prefill during registry scans
#include "box/ss_slab_reset_box.h" // Box: Reset slab metadata on reuse (C7 guard)
#include "box/tiny_class_stats_box.h" // OBSERVE: per-class shared lock stats
#include <stdint.h>
#include <stdlib.h>
@ -20,6 +21,11 @@
// Stage3(LRU) 由来の Superslab をトレースするための簡易マジック
_Atomic uintptr_t g_c7_stage3_magic_ss = 0;
static inline void sp_lock_with_stats(int class_idx) {
tiny_class_stats_on_shared_lock(class_idx);
sp_lock_with_stats(class_idx);
}
static inline void c7_log_meta_state(const char* tag, SuperSlab* ss, int slab_idx) {
if (!ss) return;
#if HAKMEM_BUILD_RELEASE
@ -351,7 +357,7 @@ stage1_retry_after_tension_drain:
atomic_fetch_add(&g_lock_acquire_slab_count, 1);
}
pthread_mutex_lock(&g_shared_pool.alloc_lock);
sp_lock_with_stats(class_idx);
// P0.3: Guard against TLS SLL orphaned pointers before reusing slab
// RACE FIX: Load SuperSlab pointer atomically BEFORE guard (consistency)
@ -498,7 +504,7 @@ stage2_fallback:
atomic_fetch_add(&g_lock_acquire_slab_count, 1);
}
pthread_mutex_lock(&g_shared_pool.alloc_lock);
sp_lock_with_stats(class_idx);
// Performance measurement: count Stage 2 lock acquisitions
if (__builtin_expect(sp_measure_enabled(), 0)) {
@ -626,11 +632,11 @@ stage2_scan:
// P0 instrumentation: count lock acquisitions
lock_stats_init();
if (g_lock_stats_enabled == 1) {
atomic_fetch_add(&g_lock_acquire_count, 1);
atomic_fetch_add(&g_lock_acquire_slab_count, 1);
}
atomic_fetch_add(&g_lock_acquire_count, 1);
atomic_fetch_add(&g_lock_acquire_slab_count, 1);
}
pthread_mutex_lock(&g_shared_pool.alloc_lock);
sp_lock_with_stats(class_idx);
// Performance measurement: count Stage 2 scan lock acquisitions
if (__builtin_expect(sp_measure_enabled(), 0)) {
@ -793,7 +799,7 @@ stage2_scan:
atomic_fetch_add(&g_lock_acquire_count, 1);
atomic_fetch_add(&g_lock_acquire_slab_count, 1); // This is part of acquisition path
}
pthread_mutex_lock(&g_shared_pool.alloc_lock);
sp_lock_with_stats(class_idx);
if (!allocated_ss) {
// Allocation failed; return now.