Commit Graph

14 Commits

Author SHA1 Message Date
David Spickett 915a8bb5ee Revert "[compiler-rt][Profile] Disable test on Arm/AArch64 Linux"
This reverts commit 8b86f8a325.

The inconsistent behaviour has been fixed with
5e50d3073a.
2021-09-06 08:45:06 +00:00
David Spickett 5e50d3073a [compiler-rt][Profile] Wait for child threads in set-file-object test
We've been seeing this test return 31 instead of 32 for the "functions"
line in this test on our AArch64 bots.

One possible cause is some of the children not finishing in time
before the llvm-profdata commands are run, if the machine is heavily loaded.

Wait for all the children to finish before exiting the parent.

Reviewed By: zequanwu

Differential Revision: https://reviews.llvm.org/D109222
2021-09-03 11:48:50 -07:00
David Spickett 8b86f8a325 [compiler-rt][Profile] Disable test on Arm/AArch64 Linux
While a fix for flaky results is being reviewed.
2021-09-03 12:58:09 +00:00
Zequan Wu 1b05245119 [Profile] Support __llvm_profile_set_file_object in continuous mode.
Replace D107203, because __llvm_profile_set_file_object is usually used when the
process doesn't have permission to open/create file. That patch trying to copy
from old profile to new profile contradicts with the usage.

Differential Revision: https://reviews.llvm.org/D108242
2021-08-27 13:06:46 -07:00
Vedant Kumar 7014a10161 [profile] Skip mmap() if there are no counters
If there are no counters, an mmap() of the counters section would fail
due to the size argument being too small (EINVAL).

rdar://78175925

Differential Revision: https://reviews.llvm.org/D102735
2021-05-19 09:31:40 -07:00
Zequan Wu 9783e20988 Revert "Revert "[Coverage] Emit gap region between statements if first statements contains terminate statements.""
Reland with update on test case ContinuousSyncmode/basic.c.

This reverts commit fe5c2c3ca6.
2021-03-04 11:52:43 -08:00
Nico Weber fe5c2c3ca6 Revert "[Coverage] Emit gap region between statements if first statements contains terminate statements."
This reverts commit 2d7374a0c6.
Breaks ContinuousSyncMode/basic.c in check-profile on macOS.
2021-03-04 08:53:30 -05:00
Zequan Wu 2d7374a0c6 [Coverage] Emit gap region between statements if first statements contains terminate statements.
Differential Revision: https://reviews.llvm.org/D97101
2021-03-03 11:25:49 -08:00
Vedant Kumar a7d4826101 [profile] Fix buffer overrun when parsing %c in filename string
Fix a buffer overrun that can occur when parsing '%c' at the end of a
filename pattern string.

rdar://74571261

Reviewed By: kastiglione

Differential Revision: https://reviews.llvm.org/D97239
2021-02-24 14:49:45 -08:00
Vedant Kumar a77a739abc [profile] Suppress spurious 'expected profile to require unlock' warning
In %c (continuous sync) mode, avoid attempting to unlock an
already-unlocked profile.

The profile is only locked when profile merging is enabled.
2020-10-26 16:25:08 -07:00
Vedant Kumar 47481cbffb [test] Deflake test/profile/ContinuousSyncMode/online-merging.c
This test spawns 32 child processes which race to update counters on
shared memory pages. On some Apple-internal machines, two processes race
to perform an update in approximately 0.5% of the test runs, leading to
dropped counter updates. Deflake the test by using atomic increments.

Tested with:

```
$ for I in $(seq 1 1000); do echo ":: Test run $I..."; ./bin/llvm-lit projects/compiler-rt/test/profile/Profile-x86_64h/ContinuousSyncMode/online-merging.c -av || break; done
```

rdar://64956774
2020-07-02 13:31:56 -07:00
Petr Hosek d3db13af7e [profile] Support counter relocation at runtime
This is an alternative to the continous mode that was implemented in
D68351. This mode relies on padding and the ability to mmap a file over
the existing mapping which is generally only available on POSIX systems
and isn't suitable for other platforms.

This change instead introduces the ability to relocate counters at
runtime using a level of indirection. On every counter access, we add a
bias to the counter address. This bias is stored in a symbol that's
provided by the profile runtime and is initially set to zero, meaning no
relocation. The runtime can mmap the profile into memory at abitrary
location, and set bias to the offset between the original and the new
counter location, at which point every subsequent counter access will be
to the new location, which allows updating profile directly akin to the
continous mode.

The advantage of this implementation is that doesn't require any special
OS support. The disadvantage is the extra overhead due to additional
instructions required for each counter access (overhead both in terms of
binary size and performance) plus duplication of counters (i.e. one copy
in the binary itself and another copy that's mmapped).

Differential Revision: https://reviews.llvm.org/D69740
2020-01-17 15:02:23 -08:00
Vedant Kumar 2492b5a125 [profile] Support online merging with continuous sync mode
Make it possible to use online profile merging ("%m" mode) with
continuous sync ("%c" mode).

To implement this, the merged profile is locked in the runtime
initialization step and either a) filled out for the first time or b)
checked for compatibility. Then, the profile can simply be mmap()'d with
MAP_SHARED set. With the mmap() in place, counter updates from every
process which uses an image are mapped onto the same set of physical
pages assigned by the filesystem cache. After the mmap() is set up, the
profile is unlocked.

Differential Revision: https://reviews.llvm.org/D69586
2019-11-18 12:56:58 -08:00
Vedant Kumar d889d1efef [profile] Add a mode to continuously sync counter updates to a file
Add support for continuously syncing profile counter updates to a file.

The motivation for this is that programs do not always exit cleanly. On
iOS, for example, programs are usually killed via a signal from the OS.
Running atexit() handlers after catching a signal is unreliable, so some
method for progressively writing out profile data is necessary.

The approach taken here is to mmap() the `__llvm_prf_cnts` section onto
a raw profile. To do this, the linker must page-align the counter and
data sections, and the runtime must ensure that counters are mapped to a
page-aligned offset within a raw profile.

Continuous mode is (for the moment) incompatible with the online merging
mode. This limitation is lifted in https://reviews.llvm.org/D69586.

Continuous mode is also (for the moment) incompatible with value
profiling, as I'm not sure whether there is interest in this and the
implementation may be tricky.

As I have not been able to test extensively on non-Darwin platforms,
only Darwin support is included for the moment. However, continuous mode
may "just work" without modification on Linux and some UNIX-likes. AIUI
the default value for the GNU linker's `--section-alignment` flag is set
to the page size on many systems. This appears to be true for LLD as
well, as its `no_nmagic` option is on by default. Continuous mode will
not "just work" on Fuchsia or Windows, as it's not possible to mmap() a
section on these platforms. There is a proposal to add a layer of
indirection to the profile instrumentation to support these platforms.

rdar://54210980

Differential Revision: https://reviews.llvm.org/D68351
2019-10-31 16:04:09 -07:00