@@ -302,12 +302,11 @@ function cleanup_proc(state, p)
302
302
end
303
303
end
304
304
305
- " Process-local count of actively-executing Dagger tasks per processor type."
306
- const ACTIVE_TASKS = Dict {UInt64,Dict{Type,Ref{UInt}}} ()
307
- const ACTIVE_TASKS_LOCK = ReentrantLock ()
305
+ " Process-local condition variable (and lock) indicating task completion."
306
+ const TASK_SYNC = Threads. Condition ()
308
307
309
- " Process-local condition variable indicating task completion ."
310
- const TASK_SYNC = Condition ()
308
+ " Process-local dictionary tracking per-processor total utilization ."
309
+ const PROC_UTILIZATION = Dict {UInt64,Dict{Type,Ref{UInt}}} ()
311
310
312
311
"""
313
312
MaxUtilization
@@ -876,19 +875,19 @@ function do_task(to_proc, extra_util, thunk_id, f, data, send_result, persist, c
876
875
end
877
876
878
877
# Check if we'll go over capacity from running this thunk
879
- real_util = lock (ACTIVE_TASKS_LOCK ) do
880
- AT = get! (()-> Dict {Type,Ref{UInt}} (), ACTIVE_TASKS , uid)
878
+ real_util = lock (TASK_SYNC ) do
879
+ AT = get! (()-> Dict {Type,Ref{UInt}} (), PROC_UTILIZATION , uid)
881
880
get! (()-> Ref {UInt} (UInt (0 )), AT, typeof (to_proc))
882
881
end
883
882
cap = UInt (capacity (OSProc (), typeof (to_proc))) * UInt (1e9 )
884
883
while true
885
- lock (ACTIVE_TASKS_LOCK )
884
+ lock (TASK_SYNC )
886
885
if ((extra_util isa MaxUtilization) && (real_util[] > 0 )) ||
887
886
((extra_util isa Real) && (extra_util + real_util[] > cap))
888
887
# Fully subscribed, wait and re-check
889
888
@debug " ($(myid ()) ) $f ($thunk_id ) Waiting for free $(typeof (to_proc)) : $extra_util | $(real_util[]) /$cap "
890
- unlock (ACTIVE_TASKS_LOCK)
891
889
wait (TASK_SYNC)
890
+ unlock (TASK_SYNC)
892
891
else
893
892
# Under-subscribed, calculate extra utilization and execute thunk
894
893
@debug " ($(myid ()) ) ($thunk_id ) Using available $to_proc : $extra_util | $(real_util[]) /$cap "
@@ -898,7 +897,7 @@ function do_task(to_proc, extra_util, thunk_id, f, data, send_result, persist, c
898
897
extra_util
899
898
end
900
899
real_util[] += extra_util
901
- unlock (ACTIVE_TASKS_LOCK )
900
+ unlock (TASK_SYNC )
902
901
break
903
902
end
904
903
end
@@ -926,11 +925,13 @@ function do_task(to_proc, extra_util, thunk_id, f, data, send_result, persist, c
926
925
end
927
926
threadtime = cputhreadtime () - threadtime_start
928
927
@dbg timespan_end (ctx, :compute , thunk_id, (f, to_proc))
929
- lock (ACTIVE_TASKS_LOCK ) do
928
+ lock (TASK_SYNC ) do
930
929
real_util[] -= extra_util
931
930
end
932
931
@debug " ($(myid ()) ) ($thunk_id ) Releasing $(typeof (to_proc)) : $extra_util | $(real_util[]) /$cap "
933
- notify (TASK_SYNC)
932
+ lock (TASK_SYNC) do
933
+ notify (TASK_SYNC)
934
+ end
934
935
metadata = (
935
936
pressure= real_util[],
936
937
loadavg= ((Sys. loadavg ()... ,) ./ Sys. CPU_THREADS),
0 commit comments