This patch gives the ability to assign performance counters within
llvm-exegesis to a specific process by passing its PID. This is needed
later on for implementing a subprocess executor. Defaults to zero, the
current process, for the InProcessFunctionExecutorImpl.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/tools/llvm-exegesis/lib/PerfHelper.h | ||
---|---|---|
79 | [nit] ProcessId (P already stands for "process") |
Format, remove LLVM_HAVE_LIBPFM guard around FileDescriptor variable so the getter doesn't cause build errors on setups that don't have libpfm installed.
This broke compilation for mingw targets (in particular, for 64 bit targets - the issue seems to be benign for 32 bit targets). For those targets, compilation fails with this error:
/home/martin/code/llvm-project/llvm/tools/llvm-exegesis/lib/PerfHelper.h:27:13: error: typedef redefinition with different types ('int' vs '_pid_t' (aka 'long long')) 27 | typedef int pid_t; | ^ /home/martin/clang-nightly/aarch64-w64-mingw32/include/sys/types.h:68:16: note: previous definition is here 68 | typedef _pid_t pid_t; | ^ 1 error generated.
(For 32 bit targets, there's no mismatch between int and long long so it doesn't error out.)
HAVE_LIBPFM isn't a good guard for whether we need to define pid_t ourselves, since we can't know whether a transitively included header has defined this type regardless of libpfm. From looking around in e.g. lldb sources, pid_t is probably generally available for all targets except for Windows/MSVC (while mingw does have it).
I would really like to unbreak the mingw build. If anybody is reading and listening - do you prefer reverting this commit for now, until we can sort out how to safely typedef int across various OSes, or just add an && !defined(__MINGW32__) into the condition? Or something else?
Sorry about that. I probably should have traced the headers more closely. It looks like just checking for __pid_t_defined should work. I'll get a patch up soon.
Or, looks like Mac doesn't define that in their unistd.h header. I'll revert for now and figure out a better solution before relanding.
Thanks, much appreciated.
Yeah it seems less trivial than I would have wanted/expected to get this done, without adding e.g. a cmake level check for it. Alternatively, a strategy like "include all of <sys/types.h> and <unistd.h> and similar that are available, and then add a typedef if MSVC" might work too, but that's not exactly neat either.
It looks like the approach that lldb takes in regards to pid_t is to include sys/types.h (which is where the type is defined according to POSIX) everywhere except where _MSC_VER is defined (so MSVC and Clang on Windows) and then typedeffing it as uint32_t (why that specific type I'm not sure since POSIX mandates it is a signed integer type, but 32 bits is fine). I'm going to take this approach and reland this commit after some testing. Hopefully there aren't any further regressions from this.
[nit] ProcessId (P already stands for "process")