87 lines
2.8 KiB
C
87 lines
2.8 KiB
C
// pool_hotbox_v2_box.h — Experimental PoolHotBox v2 (hot path scaffold)
|
|
#ifndef POOL_HOTBOX_V2_BOX_H
|
|
#define POOL_HOTBOX_V2_BOX_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdatomic.h>
|
|
|
|
#include "hakmem_pool.h" // for POOL_NUM_CLASSES and size helpers
|
|
|
|
// ENV gates (bench/実験専用):
|
|
// HAKMEM_POOL_V2_ENABLED : overall ON/OFF (default OFF)
|
|
// HAKMEM_POOL_V2_CLASSES : bitmask, bit i=1 → class i を HotBox v2 に載せる
|
|
// HAKMEM_POOL_V2_STATS : stats dump ON/OFF
|
|
|
|
typedef struct PoolHotBoxV2Stats {
|
|
_Atomic uint64_t alloc_calls;
|
|
_Atomic uint64_t alloc_fast;
|
|
_Atomic uint64_t alloc_refill;
|
|
_Atomic uint64_t alloc_refill_fail;
|
|
_Atomic uint64_t alloc_fallback_v1;
|
|
_Atomic uint64_t free_calls;
|
|
_Atomic uint64_t free_fast;
|
|
_Atomic uint64_t free_fallback_v1;
|
|
_Atomic uint64_t page_of_fail_header_missing;
|
|
_Atomic uint64_t page_of_fail_out_of_range;
|
|
_Atomic uint64_t page_of_fail_misaligned;
|
|
_Atomic uint64_t page_of_fail_unknown;
|
|
} PoolHotBoxV2Stats;
|
|
|
|
// Simple page/class structs for future HotBox v2 implementation.
|
|
typedef struct pool_page_v2 {
|
|
void* freelist;
|
|
uint32_t used;
|
|
uint32_t capacity;
|
|
uint32_t block_size;
|
|
uint32_t class_idx;
|
|
void* base;
|
|
void* slab_ref;
|
|
struct pool_page_v2* next;
|
|
} pool_page_v2;
|
|
|
|
typedef struct pool_class_v2 {
|
|
pool_page_v2* current;
|
|
pool_page_v2* partial;
|
|
uint16_t max_partial_pages;
|
|
uint16_t partial_count;
|
|
uint32_t block_size;
|
|
} pool_class_v2;
|
|
|
|
typedef struct pool_ctx_v2 {
|
|
pool_class_v2 cls[POOL_NUM_CLASSES];
|
|
} pool_ctx_v2;
|
|
|
|
typedef struct PoolColdIface {
|
|
void* (*refill_page)(void* cold_ctx,
|
|
uint32_t class_idx,
|
|
uint32_t* out_block_size,
|
|
uint32_t* out_capacity,
|
|
void** out_slab_ref);
|
|
void (*retire_page)(void* cold_ctx,
|
|
uint32_t class_idx,
|
|
void* slab_ref,
|
|
void* base);
|
|
} PoolColdIface;
|
|
|
|
// ENV helpers
|
|
int pool_hotbox_v2_class_enabled(int class_idx);
|
|
int pool_hotbox_v2_stats_enabled(void);
|
|
|
|
// TLS/context helpers
|
|
pool_ctx_v2* pool_v2_tls_get(void);
|
|
|
|
// Hot path (currently stubbed to always fall back to v1; structure only)
|
|
void* pool_hotbox_v2_alloc(uint32_t class_idx, size_t size, uintptr_t site_id);
|
|
int pool_hotbox_v2_free(uint32_t class_idx, void* raw_block);
|
|
|
|
// Stats helpers
|
|
void pool_hotbox_v2_record_free_call(uint32_t class_idx);
|
|
void pool_hotbox_v2_record_alloc_fallback(uint32_t class_idx);
|
|
void pool_hotbox_v2_record_free_fallback(uint32_t class_idx);
|
|
|
|
// Stats export (destructor in hakmem_pool.c)
|
|
extern PoolHotBoxV2Stats g_pool_hotbox_v2_stats[POOL_NUM_CLASSES];
|
|
|
|
#endif // POOL_HOTBOX_V2_BOX_H
|