This is an archive of the discontinued LLVM Phabricator instance.

[trace][intelpt] Support system-wide tracing [1] - Add a method for accessing the list of logical core ids
ClosedPublic

Authored by wallace on Apr 27 2022, 5:00 PM.

Details

Summary

In order to open perf events per core, we need to first get the list of
core ids available in the system. So I'm adding a function that does
that by parsing /proc/cpuinfo. That seems to be the simplest and most
portable way to do that.

Besides that, I made a few refactors and renames to reflect better that
the cpu info that we use in lldb-server comes from procfs.

Diff Detail

Event Timeline

wallace created this revision.Apr 27 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 5:00 PM
wallace requested review of this revision.Apr 27 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 5:00 PM
jj10306 added inline comments.Apr 28 2022, 9:13 AM
lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
22

why not use an enum here?
having "kinds" in the name already makes it sound like an enum and seeing IntelPTDataKinds:: everywhere immediately made me thing it was an enum.

wallace added inline comments.Apr 28 2022, 11:35 AM
lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
22

this is actually an enum, but it's an enum of strings. So we have a few options:

  • have a normal int enum and have another function that converts int -> const char*.
  • create a fake enum with class static variables like here
  • use header inline variables, but they are not available in the C++ version used by LLDB.

Overall I found this to be the simplest way to implement it.

jj10306 accepted this revision.Apr 28 2022, 5:21 PM
This revision is now accepted and ready to land.Apr 28 2022, 5:21 PM
wallace updated this revision to Diff 425936.Apr 28 2022, 5:30 PM

I made a mistake and I included the second of two commits. This update contains all the code.

jj10306 accepted this revision.May 2 2022, 7:34 AM
jj10306 added inline comments.
lldb/unittests/Process/Linux/PerfTests.cpp
53

Not directly related to this diff, but I just realized the proc fs parsing logic doesn't belong in the Perf files since it has nothing to do with perf. Feel free to move those functions and these associated tests to a more appropriate location or we can do it in a future diff since this isn't the diff that made that mistake.

wallace added inline comments.May 2 2022, 7:36 AM
lldb/unittests/Process/Linux/PerfTests.cpp
53

that's a valid point. I'll create a new file

wallace updated this revision to Diff 426422.May 2 2022, 8:42 AM

move procfs functions to Procfs.h

wallace updated this revision to Diff 426424.May 2 2022, 8:47 AM

final nits

Much cleaner now, thanks for separating out the procfs logic 🙂

thanks for your review :)