[compiler-rt] 79ebb63 - [memprof] Simplify initialized flags.
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 8 10:02:28 PST 2023
Author: Snehasish Kumar
Date: 2023-03-08T18:02:23Z
New Revision: 79ebb6385b3afe2b78a6923b3bbddadb791b7840
URL: https://github.com/llvm/llvm-project/commit/79ebb6385b3afe2b78a6923b3bbddadb791b7840
DIFF: https://github.com/llvm/llvm-project/commit/79ebb6385b3afe2b78a6923b3bbddadb791b7840.diff
LOG: [memprof] Simplify initialized flags.
As discussed in D145428, the memprof_init_is_running check can be moved
to the end of the initialization routine to avoid intercepting
allocations during initialization. Also, the memprof_init_done flag can
be removed and replaced with memprof_inited. Finally, memprof_inited can
also be moved to the end of the method.
Tested on the existing check-memprof tests; memprof profile collection
succeeded on a large internal workload.
Reviewed By: tejohnson
Differential Revision: https://reviews.llvm.org/D145528
Added:
Modified:
compiler-rt/lib/memprof/memprof_allocator.cpp
compiler-rt/lib/memprof/memprof_internal.h
compiler-rt/lib/memprof/memprof_rtl.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp
index c21e4e8a5694..6e3fa7f2dc7b 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.cpp
+++ b/compiler-rt/lib/memprof/memprof_allocator.cpp
@@ -75,7 +75,7 @@ static int GetCpuId(void) {
// _memprof_preinit is called via the preinit_array, which subsequently calls
// malloc. Since this is before _dl_init calls VDSO_SETUP, sched_getcpu
// will seg fault as the address of __vdso_getcpu will be null.
- if (!memprof_init_done)
+ if (!memprof_inited)
return -1;
return sched_getcpu();
}
@@ -445,8 +445,7 @@ struct Allocator {
u64 user_requested_size =
atomic_exchange(&m->user_requested_size, 0, memory_order_acquire);
- if (memprof_inited && memprof_init_done &&
- atomic_load_relaxed(&constructed) &&
+ if (memprof_inited && atomic_load_relaxed(&constructed) &&
!atomic_load_relaxed(&destructing)) {
u64 c = GetShadowCount(p, user_requested_size);
long curtime = GetTimestamp();
diff --git a/compiler-rt/lib/memprof/memprof_internal.h b/compiler-rt/lib/memprof/memprof_internal.h
index bba465e60d82..990e62ce1a55 100644
--- a/compiler-rt/lib/memprof/memprof_internal.h
+++ b/compiler-rt/lib/memprof/memprof_internal.h
@@ -76,7 +76,6 @@ void *MemprofDlSymNext(const char *sym);
extern int memprof_inited;
extern int memprof_timestamp_inited;
-extern int memprof_init_done;
// Used to avoid infinite recursion in __memprof_init().
extern bool memprof_init_is_running;
extern void (*death_callback)(void);
diff --git a/compiler-rt/lib/memprof/memprof_rtl.cpp b/compiler-rt/lib/memprof/memprof_rtl.cpp
index d30b80304f6b..5e2e7bc2be3f 100644
--- a/compiler-rt/lib/memprof/memprof_rtl.cpp
+++ b/compiler-rt/lib/memprof/memprof_rtl.cpp
@@ -65,7 +65,6 @@ static void CheckUnwind() {
// -------------------------- Globals --------------------- {{{1
int memprof_inited;
-int memprof_init_done;
bool memprof_init_is_running;
int memprof_timestamp_inited;
long memprof_init_timestamp_s;
@@ -195,11 +194,6 @@ static void MemprofInitInternal() {
InitializeAllocator();
- // On Linux MemprofThread::ThreadStart() calls malloc() that's why
- // memprof_inited should be set to 1 prior to initializing the threads.
- memprof_inited = 1;
- memprof_init_is_running = false;
-
if (flags()->atexit)
Atexit(memprof_atexit);
@@ -218,7 +212,8 @@ static void MemprofInitInternal() {
VReport(1, "MemProfiler Init done\n");
- memprof_init_done = 1;
+ memprof_init_is_running = false;
+ memprof_inited = 1;
}
void MemprofInitTime() {
More information about the llvm-commits
mailing list