mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-24 04:34:59 -07:00
unwind cache -> callstack cache
This commit is contained in:
+27
-27
@@ -1432,14 +1432,14 @@ ctrl_init(void)
|
||||
ctrl_state->thread_reg_cache.stripes[idx].arena = arena_alloc();
|
||||
ctrl_state->thread_reg_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
}
|
||||
ctrl_state->unwind_cache.slots_count = 1024;
|
||||
ctrl_state->unwind_cache.slots = push_array(arena, CTRL_UnwindCacheSlot, ctrl_state->unwind_cache.slots_count);
|
||||
ctrl_state->unwind_cache.stripes_count = os_get_system_info()->logical_processor_count;
|
||||
ctrl_state->unwind_cache.stripes = push_array(arena, CTRL_UnwindCacheStripe, ctrl_state->unwind_cache.stripes_count);
|
||||
for(U64 idx = 0; idx < ctrl_state->unwind_cache.stripes_count; idx += 1)
|
||||
ctrl_state->call_stack_cache.slots_count = 1024;
|
||||
ctrl_state->call_stack_cache.slots = push_array(arena, CTRL_CallStackCacheSlot, ctrl_state->call_stack_cache.slots_count);
|
||||
ctrl_state->call_stack_cache.stripes_count = os_get_system_info()->logical_processor_count;
|
||||
ctrl_state->call_stack_cache.stripes = push_array(arena, CTRL_CallStackCacheStripe, ctrl_state->call_stack_cache.stripes_count);
|
||||
for(U64 idx = 0; idx < ctrl_state->call_stack_cache.stripes_count; idx += 1)
|
||||
{
|
||||
ctrl_state->unwind_cache.stripes[idx].arena = arena_alloc();
|
||||
ctrl_state->unwind_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
ctrl_state->call_stack_cache.stripes[idx].arena = arena_alloc();
|
||||
ctrl_state->call_stack_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||
}
|
||||
ctrl_state->module_image_info_cache.slots_count = 1024;
|
||||
ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, ctrl_state->module_image_info_cache.slots_count);
|
||||
@@ -1484,10 +1484,10 @@ ctrl_init(void)
|
||||
ctrl_state->u2ms_ring_base = push_array(arena, U8, ctrl_state->u2ms_ring_size);
|
||||
ctrl_state->u2ms_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2ms_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->u2uw_ring_size = KB(64);
|
||||
ctrl_state->u2uw_ring_base = push_array(arena, U8, ctrl_state->u2uw_ring_size);
|
||||
ctrl_state->u2uw_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2uw_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->u2csb_ring_size = KB(64);
|
||||
ctrl_state->u2csb_ring_base = push_array(arena, U8, ctrl_state->u2csb_ring_size);
|
||||
ctrl_state->u2csb_ring_mutex = os_mutex_alloc();
|
||||
ctrl_state->u2csb_ring_cv = os_condition_variable_alloc();
|
||||
ctrl_state->ctrl_thread_log = log_alloc();
|
||||
ctrl_state->ctrl_thread = os_thread_launch(ctrl_thread__entry_point, 0, 0);
|
||||
}
|
||||
@@ -6554,57 +6554,57 @@ ASYNC_WORK_DEF(ctrl_mem_stream_work)
|
||||
//- rjf: user -> memory stream communication
|
||||
|
||||
internal B32
|
||||
ctrl_u2uw_enqueue_req(CTRL_Handle thread, U64 endt_us)
|
||||
ctrl_u2csb_enqueue_req(CTRL_Handle thread, U64 endt_us)
|
||||
{
|
||||
B32 good = 0;
|
||||
OS_MutexScope(ctrl_state->u2uw_ring_mutex) for(;;)
|
||||
OS_MutexScope(ctrl_state->u2csb_ring_mutex) for(;;)
|
||||
{
|
||||
U64 unconsumed_size = ctrl_state->u2uw_ring_write_pos - ctrl_state->u2uw_ring_read_pos;
|
||||
U64 available_size = ctrl_state->u2uw_ring_size - unconsumed_size;
|
||||
U64 unconsumed_size = ctrl_state->u2csb_ring_write_pos - ctrl_state->u2csb_ring_read_pos;
|
||||
U64 available_size = ctrl_state->u2csb_ring_size - unconsumed_size;
|
||||
if(available_size >= sizeof(thread))
|
||||
{
|
||||
good = 1;
|
||||
ctrl_state->u2uw_ring_write_pos += ring_write_struct(ctrl_state->u2uw_ring_base, ctrl_state->u2uw_ring_size, ctrl_state->u2uw_ring_write_pos, &thread);
|
||||
ctrl_state->u2csb_ring_write_pos += ring_write_struct(ctrl_state->u2csb_ring_base, ctrl_state->u2csb_ring_size, ctrl_state->u2csb_ring_write_pos, &thread);
|
||||
break;
|
||||
}
|
||||
if(os_now_microseconds() >= endt_us)
|
||||
{
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2uw_ring_cv, ctrl_state->u2uw_ring_mutex, endt_us);
|
||||
os_condition_variable_wait(ctrl_state->u2csb_ring_cv, ctrl_state->u2csb_ring_mutex, endt_us);
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
os_condition_variable_broadcast(ctrl_state->u2uw_ring_cv);
|
||||
os_condition_variable_broadcast(ctrl_state->u2csb_ring_cv);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
|
||||
internal void
|
||||
ctrl_u2uw_dequeue_req(CTRL_Handle *out_thread)
|
||||
ctrl_u2csb_dequeue_req(CTRL_Handle *out_thread)
|
||||
{
|
||||
OS_MutexScope(ctrl_state->u2uw_ring_mutex) for(;;)
|
||||
OS_MutexScope(ctrl_state->u2csb_ring_mutex) for(;;)
|
||||
{
|
||||
U64 unconsumed_size = ctrl_state->u2uw_ring_write_pos - ctrl_state->u2uw_ring_read_pos;
|
||||
U64 unconsumed_size = ctrl_state->u2csb_ring_write_pos - ctrl_state->u2csb_ring_read_pos;
|
||||
if(unconsumed_size >= sizeof(*out_thread))
|
||||
{
|
||||
ctrl_state->u2uw_ring_read_pos += ring_read_struct(ctrl_state->u2uw_ring_base, ctrl_state->u2uw_ring_size, ctrl_state->u2uw_ring_read_pos, out_thread);
|
||||
ctrl_state->u2csb_ring_read_pos += ring_read_struct(ctrl_state->u2csb_ring_base, ctrl_state->u2csb_ring_size, ctrl_state->u2csb_ring_read_pos, out_thread);
|
||||
break;
|
||||
}
|
||||
os_condition_variable_wait(ctrl_state->u2uw_ring_cv, ctrl_state->u2uw_ring_mutex, max_U64);
|
||||
os_condition_variable_wait(ctrl_state->u2csb_ring_cv, ctrl_state->u2csb_ring_mutex, max_U64);
|
||||
}
|
||||
os_condition_variable_broadcast(ctrl_state->u2uw_ring_cv);
|
||||
os_condition_variable_broadcast(ctrl_state->u2csb_ring_cv);
|
||||
}
|
||||
|
||||
//- rjf: entry point
|
||||
|
||||
ASYNC_WORK_DEF(ctrl_unwind_work)
|
||||
ASYNC_WORK_DEF(ctrl_call_stack_build_work)
|
||||
{
|
||||
CTRL_UnwindCache *cache = &ctrl_state->unwind_cache;
|
||||
CTRL_CallStackCache *cache = &ctrl_state->call_stack_cache;
|
||||
|
||||
//- rjf: get next request
|
||||
CTRL_Handle thread_handle = {0};
|
||||
ctrl_u2uw_dequeue_req(&thread_handle);
|
||||
ctrl_u2csb_dequeue_req(&thread_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+28
-27
@@ -590,41 +590,42 @@ struct CTRL_ThreadRegCache
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Unwind Cache Types
|
||||
//~ rjf: Call Stack Cache Types
|
||||
|
||||
typedef struct CTRL_UnwindCacheNode CTRL_UnwindCacheNode;
|
||||
struct CTRL_UnwindCacheNode
|
||||
typedef struct CTRL_CallStackCacheNode CTRL_CallStackCacheNode;
|
||||
struct CTRL_CallStackCacheNode
|
||||
{
|
||||
CTRL_UnwindCacheNode *next;
|
||||
CTRL_UnwindCacheNode *prev;
|
||||
CTRL_CallStackCacheNode *next;
|
||||
CTRL_CallStackCacheNode *prev;
|
||||
Arena *arena;
|
||||
CTRL_Handle thread;
|
||||
U64 reg_gen;
|
||||
U64 mem_gen;
|
||||
CTRL_Unwind unwind;
|
||||
CTRL_CallStack call_stack;
|
||||
};
|
||||
|
||||
typedef struct CTRL_UnwindCacheSlot CTRL_UnwindCacheSlot;
|
||||
struct CTRL_UnwindCacheSlot
|
||||
typedef struct CTRL_CallStackCacheSlot CTRL_CallStackCacheSlot;
|
||||
struct CTRL_CallStackCacheSlot
|
||||
{
|
||||
CTRL_UnwindCacheNode *first;
|
||||
CTRL_UnwindCacheNode *last;
|
||||
CTRL_CallStackCacheNode *first;
|
||||
CTRL_CallStackCacheNode *last;
|
||||
};
|
||||
|
||||
typedef struct CTRL_UnwindCacheStripe CTRL_UnwindCacheStripe;
|
||||
struct CTRL_UnwindCacheStripe
|
||||
typedef struct CTRL_CallStackCacheStripe CTRL_CallStackCacheStripe;
|
||||
struct CTRL_CallStackCacheStripe
|
||||
{
|
||||
Arena *arena;
|
||||
OS_Handle rw_mutex;
|
||||
};
|
||||
|
||||
typedef struct CTRL_UnwindCache CTRL_UnwindCache;
|
||||
struct CTRL_UnwindCache
|
||||
typedef struct CTRL_CallStackCache CTRL_CallStackCache;
|
||||
struct CTRL_CallStackCache
|
||||
{
|
||||
U64 slots_count;
|
||||
CTRL_UnwindCacheSlot *slots;
|
||||
CTRL_CallStackCacheSlot *slots;
|
||||
U64 stripes_count;
|
||||
CTRL_UnwindCacheStripe *stripes;
|
||||
CTRL_CallStackCacheStripe *stripes;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -720,7 +721,7 @@ struct CTRL_State
|
||||
// rjf: caches
|
||||
CTRL_ProcessMemoryCache process_memory_cache;
|
||||
CTRL_ThreadRegCache thread_reg_cache;
|
||||
CTRL_UnwindCache unwind_cache;
|
||||
CTRL_CallStackCache call_stack_cache;
|
||||
CTRL_ModuleImageInfoCache module_image_info_cache;
|
||||
|
||||
// rjf: user -> ctrl msg ring buffer
|
||||
@@ -765,13 +766,13 @@ struct CTRL_State
|
||||
OS_Handle u2ms_ring_mutex;
|
||||
OS_Handle u2ms_ring_cv;
|
||||
|
||||
// rjf: user -> unwind ring buffer
|
||||
U64 u2uw_ring_size;
|
||||
U8 *u2uw_ring_base;
|
||||
U64 u2uw_ring_write_pos;
|
||||
U64 u2uw_ring_read_pos;
|
||||
OS_Handle u2uw_ring_mutex;
|
||||
OS_Handle u2uw_ring_cv;
|
||||
// rjf: user -> call stack builder ring buffer
|
||||
U64 u2csb_ring_size;
|
||||
U8 *u2csb_ring_base;
|
||||
U64 u2csb_ring_write_pos;
|
||||
U64 u2csb_ring_read_pos;
|
||||
OS_Handle u2csb_ring_mutex;
|
||||
OS_Handle u2csb_ring_cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -1053,13 +1054,13 @@ internal void ctrl_u2ms_dequeue_req(CTRL_Handle *out_process, Rng1U64 *out_vaddr
|
||||
ASYNC_WORK_DEF(ctrl_mem_stream_work);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Asynchronous Unwinding Functions
|
||||
//~ rjf: Asynchronous Call Stack Building Functions
|
||||
|
||||
//- rjf: user -> memory stream communication
|
||||
internal B32 ctrl_u2uw_enqueue_req(CTRL_Handle thread, U64 endt_us);
|
||||
internal void ctrl_u2uw_dequeue_req(CTRL_Handle *out_thread);
|
||||
internal B32 ctrl_u2csb_enqueue_req(CTRL_Handle thread, U64 endt_us);
|
||||
internal void ctrl_u2csb_dequeue_req(CTRL_Handle *out_thread);
|
||||
|
||||
//- rjf: entry point
|
||||
ASYNC_WORK_DEF(ctrl_unwind_work);
|
||||
ASYNC_WORK_DEF(ctrl_call_stack_build_work);
|
||||
|
||||
#endif // CTRL_CORE_H
|
||||
|
||||
@@ -56,9 +56,11 @@ dmn_w32_entity_alloc(DMN_W32_Entity *parent, DMN_W32_EntityKind kind, U64 id)
|
||||
// rjf: allocate
|
||||
DMN_W32_Entity *e = dmn_w32_shared->entities_first_free;
|
||||
{
|
||||
U32 gen = 0;
|
||||
if(e != 0)
|
||||
{
|
||||
SLLStackPop(dmn_w32_shared->entities_first_free);
|
||||
gen = e->gen;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user