Skip to content
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

[backports-release-1.11] 1.11 Profiling threading fix backports #56358

Conversation

IanButterworth
Copy link
Member

@IanButterworth IanButterworth commented Oct 27, 2024

…liaLang#55622)

Fixes an issue with JuliaLang#55500, where signals may abruptly abort the process
as they observe it is still processing the resume SIGUSR2 message and
are not able to wait for that processing to end before setting the new
message to exit.

(cherry picked from commit da3468c)
I forgot about the existence of threads, so had hard-coded this to only
support one thread. Clearly that is not sufficient though, so use the
semaphore here as it is intended to be used.

Fixes JuliaLang#55703

---------

Co-authored-by: Ian Butterworth <i.r.butterworth@gmail.com>
(cherry picked from commit 4f0a333)
@gdalle
Copy link
Contributor

gdalle commented Oct 27, 2024

What should the tests look like? The profiling result is not exactly empty, it does have a few (trivial) things in the flame graph, so what would be a good criterion for a test that fails in the current state of things?

@IanButterworth
Copy link
Member Author

I'm guessing that if you start with -t8 and do Profile.print(groupby=:thread) on 1.11.1 you only get 1 thread, but here you get all threads?

@IanButterworth
Copy link
Member Author

I checked on a linux x86 machine with -t8 and it does appear fixed here.

On 1.11.1 only the first thread appears to be sampled.

$ julia +1.11 -t8
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.1 (2024-10-16)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> function profile_test(n)
                  for i = 1:n
                      A = randn(100,100,20)
                      m = maximum(A)
                      Am = mapslices(sum, A; dims=2)
                      B = A[:,:,5]
                      Bsort = mapslices(sort, B; dims=1)
                      b = rand(100)
                      C = B.*b
                  end
              end
profile_test (generic function with 1 method)

julia> using Profile

julia> @profile profile_test(2)

julia> Profile.clear(); @profile profile_test(1000)

julia> Profile.print(groupby=:thread)
Overhead ╎ [+additional indent] Count File:Line; Function
=========================================================
Thread 1 Total snapshots: 781. Utilization: 100%
   ╎781 @Base/client.jl:541; _start()
   ╎ 781 @Base/client.jl:567; repl_main
   ╎  781 @Base/client.jl:430; run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
... etc.

┌ Warning: There were no samples collected in one or more groups.
│ This may be due to idle threads, or you may need to run your
│ program longer (perhaps by running it multiple times),
│ or adjust the delay between samples with `Profile.init()`.
└ @ Profile ~/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/stdlib/v1.11/Profile/src/Profile.jl:1240

On this PR all are sampled.

$ ./julia --start=no -t8
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.1 (2024-10-27)
 _/ |\__'_|_|_|\__'_|  |  ib/1.11_profile_backports/0495045cc1* (fork: 487 commits, 254 days)
|__/                   |

...

julia> Profile.print(groupby=:thread)
Overhead ╎ [+additional indent] Count File:Line; Function
=========================================================
Thread 1 Total snapshots: 582. Utilization: 100%
   ╎582 @Base/client.jl:541; _start()
   ╎ 582 @Base/client.jl:567; repl_main
   ╎  582 @Base/client.jl:430; run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
... etc.

Thread 2 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 3 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 4 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 5 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 6 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 7 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 8 Total snapshots: 582. Utilization: 0%
   ╎582 @Base/task.jl:694; task_done_hook(t::Task)
   ╎ 582 @Base/task.jl:1021; wait()
581╎  582 @Base/task.jl:1012; poptask(W::Base.IntrusiveLinkedListSynchronized{Task})

Thread 9 Total snapshots: 582. Utilization: 100%

Thread 10 Total snapshots: 582. Utilization: 100%

Thread 11 Total snapshots: 582. Utilization: 100%

┌ Warning: There were no samples collected in one or more groups.
│ This may be due to idle threads, or you may need to run your
│ program longer (perhaps by running it multiple times),
│ or adjust the delay between samples with `Profile.init()`.
└ @ Profile ~/Documents/GitHub/julia/usr/share/julia/stdlib/v1.11/Profile/src/Profile.jl:1240

@IanButterworth IanButterworth marked this pull request as ready for review October 28, 2024 00:51
@IanButterworth IanButterworth changed the title [backports-release-1.11] 1.11 Profiling backports [backports-release-1.11] 1.11 Profiling threading fix backports Oct 28, 2024
@vtjnash
Copy link
Member

vtjnash commented Oct 28, 2024

SGTM

@IanButterworth IanButterworth merged commit 0f7f762 into JuliaLang:backports-release-1.11 Oct 28, 2024
7 of 9 checks passed
@IanButterworth IanButterworth deleted the ib/1.11_profile_backports branch October 28, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
don't squash Don't squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants