Fix C7 warm/TLS Release path and unify debug instrumentation
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include "../hakmem_tiny_config.h"
|
||||
#include "../box/tiny_page_box.h" // For tiny_page_box_on_new_slab()
|
||||
#include <stdio.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
// Forward declaration if not included
|
||||
// CRITICAL FIX: type must match core/hakmem_tiny_config.h (const size_t, not uint16_t)
|
||||
@ -64,9 +65,7 @@ static inline int ss_tls_bind_one(int class_idx,
|
||||
// superslab_init_slab() only sets it if meta->class_idx==255.
|
||||
// We must explicitly set it to the requested class to avoid C0/C7 confusion.
|
||||
TinySlabMeta* meta = &ss->slabs[slab_idx];
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
uint8_t old_cls = meta->class_idx;
|
||||
#endif
|
||||
meta->class_idx = (uint8_t)class_idx;
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
if (class_idx == 7 && old_cls != class_idx) {
|
||||
@ -75,6 +74,36 @@ static inline int ss_tls_bind_one(int class_idx,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAKMEM_BUILD_RELEASE
|
||||
static _Atomic int rel_c7_bind_logged = 0;
|
||||
if (class_idx == 7 &&
|
||||
atomic_load_explicit(&rel_c7_bind_logged, memory_order_relaxed) == 0) {
|
||||
fprintf(stderr,
|
||||
"[REL_C7_BIND] ss=%p slab=%d cls=%u cap=%u used=%u carved=%u\n",
|
||||
(void*)ss,
|
||||
slab_idx,
|
||||
(unsigned)meta->class_idx,
|
||||
(unsigned)meta->capacity,
|
||||
(unsigned)meta->used,
|
||||
(unsigned)meta->carved);
|
||||
atomic_store_explicit(&rel_c7_bind_logged, 1, memory_order_relaxed);
|
||||
}
|
||||
#else
|
||||
static __thread int dbg_c7_bind_logged = 0;
|
||||
if (class_idx == 7 && dbg_c7_bind_logged == 0) {
|
||||
fprintf(stderr,
|
||||
"[DBG_C7_BIND] ss=%p slab=%d old_cls=%u new_cls=%u cap=%u used=%u carved=%u\n",
|
||||
(void*)ss,
|
||||
slab_idx,
|
||||
(unsigned)old_cls,
|
||||
(unsigned)meta->class_idx,
|
||||
(unsigned)meta->capacity,
|
||||
(unsigned)meta->used,
|
||||
(unsigned)meta->carved);
|
||||
dbg_c7_bind_logged = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Bind this slab to TLS for fast subsequent allocations.
|
||||
// Inline implementation of tiny_tls_bind_slab() to avoid header dependencies.
|
||||
// Original logic:
|
||||
@ -109,4 +138,4 @@ static inline int ss_tls_bind_one(int class_idx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // HAK_SS_TLS_BIND_BOX_H
|
||||
#endif // HAK_SS_TLS_BIND_BOX_H
|
||||
|
||||
Reference in New Issue
Block a user