From b8a169119bbf8bffcd06fcf68e5634defbe217f8 Mon Sep 17 00:00:00 2001 From: liutiexing <74819124+liutiexing@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:13:03 +0800 Subject: [PATCH] Workqueue threadnames (#40035) * add align for WorkQueue * add spinlock * merge develop * merge * Add EventsWaiter * Revert "Add EventsWaiter" This reverts commit e206173aa9be7401b83a53581627bfaf557c8fb2. * Set thread name for WorkQueue * Add thread names * fix ut Co-authored-by: liutiexing --- .../new_executor/workqueue/nonblocking_threadpool.h | 2 +- paddle/fluid/platform/init.cc | 3 +++ paddle/fluid/platform/os_info_test.cc | 3 +-- paddle/fluid/platform/profiler/host_event_recorder.h | 8 ++++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/new_executor/workqueue/nonblocking_threadpool.h b/paddle/fluid/framework/new_executor/workqueue/nonblocking_threadpool.h index 7b3916bafc9..bc65231abe7 100644 --- a/paddle/fluid/framework/new_executor/workqueue/nonblocking_threadpool.h +++ b/paddle/fluid/framework/new_executor/workqueue/nonblocking_threadpool.h @@ -409,7 +409,7 @@ class ThreadPoolTempl { return false; } platform::RecordEvent("SleepWaitForWork", - platform::TracerEventType::UserDefined, 2); + platform::TracerEventType::UserDefined, 10); ec_.CommitWait(waiter); blocked_--; return true; diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index 71fd0d20143..372bfbce2ac 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -28,6 +28,7 @@ limitations under the License. */ #include "paddle/fluid/platform/device/device_wrapper.h" #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/init.h" +#include "paddle/fluid/platform/os_info.h" #include "paddle/fluid/platform/place.h" #ifdef PADDLE_WITH_XPU @@ -161,6 +162,8 @@ void LoadCustomDevice(const std::string &library_dir) { #endif void InitDevices() { + // set name at the entry point of Paddle + platform::SetCurrentThreadName("MainThread"); // CUPTI attribute should be set before any CUDA context is created (see CUPTI // documentation about CUpti_ActivityAttribute). #ifdef PADDLE_WITH_CUDA diff --git a/paddle/fluid/platform/os_info_test.cc b/paddle/fluid/platform/os_info_test.cc index b309bb98512..b3311f1d19e 100644 --- a/paddle/fluid/platform/os_info_test.cc +++ b/paddle/fluid/platform/os_info_test.cc @@ -30,8 +30,7 @@ TEST(ThreadInfo, TestThreadNameUtils) { using paddle::platform::GetCurrentThreadName; using paddle::platform::SetCurrentThreadName; using paddle::platform::GetAllThreadNames; - EXPECT_EQ("unset", GetCurrentThreadName()); - EXPECT_TRUE(SetCurrentThreadName("MainThread")); + SetCurrentThreadName("MainThread"); EXPECT_FALSE(SetCurrentThreadName("MainThread")); auto names = GetAllThreadNames(); EXPECT_TRUE(names.find(GetCurrentThreadStdId()) != names.end()); diff --git a/paddle/fluid/platform/profiler/host_event_recorder.h b/paddle/fluid/platform/profiler/host_event_recorder.h index 49f93625275..afd41352465 100644 --- a/paddle/fluid/platform/profiler/host_event_recorder.h +++ b/paddle/fluid/platform/profiler/host_event_recorder.h @@ -189,7 +189,10 @@ struct ThreadEventSection { class ThreadEventRecorder { public: - ThreadEventRecorder() { thread_id_ = GetCurrentThreadSysId(); } + ThreadEventRecorder() { + thread_id_ = GetCurrentThreadSysId(); + thread_name_ = GetCurrentThreadName(); + } DISABLE_COPY_AND_ASSIGN(ThreadEventRecorder); @@ -202,7 +205,7 @@ class ThreadEventRecorder { ThreadEventSection GatherEvents() { ThreadEventSection thr_sec; - thr_sec.thread_name = GetCurrentThreadName(); + thr_sec.thread_name = thread_name_; thr_sec.thread_id = thread_id_; thr_sec.events = std::move(base_evt_cntr_.Reduce()); return thr_sec; @@ -210,6 +213,7 @@ class ThreadEventRecorder { private: uint64_t thread_id_; + std::string thread_name_; EventContainer base_evt_cntr_; }; -- GitLab