mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 22:08:41 +00:00
eliminate fallback cache in text cache layer; we can use the hash store layer to rewind
This commit is contained in:
@@ -1055,7 +1055,7 @@ internal U128
|
|||||||
ctrl_hash_store_key_from_process_vaddr_range(CTRL_MachineID machine_id, DMN_Handle process, Rng1U64 range, B32 zero_terminated)
|
ctrl_hash_store_key_from_process_vaddr_range(CTRL_MachineID machine_id, DMN_Handle process, Rng1U64 range, B32 zero_terminated)
|
||||||
{
|
{
|
||||||
U128 key = ctrl_calc_hash_store_key_from_process_vaddr_range(machine_id, process, range, zero_terminated);
|
U128 key = ctrl_calc_hash_store_key_from_process_vaddr_range(machine_id, process, range, zero_terminated);
|
||||||
ctrl_stored_hash_from_process_vaddr_range(machine_id, process, range, 0, 0, 0);
|
ctrl_stored_hash_from_process_vaddr_range(machine_id, process, range, zero_terminated, 0, 0);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -686,27 +686,13 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(text)
|
|||||||
DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread);
|
DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread);
|
||||||
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
|
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
|
||||||
|
|
||||||
//- rjf: unique identifying info about this address -> unique key
|
//- rjf: unpack key for this region in memory
|
||||||
U128 text_key = {0};
|
U128 text_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vaddr_range, 1);
|
||||||
{
|
|
||||||
U64 data[] =
|
|
||||||
{
|
|
||||||
(U64)process->ctrl_machine_id,
|
|
||||||
(U64)process->ctrl_handle.u64[0],
|
|
||||||
vaddr_range.min,
|
|
||||||
vaddr_range.max,
|
|
||||||
};
|
|
||||||
text_key = hs_hash_from_data(str8((U8 *)data, sizeof(data)));
|
|
||||||
}
|
|
||||||
|
|
||||||
//- rjf: address range -> hash
|
//- rjf: key -> parsed text info
|
||||||
U128 hash = ctrl_stored_hash_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vaddr_range, 1, 0, 0);
|
U128 text_hash = {0};
|
||||||
|
TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, text_key, top.lang, &text_hash);
|
||||||
//- rjf: hash -> data
|
String8 data = hs_data_from_hash(hs_scope, text_hash);
|
||||||
String8 data = hs_data_from_hash(hs_scope, hash);
|
|
||||||
|
|
||||||
//- rjf: key * hash -> parsed text info
|
|
||||||
TXT_TextInfo info = txt_text_info_from_key_hash_lang(txt_scope, text_key, hash, top.lang);
|
|
||||||
|
|
||||||
//- rjf: info -> code slice info
|
//- rjf: info -> code slice info
|
||||||
DF_CodeSliceParams code_slice_params = {0};
|
DF_CodeSliceParams code_slice_params = {0};
|
||||||
|
|||||||
+27
-84
@@ -644,16 +644,6 @@ txt_init(void)
|
|||||||
txt_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
txt_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||||
txt_shared->stripes[idx].cv = os_condition_variable_alloc();
|
txt_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||||
}
|
}
|
||||||
txt_shared->fallback_slots_count = 256;
|
|
||||||
txt_shared->fallback_stripes_count = Min(txt_shared->fallback_slots_count, os_logical_core_count());
|
|
||||||
txt_shared->fallback_slots = push_array(arena, TXT_KeyFallbackSlot, txt_shared->fallback_slots_count);
|
|
||||||
txt_shared->fallback_stripes = push_array(arena, TXT_Stripe, txt_shared->fallback_stripes_count);
|
|
||||||
for(U64 idx = 0; idx < txt_shared->fallback_stripes_count; idx += 1)
|
|
||||||
{
|
|
||||||
txt_shared->fallback_stripes[idx].arena = arena_alloc();
|
|
||||||
txt_shared->fallback_stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
|
||||||
txt_shared->fallback_stripes[idx].cv = os_condition_variable_alloc();
|
|
||||||
}
|
|
||||||
txt_shared->u2p_ring_size = KB(64);
|
txt_shared->u2p_ring_size = KB(64);
|
||||||
txt_shared->u2p_ring_base = push_array_no_zero(arena, U8, txt_shared->u2p_ring_size);
|
txt_shared->u2p_ring_base = push_array_no_zero(arena, U8, txt_shared->u2p_ring_size);
|
||||||
txt_shared->u2p_ring_cv = os_condition_variable_alloc();
|
txt_shared->u2p_ring_cv = os_condition_variable_alloc();
|
||||||
@@ -767,7 +757,7 @@ txt_scope_touch_node__stripe_r_guarded(TXT_Scope *scope, TXT_Node *node)
|
|||||||
//~ rjf: Cache Lookups
|
//~ rjf: Cache Lookups
|
||||||
|
|
||||||
internal TXT_TextInfo
|
internal TXT_TextInfo
|
||||||
txt_text_info_from_key_hash_lang(TXT_Scope *scope, U128 key, U128 hash, TXT_LangKind lang)
|
txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang)
|
||||||
{
|
{
|
||||||
TXT_TextInfo info = {0};
|
TXT_TextInfo info = {0};
|
||||||
if(!u128_match(hash, u128_zero()))
|
if(!u128_match(hash, u128_zero()))
|
||||||
@@ -825,63 +815,46 @@ txt_text_info_from_key_hash_lang(TXT_Scope *scope, U128 key, U128 hash, TXT_Lang
|
|||||||
}
|
}
|
||||||
if(node_is_new)
|
if(node_is_new)
|
||||||
{
|
{
|
||||||
txt_u2p_enqueue_req(key, hash, lang, max_U64);
|
txt_u2p_enqueue_req(hash, lang, max_U64);
|
||||||
}
|
|
||||||
if(!found)
|
|
||||||
{
|
|
||||||
U128 fallback_hash = {0};
|
|
||||||
TXT_LangKind fallback_lang = TXT_LangKind_Null;
|
|
||||||
U64 fallback_slot_idx = key.u64[1]%txt_shared->fallback_slots_count;
|
|
||||||
U64 fallback_stripe_idx = fallback_slot_idx%txt_shared->fallback_stripes_count;
|
|
||||||
TXT_KeyFallbackSlot *fallback_slot = &txt_shared->fallback_slots[fallback_slot_idx];
|
|
||||||
TXT_Stripe *fallback_stripe = &txt_shared->fallback_stripes[fallback_stripe_idx];
|
|
||||||
OS_MutexScopeR(fallback_stripe->rw_mutex) for(TXT_KeyFallbackNode *n = fallback_slot->first; n != 0; n = n->next)
|
|
||||||
{
|
|
||||||
if(u128_match(key, n->key))
|
|
||||||
{
|
|
||||||
fallback_hash = n->hash;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!u128_match(fallback_hash, u128_zero()))
|
|
||||||
{
|
|
||||||
U64 retry_slot_idx = fallback_hash.u64[1]%txt_shared->slots_count;
|
|
||||||
U64 retry_stripe_idx = retry_slot_idx%txt_shared->stripes_count;
|
|
||||||
TXT_Slot *retry_slot = &txt_shared->slots[retry_slot_idx];
|
|
||||||
TXT_Stripe *retry_stripe = &txt_shared->stripes[retry_stripe_idx];
|
|
||||||
OS_MutexScopeR(retry_stripe->rw_mutex)
|
|
||||||
{
|
|
||||||
for(TXT_Node *n = retry_slot->first; n != 0; n = n->next)
|
|
||||||
{
|
|
||||||
if(u128_match(fallback_hash, n->hash) && fallback_lang == n->lang)
|
|
||||||
{
|
|
||||||
MemoryCopyStruct(&info, &n->info);
|
|
||||||
txt_scope_touch_node__stripe_r_guarded(scope, n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal TXT_TextInfo
|
||||||
|
txt_text_info_from_key_lang(TXT_Scope *scope, U128 key, TXT_LangKind lang, U128 *hash_out)
|
||||||
|
{
|
||||||
|
TXT_TextInfo result = {0};
|
||||||
|
for(U64 rewind_idx = 0; rewind_idx < 2; rewind_idx += 1)
|
||||||
|
{
|
||||||
|
U128 hash = hs_hash_from_key(key, rewind_idx);
|
||||||
|
result = txt_text_info_from_hash_lang(scope, hash, lang);
|
||||||
|
if(result.lines_count != 0)
|
||||||
|
{
|
||||||
|
if(hash_out)
|
||||||
|
{
|
||||||
|
*hash_out = hash;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Transfer Threads
|
//~ rjf: Transfer Threads
|
||||||
|
|
||||||
internal B32
|
internal B32
|
||||||
txt_u2p_enqueue_req(U128 key, U128 hash, TXT_LangKind lang, U64 endt_us)
|
txt_u2p_enqueue_req(U128 hash, TXT_LangKind lang, U64 endt_us)
|
||||||
{
|
{
|
||||||
B32 good = 0;
|
B32 good = 0;
|
||||||
OS_MutexScope(txt_shared->u2p_ring_mutex) for(;;)
|
OS_MutexScope(txt_shared->u2p_ring_mutex) for(;;)
|
||||||
{
|
{
|
||||||
U64 unconsumed_size = txt_shared->u2p_ring_write_pos - txt_shared->u2p_ring_read_pos;
|
U64 unconsumed_size = txt_shared->u2p_ring_write_pos - txt_shared->u2p_ring_read_pos;
|
||||||
U64 available_size = txt_shared->u2p_ring_size - unconsumed_size;
|
U64 available_size = txt_shared->u2p_ring_size - unconsumed_size;
|
||||||
if(available_size >= sizeof(key)+sizeof(hash))
|
if(available_size >= sizeof(hash)+sizeof(lang))
|
||||||
{
|
{
|
||||||
good = 1;
|
good = 1;
|
||||||
txt_shared->u2p_ring_write_pos += ring_write_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_write_pos, &key);
|
|
||||||
txt_shared->u2p_ring_write_pos += ring_write_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_write_pos, &hash);
|
txt_shared->u2p_ring_write_pos += ring_write_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_write_pos, &hash);
|
||||||
txt_shared->u2p_ring_write_pos += ring_write_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_write_pos, &lang);
|
txt_shared->u2p_ring_write_pos += ring_write_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_write_pos, &lang);
|
||||||
break;
|
break;
|
||||||
@@ -900,14 +873,13 @@ txt_u2p_enqueue_req(U128 key, U128 hash, TXT_LangKind lang, U64 endt_us)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
txt_u2p_dequeue_req(U128 *key_out, U128 *hash_out, TXT_LangKind *lang_out)
|
txt_u2p_dequeue_req(U128 *hash_out, TXT_LangKind *lang_out)
|
||||||
{
|
{
|
||||||
OS_MutexScope(txt_shared->u2p_ring_mutex) for(;;)
|
OS_MutexScope(txt_shared->u2p_ring_mutex) for(;;)
|
||||||
{
|
{
|
||||||
U64 unconsumed_size = txt_shared->u2p_ring_write_pos - txt_shared->u2p_ring_read_pos;
|
U64 unconsumed_size = txt_shared->u2p_ring_write_pos - txt_shared->u2p_ring_read_pos;
|
||||||
if(unconsumed_size >= sizeof(*key_out) + sizeof(*hash_out))
|
if(unconsumed_size >= sizeof(*hash_out) + sizeof(*lang_out))
|
||||||
{
|
{
|
||||||
txt_shared->u2p_ring_read_pos += ring_read_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_read_pos, key_out);
|
|
||||||
txt_shared->u2p_ring_read_pos += ring_read_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_read_pos, hash_out);
|
txt_shared->u2p_ring_read_pos += ring_read_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_read_pos, hash_out);
|
||||||
txt_shared->u2p_ring_read_pos += ring_read_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_read_pos, lang_out);
|
txt_shared->u2p_ring_read_pos += ring_read_struct(txt_shared->u2p_ring_base, txt_shared->u2p_ring_size, txt_shared->u2p_ring_read_pos, lang_out);
|
||||||
break;
|
break;
|
||||||
@@ -925,10 +897,9 @@ txt_parse_thread__entry_point(void *p)
|
|||||||
HS_Scope *scope = hs_scope_open();
|
HS_Scope *scope = hs_scope_open();
|
||||||
|
|
||||||
//- rjf: get next key
|
//- rjf: get next key
|
||||||
U128 key = {0};
|
|
||||||
U128 hash = {0};
|
U128 hash = {0};
|
||||||
TXT_LangKind lang = TXT_LangKind_Null;
|
TXT_LangKind lang = TXT_LangKind_Null;
|
||||||
txt_u2p_dequeue_req(&key, &hash, &lang);
|
txt_u2p_dequeue_req(&hash, &lang);
|
||||||
|
|
||||||
//- rjf: unpack hash
|
//- rjf: unpack hash
|
||||||
U64 slot_idx = hash.u64[1]%txt_shared->slots_count;
|
U64 slot_idx = hash.u64[1]%txt_shared->slots_count;
|
||||||
@@ -1057,34 +1028,6 @@ txt_parse_thread__entry_point(void *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: commit this key/hash pair to fallback cache
|
|
||||||
if(got_task && !u128_match(key, u128_zero()) && !u128_match(hash, u128_zero()))
|
|
||||||
{
|
|
||||||
U64 fallback_slot_idx = key.u64[1]%txt_shared->fallback_slots_count;
|
|
||||||
U64 fallback_stripe_idx = fallback_slot_idx%txt_shared->fallback_stripes_count;
|
|
||||||
TXT_KeyFallbackSlot *fallback_slot = &txt_shared->fallback_slots[fallback_slot_idx];
|
|
||||||
TXT_Stripe *fallback_stripe = &txt_shared->fallback_stripes[fallback_stripe_idx];
|
|
||||||
OS_MutexScopeW(fallback_stripe->rw_mutex)
|
|
||||||
{
|
|
||||||
TXT_KeyFallbackNode *node = 0;
|
|
||||||
for(TXT_KeyFallbackNode *n = fallback_slot->first; n != 0; n = n->next)
|
|
||||||
{
|
|
||||||
if(u128_match(n->key, key))
|
|
||||||
{
|
|
||||||
node = n;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(node == 0)
|
|
||||||
{
|
|
||||||
node = push_array(fallback_stripe->arena, TXT_KeyFallbackNode, 1);
|
|
||||||
SLLQueuePush(fallback_slot->first, fallback_slot->last, node);
|
|
||||||
}
|
|
||||||
node->key = key;
|
|
||||||
node->hash = hash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hs_scope_close(scope);
|
hs_scope_close(scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,21 +114,6 @@ typedef TXT_TokenArray TXT_LangLexFunctionType(Arena *arena, U64 *bytes_processe
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Cache Types
|
//~ rjf: Cache Types
|
||||||
|
|
||||||
typedef struct TXT_KeyFallbackNode TXT_KeyFallbackNode;
|
|
||||||
struct TXT_KeyFallbackNode
|
|
||||||
{
|
|
||||||
TXT_KeyFallbackNode *next;
|
|
||||||
U128 key;
|
|
||||||
U128 hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct TXT_KeyFallbackSlot TXT_KeyFallbackSlot;
|
|
||||||
struct TXT_KeyFallbackSlot
|
|
||||||
{
|
|
||||||
TXT_KeyFallbackNode *first;
|
|
||||||
TXT_KeyFallbackNode *last;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct TXT_Node TXT_Node;
|
typedef struct TXT_Node TXT_Node;
|
||||||
struct TXT_Node
|
struct TXT_Node
|
||||||
{
|
{
|
||||||
@@ -206,12 +191,6 @@ struct TXT_Shared
|
|||||||
TXT_Stripe *stripes;
|
TXT_Stripe *stripes;
|
||||||
TXT_Node **stripes_free_nodes;
|
TXT_Node **stripes_free_nodes;
|
||||||
|
|
||||||
// rjf: fallback cache
|
|
||||||
U64 fallback_slots_count;
|
|
||||||
U64 fallback_stripes_count;
|
|
||||||
TXT_KeyFallbackSlot *fallback_slots;
|
|
||||||
TXT_Stripe *fallback_stripes;
|
|
||||||
|
|
||||||
// rjf: user -> parse thread
|
// rjf: user -> parse thread
|
||||||
U64 u2p_ring_size;
|
U64 u2p_ring_size;
|
||||||
U8 *u2p_ring_base;
|
U8 *u2p_ring_base;
|
||||||
@@ -280,13 +259,14 @@ internal void txt_scope_touch_node__stripe_r_guarded(TXT_Scope *scope, TXT_Node
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Cache Lookups
|
//~ rjf: Cache Lookups
|
||||||
|
|
||||||
internal TXT_TextInfo txt_text_info_from_key_hash_lang(TXT_Scope *scope, U128 key, U128 hash, TXT_LangKind lang);
|
internal TXT_TextInfo txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang);
|
||||||
|
internal TXT_TextInfo txt_text_info_from_key_lang(TXT_Scope *scope, U128 key, TXT_LangKind lang, U128 *hash_out);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Transfer Threads
|
//~ rjf: Transfer Threads
|
||||||
|
|
||||||
internal B32 txt_u2p_enqueue_req(U128 key, U128 hash, TXT_LangKind lang, U64 endt_us);
|
internal B32 txt_u2p_enqueue_req(U128 hash, TXT_LangKind lang, U64 endt_us);
|
||||||
internal void txt_u2p_dequeue_req(U128 *key_out, U128 *hash_out, TXT_LangKind *lang_out);
|
internal void txt_u2p_dequeue_req(U128 *hash_out, TXT_LangKind *lang_out);
|
||||||
internal void txt_parse_thread__entry_point(void *p);
|
internal void txt_parse_thread__entry_point(void *p);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user