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

Busy loop on profiling external Cmd's #16

Closed
binarybana opened this issue Jun 11, 2013 · 9 comments
Closed

Busy loop on profiling external Cmd's #16

binarybana opened this issue Jun 11, 2013 · 9 comments

Comments

@binarybana
Copy link

julia> require("Profile")
julia> using SProfile 
julia> function test()
       run(`echo hi`)
       end
# methods for generic function test
test() at none:2

julia> test()
hi
julia> @sprofile test() 

Where the last line hangs at 100% CPU for (at least) several minutes on my Ubuntu 13.04 system running a recent version of Julia 0.2-.

Thanks!

@timholy
Copy link
Owner

timholy commented Jun 14, 2013

Sorry for the delay, I had no laptop or internet for several days.

I can indeed replicate this, although it's intermittent: once I got it to run through fine. A simple workaround is to increase the delay, e.g., sprofile_init(10^6,10^7).

It's hanging at the ccall to :jl_spawn in _jl_spawn. This is not an area of Julia that I know well, so I'm CCing others @vtjnash, @loladiro, @JeffBezanson.

A gist to facilitate debugging is here: https://gist.github.com/timholy/5782437. I can trigger with

require("Profile"); using SProfile
include("/tmp/newspawn.jl")
@sprofile newspawn(`echo hi`)

If there's no other way, this can presumably be fixed by disabling the profiling timer upon entry into the C function jl_spawn. But only once SProfile gets merged into base. JuliaLang/julia#2597.

@timholy
Copy link
Owner

timholy commented Jun 14, 2013

As a very minor update, it's not dependent upon console output: @sprofile run(sleep 1) can also hang. But the intermittency puzzles me, as I've gotten that to both work and fail multiple times on my own laptop. Even launching an scp sometimes worked and sometimes didn't.

When one of these works, you get a successful profile out of it (lots of samples inside uv__epoll_wait, line 54).

@binarybana
Copy link
Author

Thanks for the workaround, sadly I know even less of Julia internals so I'm not of much help here.

vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Jun 18, 2013
@timholy
Copy link
Owner

timholy commented Jun 19, 2013

Jameson, thanks very much for looking into this!

I see that your fix is in the julia 0.3 branch. Any thoughts about whether this can be applied to master? (Note I haven't tested, but it sure looks promising.)

@vtjnash
Copy link

vtjnash commented Jun 19, 2013

The julia0.3 branch is the current head for julia. We just need to update the sha1 in the julia repository.

Note that it seems to me that you in fact found a linux kernel bug -- it appears that the linux scheduler refuses to run any more code after returning from the clone syscall as part of the libc call to fork. (The exact mechanism of this failure is not apparent to me -- whether it is the SIGUSR1 interruption, or the timer & alarm reset and disable that is supposed to occur.)

@timholy
Copy link
Owner

timholy commented Jun 19, 2013

Wow. Should I report this somewhere? I'd need a simple testcase (may have to bug you for pointers).

Or if it's just too complicated we can work around it...

@vtjnash
Copy link

vtjnash commented Jun 19, 2013

The trick would be in building a simple testcase -- might be enough to just setup a timer as you do here, call fork() then exit().

The patch to libuv also just works around it by disabling all signals upon entry to and re-enabling them upon exit from uv_spawn(), this is probably a good idea anyways for making spawn robust against signals.

@timholy
Copy link
Owner

timholy commented Jun 19, 2013

Alright, let's just use the workaround, and if I'm feeling ambitious I'll make a weekend project out of the kernel bug report. (I'm sure they'll want me to test on the current kernel, etc.)

@timholy
Copy link
Owner

timholy commented Jun 22, 2013

@vtjnash, your fix has now been merged and works great for me. Thanks again!

@timholy timholy closed this as completed Jun 22, 2013
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Jul 26, 2013
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Feb 23, 2014
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Mar 29, 2014
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Mar 30, 2014
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Mar 30, 2014
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Jun 3, 2014
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Jul 18, 2015
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue Nov 1, 2015
vtjnash added a commit to JuliaAttic/libuv-archive that referenced this issue May 3, 2016
vtjnash added a commit to vtjnash/libuv that referenced this issue Nov 17, 2017
ararslan pushed a commit to JuliaAttic/libuv-archive that referenced this issue Apr 2, 2018
vtjnash added a commit to vtjnash/libuv that referenced this issue Nov 14, 2018
vtjnash added a commit to vtjnash/libuv that referenced this issue Nov 14, 2018
vtjnash added a commit to vtjnash/libuv that referenced this issue Nov 14, 2018
vtjnash added a commit to vtjnash/libuv that referenced this issue May 28, 2019
vtjnash added a commit to JuliaLang/libuv that referenced this issue Jun 10, 2019
musm pushed a commit to musm/libuv that referenced this issue Jul 8, 2020
musm pushed a commit to musm/libuv that referenced this issue Jul 8, 2020
musm pushed a commit to musm/libuv that referenced this issue Jul 8, 2020
musm pushed a commit to musm/libuv that referenced this issue Jul 8, 2020
(cherry picked from commit 6c86f09)
(cherry picked from commit c4ad8c2)
vtjnash added a commit to JuliaLang/libuv that referenced this issue Aug 25, 2020
vtjnash added a commit to vtjnash/libuv that referenced this issue Jul 20, 2021
vtjnash added a commit to JuliaLang/libuv that referenced this issue Jul 23, 2021
vtjnash added a commit to JuliaLang/libuv that referenced this issue Jul 23, 2021
vtjnash added a commit to JuliaLang/libuv that referenced this issue Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants