This is an archive of the discontinued LLVM Phabricator instance.

[llvm-exegesis] Support older kernel versions in subprocess executor
ClosedPublic

Authored by aidengrossman on Jun 30 2023, 6:02 PM.

Details

Summary

This patch switches from moving the performance counter file descriptor to the child process to socket calls rather than using the pidfd_getfd system call which was introduced in kernel 5.6. This significantly expands the range of kernel versions that are supported.

Diff Detail

Event Timeline

aidengrossman created this revision.Jun 30 2023, 6:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 6:02 PM
Herald added a subscriber: mstojanovic. · View Herald Transcript
aidengrossman requested review of this revision.Jun 30 2023, 6:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 6:02 PM

Remove unnecessary error message, fix function name.

Ping. This is ready for review when the reviewers have a chance. Thanks!

courbet added inline comments.Jul 17 2023, 12:17 AM
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
205

I think this is technically UB in C++ (it violates strict aliasing). I'd be more comfortable with memcpy(CMSG_DATA(ControlMessage)), FD, sizeof(FD));, which does the same thing while having defined semantics.

232

I'm not sure you cant just read 4 bytes from the message unconditionally, you need to check that they are indeed available by checking cmsg_len.

struct cmsghdr {
    socklen_t cmsg_len;    /* data byte count, including header */
   ...
};
233

Ditto:

int FD;
mempcy(&FD, RawData, sizeof(FD));

Reminder that please make sure a reviewed commit has Differential Revision:. If you use arc diff 'HEAD^' to upload a differential, you'll get this automatically.
I typically run arc amend before pushing to get Reviewed By:

@MaskRay Did you mean to post that on another patch? This one hasn't landed yet. There are also a couple minor patches that I committed without review that added preprocessor directives/very minor fixes related to kernel versioning to fix some build configurations that broke.

aidengrossman marked 3 inline comments as done.

Address reviewer feedback.

@courbet This should be ready for another round of review when you have time. Thanks!

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
205

Thanks for the suggestion! I definitely wasn't particularly happy with that level of casting, not sure why a memcpy didn't come up to me. That is definitely a lot cleaner and avoids the UB (and compiler warning).

courbet accepted this revision.Jul 18 2023, 2:08 AM
This revision is now accepted and ready to land.Jul 18 2023, 2:08 AM
This revision was landed with ongoing or failed builds.Jul 18 2023, 10:45 AM
This revision was automatically updated to reflect the committed changes.
uabelho added inline comments.
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
224

Should be ssize_t ?

The

BytesRead < 0

check below is currently always false since size_t is unsigned.

I noticed this when I compiled with gcc which warned

../tools/llvm-exegesis/lib/BenchmarkRunner.cpp:226:19: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
  226 |     if (BytesRead < 0)
      |         ~~~~~~~~~~^~~
aidengrossman added inline comments.Aug 22 2023, 11:44 PM
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
224

Yep. Thanks for pointing this out! Not sure how I missed it. recvmsg definitely returns ssize_t.

Fixed in 34e3bc0b92d7fdc59477c93d187546a2566fbc22.