Files
hakmem/core/tiny_tls_guard.h
Moe Charm (CI) 52386401b3 Debug Counters Implementation - Clean History
Major Features:
- Debug counter infrastructure for Refill Stage tracking
- Free Pipeline counters (ss_local, ss_remote, tls_sll)
- Diagnostic counters for early return analysis
- Unified larson.sh benchmark runner with profiles
- Phase 6-3 regression analysis documentation

Bug Fixes:
- Fix SuperSlab disabled by default (HAKMEM_TINY_USE_SUPERSLAB)
- Fix profile variable naming consistency
- Add .gitignore patterns for large files

Performance:
- Phase 6-3: 4.79 M ops/s (has OOM risk)
- With SuperSlab: 3.13 M ops/s (+19% improvement)

This is a clean repository without large log files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-05 12:31:14 +09:00

79 lines
2.4 KiB
C

#ifndef TINY_TLS_GUARD_H
#define TINY_TLS_GUARD_H
#include <stdatomic.h>
#include <inttypes.h>
#include <stdio.h>
#include "hakmem_tiny.h"
#include "hakmem_tiny_superslab.h"
#include "hakmem_tiny_tls_list.h"
#include "tiny_debug_ring.h"
#include "tiny_remote.h"
static inline void tiny_tls_list_guard_push(int class_idx, TinyTLSList* tls, void* node) {
if (!node) return;
extern int g_debug_remote_guard;
if (!__builtin_expect(g_debug_remote_guard, 0)) {
return;
}
uintptr_t prior = atomic_load_explicit((_Atomic uintptr_t*)node, memory_order_relaxed);
tiny_remote_report_corruption("tls_push", node, prior);
int warn = 0;
size_t blk = (size_t)g_tiny_class_sizes[class_idx];
int slab_idx = -1;
SuperSlab* ss = hak_super_lookup(node);
TinySlabMeta* meta = NULL;
uintptr_t base_val = 0;
size_t ss_size = 0;
if (ss && ss->magic == SUPERSLAB_MAGIC) {
slab_idx = slab_index_for(ss, node);
if (slab_idx >= 0) {
meta = &ss->slabs[slab_idx];
uint8_t* base = (uint8_t*)slab_data_start(ss, slab_idx);
base_val = (uintptr_t)base;
ss_size = (size_t)1ULL << ss->lg_size;
if (blk != 0) {
uintptr_t delta = (uintptr_t)node - (uintptr_t)base;
if ((delta % blk) != 0 || (meta && meta->capacity > 0 && (delta / blk) >= meta->capacity)) {
warn = 1;
}
}
} else {
warn = 1;
}
} else {
warn = 1;
}
if (!warn && (prior & (sizeof(void*) - 1)) != 0) {
warn = 1;
}
if (warn) {
uintptr_t aux = 0;
if (ss) {
aux = tiny_remote_pack_diag(0xB301u, base_val, ss_size, (uintptr_t)node);
} else {
aux = ((uintptr_t)(uint16_t)class_idx << 32) | 0xB302u;
}
tiny_debug_ring_record(TINY_RING_EVENT_REMOTE_INVALID, (uint16_t)class_idx, node, aux);
fprintf(stderr,
"[TLS_LIST_GUARD] cls=%d node=%p prior=0x%016" PRIxPTR " ss=%p meta=%p count=%u cap=%u\n",
class_idx,
node,
prior,
(void*)ss,
(void*)meta,
tls ? tls->count : 0u,
tls ? tls->cap : 0u);
}
if (tiny_remote_watch_is(node)) {
tiny_remote_watch_note("tls_push", ss, slab_idx, node, 0xA241u, 0, 0);
}
}
#endif