Skip to content

Commit 02c3724

Browse files
committed
[BOLT][Instrumentation] Don't share counters when using append-pid
The point of append-pid option is to record separate profiles for separate forks, which is impossible when counters are the same for every process. It leads to a sum of all profiles in every file, plus GlobalWriteProfileMutex located in a shared memory prevents some processes from dumping their data at all. Reviewed By: rafauler, Amir Differential Revision: https://reviews.llvm.org/D153771
1 parent 8f7c53e commit 02c3724

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

bolt/runtime/instr.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,25 +1541,29 @@ extern "C" void __bolt_instr_indirect_tailcall();
15411541

15421542
/// Initialization code
15431543
extern "C" void __attribute((force_align_arg_pointer)) __bolt_instr_setup() {
1544+
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
1545+
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
1546+
15441547
const uint64_t CountersStart =
15451548
reinterpret_cast<uint64_t>(&__bolt_instr_locations[0]);
15461549
const uint64_t CountersEnd = alignTo(
15471550
reinterpret_cast<uint64_t>(&__bolt_instr_locations[__bolt_num_counters]),
15481551
0x1000);
15491552
DEBUG(reportNumber("replace mmap start: ", CountersStart, 16));
15501553
DEBUG(reportNumber("replace mmap stop: ", CountersEnd, 16));
1551-
assert (CountersEnd > CountersStart, "no counters");
1552-
// Maps our counters to be shared instead of private, so we keep counting for
1553-
// forked processes
1554+
assert(CountersEnd > CountersStart, "no counters");
1555+
1556+
const bool Shared = !__bolt_instr_use_pid;
1557+
const uint64_t MapPrivateOrShared = Shared ? MAP_SHARED : MAP_PRIVATE;
1558+
15541559
void *Ret =
15551560
__mmap(CountersStart, CountersEnd - CountersStart, PROT_READ | PROT_WRITE,
1556-
MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED, -1, 0);
1561+
MAP_ANONYMOUS | MapPrivateOrShared | MAP_FIXED, -1, 0);
15571562
assert(Ret != MAP_FAILED, "__bolt_instr_setup: Failed to mmap counters!");
1558-
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
1559-
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
1563+
15601564
// Conservatively reserve 100MiB shared pages
15611565
GlobalAlloc.setMaxSize(0x6400000);
1562-
GlobalAlloc.setShared(true);
1566+
GlobalAlloc.setShared(Shared);
15631567
GlobalWriteProfileMutex = new (GlobalAlloc, 0) Mutex();
15641568
if (__bolt_instr_num_ind_calls > 0)
15651569
GlobalIndCallCounters =

0 commit comments

Comments
 (0)