161 Commits

Author SHA1 Message Date
Kazu Hirata
0f77887108 [llvm-exegesis] Fix a warning
This patch fixes:

  llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp:602:6: error:
  unused function 'printInstructions' [-Werror,-Wunused-function]
2025-08-13 09:41:40 -07:00
Lakshay Kumar
d35686b25c
[llvm-exegesis] Print generated assembly snippet (#142540)
Debug generated disassembly by passing argument
`debug-only="print-gen-assembly"` or `debug-only=preview-gen-assembly`
of exegesis call.
`--debug-only="print-gen-assembly"` debugs the whole generated assembly
snippet .
`--debug-only=preview-gen-assembly` debugs the initial 10 instructions
and ending 3 lines.
Thus, We can in glance see the initial setup code like registers setup
and instruction followed by truncated middle and finally print out the
last 3 instructions.

This helps us look into assembly that exegesis is execution in hardware,
Thus, it is simply functionally alias to separate objdump command on the
dumped object file.
2025-08-13 10:37:24 +01:00
Min Hsu
72225ca27f Revert "Reland: "[Exegesis] Add the ability to dry-run the measurement phase (#121991)" (#122775)"
This reverts commit a39aaf35d3858a5542f532e399482c2bb0259dac and
63d3bd6d0caf8185aba49540fe2f67512fdf3a98.

Due to test failures on MacOSX.
2025-01-14 14:18:58 -08:00
Min-Yih Hsu
a39aaf35d3
Reland: "[Exegesis] Add the ability to dry-run the measurement phase (#121991)" (#122775)
This relands f8f8598fd886cddfd374fa43eb6d7d37d301b576

Follow up on #122371:
The problem here is a little subtle: when we dry-run the measurement
phase, we create a LLJIT instance without actually executing the
snippets. The key is, LLJIT has its own TargetMachine which uses triple
designated by LLVM_TARGET_ARCH (which is default to host). On a machine
that does not support Exegesis, the LLJIT would fail to create its
TargetMachine because llvm-exegesis don't even register the host's
target!

Putting this test into any of the target-specific folder won't help,
because it's about the host. And personally I don't really want to use
`exegesis-can-execute-<arch>` for generic tests like this -- it's too
strict as we don't actually need to execute the snippet.

My solution here is creating another test feature which is added only
when LLVM_TARGET_ARCH is supported by llvm-exegesis. This feature is
something in between `<arch>-registered-target` and
`exegesis-can-execute-<arch>`.
2025-01-13 13:42:59 -08:00
Min-Yih Hsu
d01ae56774
Revert "[Exegesis] Add the ability to dry-run the measurement phase (… (#122371)
…#121991)"

This reverts commit f8f8598fd886cddfd374fa43eb6d7d37d301b576.

This breaks ARMv7 and s390x buildbot with the following message:
```
llvm-exegesis error: No available targets are compatible with triple "armv8l-unknown-linux-gnueabihf"
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/tcwg-buildbot/worker/clang-armv7-2stage/stage2/bin/FileCheck /home/tcwg-buildbot/worker/clang-armv7-2stage/llvm/llvm/test/tools/llvm-exegesis/dry-run-measurement.test
```
2025-01-09 12:59:57 -08:00
Min-Yih Hsu
f8f8598fd8
[Exegesis] Add the ability to dry-run the measurement phase (#121991)
With the new benchmark phase, `dry-run-measurement`, llvm-exegesis can
run everything except the actual snippet execution. It is useful when we
want to test some parts of the code between the `assemble-measured-code`
and `measure` phase without actually running on native platforms.
2025-01-09 09:25:51 -08:00
Aiden Grossman
48a6e51445 [llvm-exegesis] Fix typo in f2334c5919ec077e6a8deeaf43a5b5188baf0251
This should have been in the original commit, but I somehow forgot to
run git add && git commit --amend --no-edit between making the change in
my editor, saving the file, and pushing the commit.
2024-12-24 21:54:30 +00:00
Aiden Grossman
f2334c5919 [llvm-exegesis] Make benchmark pinning actually work
When originally writing this feature up, I apparently completely forgot
to actually make the test exercise it and left an extra exit in the
function implementing the functionality without the appropriate
preprocessor macros around it, causing things to never work. This patch
should fix that.
2024-12-24 21:48:44 +00:00
Aiden Grossman
e093bb9e5a
Reland "[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)" (#109688)
This reverts commit 2cd20c255684257b86940bdda6861897f0bf3c00.

This relands commit 9886788a8a500a1b429a6db64397c849b112251c.

This was causing more buildbot failures due to getcpu not being
available with glibc <=2.29. This patch fixes that by directly making
the syscall, assuming the syscall number macro is available.
2024-09-23 11:32:19 -07:00
Aiden Grossman
2cd20c2556 Revert "[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)"
This reverts commit 6fc2451167ec991361dd0568de9a9fa2926f8da8.

This broke some more buildbots.
2024-09-23 16:08:14 +00:00
Jie Fu
cd80ed424b [llvm-exegesis] Fix -Wunused-variable in BenchmarkRunner.cpp (NFC)
/llvm-project/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp:415:18:
error: unused variable 'CurrentCPU' [-Werror,-Wunused-variable]
    unsigned int CurrentCPU;
                 ^
1 error generated.
2024-09-23 17:32:11 +08:00
Aiden Grossman
6fc2451167 Reland "[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)"
This reverts commit 5e3d48a68096a0017a0fa4bb89f2d48767c8a7e4.

This relands commit 9886788a8a500a1b429a6db64397c849b112251c.

This was originally causing build failures on more esoteric platforms
that have different definitions of getcpu. This is only intended to be
supported on x86-64 currently, so just use preprocessor definitions to
special case the function.
2024-09-23 08:53:24 +00:00
Aiden Grossman
5e3d48a680 Revert "[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)"
This reverts commit 9886788a8a500a1b429a6db64397c849b112251c.

This was breaking builds on ppc64 and AIX. Pulling so I have time to
investigate.
2024-09-19 14:02:07 +00:00
Aiden Grossman
9886788a8a
[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)
This patch adds in support for pinning a benchmarking process to a
specific CPU (in the subprocess benchmarking mode on Linux). This is
intended to be used in environments where a certain set of CPUs is
isolated from the scheduler using something like cgroups and thus should
present less potential for noise than normal. This also opens up the
door for doing multithreaded benchmarking as we can now pin benchmarking
processes to specific CPUs that we know won't interfere with each other.
2024-09-19 06:34:21 -07:00
Daniil Fukalov
89e6a28867
[NFC] Add explicit #include llvm-config.h where its macros are used. (#106621)
Without these explicit includes, removing other headers, who implicitly
include llvm-config.h, may have non-trivial side effects.
2024-08-30 09:35:06 +02:00
Aiden Grossman
fac87b889c
[llvm-exegesis] Switch from intptr_t to uintptr_t in most cases (#102860)
This patch switches most of the uses of intptr_t to uintptr_t within
llvm-exegesis for the subprocess memory support. In the vast majority of
cases we do not want a signed component of the address, hence making
intptr_t undesirable. intptr_t is left for error handling, for example
when making syscalls and we need to see if the syscall returned -1.
2024-08-27 11:19:44 -07:00
Aiden Grossman
1e8df9e85a
[llvm-exegesis] Use correct rseq struct size (#100804)
Glibc v2.40 changes the definition of __rseq_size to the usable area of
the struct rather than the actual size of the struct to accommodate
users trying to figure out what features can be used. This change breaks
llvm-exegesis trying to disable rseq as the size registered in the
kernel is no longer equal to __rseq_size. This patch adds a check to see
if __rseq_size is less than 32 bytes and uses 32 as a value if it is
given alignment requirements.

Fixes #100791.
2024-07-27 10:53:23 -07:00
Aiden Grossman
74a5e7784b
[llvm-exegesis] Close file descriptors after use (#86584)
There are several insstances in the subprocess executor in llvm-exegesis
where we fail to close file descriptors after using them. This leaves
them open, which can cause issues later on if a third-party binary is
using the exegesis libraries and executing many blocks before exiting.
Leaving the descriptors open until process exit is also bad practice.
This patch fixes that by explicitly calling close() when we are done
with a specific file descriptor.

This patch fixes #86583.
2024-04-26 02:41:21 -07:00
Aiden Grossman
50e6218132 Reland "[llvm-exegesis] Add thread IDs to subprocess memory names (#84451)"
This reverts commit 1fe9c417a0bf143f9bb9f9e1fbf7b20f44196883.

This relands commit 6bbe8a296ee91754d423c59c35727eaa624f7140.

This was causing build failures on one of the ARMv8 builders. Still not
completely sure why, but relanding it to see if the failure pops up
again. If it does, the plan is to fix forward by disabling tests on ARM
temporarily as llvm-exegesis does not currently use SubprocessMemory
on ARM.
2024-03-22 11:51:09 -07:00
Aiden Grossman
36a6afdd2c Reland "[llvm-exegesis] Refactor parent code to separate function (#86232)"
This reverts commit c3a41aac5f32475b9a0499e6e888e713763566dc.

This relands commit bd493756fa51e538575fc320aae50d75394f0567.

Apparently I forgot to update a couple values, so this change failed on
every builder that builds those sections (should be every Linux
platform) rather than something architecture specific like originally
thought. I swore I updated the values and ran check-llvm before merging.
Wondering If I forgot to push those changes...
2024-03-22 10:30:42 -07:00
Aiden Grossman
c3a41aac5f Revert "[llvm-exegesis] Refactor parent code to separate function (#86232)"
This reverts commit bd493756fa51e538575fc320aae50d75394f0567.

Causes build failures on non-X86 platforms.
https://lab.llvm.org/buildbot/#/changes/128363
2024-03-22 10:25:23 -07:00
Aiden Grossman
bd493756fa
[llvm-exegesis] Refactor parent code to separate function (#86232)
This patch refactors the parent code to a separate function in the
subprocess executor to make the code more clear and easy to follow.
2024-03-22 10:01:39 -07:00
Aiden Grossman
718fbbef5f
[llvm-exegesis] Kill process that recieve a signal (#86069)
Before this patch, llvm-exegesis would leave processes lingering that
experienced signals like segmentation faults. They would up in a
signal-delivery-stop state under the ptrace and never exit. This does
not cause problems (or at least many) in llvm-exegesis as they are
cleaned up after the main process exits, which usually happens quickly.
However, in downstream use, when many blocks are being executed (many of
which run into signals) within a single process, these processes stay
around and can easily exhaust the process limit on some systems.

This patch cleans them up by sending SIGKILL after information about the
signal that was sent has been gathered.
2024-03-21 18:14:18 -07:00
Aiden Grossman
1fe9c417a0 Revert "Reland "[llvm-exegesis] Add thread IDs to subprocess memory names (#84451)""
This reverts commit 8003f553a01a9a2a7eb09fe07e88f1ba9ee7d3a7.

This (and/or a related commit) was causing build failures on one of the
buildbots that needs more investigation. More information is available
at https://lab.llvm.org/buildbot/#/builders/178/builds/7015.
2024-03-13 00:49:23 -07:00
Aiden Grossman
5a4e2210bd Revert "[llvm-exegesis] Use LLVM Support to get thread ID"
This reverts commit 1c3b15e9f5bc671e40bcf5d3475f5425466754ce.

This (and/or) a related patch was causing build failures on one of the
buildbots. More information is available at
https://lab.llvm.org/buildbot/#/builders/178/builds/7015.
2024-03-13 00:48:46 -07:00
Aiden Grossman
1c3b15e9f5 [llvm-exegesis] Use LLVM Support to get thread ID
This patch switches from manually using the Linux syscall to get the
current thread ID to using the relevant LLVM Support libraries that
abstract over the low level system details.
2024-03-12 16:55:01 -07:00
Aiden Grossman
8003f553a0 Reland "[llvm-exegesis] Add thread IDs to subprocess memory names (#84451)"
This reverts commit aefad27096bba513f06162fac2763089578f3de4.

This relands commit 6bbe8a296ee91754d423c59c35727eaa624f7140.

This patch was casuing build failures on non-Linux platforms due to the
default implementations for the functions not being updated. This ended
up causing out-of-line definition errors. Fixed for the relanding.
2024-03-12 16:35:05 -07:00
Florian Hahn
aefad27096
Revert "[llvm-exegesis] Add thread IDs to subprocess memory names (#84451)"
This reverts commit 6bbe8a296ee91754d423c59c35727eaa624f7140.

This breaks building LLVM on macOS, failing with

    llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp:146:33: error: out-of-line definition of 'setupAuxiliaryMemoryInSubprocess' does not match any declaration in 'llvm::exegesis::SubprocessMemory'
    Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
2024-03-12 08:52:29 +00:00
Aiden Grossman
6bbe8a296e
[llvm-exegesis] Add thread IDs to subprocess memory names (#84451)
This patch adds the thread ID to the subprocess memory shared memory
names. This avoids conflicts for downstream consumers that might want to
consume llvm-exegesis across multiple threads, which would otherwise run
into conflicts due to the same PID running multiple instances.
2024-03-12 01:24:21 -07:00
Aiden Grossman
db8b76dbb0 [NFC][llvm-exegesis] Clean up BenchmarkRunner comments
There were a couple things in the comments of BenchmarkRunner.cpp (and
maybe other files, I can't really remember) that were bugging me. This
patch fixes a couple of minor issues specifically in BenchmarkRunner
like typos and makes a couple instances more clear.
2024-02-17 16:13:29 -08:00
Aiden Grossman
415bf200a7
[llvm-exegesis] Replace --num-repetitions with --min-instructions (#77153)
This patch replaces --num-repetitions with --min-instructions to make it
more clear that the value refers to the minimum number of instructions
in the final assembled snippet rather than the number of repetitions of
the snippet. This patch also refactors some llvm-exegesis internal
variable names to reflect the name change.

Fixes #76890.
2024-02-01 01:58:27 -08:00
Aiden Grossman
faf675ce34
[llvm-exegesis] Remove llvm prefix where unnecessary (#79802)
This patch removes the llvm:: prefix within llvm-exegesis where it is
not necessary. This is most occurrences of the prefix within exegesis as
exegesis is within the llvm namespace. This patch makes things more
consistent as the vast majority of the code did not use the llvm::
prefix for anything.
2024-01-29 11:40:06 -08:00
Aiden Grossman
f670112a59
[llvm-exegesis] Add support for validation counters (#76653)
This patch adds support for validation counters. Validation counters can
be used to measure events that occur during snippet execution like cache
misses to ensure that certain assumed invariants about the benchmark
actually hold. Validation counters are setup within a perf event group,
so are turned on and off at exactly the same time as the "group leader"
counter that measures the desired value.
2024-01-19 02:00:33 -08:00
Kazu Hirata
c03c4e2b14 [tools] Use SmallString::operator std::string (NFC) 2024-01-19 00:19:31 -08:00
Aiden Grossman
16b2387982
[llvm-exegesis] Fix snippet value scaling (#77226)
Currently, BenchmarkRunner scales the per snippet counters by
multiplying the raw counter values by the number of instructions (casted
to a double) divided by the minimum number of instructions. This is
incorrect for the loop repetition mode for snippets that don't fit a
whole number of times into the minimum instruction count. For example,
with 3 instructions in the snippet and the minimum number of
instructions set to 4, the loop repetitor will execute a total of six
instructions, but BenchmarkRunner will scale the raw count by 3/4
instead of 3/6=1/2. This will also be incorrect for the duplicate
snippet repetitor after #77224.

This patch fixes this behavior by dividing the raw count by the ceiling
of the number of repetitions divided by the instruction count.
2024-01-16 11:49:17 -08:00
Aiden Grossman
e366e04d5a
[llvm-exegesis] Refactor Counter to CounterGroup (#77887)
This refactoring gets things ready for validation counters where the
plan is to reuse the existing Counter infrastructure to contain event
groups that consist of a single event that is being measured along with
validation counters.
2024-01-16 01:24:22 -08:00
Aiden Grossman
6f4cc1310b
[llvm-exegesis] Remove unused Counter::read method (#76651)
This method was simply a wrapper around readOrError. All users within
the llvm-exegesis code base should have been processing an actual error
rather than using the wrapper. This patch removes the wrapper and
rewrites the users (just 1) to use the readOrError method.
2024-01-05 13:31:48 -08:00
Aiden Grossman
a25b66217f [NFC][llvm-exegesis] Remove redundant register initial values argument
This patch removes the redundant RegisterInitialValues parameter from
assembleToStream and friends as it is included within the BenchmarkKey
struct that is also passed to all the functions that need this
information.
2024-01-03 15:25:21 -08:00
Aiden Grossman
3f3c5e5583
[NFC][llvm-exegesis] Refactor InstrBenchmark to BenchmarkResult (#76388)
This patch refactors InstrBenchmark to BenchmarkResult. Most of the
renaming away from things prefixed with Instr was performed in a
previous commit, but this specific instance was missed.
2023-12-26 00:43:16 -08:00
Aiden Grossman
ceb196d990
[llvm-exegesis] Validate that address annotations are aligned (#75554)
This patch adds in validation at two different levels that address
annotations are page aligned. This is necessary as otherwise the mmap
calls will fail as MAP_FIXED/MAP_FIXED_NOREPLACE require page aligned
addresses. This happens silently in the subprocess. This patch adds
validation at snippet parsing time to give feedback to the user and also
adds asserts at code generation/address usage time to ensure that other
users of the Exegesis APIs conform to the same requirements.
2023-12-15 09:45:30 -08:00
Aiden Grossman
3194928c3c
[llvm-exegesis] Refactor MMAP platform-specific preprocessor directives (#75422)
This patch refactors the MMAP platform-specific preprocessor directives
in llvm-exegesis to a single file instead of having duplicate code split
across multiple files. These originally got introduced to get buildbots
green again due to platform specific failures.
2023-12-14 12:07:46 -08:00
Abhina Sree
ec41462d7a
[SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (#75339)
This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files.
2023-12-13 13:13:53 -05:00
Aiden Grossman
5830e8e745
[llvm-exegesis] Use explicit error classes for different snippet crashes (#74210)
This patch switches to using explicit snippet crashes that contain more
information about the specific type of error (like the address for a
segmentation fault) that occurred. All these new error classes inherit
from SnippetExecutionFailure to allow for easily grabbing all of them in
addition to filtering for specific types using the standard LLVM error
primitives.
2023-12-11 23:15:56 -08:00
Clement Courbet
9017229ecd
[llvm-exegesis]Allow clients to do their own snippet running error ha… (#74711)
…ndling.

Returns an error *and* a benchmark rather than an error *or* a
benchmark. This allows users to have custom error handling while still
being able to inspect the benchmark.

Apart from this small API change, this is an NFC.

This is an alternative to #74211.
2023-12-08 13:01:01 +01:00
Aiden Grossman
5058d738ba [llvm-exegesis] Add MAP_FIXED_NOREPLACE definiton
MAP_FIXED_NOREPLACE doesn't exist on older kernels, so we need to define
it to be MAP_FIXED.
2023-12-07 00:47:04 -08:00
Aiden Grossman
f1963fde9f Reland "[llvm-exegesis] Add in snippet address annotation (#74218)"
This reverts commit 30d700117b772d94d8474ec56bd6f9cc423fc613.

This relands commit 3ab41f912a6c219a93b87c257139822ea07c8863.

When I was updating the patch to use llvm::to_integer, I only ran the
lit tests and didn't run the unit tests, one of which started to fail.
This patch fixes the broken unit test.
2023-12-07 00:20:24 -08:00
Aiden Grossman
30d700117b Revert "[llvm-exegesis] Add in snippet address annotation (#74218)"
This reverts commit 3ab41f912a6c219a93b87c257139822ea07c8863.

Unit tests break after recent changes. Will investigate/reland.
2023-12-06 11:25:03 -08:00
Aiden Grossman
3ab41f912a
[llvm-exegesis] Add in snippet address annotation (#74218) 2023-12-06 11:05:33 -08:00
Kazu Hirata
c630f95f33 [llvm-exegesis] Remove unnecessary includes (NFC)
Identified with clangd.
2023-12-05 23:28:09 -08:00
Kazu Hirata
06c5c27e44 [llvm-exegesis] Stop including array (NFC)
Identified with clangd.
2023-12-05 20:58:17 -08:00