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

Reintegrate external profiling support #27466

Merged
merged 1 commit into from
Jul 19, 2018

Conversation

fisiognomico
Copy link
Contributor

@fisiognomico fisiognomico commented Jun 6, 2018

Julia external profiling plus perf support

As presented in #26999, during ORC JIT transition Julia lost the LLVM native support to register JIT events. This was my first activity.

Also with my mentors of the Gsoc we agreed on adding perf support, similarly to what @maleadt did in
#14727 .

Then I have added IntelJITEventListener and OProfile support. OProfile is currently missing line level code annotations, as the current OProfile LLVM support is not implementing it.

That's why I have linked directly the OPprofileJITEventListener code, to avoid having to re-compile LLVM each time 😅 .

This is an example of visualizing the Perf output of runtime code using gprof2dot.

output

TODO

  • Work on making an LLVM Patch to add DWARF debug symbols support in Operf.
  • After that, the OProfileJITEventListener source can be ditched, and the LLVM event listener can be registered directly to the Julia execution engine.
  • Maybe move the PerfJITEventListener class somewhere else, like in debuginfo.cpp, as it is quite awful linked in the Makefile.
    @vtjnash suggested to add some features to the @profile macro. This can be useful, as perf support is intended to profile the whole runtime. I can add a feature so that a particular section of Julia code is profiled with perf events. Also it would not require to compile Julia with perf support.
    If anybody fthinks that this can be useful, I will work on that too.

EDIT: The perf wrapper is maintained as an external package.

cc @vtjnash @vchuravy

Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still prefer if we could use the OProfileWrapper from LLVM instead of duplicating it here. Are there any patches we need for that?

@@ -0,0 +1 @@
788a11a35fa62eb008019b37187d09d2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rebase onto master which already should have these files (You should not check them int)

// Build a path from the current entry name
SmallString<256> CmdLineFName;
raw_svector_ostream(CmdLineFName) << "/proc/" << Entry->d_name
<< "/cmdline";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting seems weird here

@fisiognomico
Copy link
Contributor Author

fisiognomico commented Jun 6, 2018

Well if we want to integrate line level annotations for OProfile yup, I need to patch the LLVM integration.

Either way I agree, the OProfile code will be ditched as it is redundant, and I will register the event from LLVM, as is done with IntelJITEventListener.
I have added it as for the moment is more convenient to test than recompiling every time LLVM 😄

Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! PerfJITEventListener.cpp is from LLVM as well right? If so we should also add this as a patch and any changes that you made should be contributed back upstream.

deps/llvm.mk Outdated
@@ -515,6 +515,8 @@ $(eval $(call LLVM_PATCH,llvm-D38765-gvn_5.0)) # Remove for 6.0
$(eval $(call LLVM_PATCH,llvm-D42262-jumpthreading-not-i1))
$(eval $(call LLVM_PATCH,llvm-PPC-addrspaces)) # PPC
$(eval $(call LLVM_PATCH,llvm-PR36292-5.0)) # PPC fixes #26249, remove for 6.0
else ifeq ($(LLVM_VER_SHORT),6.0)
$(eval $(call LLVM_PATCH,llvm-OProfile-line-num)) # In #27466, to be upstreamed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably rebase your branch onto current master so that you have the other 6.0 patches as well

@fisiognomico
Copy link
Contributor Author

fisiognomico commented Jun 11, 2018

The PerfJITEventListener code has been moved to the LLVM patches, now the codebase seems much cleaner! I am still testing a bit with this, in particular you can follow the OProfile patch review at D47925.
For the moment a build with LLVM_USE_VER = 6.0.0 is required, i think that it would be necessary to port it to llvm 3.9.1. The only difference that I notice between the two is DWARF Context definition.

@vchuravy
Copy link
Member

For the moment a build with LLVM_USE_VER = 6.0.0 is required, i think that it would be necessary to port it to llvm 3.9.1. The only difference that I notice between the two is DWARF Context definition.

Julia moved to LLVM 6.0, so no need to worry about 3.9.1

@vchuravy
Copy link
Member

You probably also want to squash your commits into one introducing the LLVM patches and one or two for the integration work.

@fisiognomico
Copy link
Contributor Author

Yup it should be cleaner now
Also the OProfile patch has now been upstreamed!

As for a wrapper to Perf events in Julia LinuxPerf.jl will be maintained as an external package, so I took that out of th todo list.

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (other than some minor formatting changes). Can you rebase to get CI to re-run? We'll also need BinaryBuilder to ingest these patches. But since this is off by default, I don't think that needs happen before merging.

@@ -681,7 +682,16 @@ Function *JuliaOJIT::FindFunctionNamed(const std::string &Name)

void JuliaOJIT::RegisterJITEventListener(JITEventListener *L)
{
// TODO
if(!L)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between if and (

void JuliaOJIT::NotifyFinalizer(const object::ObjectFile &Obj,
const RuntimeDyld::LoadedObjectInfo &LoadedObjectInfo)
{
for(auto &Listener : EventListeners)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between for and (

src/codegen.cpp Outdated
@@ -7474,6 +7474,22 @@ extern "C" void *jl_init_llvm(void)
jl_setup_module(engine_module);
jl_setup_module(m);
return (void*)m;

#ifdef JL_USE_INTEL_JITEVENTS
if(jl_using_intel_jitevents)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between if and (

@vtjnash
Copy link
Member

vtjnash commented Jul 13, 2018

(CI failures are unrelated – httpbin.com flakiness and macOS FileWatching)

@vtjnash vtjnash changed the title [WIP] Reintegrate external profiling Reintegrate external profiling support Jul 13, 2018
Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits and do we need to add https://reviews.llvm.org/D47343 and https://reviews.llvm.org/D44890?

deps/llvm.mk Outdated
@@ -494,6 +498,9 @@ $(eval $(call LLVM_PATCH,llvm-rL332302)) # remove for 7.0
$(eval $(call LLVM_PATCH,llvm-rL332694)) # remove for 7.0
$(eval $(call LLVM_PATCH,llvm-rL327898)) # remove for 7.0
$(eval $(call LLVM_PATCH,llvm-6.0-DISABLE_ABI_CHECKS))
$(eval $(call LLVM_PATCH,llvm-OProfile-line-num)) # In #27466, to be upstreamed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate

@fisiognomico
Copy link
Contributor Author

D44890 and D47343 are superfluous as we do object notification in JuliaOJIT!

Moved Oprofile Wrapper, implemented RegisterJITEventListener and NotifyFinalized

Added PerfJITEventListener as an LLVM Patch

Added IntelJITEventListener Support

Added LLVM Patch, removed redundant Oprofile code, wipe blanklines, Register OProfile JITEvent, fixed oprofile compile flag, rebased llvm 6.0 checksums

Added Perf profiling support as an LLVM patch.
Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, after CI passes

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

Successfully merging this pull request may close these issues.

3 participants