Files
hakmem/core/mid_tcache.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

60 lines
1.8 KiB
C

// mid_tcache.h - Mid-size TLS tcache (classes 4..7)
// Box: Per-thread, per-class singly-linked stack. No atomics, no sharing.
// Goal: O(1) pop/push on alloc/free for 128..1024B while keeping Box boundaries.
#pragma once
#include <stdint.h>
#include <stdlib.h>
#ifndef TINY_NUM_CLASSES
#define TINY_NUM_CLASSES 8
#endif
static inline int midtc_enabled(void) {
static int en = -1;
if (__builtin_expect(en == -1, 0)) {
const char* s = getenv("HAKMEM_MID_TC");
en = (s && *s && *s != '0') ? 1 : 0;
}
return en;
}
static inline int midtc_cap_global(void) {
static int cap = -1;
if (__builtin_expect(cap == -1, 0)) {
const char* s = getenv("HAKMEM_MID_TC_CAP");
int v = (s && *s) ? atoi(s) : 32; // conservative default
if (v < 0) v = 0; if (v > 1024) v = 1024;
cap = v;
}
return cap;
}
// Per-thread state
static __thread void* g_midtc_head[TINY_NUM_CLASSES];
static __thread uint16_t g_midtc_count[TINY_NUM_CLASSES];
// Push returns 1 on accept, 0 to fallback to existing path.
static inline int midtc_push(int class_idx, void* p) {
if (!midtc_enabled()) return 0;
if (class_idx < 4 || class_idx >= TINY_NUM_CLASSES) return 0; // only 128..1024B
uint16_t cnt = g_midtc_count[class_idx];
int cap = midtc_cap_global();
if (cnt >= (uint16_t)cap) return 0;
*(void**)p = g_midtc_head[class_idx];
g_midtc_head[class_idx] = p;
g_midtc_count[class_idx] = (uint16_t)(cnt + 1);
return 1;
}
static inline void* midtc_pop(int class_idx) {
if (!midtc_enabled()) return NULL;
if (class_idx < 4 || class_idx >= TINY_NUM_CLASSES) return NULL;
void* h = g_midtc_head[class_idx];
if (!h) return NULL;
g_midtc_head[class_idx] = *(void**)h;
if (g_midtc_count[class_idx] > 0) g_midtc_count[class_idx]--;
return h;
}