From: Snehasish Kumar Date: Tue, 7 Mar 2023 23:38:51 +0000 (+0000) Subject: [memprof] Simplify initialized flags. X-Git-Tag: upstream/17.0.6~15490 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79ebb6385b3afe2b78a6923b3bbddadb791b7840;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp index c21e4e8..6e3fa7f 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 bba465e..990e62c 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 d30b803..5e2e7bc 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() {