diff options
author | Rong Xu <xur@google.com> | 2017-02-16 19:21:31 +0000 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2017-02-16 19:21:31 +0000 |
commit | aa1e41788966f989fd5b9d315b14de764cb498d3 (patch) | |
tree | e1d5cfd5187c4581a60e8312fff7eb78cb87cf58 /test/profile | |
parent | cc987494aa3c360b05802bdb8e836c642c4fd35c (diff) |
[PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-write
Summary:
We found a nondeterministic behavior when doing online profile merging
for multi-process applications. The application forks a sub-process and
sub-process sets to get SIGKILL when the parent process exits,
The first process gets the lock, and dumps the profile. The second one
will mmap the file, do the merge and write out the file. Note that before
the merged write, we truncate the profile.
Depending on the timing, the child process might be terminated
abnormally when the parent exits first. If this happens:
(1) before the truncation, we will get the profile for the main process
(2) after the truncation, and before write-out the profile, we will get
0 size profile.
(3) after the merged write, we get merged profile.
This patch temporarily suspend the SIGKILL for PR_SET_PDEATHSIG
before profile-write and restore it after the write.
This patch only applies to Linux system.
Reviewers: davidxl
Reviewed By: davidxl
Subscribers: xur, llvm-commits
Differential Revision: https://reviews.llvm.org/D29954
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295364 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/profile')
-rw-r--r-- | test/profile/Linux/prctl.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/profile/Linux/prctl.c b/test/profile/Linux/prctl.c new file mode 100644 index 000000000..43baf6543 --- /dev/null +++ b/test/profile/Linux/prctl.c @@ -0,0 +1,36 @@ +// RUN: %clang_pgogen -O2 -o %t %s +// RUN: rm -rf default_*.profraw +// RUN: %run %t && sleep 1 +// RUN: llvm-profdata show default_*.profraw 2>&1 | FileCheck %s + +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/prctl.h> +#include <unistd.h> + +#define FAKE_COUNT_SZ 2000000 +/* fake counts to increse the profile size. */ +unsigned long long __attribute__((section("__llvm_prf_cnts"))) +counts[FAKE_COUNT_SZ]; + +int main(int argc, char **argv) { + pid_t pid = fork(); + if (pid == 0) { + int i; + int sum = 0; + /* child process: sleep 500us and get to runtime before the + * main process exits. */ + prctl(PR_SET_PDEATHSIG, SIGKILL); + usleep(500); + for (i = 0; i < 5000; ++i) + sum += i * i * i; + printf("child process (%d): sum=%d\n", getpid(), sum); + } else if (pid > 0) { + /* parent process: sleep 100us to get into profile runtime first. */ + usleep(100); + } + return 0; +} + +// CHECK-NOT: Empty raw profile file |