2025-11-05 12:31:14 +09:00
|
|
|
|
// tiny_refill.h - Refill Boundary box (inline helpers)
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include <stdatomic.h>
|
|
|
|
|
|
#include "hakmem_tiny_superslab.h"
|
Phase 4c: Add master trace control (HAKMEM_TRACE)
Add unified trace control that allows enabling specific trace modules
using comma-separated values or "all" to enable everything.
New file: core/hakmem_trace_master.h
- HAKMEM_TRACE=all: Enable all trace modules
- HAKMEM_TRACE=ptr,refill,free,mailbox: Enable specific modules
- HAKMEM_TRACE_LEVEL=N: Set trace verbosity (1-3)
- hak_trace_check(): Check if module should enable tracing
Available trace modules:
ptr, refill, superslab, ring, free, mailbox, registry
Priority order:
1. HAKMEM_QUIET=1 → suppress all
2. Specific module ENV (e.g., HAKMEM_PTR_TRACE=1)
3. HAKMEM_TRACE=module1,module2
4. Default → disabled
Updated files:
- core/tiny_refill.h: Use hak_trace_check() for refill tracing
- core/box/mailbox_box.c: Use hak_trace_check() for mailbox tracing
Performance: No regression (72.9M ops/s)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 16:08:44 +09:00
|
|
|
|
#include "hakmem_trace_master.h" // Phase 4c: Master trace control
|
2025-11-05 12:31:14 +09:00
|
|
|
|
#include "slab_handle.h"
|
|
|
|
|
|
#include "tiny_sticky.h"
|
2025-11-07 01:27:04 +09:00
|
|
|
|
#include "tiny_ready.h"
|
|
|
|
|
|
#include "box/mailbox_box.h"
|
|
|
|
|
|
#include "tiny_remote_bg.h" // Background remote-drain step (best-effort)
|
|
|
|
|
|
#include "tiny_ready_bg.h" // Ready aggregator (mailbox→ready hint)
|
|
|
|
|
|
#include "tiny_route.h" // Route Fingerprint (Box boundary tracing)
|
2025-11-05 12:31:14 +09:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
// External helpers from main TU
|
|
|
|
|
|
static inline uint32_t tiny_self_u32(void);
|
|
|
|
|
|
static inline void tiny_tls_bind_slab(TinyTLSSlab* tls, SuperSlab* ss, int slab_idx);
|
|
|
|
|
|
|
|
|
|
|
|
// Forward decls in main TU
|
|
|
|
|
|
static inline uintptr_t hot_slot_pop(int class_idx);
|
|
|
|
|
|
static inline uintptr_t bench_pub_pop(int class_idx);
|
|
|
|
|
|
static inline SuperSlab* slab_entry_ss(uintptr_t ent);
|
|
|
|
|
|
static inline int slab_entry_idx(uintptr_t ent);
|
|
|
|
|
|
|
2025-11-26 14:45:26 +09:00
|
|
|
|
// Mailbox/Ready consumption always allowed (ENV gate removed)
|
|
|
|
|
|
static inline int tiny_mail_ready_allowed(void) { return 1; }
|
2025-11-07 18:07:48 +09:00
|
|
|
|
|
2025-11-05 12:31:14 +09:00
|
|
|
|
// Registry scan window (ENV: HAKMEM_TINY_REG_SCAN_MAX, default 256)
|
|
|
|
|
|
static inline int tiny_reg_scan_max(void) {
|
|
|
|
|
|
static int v = -1;
|
|
|
|
|
|
if (__builtin_expect(v == -1, 0)) {
|
|
|
|
|
|
const char* s = getenv("HAKMEM_TINY_REG_SCAN_MAX");
|
|
|
|
|
|
int defv = 256; // conservative default
|
|
|
|
|
|
if (s && *s) {
|
|
|
|
|
|
int parsed = atoi(s);
|
|
|
|
|
|
v = (parsed > 0) ? parsed : defv;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
v = defv;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return v;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-26 14:45:26 +09:00
|
|
|
|
// Opportunistic background remote-drain knobs (ENV removed; fixed defaults)
|
|
|
|
|
|
static inline int tiny_bg_remote_tryrate(void) { return 16; }
|
|
|
|
|
|
static inline int tiny_bg_remote_budget_default(void) { return 2; }
|
2025-11-07 01:27:04 +09:00
|
|
|
|
|
2025-11-05 12:31:14 +09:00
|
|
|
|
// Mid-size simple refill (ENV: HAKMEM_TINY_MID_REFILL_SIMPLE)
|
|
|
|
|
|
static inline int tiny_mid_refill_simple_enabled(void) {
|
|
|
|
|
|
static int v = -1;
|
|
|
|
|
|
if (__builtin_expect(v == -1, 0)) {
|
|
|
|
|
|
const char* s = getenv("HAKMEM_TINY_MID_REFILL_SIMPLE");
|
|
|
|
|
|
v = (s && *s && *s != '0') ? 1 : 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
return v;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-30 11:06:44 +09:00
|
|
|
|
#include "box/tiny_adopt_refill_box.h" // adopt/refill 境界の集約(Step 5)
|
|
|
|
|
|
|
2025-11-05 12:31:14 +09:00
|
|
|
|
// Try a quick adopt from sticky/hot/bench/mailbox (single pass)
|
|
|
|
|
|
static inline SuperSlab* tiny_refill_try_fast(int class_idx, TinyTLSSlab* tls) {
|
2025-11-30 11:06:44 +09:00
|
|
|
|
return tiny_adopt_refill_box(class_idx, tls);
|
2025-11-05 12:31:14 +09:00
|
|
|
|
}
|