-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify_overheads.jl
53 lines (50 loc) · 1.43 KB
/
notify_overheads.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using JSON
include("utils.jl")
function notify_overheads()
results = [Ref{Any}() for _ in 1:Threads.nthreads()]
counter1 = Ref(0)
cond = Threads.Condition()
tasks = Task[]
for (tid, ref) in pairs(results)
task = @task begin
@assert tid == Threads.threadid()
# print('.')
lock(cond) do
if (counter1[] += 1) == Threads.nthreads()
# println("notifying")
t0 = time_ns()
notify(cond)
t1 = time_ns()
ref[] = (t0, t1)
else
while counter1[] < Threads.nthreads()
wait(cond)
end
ref[] = time_ns()
end
end
end
ccall(:jl_set_task_tid, Cvoid, (Any, Cint), task, tid - 1)
schedule(task)
push!(tasks, task)
end
foreach(wait, tasks)
T = typeof(time_ns())
notified = T[r[] for r in results if r[] isa Number]
pre, post = only(r[] for r in results if !(r[] isa Number))
return (; notified, pre, post)
end
function main(args = ARGS)
output, = args
mkpath(dirname(output))
data = Dict(
:results => sample(notify_overheads, 1000),
:metadata => metadata(),
)
open(output, write = true) do io
JSON.print(io, data)
end
end
if abspath(PROGRAM_FILE) == @__FILE__
main()
end