mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-03 16:03:21 +00:00
Resubmit r295469 [PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-write
And also r295364 [PGO] remove unintended debug trace. NFC I removed the test case: it's hard to write synchronized test b/w processes in this framework. I will revisit the test-case later. llvm-svn: 298113
This commit is contained in:
parent
848582181e
commit
cf1f6fb1b2
@ -530,6 +530,7 @@ int __llvm_profile_write_file(void) {
|
|||||||
int rc, Length;
|
int rc, Length;
|
||||||
const char *Filename;
|
const char *Filename;
|
||||||
char *FilenameBuf;
|
char *FilenameBuf;
|
||||||
|
int PDeathSig = 0;
|
||||||
|
|
||||||
if (lprofProfileDumped()) {
|
if (lprofProfileDumped()) {
|
||||||
PROF_NOTE("Profile data not written to file: %s.\n",
|
PROF_NOTE("Profile data not written to file: %s.\n",
|
||||||
@ -556,10 +557,18 @@ int __llvm_profile_write_file(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temporarily suspend getting SIGKILL when the parent exits.
|
||||||
|
PDeathSig = lprofSuspendSigKill();
|
||||||
|
|
||||||
/* Write profile data to the file. */
|
/* Write profile data to the file. */
|
||||||
rc = writeFile(Filename);
|
rc = writeFile(Filename);
|
||||||
if (rc)
|
if (rc)
|
||||||
PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno));
|
PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno));
|
||||||
|
|
||||||
|
// Restore SIGKILL.
|
||||||
|
if (PDeathSig == 1)
|
||||||
|
lprofRestoreSigKill();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
COMPILER_RT_VISIBILITY
|
COMPILER_RT_VISIBILITY
|
||||||
void __llvm_profile_recursive_mkdir(char *path) {
|
void __llvm_profile_recursive_mkdir(char *path) {
|
||||||
int i;
|
int i;
|
||||||
@ -219,3 +224,21 @@ COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
|
|||||||
#endif
|
#endif
|
||||||
return Sep;
|
return Sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COMPILER_RT_VISIBILITY int lprofSuspendSigKill() {
|
||||||
|
#if defined(__linux__)
|
||||||
|
int PDeachSig = 0;
|
||||||
|
/* Temporarily suspend getting SIGKILL upon exit of the parent process. */
|
||||||
|
if (prctl(PR_GET_PDEATHSIG, &PDeachSig) == 0 && PDeachSig == SIGKILL)
|
||||||
|
prctl(PR_SET_PDEATHSIG, 0);
|
||||||
|
return (PDeachSig == SIGKILL);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
COMPILER_RT_VISIBILITY void lprofRestoreSigKill() {
|
||||||
|
#if defined(__linux__)
|
||||||
|
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -51,4 +51,12 @@ int lprofGetHostName(char *Name, int Len);
|
|||||||
unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
|
unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
|
||||||
void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
|
void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
|
||||||
|
|
||||||
|
/* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.
|
||||||
|
* Other return values mean no restore is needed.
|
||||||
|
*/
|
||||||
|
int lprofSuspendSigKill();
|
||||||
|
|
||||||
|
/* Restore previously suspended SIGKILL. */
|
||||||
|
void lprofRestoreSigKill();
|
||||||
|
|
||||||
#endif /* PROFILE_INSTRPROFILINGUTIL_H */
|
#endif /* PROFILE_INSTRPROFILINGUTIL_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user