adjustments

This commit is contained in:
2025-11-07 00:41:44 -05:00
parent e632bc4c78
commit 32b69d50cb
4 changed files with 24 additions and 39 deletions

View File

@@ -14,9 +14,7 @@ load_client_api :: proc(version_id: int) -> (loaded_module: Client_API) {
using loaded_module
// Make sure we have a dll to work with
file_io_err: OS_Error; write_time, file_io_err = file_last_write_time_by_name("sectr.dll")
if file_io_err != OS_ERROR_NONE {
panic_contextless( "Could not resolve the last write time for sectr")
}
if file_io_err != OS_ERROR_NONE { panic_contextless( "Could not resolve the last write time for sectr") }
//TODO(Ed): Lets try to minimize this...
thread_sleep( Millisecond * 25 )
// Get the live dll loaded up
@@ -84,16 +82,12 @@ main :: proc()
startup_time := time_now()
year, month, day := time_date( startup_time)
hour, min, sec := time_clock_from_time( startup_time)
if ! os_is_directory( Path_Logs ) {
os_make_directory( Path_Logs )
}
if ! os_is_directory( Path_Logs ) { os_make_directory( Path_Logs ) }
timestamp := str_pfmt_tmp("%04d-%02d-%02d_%02d-%02d-%02d", year, month, day, hour, min, sec)
host_memory.path_logger_finalized = str_pfmt("%s/sectr_%v.log", Path_Logs, timestamp)
}
logger_init( & host_memory.host_logger, "Sectr Host", str_pfmt_tmp("%s/sectr.log", Path_Logs))
context.logger = to_odin_logger( & host_memory.host_logger )
{
context.logger = to_odin_logger( & host_memory.host_logger ); {
// Log System Context
builder := strbuilder_make_len(16 * Kilo, context.temp_allocator)
str_pfmt_builder( & builder, "Core Count: %v, ", os_core_count() )
@@ -103,8 +97,7 @@ main :: proc()
free_all(context.temp_allocator)
}
context.logger = to_odin_logger( & host_memory.host_logger )
// Load the Enviornment API for the first-time
{
/*Load the Enviornment API for the first-time*/{
host_memory.client_api = load_client_api( 1 )
verify( host_memory.client_api.lib_version != 0, "Failed to initially load the sectr module" )
}
@@ -120,7 +113,10 @@ main :: proc()
barrier_init(& host_memory.lane_sync, THREAD_TICK_LANES)
when THREAD_TICK_LANES > 1 {
for id in 1 ..= (THREAD_TICK_LANES - 1) {
launch_tick_lane_thread(cast(WorkerID) id)
lane_thread := thread_create_ex(host_tick_lane_entrypoint, .High, enum_to_string(cast(WorkerID)id))
lane_thread.user_index = id
host_memory.threads[lane_thread.user_index] = lane_thread
thread_start(lane_thread)
}
}
}
@@ -136,7 +132,7 @@ main :: proc()
barrier_init(& host_memory.job_hot_reload_sync, THREAD_JOB_WORKERS + 1)
for id in THREAD_JOB_WORKER_ID_START ..< THREAD_JOB_WORKER_ID_END {
log_print_fmt("Spawned job worker: %v", cast(WorkerID) id)
worker_thread := thread_create(host_job_worker_entrypoint, .Normal)
worker_thread := thread_create_ex(host_job_worker_entrypoint, .Normal, enum_to_string(cast(WorkerID) id))
worker_thread.user_index = int(id)
host_memory.threads[worker_thread.user_index] = worker_thread
thread_start(worker_thread)
@@ -146,6 +142,7 @@ main :: proc()
}
free_all(context.temp_allocator)
host_tick_lane()
host_lane_shutdown()
profile_begin("Host Shutdown")
if thread_memory.id == .Master_Prepper {
@@ -165,14 +162,6 @@ main :: proc()
spall_buffer_destroy(& host_memory.spall_context, & thread_memory.spall_buffer)
spall_context_destroy( & host_memory.spall_context )
}
launch_tick_lane_thread :: proc(id : WorkerID) {
assert_contextless(thread_memory.id == .Master_Prepper)
// TODO(Ed): We need to make our own version of this that doesn't allocate memory.
lane_thread := thread_create(host_tick_lane_entrypoint, .High)
lane_thread.user_index = int(id)
host_memory.threads[lane_thread.user_index] = lane_thread
thread_start(lane_thread)
}
host_tick_lane_entrypoint :: proc(lane_thread: ^SysThread) {
thread_memory.system_ctx = lane_thread
@@ -184,13 +173,12 @@ host_tick_lane_entrypoint :: proc(lane_thread: ^SysThread) {
grime_set_profiler_thread_buffer(& thread_memory.spall_buffer)
}
host_tick_lane()
host_lane_shutdown()
}
host_tick_lane :: proc()
{
profile(#procedure)
delta_ns: Duration
host_tick := time_tick_now()
for ; sync_load(& host_memory.tick_running, .Relaxed);
{
profile("Host Tick")
@@ -207,7 +195,6 @@ host_tick_lane :: proc()
// Lanes are synced before doing running check..
sync_client_api()
}
host_lane_shutdown()
}
host_lane_shutdown :: proc()
{
@@ -218,8 +205,8 @@ host_lane_shutdown :: proc()
for ; jobs_enqueued; {
jobs_enqueued = false
jobs_enqueued |= host_memory.job_system.job_lists[.Normal].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.Low].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.High].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.Low ].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.High ].head != nil
// if jobs_enqueued == false do debug_trap()
}
sync_store(& host_memory.job_system.running, false, .Release)
@@ -242,8 +229,8 @@ host_job_worker_entrypoint :: proc(worker_thread: ^SysThread)
}
jobs_enqueued := false
jobs_enqueued |= host_memory.job_system.job_lists[.Normal].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.Low].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.High].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.Low ].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.High ].head != nil
delta_ns: Duration
host_tick := time_tick_now()
for ; jobs_enqueued || sync_load(& host_memory.job_system.running, .Relaxed);
@@ -251,15 +238,12 @@ host_job_worker_entrypoint :: proc(worker_thread: ^SysThread)
// profile("Host Job Tick")
host_memory.client_api.jobsys_worker_tick(duration_seconds(delta_ns), delta_ns)
delta_ns = time_tick_lap_time( & host_tick )
host_tick = time_tick_now()
jobs_enqueued = false
jobs_enqueued |= host_memory.job_system.job_lists[.Normal].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.Low].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.High].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.Low ].head != nil
jobs_enqueued |= host_memory.job_system.job_lists[.High ].head != nil
if jobs_enqueued == false && sync_load(& host_memory.client_api_hot_reloaded, .Acquire) {
// Signals to main hread when all jobs have drained.
leader :=barrier_wait(& host_memory.job_hot_reload_sync)

View File

@@ -43,6 +43,9 @@ import "core:prof/spall"
spall_buffer_create :: spall.buffer_create
spall_buffer_destroy :: spall.buffer_destroy
import "core:reflect"
enum_to_string :: reflect.enum_string
import "core:strings"
strbuilder_from_bytes :: strings.builder_from_bytes
strbuilder_make_len :: strings.builder_make_len
@@ -72,6 +75,7 @@ import "core:time"
import "core:thread"
SysThread :: thread.Thread
thread_create :: thread.create
thread_create_ex :: thread.create_ex
thread_start :: thread.start
thread_destroy :: thread.destroy
thread_join_multiple :: thread.join_multiple
@@ -93,8 +97,7 @@ import grime "codebase:grime"
// Need to have it with un-wrapped allocator
// file_copy_sync :: grime.file_copy_sync
file_copy_sync :: proc( path_src, path_dst: string, allocator := context.allocator ) -> b32
{
file_copy_sync :: proc( path_src, path_dst: string, allocator := context.allocator ) -> b32 {
file_size : i64
{
path_info, result := file_status( path_src, allocator )
@@ -104,14 +107,12 @@ import grime "codebase:grime"
}
file_size = path_info.size
}
src_content, result := os.read_entire_file_from_filename( path_src, allocator )
if ! result {
log_print_fmt( "Failed to read file to copy: %v", path_src, LoggerLevel.Error )
debug_trap()
return false
}
result = os.write_entire_file( path_dst, src_content, false )
if ! result {
log_print_fmt( "Failed to copy file: %v", path_dst, LoggerLevel.Error )

View File

@@ -56,7 +56,7 @@ Host_API :: struct {
}
ThreadMemory :: struct {
using _: ThreadWorkerContext,
using _: ThreadWorkerContext,
// Per-thread profiling
spall_buffer_backing: [SPALL_BUFFER_DEFAULT_SIZE]byte,

View File

@@ -77,8 +77,8 @@ import "codebase:grime"
logger_init :: grime.logger_init
// Memory
mem_alloc :: grime.mem_alloc
mem_copy_overlapping :: grime.mem_copy_overlapping
mem_copy :: grime.mem_copy
mem_copy_non_overlapping :: grime.mem_copy_non_overlapping
mem_zero :: grime.mem_zero
slice_zero :: grime.slice_zero
// Ring Buffer