Files
hakmem/core/box/ptr_conversion_box.h

84 lines
2.6 KiB
C
Raw Normal View History

Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
/**
* @file ptr_conversion_box.h
* @brief Box 3: Unified Pointer Conversion Layer
*
* MISSION: Fix BASE/USER pointer confusion across codebase
*
* DESIGN:
* - BASE pointer: Points to start of block in storage (0-byte aligned)
* - USER pointer: Points to usable memory (+1 byte for classes 0-6, +0 for class 7)
* - Class 7 (2KB) is headerless (no +1 offset)
* - Classes 0-6 have 1-byte header (need +1 offset)
*
* BOX BOUNDARIES:
* - Box 1 (Front Gate) Box 3 Box 4 (User) [BASE to USER]
* - Box 4 (User) Box 3 Box 1 (Front Gate) [USER to BASE]
*/
#ifndef HAKMEM_PTR_CONVERSION_BOX_H
#define HAKMEM_PTR_CONVERSION_BOX_H
#include <stdint.h>
#include <stddef.h>
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
#include "ptr_type_box.h"
#include "tiny_layout_box.h"
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
#ifdef HAKMEM_PTR_CONVERSION_DEBUG
#include <stdio.h>
#define PTR_CONV_LOG(...) fprintf(stderr, "[PTR_CONV] " __VA_ARGS__)
#else
#define PTR_CONV_LOG(...) ((void)0)
#endif
/**
* Convert BASE pointer (storage) to USER pointer (returned to caller)
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
* Phase E1-CORRECT: Offsets defined in tiny_layout_box.h
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
*
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
* @param base Block start in storage (wrapped hak_base_ptr_t)
* @param class_idx Size class
* @return User pointer (wrapped hak_user_ptr_t)
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
*/
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
static inline hak_user_ptr_t ptr_base_to_user(hak_base_ptr_t base, int class_idx) {
void* raw_base = HAK_BASE_TO_RAW(base);
if (raw_base == NULL) {
return HAK_USER_FROM_RAW(NULL);
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
}
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
size_t offset = tiny_user_offset(class_idx);
void* raw_user = (void*)((uint8_t*)raw_base + offset);
PTR_CONV_LOG("BASE→USER cls=%d base=%p → user=%p (+%zu)\n",
class_idx, raw_base, raw_user, offset);
return HAK_USER_FROM_RAW(raw_user);
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
}
/**
* Convert USER pointer (from caller) to BASE pointer (storage)
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
* Phase E1-CORRECT: Offsets defined in tiny_layout_box.h
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
*
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
* @param user Pointer from user (wrapped hak_user_ptr_t)
* @param class_idx Size class
* @return Base pointer (wrapped hak_base_ptr_t)
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
*/
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
static inline hak_base_ptr_t ptr_user_to_base(hak_user_ptr_t user, int class_idx) {
void* raw_user = HAK_USER_TO_RAW(user);
if (raw_user == NULL) {
return HAK_BASE_FROM_RAW(NULL);
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
}
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅ Summary: - Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions - Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization) - Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support - Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking Verification Results (by Task Agent): - Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented - Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed - Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned - Performance: 0 bytes, 0 cycles overhead in Release build - Build Status: ✅ Success (526KB libhakmem.so, zero warnings) Key Achievements: 1. Single Source of Truth principle fully implemented 2. Circular dependency eliminated (layout→header→nextptr→conversion) 3. Release build: 100% inlining, zero overhead 4. Debug build: Full type checking with Phantom Types 5. HAK_RET_ALLOC macro migrated to Box API Known Issues (unrelated to Phase 1): - TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2) Next Steps: - Phase 2 readiness: ✅ READY - Recommended: Create migration guide + runtime test suite - Alignment guarantee will be addressed in Phase 2 (Headerless layout) 🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification) Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:38:11 +09:00
size_t offset = tiny_user_offset(class_idx);
void* raw_base = (void*)((uint8_t*)raw_user - offset);
PTR_CONV_LOG("USER→BASE cls=%d user=%p → base=%p (-%zu)\n",
class_idx, raw_user, raw_base, offset);
return HAK_BASE_FROM_RAW(raw_base);
Add Box 3 (Pointer Conversion Layer) and fix POOL_TLS_PHASE1 default ## Major Changes ### 1. Box 3: Pointer Conversion Module (NEW) - File: core/box/ptr_conversion_box.h - Purpose: Unified BASE ↔ USER pointer conversion (single source of truth) - API: PTR_BASE_TO_USER(), PTR_USER_TO_BASE() - Features: Zero-overhead inline, debug mode, NULL-safe, class 7 headerless support - Design: Header-only, fully modular, no external dependencies ### 2. POOL_TLS_PHASE1 Default OFF (CRITICAL FIX) - File: build.sh - Change: POOL_TLS_PHASE1 now defaults to 0 (was hardcoded to 1) - Impact: Eliminates pthread_mutex overhead on every free() (was causing 3.3x slowdown) - Usage: Set POOL_TLS_PHASE1=1 env var to enable if needed ### 3. Pointer Conversion Fixes (PARTIAL) - Files: core/box/front_gate_box.c, core/tiny_alloc_fast.inc.h, etc. - Status: Partial implementation using Box 3 API - Note: Work in progress, some conversions still need review ### 4. Performance Investigation Report (NEW) - File: HOTPATH_PERFORMANCE_INVESTIGATION.md - Findings: - Hotpath works (+24% vs baseline) after POOL_TLS fix - Still 9.2x slower than system malloc due to: * Heavy initialization (23.85% of cycles) * Syscall overhead (2,382 syscalls per 100K ops) * Workload mismatch (C7 1KB is 49.8%, but only C5 256B has hotpath) * 9.4x more instructions than system malloc ### 5. Known Issues - SEGV at 20K-30K iterations (pre-existing bug, not related to pointer conversions) - Root cause: Likely active counter corruption or TLS-SLL chain issues - Status: Under investigation ## Performance Results (100K iterations, 256B) - Baseline (Hotpath OFF): 7.22M ops/s - Hotpath ON: 8.98M ops/s (+24% improvement ✓) - System malloc: 82.2M ops/s (still 9.2x faster) ## Next Steps - P0: Fix 20K-30K SEGV bug (GDB investigation needed) - P1: Lazy initialization (+20-25% expected) - P1: C7 (1KB) hotpath (+30-40% expected, biggest win) - P2: Reduce syscalls (+15-20% expected) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 01:01:23 +09:00
}
/**
* Convenience macros for cleaner call sites
*/
#define PTR_BASE_TO_USER(base, cls) ptr_base_to_user((base), (cls))
#define PTR_USER_TO_BASE(user, cls) ptr_user_to_base((user), (cls))
#endif /* HAKMEM_PTR_CONVERSION_BOX_H */