mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-26 13:35:00 -07:00
dead ctrl process memory cache elimination
This commit is contained in:
@@ -1756,202 +1756,6 @@ ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32
|
||||
return key;
|
||||
}
|
||||
|
||||
//- rjf: process memory cache interaction
|
||||
|
||||
#if 0 // TODO(rjf): @hs
|
||||
internal U128
|
||||
ctrl_calc_hash_store_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated)
|
||||
{
|
||||
U64 key_hash_data[] =
|
||||
{
|
||||
(U64)process.machine_id,
|
||||
(U64)process.dmn_handle.u64[0],
|
||||
range.min,
|
||||
range.max,
|
||||
(U64)zero_terminated,
|
||||
};
|
||||
U128 key = hs_hash_from_data(str8((U8*)key_hash_data, sizeof(key_hash_data)));
|
||||
return key;
|
||||
}
|
||||
|
||||
internal U128
|
||||
ctrl_stored_hash_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated, B32 *out_is_stale, U64 endt_us)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
U128 result = {0};
|
||||
U64 size = dim_1u64(range);
|
||||
U64 pre_mem_gen = dmn_mem_gen();
|
||||
CTRL_ProcessMemoryCache *cache = &ctrl_state->process_memory_cache;
|
||||
U64 range_hash = ctrl_hash_from_string(str8_struct(&range));
|
||||
U64 process_hash = ctrl_hash_from_string(str8_struct(&process));
|
||||
U64 process_slot_idx = process_hash%cache->slots_count;
|
||||
U64 process_stripe_idx = process_slot_idx%cache->stripes_count;
|
||||
CTRL_ProcessMemoryCacheSlot *process_slot = &cache->slots[process_slot_idx];
|
||||
CTRL_ProcessMemoryCacheStripe *process_stripe = &cache->stripes[process_stripe_idx];
|
||||
if(size != 0) for(;;)
|
||||
{
|
||||
//- rjf: try to read from cache
|
||||
B32 is_good = 0;
|
||||
B32 process_node_exists = 0;
|
||||
B32 is_stale = 1;
|
||||
OS_MutexScopeR(process_stripe->rw_mutex)
|
||||
{
|
||||
for(CTRL_ProcessMemoryCacheNode *n = process_slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(ctrl_handle_match(n->handle, process))
|
||||
{
|
||||
process_node_exists = 1;
|
||||
U64 range_slot_idx = range_hash%n->range_hash_slots_count;
|
||||
CTRL_ProcessMemoryRangeHashSlot *range_slot = &n->range_hash_slots[range_slot_idx];
|
||||
for(CTRL_ProcessMemoryRangeHashNode *range_n = range_slot->first; range_n != 0; range_n = range_n->next)
|
||||
{
|
||||
if(MemoryMatchStruct(&range_n->vaddr_range, &range) && range_n->zero_terminated == zero_terminated)
|
||||
{
|
||||
result = range_n->hash;
|
||||
is_good = 1;
|
||||
is_stale = (range_n->mem_gen != pre_mem_gen);
|
||||
goto read_cache__break_all;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
read_cache__break_all:;
|
||||
}
|
||||
|
||||
//- rjf: not good -> create process cache node if necessary
|
||||
if(!is_good && !process_node_exists)
|
||||
{
|
||||
OS_MutexScopeW(process_stripe->rw_mutex)
|
||||
{
|
||||
B32 process_node_exists = 0;
|
||||
for(CTRL_ProcessMemoryCacheNode *n = process_slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(ctrl_handle_match(n->handle, process))
|
||||
{
|
||||
process_node_exists = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!process_node_exists)
|
||||
{
|
||||
Arena *node_arena = arena_alloc();
|
||||
CTRL_ProcessMemoryCacheNode *node = push_array(node_arena, CTRL_ProcessMemoryCacheNode, 1);
|
||||
node->arena = node_arena;
|
||||
node->handle = process;
|
||||
node->range_hash_slots_count = 1024;
|
||||
node->range_hash_slots = push_array(node_arena, CTRL_ProcessMemoryRangeHashSlot, node->range_hash_slots_count);
|
||||
DLLPushBack(process_slot->first, process_slot->last, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: not good -> create range node if necessary
|
||||
U64 last_time_requested_us = 0;
|
||||
if(!is_good)
|
||||
{
|
||||
OS_MutexScopeW(process_stripe->rw_mutex)
|
||||
{
|
||||
for(CTRL_ProcessMemoryCacheNode *n = process_slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(ctrl_handle_match(n->handle, process))
|
||||
{
|
||||
U64 range_slot_idx = range_hash%n->range_hash_slots_count;
|
||||
CTRL_ProcessMemoryRangeHashSlot *range_slot = &n->range_hash_slots[range_slot_idx];
|
||||
B32 range_node_exists = 0;
|
||||
for(CTRL_ProcessMemoryRangeHashNode *range_n = range_slot->first; range_n != 0; range_n = range_n->next)
|
||||
{
|
||||
if(MemoryMatchStruct(&range_n->vaddr_range, &range) && range_n->zero_terminated == zero_terminated)
|
||||
{
|
||||
last_time_requested_us = range_n->last_time_requested_us;
|
||||
range_node_exists = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!range_node_exists)
|
||||
{
|
||||
CTRL_ProcessMemoryRangeHashNode *range_n = push_array(n->arena, CTRL_ProcessMemoryRangeHashNode, 1);
|
||||
SLLQueuePush(range_slot->first, range_slot->last, range_n);
|
||||
range_n->vaddr_range = range;
|
||||
range_n->zero_terminated = zero_terminated;
|
||||
range_n->vaddr_range_clamped = range;
|
||||
{
|
||||
range_n->vaddr_range_clamped.max = Max(range_n->vaddr_range_clamped.max, range_n->vaddr_range_clamped.min);
|
||||
U64 max_size_cap = Min(max_U64-range_n->vaddr_range_clamped.min, GB(1));
|
||||
range_n->vaddr_range_clamped.max = Min(range_n->vaddr_range_clamped.max, range_n->vaddr_range_clamped.min+max_size_cap);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: not good, or is stale -> submit hash request
|
||||
if((!is_good || is_stale) && os_now_microseconds() >= last_time_requested_us+100000)
|
||||
{
|
||||
if(ctrl_u2ms_enqueue_req(process, range, zero_terminated, endt_us))
|
||||
{
|
||||
OS_MutexScopeW(process_stripe->rw_mutex)
|
||||
{
|
||||
for(CTRL_ProcessMemoryCacheNode *n = process_slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(ctrl_handle_match(n->handle, process))
|
||||
{
|
||||
U64 range_slot_idx = range_hash%n->range_hash_slots_count;
|
||||
CTRL_ProcessMemoryRangeHashSlot *range_slot = &n->range_hash_slots[range_slot_idx];
|
||||
for(CTRL_ProcessMemoryRangeHashNode *range_n = range_slot->first; range_n != 0; range_n = range_n->next)
|
||||
{
|
||||
if(MemoryMatchStruct(&range_n->vaddr_range, &range) && range_n->zero_terminated == zero_terminated)
|
||||
{
|
||||
range_n->last_time_requested_us = os_now_microseconds();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async_push_work(ctrl_mem_stream_work);
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: out of time? -> exit
|
||||
if(os_now_microseconds() >= endt_us)
|
||||
{
|
||||
if(is_stale && out_is_stale)
|
||||
{
|
||||
out_is_stale[0] = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//- rjf: done? -> exit
|
||||
if(is_good && !is_stale)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
U64 post_mem_gen = dmn_mem_gen();
|
||||
if(post_mem_gen != pre_mem_gen && out_is_stale)
|
||||
{
|
||||
out_is_stale[0] = 1;
|
||||
}
|
||||
ProfEnd();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//- rjf: bundled key/stream helper
|
||||
|
||||
#if 0 // TODO(rjf): @hs
|
||||
internal U128
|
||||
ctrl_hash_store_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated)
|
||||
{
|
||||
U128 key = ctrl_calc_hash_store_key_from_process_vaddr_range(process, range, zero_terminated);
|
||||
ctrl_stored_hash_from_process_vaddr_range(process, range, zero_terminated, 0, 0);
|
||||
return key;
|
||||
}
|
||||
#endif
|
||||
|
||||
//- rjf: process memory cache reading helpers
|
||||
|
||||
internal CTRL_ProcessMemorySlice
|
||||
|
||||
@@ -993,17 +993,6 @@ internal void ctrl_set_wakeup_hook(CTRL_WakeupFunctionType *wakeup_hook);
|
||||
//- rjf: process memory cache key reading
|
||||
internal HS_Key ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32 zero_terminated, U64 endt_us, B32 *out_is_stale);
|
||||
|
||||
//- rjf: process memory cache interaction
|
||||
#if 0 // TODO(rjf): @hs
|
||||
internal U128 ctrl_calc_hash_store_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated);
|
||||
internal U128 ctrl_stored_hash_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated, B32 *out_is_stale, U64 endt_us);
|
||||
#endif
|
||||
|
||||
//- rjf: bundled key/stream helper
|
||||
#if 0 // TODO(rjf): @hs
|
||||
internal U128 ctrl_hash_store_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated);
|
||||
#endif
|
||||
|
||||
//- rjf: process memory cache reading helpers
|
||||
internal CTRL_ProcessMemorySlice ctrl_process_memory_slice_from_vaddr_range(Arena *arena, CTRL_Handle process, Rng1U64 range, U64 endt_us);
|
||||
internal B32 ctrl_process_memory_read(CTRL_Handle process, Rng1U64 range, B32 *is_stale_out, void *out, U64 endt_us);
|
||||
|
||||
Reference in New Issue
Block a user