Phase v4-3.1: reuse C7 v4 pages and record prep calls
This commit is contained in:
21
core/box/smallobject_cold_iface_v4.h
Normal file
21
core/box/smallobject_cold_iface_v4.h
Normal file
@ -0,0 +1,21 @@
|
||||
// smallobject_cold_iface_v4.h - SmallObject HotHeap v4 Cold Interface (境界 API のみ)
|
||||
//
|
||||
// 役割:
|
||||
// - HotBox_v4 と Superslab/Warm/Remote を繋ぐ関数ポインタの箱を定義する。
|
||||
// - 実装は後続フェーズで追加し、いまは型と宣言だけを置く。
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "smallobject_hotbox_v4_box.h"
|
||||
|
||||
typedef struct SmallColdIfaceV4 {
|
||||
small_page_v4* (*refill_page)(small_heap_ctx_v4*, uint32_t class_idx);
|
||||
void (*retire_page)(small_heap_ctx_v4*, uint32_t class_idx, small_page_v4* page);
|
||||
bool (*remote_push)(small_page_v4* page, void* ptr, uint32_t self_tid);
|
||||
void (*remote_drain)(small_heap_ctx_v4*);
|
||||
} SmallColdIfaceV4;
|
||||
|
||||
// Cold iface accessor(実装は後続フェーズ)
|
||||
const SmallColdIfaceV4* small_cold_iface_v4_get(void);
|
||||
48
core/box/smallobject_hotbox_v4_box.h
Normal file
48
core/box/smallobject_hotbox_v4_box.h
Normal file
@ -0,0 +1,48 @@
|
||||
// smallobject_hotbox_v4_box.h - SmallObject HotHeap v4 (型スケルトン)
|
||||
//
|
||||
// 役割:
|
||||
// - v4 のページ / クラス / TLS コンテキスト型と API 宣言だけを定義する箱。
|
||||
// - 挙動はまだ v3/v1 のまま。alloc/free 本体は後続フェーズで実装する。
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "tiny_geometry_box.h"
|
||||
|
||||
#ifndef SMALLOBJECT_NUM_CLASSES
|
||||
#define SMALLOBJECT_NUM_CLASSES TINY_NUM_CLASSES
|
||||
#endif
|
||||
|
||||
// Page metadata for v4 HotBox
|
||||
typedef struct small_page_v4 {
|
||||
void* freelist;
|
||||
uint16_t used;
|
||||
uint16_t capacity;
|
||||
uint8_t class_idx;
|
||||
uint8_t flags;
|
||||
uint32_t block_size;
|
||||
uint8_t* base;
|
||||
void* slab_ref; // Superslab / lease token (box境界で扱う)
|
||||
struct small_page_v4* next;
|
||||
} small_page_v4;
|
||||
|
||||
// Per-class heap state (current / partial / full lists)
|
||||
typedef struct small_class_heap_v4 {
|
||||
small_page_v4* current;
|
||||
small_page_v4* partial_head;
|
||||
small_page_v4* full_head;
|
||||
uint32_t partial_count;
|
||||
} small_class_heap_v4;
|
||||
|
||||
// TLS heap context (per-thread)
|
||||
typedef struct small_heap_ctx_v4 {
|
||||
small_class_heap_v4 cls[SMALLOBJECT_NUM_CLASSES];
|
||||
} small_heap_ctx_v4;
|
||||
|
||||
// TLS accessor (実装は後続フェーズで追加)
|
||||
small_heap_ctx_v4* small_heap_ctx_v4_get(void);
|
||||
|
||||
// Hot path API (C7-only stub; later phases will expand)
|
||||
void* small_heap_alloc_fast_v4(small_heap_ctx_v4* ctx, int class_idx);
|
||||
void small_heap_free_fast_v4(small_heap_ctx_v4* ctx, int class_idx, void* ptr);
|
||||
45
core/box/smallobject_hotbox_v4_env_box.h
Normal file
45
core/box/smallobject_hotbox_v4_env_box.h
Normal file
@ -0,0 +1,45 @@
|
||||
// smallobject_hotbox_v4_env_box.h - ENV gate for SmallObject HotHeap v4
|
||||
// デフォルト: OFF(研究用に明示 opt-in)
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../hakmem_tiny_config.h"
|
||||
|
||||
static inline int small_heap_v4_enabled(void) {
|
||||
static int g_enable = -1;
|
||||
if (__builtin_expect(g_enable == -1, 0)) {
|
||||
const char* e = getenv("HAKMEM_SMALL_HEAP_V4_ENABLED");
|
||||
if (e && *e) {
|
||||
g_enable = (*e != '0') ? 1 : 0;
|
||||
} else {
|
||||
// v4 は研究箱。明示しない限り OFF
|
||||
g_enable = 0;
|
||||
}
|
||||
}
|
||||
return g_enable;
|
||||
}
|
||||
|
||||
static inline int small_heap_v4_class_enabled(uint8_t class_idx) {
|
||||
static int g_parsed = 0;
|
||||
static unsigned g_mask = 0;
|
||||
if (__builtin_expect(!g_parsed, 0)) {
|
||||
const char* e = getenv("HAKMEM_SMALL_HEAP_V4_CLASSES");
|
||||
if (e && *e) {
|
||||
unsigned v = (unsigned)strtoul(e, NULL, 0);
|
||||
g_mask = v & 0xFFu;
|
||||
} else {
|
||||
// デフォルトは全クラス OFF
|
||||
g_mask = 0;
|
||||
}
|
||||
g_parsed = 1;
|
||||
}
|
||||
if (!small_heap_v4_enabled()) return 0;
|
||||
if (class_idx >= TINY_NUM_CLASSES) return 0;
|
||||
return (g_mask & (1u << class_idx)) != 0;
|
||||
}
|
||||
|
||||
static inline int small_heap_v4_c7_enabled(void) {
|
||||
return small_heap_v4_class_enabled(7);
|
||||
}
|
||||
@ -10,12 +10,14 @@
|
||||
#include "tiny_heap_env_box.h"
|
||||
|
||||
#include "smallobject_hotbox_v3_env_box.h"
|
||||
#include "smallobject_hotbox_v4_env_box.h"
|
||||
|
||||
typedef enum {
|
||||
TINY_ROUTE_LEGACY = 0,
|
||||
TINY_ROUTE_HEAP = 1, // TinyHeap v1
|
||||
TINY_ROUTE_HOTHEAP_V2 = 2, // TinyHotHeap v2
|
||||
TINY_ROUTE_SMALL_HEAP_V3 = 3, // SmallObject HotHeap v3 (C7-first,研究箱)
|
||||
TINY_ROUTE_SMALL_HEAP_V4 = 4, // SmallObject HotHeap v4 (stub, route未使用)
|
||||
} tiny_route_kind_t;
|
||||
|
||||
extern tiny_route_kind_t g_tiny_route_class[TINY_NUM_CLASSES];
|
||||
@ -23,7 +25,9 @@ extern int g_tiny_route_snapshot_done;
|
||||
|
||||
static inline void tiny_route_snapshot_init(void) {
|
||||
for (int i = 0; i < TINY_NUM_CLASSES; i++) {
|
||||
if (small_heap_v3_class_enabled((uint8_t)i)) {
|
||||
if (small_heap_v4_class_enabled((uint8_t)i)) {
|
||||
g_tiny_route_class[i] = TINY_ROUTE_SMALL_HEAP_V4;
|
||||
} else if (small_heap_v3_class_enabled((uint8_t)i)) {
|
||||
g_tiny_route_class[i] = TINY_ROUTE_SMALL_HEAP_V3;
|
||||
} else if (tiny_hotheap_v2_class_enabled((uint8_t)i)) {
|
||||
g_tiny_route_class[i] = TINY_ROUTE_HOTHEAP_V2;
|
||||
@ -47,7 +51,10 @@ static inline tiny_route_kind_t tiny_route_for_class(uint8_t ci) {
|
||||
}
|
||||
|
||||
static inline int tiny_route_is_heap_kind(tiny_route_kind_t route) {
|
||||
return route == TINY_ROUTE_HEAP || route == TINY_ROUTE_HOTHEAP_V2 || route == TINY_ROUTE_SMALL_HEAP_V3;
|
||||
return route == TINY_ROUTE_HEAP ||
|
||||
route == TINY_ROUTE_HOTHEAP_V2 ||
|
||||
route == TINY_ROUTE_SMALL_HEAP_V3 ||
|
||||
route == TINY_ROUTE_SMALL_HEAP_V4;
|
||||
}
|
||||
|
||||
// C7 front が TinyHeap を使うか(Route snapshot 経由で判定)
|
||||
|
||||
Reference in New Issue
Block a user