Skip to content

Retry jl_set_task_tid on failure #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Dagger.jl
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ include("utils/dagdebug.jl")

# Distributed data
include("utils/locked-object.jl")
include("utils/tasks.jl")
include("options.jl")
include("processor.jl")
include("scopes.jl")
7 changes: 1 addition & 6 deletions src/processor.jl
Original file line number Diff line number Diff line change
@@ -166,12 +166,7 @@ function execute!(proc::ThreadProc, @nospecialize(f), @nospecialize(args...); @n
TimespanLogging.prof_task_put!(tls.sch_handle.thunk_id.id)
@invokelatest f(args...; kwargs...)
end
task.sticky = true
ret = ccall(:jl_set_task_tid, Cint, (Any, Cint), task, proc.tid-1)
if ret == 0
error("jl_set_task_tid == 0")
end
@assert Threads.threadid(task) == proc.tid
set_task_tid!(task, proc.tid)
schedule(task)
try
fetch(task)
6 changes: 2 additions & 4 deletions src/sch/Sch.jl
Original file line number Diff line number Diff line change
@@ -1286,8 +1286,7 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
lock(istate.queue) do _
tid = task_tid_for_processor(to_proc)
if tid !== nothing
t.sticky = true
ret = ccall(:jl_set_task_tid, Cint, (Any, Cint), t, tid-1)
Dagger.set_task_tid!(t, tid)
else
t.sticky = false
end
@@ -1299,8 +1298,7 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
end
tid = task_tid_for_processor(to_proc)
if tid !== nothing
proc_run_task.sticky = true
ret = ccall(:jl_set_task_tid, Cint, (Any, Cint), proc_run_task, tid-1)
Dagger.set_task_tid!(proc_run_task, tid)
else
proc_run_task.sticky = false
end
20 changes: 20 additions & 0 deletions src/utils/tasks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function set_task_tid!(task::Task, tid::Integer)
task.sticky = true
ctr = 0
while true
ret = ccall(:jl_set_task_tid, Cint, (Any, Cint), task, tid-1)
if ret == 1
break
elseif ret == 0
yield()
else
error("Unexpected retcode from jl_set_task_tid: $ret")
end
ctr += 1
if ctr > 10
@warn "Setting task TID to $tid failed, giving up!"
return
end
end
@assert Threads.threadid(task) == tid "jl_set_task_tid failed!"
end